create android TCP client for rtl-tcp-android
I am trying to get the I/Q signals from an RTL-SDR dongle (RTL2832U R820T2) connected to an android phone (samsung galaxy 7, android 8.0) using an OTG cable. I am using the rtl-tcp-android driver. I have installed the driver by compiling and downloading from it's source code, and I can receive FM signals using the SDR Touch app (created by the driver's author) so as far as I understand the driver installation itself should be fine.
The github page for the driver explains how to get I/Q samples. It says once the driver has been properly invoked using an Android intent I should be able to just read interleaving I/Q data in uint_8 format if I can read the driver's output using a tcp client. I am trying to use this answer to make a tcp client. In the TcpClinet
class, inside the while (mRun)
loop, I have changed the line
mServerMessage = mBufferIn.readLine();
to
mServerMessage = Integer.toString( mBufferIn.read() );
Apparently that answer expects the tcp data to come in as lines of text, while the data I should be getting is continuous streams of uint_8 data. (in fact, if I don't make this change the program eventually crashes with an outofmemory exception at the readLine() function). I have also changed the values of SERVER_IP and SERVER_PORT member variables in TcpClient class with appropriate values for my device. Everything else related to the tcp client is same as in that answer.
In onProgressUpdate() I am getting random sequences of 0x7f and 0xfffd.
This is the onProgressUpdate() function I am using now in MainActivity:
@Override
protected void onProgressUpdate(String...values){
super.onProgressUpdate(values);
Log.d("MYLOG", "response " + values[0] + String.format( "(0x%x)", Integer.parseInt( values[0] ) );
}
Here is a section of my logcat:
2019-10-31 14:37:21.629 7232-7232/? D/MYLOG: response 65533(0xfffd)
2019-10-31 14:37:21.633 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.635 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.643 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.645 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.651 7232-7232/? D/MYLOG: response 65533(0xfffd)
2019-10-31 14:37:21.654 7232-7232/? D/MYLOG: response 65533(0xfffd)
2019-10-31 14:37:21.655 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.657 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.658 7232-7232/? D/MYLOG: response 65533(0xfffd)
2019-10-31 14:37:21.663 7232-7232/? D/MYLOG: response 65533(0xfffd)
2019-10-31 14:37:21.666 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.669 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.671 7232-7232/? D/MYLOG: response 65533(0xfffd)
2019-10-31 14:37:21.673 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.687 7232-7232/? D/MYLOG: response 127(0x7f)
2019-10-31 14:37:21.689 7232-7232/? D/MYLOG: response 65533(0xfffd)
I am pretty sure this is not correct, and I suspect there is something wrong with the tcp client code. How can I modify this code to properly talk with the rtl-tcp-android driver?
EDIT 1---
This is an edit to the code that I tried but didn't work (based on this answer to the same linked question):
mRun = true;
try {
InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
Log.e("TCP Client", "C: Connecting...");
Socket socket = new Socket(serverAddr, SERVER_PORT);
try {
mBufferOut = new PrintWriter(socket.getOutputStream());
Log.e("MYLOG", "TCP Client; C: Sent.");
mBufferIn = new DataInputStream(socket.getInputStream());
int charsRead = 0; short[] buffer = new short[1024]; //choose your buffer size if you need other than 1024
while (mRun) {
// charsRead = mBufferIn.read(buffer);
// int length = mBufferIn.readInt();
int length = 5;
// Log.d("MYLOG", String.format("length = %d", length ) );
if(length > 0){
byte[] message = new byte[length];
// mBufferIn.readFully(message, 0, message.length);
mBufferIn.read(message, 0, message.length);
// just display here instead of sending as a String to onProgressUpdate()
for(int i=0; i<length; i++){
Log.d("MYLOG", String.format("message[%d] = %d (0x%x)", i, message[i], message[i]) );
}
}
// mServerMessage = new String(buffer).substring(0, charsRead);
if (mServerMessage != null && mMessageListener != null) {
mMessageListener.messageReceived(mServerMessage);}
mServerMessage = null;
}
Log.e("MYLOG", "RESPONSE FROM SERVER; S: Received Message: '" + mServerMessage + "'");
mBufferIn
declaration has been changed to
private DataInputStream mBufferIn;
I would like to first make sure the correct data is coming in the TcpClient
class's run()
function itself, before the program does anything else. With this update I am getting 0x7f and 0x80 in the logcat.