Java/android: combining two libraries, android file layout? - java

I'm using two libraries in an android app I'm trying to make. New to android. The app is for connecting to serial devices and controlling their console via a terminal.
One library is for setting up a serial connection, setting baud rate etc and can also write read/data over serial.. The other is for creating a terminal session. I have no problem running these libraries to get simple separate examples up and running. Eg, with the first library I can set up a serial connection with a router and send/receive data via textboxes which looks like this:
https://lh5.ggpht.com/R4CAJXY9ZPDVsgt8jUZg5hc-v81aa70sctiegIGDjzv2lyvuG6OZyYas_4I-h_es-4Aq
With the second library I am able to set up local terminal on a tablet and look at the directories etc. My problem lies in incorporating both of these together to have a terminal that is connected to a serial device and with the layout/passing of data.
In the terminal library I need to supply an InputStream and OutputStream to provide input and output to the terminal. So I have to call setTermIn(java.io.InputStream) and setTermOut(java.io.OutputStream) to connect the input and output streams to the emulator.
In the serial library however there are two methods for sending and receiving and these deal with arrays of bytes.
sendData(byte[] data) for sending data and a dataListener for receiving data. I have to implement this and code the method onDataReceived(int id, byte[] data) with id being the name of the device.
So my question is, how do I hook these up? Do I create java.io.InputStream/OutputStream implementations on top of sendData and OnDataReceived, just convert the arrays to streams and call the setTermIn/Out methods?
For OnDataReceived I suppose all I do is receive the byte[] data and convert it to a stream inside the method and send this to the terminalActivity?
but what about sendData, I am not implementing this, I just send an array of bytes, how do I send it as a stream instead to setTermIn?
I am also very confused about having these things happening in different activities and how that works. Because I have the serial stuff happening in one activity, so I hit connect, it reads the relevant baud rate etc and connects to the serial device, then a terminal is opened in a new terminalActivity which is currently connected to nothing, just looks like a blank terminal. I'm not sure how everything should be laid out. Like if I hit the enter key in a terminal, should the implementation for sending data over serial not be in that same activity, not the one I am initially in where I am connecting to a serial device? But to know if I am connected to a serial device in the first place I need to send/receive data...should there be implementations of these methods in both activities?! Or maybe I should simplify it and add the connection options and the terminal to the same activity?
Should I be combining these both in one activity maybe?

Simplest way was to combine into one activity.

Related

Reading the List of Open Networks in Cytoscape

I am trying to get a CyNetwork[] containing all of the networks open in the Cytoscape network tab. My understanding is that I need a CyNetworkReader to call CyNetworkReader.getNetworks() and to get a CyNetworkReader I need a CyNetworkReaderManager. However, I don't know how to get a CyNetworkReaderManager, nor do I know the proper InputStream or input name to use CyNetworkReaderManager.getReader(). Any help would be much appreciated.
Close. Actually, you would need a CyNetworkReader to read in a new network from disk. If you want to get the list of currently loaded networks, you would need to use the CyNetworkManager.getNetworkSet() method. To get a handle on the CyNetworkManager, you just need to get it from OSGi, so in your CyActivator, you would do something like:
CyNetworkManager cyNetworkManager = getService(CyNetworkManager.class);
That's it.
-- scooter

Is there a way to read Raw midi data in java?

Using javax.sound.midi i've managed to open my midi device up for outputting a .midi file in the past but the issue is i need to be able to pickup the midievent in it's raw form as in "3C40"/"903C40".
I'm able to find documentation on opening transmitters/receivers/sequencers but no code examples using these to output to say a string as the raw data from the midi device example of which is my yamaha ypt-240
digital keyboard.
Basically the reasoning behind why i want this raw data is to make some simple keybindings that would be triggered by said raw data from the midi device almost like a stream deck or using software that allows this.
The ShortMessage seems like the way to go but again can't find any code using it the way i would like to.
Every example is mididevice||file.midi -> synth||mididevice
I need a way to intercept that input java is getting from the device...
please help lol

Arduino-Processing Serial.send/Serial.get interaction

I'm trying to get my Arduino environment to send data to processing for a data visualization project.
I have managed to get the handshake working and can Serial.println(...) to print the data I need from Arduino to the Processing console. What I need now is to somehow use that data to alter a variable within Processing.
I know that neither of the methods that I mention in the title exist within the Serial class but I was hoping someone would know how to manage this functionality.
Thanks in advance!
I will assume that you are using the serialEvent method in processing. Example code:
String val = myPort.readStringUntil('\n');
Where myPort is the port that your android device is on.

Java - Client/Server Game Server Protocol. How to transmit commands?

I wrote a client-server pair for a 2D top down RPG game using sockets. However, I'm not clear on how exactly to transmit what the user wants to do.
Would I simply transmit a string like "Move north" and then use switch statements to decide what action to take or is there a more elegant solution?
If both client and server are java programs, then I would go with Command pattern where each command class does a specific job (like "Move north" in your case) and the command objects are exchanged between the client and the server.
We used to use this approach in our enterprise application (though not a game), while implementing multi-master replication and it was quite extendible without any if/else chains or switch statements anywhere, just receive command and call command.execute() without worrying about what the command is.
Yeah, basically. You can transmit strings, integers, whatever you want. You basically write the commands to the OutputStream you can get from the network socket on the client side, and read them in on the InputStream on the server side.
You can wrap the Input/OutputStream objects that come from a Socket with other stream types, such as ObjectOutputStream / ObjectInputStream, which allow you to read/write full objects and primitive types directly to the stream, the same way you would read/write data to a file on your file system using these same stream types.
Reading/writing to the network is really no different than read/writing from/to any other place, except that in networking you have to first establish a connection via a socket. Once you've got that socket and a proper stream type setup you just read/write data the same way you would anywhere else in your app.
Instead of raw parsing from stream, I think you should choose a Serialize library to do this.
I suggest Protocol Buffers or FlatBuffers.
Just transmit bytes array and they will parse to Object for you.

send real time voice using udp

hi every body could you please help me . I write java code for sending string msg between client and server using udp socket . but I want to to send real time voice so could you please give some notes to do it
I can point you a little of the way, you probably would want to use the Real-time Transport Protocol (RTP), which is more or less the standard for sending audio or video real time over the net. However the implementation is not straight forward, and you should use a helper library like jlibrtp for the implementation. There is also a RTP packetizer in Java Media Framework (JMF), but you don't wanna go there....
UDP has no quality of service guarantee, so when sending your packets of data you will need to add some sort of order number to your data to detremine how to put the data back together. For example you could send 3 datagram packets in order from the server, yet the client may get them in a different order (2,1,3). Or it may not get one of them at all, in which case you either want it resent (doubtful) or simply ignore it and move on at some timeout.
Look into using Real Time Protocol RFC3550 (http://en.wikipedia.org/wiki/Real-time_Transport_Protocol)
as the transport over UDP. RTCP as the control over TCP.

Categories