Commit f90b91fe authored by Matej Frančeškin's avatar Matej Frančeškin

Taisync android - send telemetry messages to TCP port 8200 instead to UDP 14550.

parent 05e3abe8
...@@ -27,17 +27,19 @@ public class TaiSync ...@@ -27,17 +27,19 @@ public class TaiSync
private static final byte PROTOCOL_CHANNEL = 0x02; private static final byte PROTOCOL_CHANNEL = 0x02;
private static final byte PROTOCOL_DATA = 0x03; private static final byte PROTOCOL_DATA = 0x03;
private static final int TELEM_PORT = 14550; private static final int VIDEO_PORT = 5600;
private static final int VIDEO_PORT = 5000;
private static final int TAISYNC_VIDEO_PORT = 8000; private static final int TAISYNC_VIDEO_PORT = 8000;
private static final int TAISYNC_SETTINGS_PORT = 8200; private static final int TAISYNC_SETTINGS_PORT = 8200;
private static final int TAISYNC_TELEMETRY_PORT = 8400; private static final int TAISYNC_TELEMETRY_PORT = 8400;
private boolean running = false; private boolean running = false;
private DatagramSocket udpSocket = null; private DatagramSocket udpSocket = null;
private Socket tcpSocket = null; private Socket tcpSettingsSocket = null;
private InputStream tcpInStream = null; private InputStream settingsInStream = null;
private OutputStream tcpOutStream = null; private OutputStream settingsOutStream = null;
private Socket tcpTelemetrySocket = null;
private InputStream telemetryInStream = null;
private OutputStream telemetryOutStream = null;
private ParcelFileDescriptor mParcelFileDescriptor; private ParcelFileDescriptor mParcelFileDescriptor;
private FileInputStream mFileInputStream; private FileInputStream mFileInputStream;
private FileOutputStream mFileOutputStream; private FileOutputStream mFileOutputStream;
...@@ -79,9 +81,12 @@ public class TaiSync ...@@ -79,9 +81,12 @@ public class TaiSync
udpSocket = new DatagramSocket(); udpSocket = new DatagramSocket();
final InetAddress address = InetAddress.getByName("localhost"); final InetAddress address = InetAddress.getByName("localhost");
tcpSocket = new Socket(address, TAISYNC_SETTINGS_PORT); tcpTelemetrySocket = new Socket(address, TAISYNC_TELEMETRY_PORT);
tcpInStream = tcpSocket.getInputStream(); telemetryInStream = tcpTelemetrySocket.getInputStream();
tcpOutStream = tcpSocket.getOutputStream(); telemetryOutStream = tcpTelemetrySocket.getOutputStream();
tcpSettingsSocket = new Socket(address, TAISYNC_SETTINGS_PORT);
settingsInStream = tcpSettingsSocket.getInputStream();
settingsOutStream = tcpSettingsSocket.getOutputStream();
// Request connection packet // Request connection packet
sendTaiSyncMessage(PROTOCOL_REQUEST_CONNECTION, 0, null, 0); sendTaiSyncMessage(PROTOCOL_REQUEST_CONNECTION, 0, null, 0);
...@@ -131,10 +136,9 @@ public class TaiSync ...@@ -131,10 +136,9 @@ public class TaiSync
DatagramPacket packet = new DatagramPacket(sBytes, sBytes.length, address, VIDEO_PORT); DatagramPacket packet = new DatagramPacket(sBytes, sBytes.length, address, VIDEO_PORT);
udpSocket.send(packet); udpSocket.send(packet);
} else if (dPort == TAISYNC_SETTINGS_PORT) { } else if (dPort == TAISYNC_SETTINGS_PORT) {
tcpOutStream.write(sBytes); settingsOutStream.write(sBytes);
} else if (dPort == TAISYNC_TELEMETRY_PORT) { } else if (dPort == TAISYNC_TELEMETRY_PORT) {
DatagramPacket packet = new DatagramPacket(sBytes, sBytes.length, address, TELEM_PORT); telemetryOutStream.write(sBytes);
udpSocket.send(packet);
} }
} }
} }
...@@ -163,9 +167,10 @@ public class TaiSync ...@@ -163,9 +167,10 @@ public class TaiSync
} }
} }
DatagramPacket packet = new DatagramPacket(inbuf, inbuf.length); int bytesRead = telemetryInStream.read(inbuf, 0, inbuf.length);
udpSocket.receive(packet); if (bytesRead > 0) {
sendTaiSyncMessage(PROTOCOL_DATA, TAISYNC_TELEMETRY_PORT, packet.getData(), packet.getLength()); sendTaiSyncMessage(PROTOCOL_DATA, TAISYNC_TELEMETRY_PORT, inbuf, bytesRead);
}
} }
} catch (IOException e) { } catch (IOException e) {
Log.e("QGC_TaiSync", "Exception: " + e); Log.e("QGC_TaiSync", "Exception: " + e);
...@@ -191,7 +196,7 @@ public class TaiSync ...@@ -191,7 +196,7 @@ public class TaiSync
} }
} }
int bytesRead = tcpInStream.read(inbuf, 0, inbuf.length); int bytesRead = settingsInStream.read(inbuf, 0, inbuf.length);
if (bytesRead > 0) { if (bytesRead > 0) {
sendTaiSyncMessage(PROTOCOL_DATA, TAISYNC_SETTINGS_PORT, inbuf, bytesRead); sendTaiSyncMessage(PROTOCOL_DATA, TAISYNC_SETTINGS_PORT, inbuf, bytesRead);
} }
...@@ -213,6 +218,7 @@ public class TaiSync ...@@ -213,6 +218,7 @@ public class TaiSync
byte[] lA = new byte[4]; byte[] lA = new byte[4];
int len = HEADER_SIZE + dataLen; int len = HEADER_SIZE + dataLen;
Log.i("QGC_TaiSync", "Sending to " + dataPort + " length = " + len);
byte[] buffer = new byte[len]; byte[] buffer = new byte[len];
for (int i = 3; i >= 0; i--) { for (int i = 3; i >= 0; i--) {
...@@ -251,8 +257,14 @@ public class TaiSync ...@@ -251,8 +257,14 @@ public class TaiSync
} catch (Exception e) { } catch (Exception e) {
} }
try { try {
if (tcpSocket != null) { if (tcpTelemetrySocket != null) {
tcpSocket.close(); tcpTelemetrySocket.close();
}
} catch (Exception e) {
}
try {
if (tcpSettingsSocket != null) {
tcpSettingsSocket.close();
} }
} catch (Exception e) { } catch (Exception e) {
} }
...@@ -263,9 +275,10 @@ public class TaiSync ...@@ -263,9 +275,10 @@ public class TaiSync
} catch (Exception e) { } catch (Exception e) {
} }
udpSocket = null; udpSocket = null;
tcpSocket = null; tcpSettingsSocket = null;
tcpInStream = null; tcpTelemetrySocket = null;
tcpOutStream = null; settingsInStream = null;
settingsOutStream = null;
mParcelFileDescriptor = null; mParcelFileDescriptor = null;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment