1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Fixed some timer issues. Got connection with this.

This commit is contained in:
James Cotton 2011-03-10 21:36:09 -06:00
parent 03b9bbbb8a
commit 06f583ff75
3 changed files with 15 additions and 13 deletions

View File

@ -101,7 +101,14 @@ public class Telemetry {
} }
synchronized void transTimerSetPeriod(int periodMs) { synchronized void transTimerSetPeriod(int periodMs) {
transTimer = new Timer(); if(transTimerTask != null)
transTimerTask.cancel();
if(transTimer != null)
transTimer.purge();
transTimer = new Timer();
transTimerTask = new TimerTask() { transTimerTask = new TimerTask() {
@Override @Override
public void run() { public void run() {

View File

@ -164,7 +164,6 @@ public class TelemetryMonitor {
gcsStatsObj = objMngr.getObject("GCSTelemetryStats"); gcsStatsObj = objMngr.getObject("GCSTelemetryStats");
flightStatsObj = objMngr.getObject("FlightTelemetryStats"); flightStatsObj = objMngr.getObject("FlightTelemetryStats");
System.out.println(flightStatsObj.toString());
if ( ((String) gcsStatsObj.getField("Status").getValue()).compareTo("Connected") != 0 || if ( ((String) gcsStatsObj.getField("Status").getValue()).compareTo("Connected") != 0 ||
((String) flightStatsObj.getField("Status").getValue()).compareTo("Connected") == 0 ) ((String) flightStatsObj.getField("Status").getValue()).compareTo("Connected") == 0 )
{ {
@ -250,8 +249,6 @@ public class TelemetryMonitor {
boolean gcsConnected = ((String) statusField.getValue()).compareTo("Connected") == 0; boolean gcsConnected = ((String) statusField.getValue()).compareTo("Connected") == 0;
boolean gcsDisconnected = ((String) statusField.getValue()).compareTo("Disconnected") == 0; boolean gcsDisconnected = ((String) statusField.getValue()).compareTo("Disconnected") == 0;
if(gcsConnected)
System.out.println("Detected here");
if ( gcsStatusChanged || if ( gcsStatusChanged ||
((String) flightStatsObj.getField("Status").getValue()).compareTo("Disconnected") != 0 ) ((String) flightStatsObj.getField("Status").getValue()).compareTo("Disconnected") != 0 )
{ {

View File

@ -180,7 +180,7 @@ public class UAVTalk extends Observable{
break; break;
} }
System.out.println("Received byte " + val + " in state + " + rxState); //System.out.println("Received byte " + val + " in state + " + rxState);
processInputByte(val); processInputByte(val);
} }
} }
@ -423,7 +423,6 @@ public class UAVTalk extends Observable{
// Update CRC // Update CRC
rxCS = updateCRC(rxCS, rxbyte); rxCS = updateCRC(rxCS, rxbyte);
//System.out.println(rxCount + "/" + rxLength);
rxBuffer.put(rxCount++, (byte) (rxbyte & 0xff)); rxBuffer.put(rxCount++, (byte) (rxbyte & 0xff));
if (rxCount < rxLength) if (rxCount < rxLength)
break; break;
@ -491,7 +490,7 @@ public class UAVTalk extends Observable{
// All instances, not allowed for OBJ messages // All instances, not allowed for OBJ messages
if (!allInstances) if (!allInstances)
{ {
System.out.println("Received object: " + objId + " " + objMngr.getObject(objId).getName()); System.out.println("Received object: " + objMngr.getObject(objId).getName());
// Get object and update its data // Get object and update its data
obj = updateObject(objId, instId, data); obj = updateObject(objId, instId, data);
// Check if an ack is pending // Check if an ack is pending
@ -513,7 +512,7 @@ public class UAVTalk extends Observable{
// All instances, not allowed for OBJ_ACK messages // All instances, not allowed for OBJ_ACK messages
if (!allInstances) if (!allInstances)
{ {
System.out.println("Received object ack: " + objId + " " + objMngr.getObject(objId).getName()); // System.out.println("Received object ack: " + objId + " " + objMngr.getObject(objId).getName());
// Get object and update its data // Get object and update its data
obj = updateObject(objId, instId, data); obj = updateObject(objId, instId, data);
// Transmit ACK // Transmit ACK
@ -533,7 +532,7 @@ public class UAVTalk extends Observable{
break; break;
case TYPE_OBJ_REQ: case TYPE_OBJ_REQ:
// Get object, if all instances are requested get instance 0 of the object // Get object, if all instances are requested get instance 0 of the object
System.out.println("Received object request: " + objId + " " + objMngr.getObject(objId).getName()); // System.out.println("Received object request: " + objId + " " + objMngr.getObject(objId).getName());
if (allInstances) if (allInstances)
{ {
obj = objMngr.getObject(objId); obj = objMngr.getObject(objId);
@ -556,7 +555,7 @@ public class UAVTalk extends Observable{
// All instances, not allowed for ACK messages // All instances, not allowed for ACK messages
if (!allInstances) if (!allInstances)
{ {
System.out.println("Received ack: " + objId + " " + objMngr.getObject(objId).getName()); // System.out.println("Received ack: " + objId + " " + objMngr.getObject(objId).getName());
// Get object // Get object
obj = objMngr.getObject(objId, instId); obj = objMngr.getObject(objId, instId);
// Check if an ack is pending // Check if an ack is pending
@ -617,14 +616,14 @@ public class UAVTalk extends Observable{
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("Unpacking new object"); // System.out.println("Unpacking new object");
instobj.unpack(data); instobj.unpack(data);
return instobj; return instobj;
} }
else else
{ {
// Unpack data into object instance // Unpack data into object instance
System.out.println("Unpacking existing object: " + data.position() + " / " + data.capacity() ); // System.out.println("Unpacking existing object: " + data.position() + " / " + data.capacity() );
obj.unpack(data); obj.unpack(data);
return obj; return obj;
} }
@ -772,7 +771,6 @@ public class UAVTalk extends Observable{
bbuf.position(0); bbuf.position(0);
byte [] dst = new byte[packlen]; byte [] dst = new byte[packlen];
bbuf.get(dst,0,packlen); bbuf.get(dst,0,packlen);
System.out.println("Outputting: " + dst.length);
outStream.write(dst); outStream.write(dst);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block