git.haldean.org droidcopter / bd216de
Increased Heartbeat timer; fixed pilot code. Needs testing. Ben 11 years ago
3 changed file(s) with 11 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
Binary diff not shown
5858 public static final int FIRST_PULSE = 30000;
5959
6060 /** How long (in ms) to wait for subsequent PULSE signals before assuming connectivity failure. */
61 public static final int PULSE_RATE = 4000;
61 public static final int PULSE_RATE = 15000;
6262
6363 /** Tag for logging */
6464 public static final String TAG = "chopper.Comm";
143143 Log.i(TAG, "Connection established");
144144
145145 /* Initializes heartbeat protocol */
146 mHeartbeat.cancel();
146147 mCountdown.purge();
148 //mCountdown.cancel();
149 //mCountdown = new Timer();
147150 mCountdown.schedule(mHeartbeat, FIRST_PULSE);
148151 startReading();
149152 }
246249 public void handleMessage(Message msg) {
247250 switch (msg.what) {
248251 case MAKE_TEXT_CONN:
249 Log.i(TAG, "Making Text connection");
250 if (mTextConnLock.tryLock()) { //if not, the thread is in the process of being created. No action necessary
252 if (mTextConnLock.tryLock()) { //if not, the thread is in the process of being created. No action necessary
251253 if (!mTextConn.isAlive()) {//a connection is being established
254 Log.i(TAG, "Making Text connection");
252255 mTextConn = new Thread(mTextConnArg);
253256 mTextConn.start(); //Try to connect
254257 mTextConnLock.unlock();
256259 }
257260 break;
258261 case MAKE_DATA_CONN:
259 Log.i(TAG, "Making data connection");
260262 if (mDataConnLock.tryLock()) { //if not, the thread is in the process of being created. No action necessary
261263 if (!mDataConn.isAlive()) {//a connection is being established
264 Log.i(TAG, "Making data connection");
262265 mDataConn = new Thread(mDataConnArg);
263266 mDataConn.start(); //Try to connect
264267 mDataConnLock.unlock();
359362 if (parts[1].equals("PULSE")) {
360363 sendMessage(msg);
361364 //Reset the heartbeat countdown
365 mHeartbeat.cancel();
362366 mCountdown.purge();
367 //mCountdown.cancel();
368 //mCountdown = new Timer();
363369 mCountdown.schedule(mHeartbeat, PULSE_RATE);
364370 return true;
365371 }
1515 private static HeartbeatThread instance;
1616
1717 /* Milliseconds between updates */
18 private int period = 500;
18 private int period = 1000;
1919 private int lastMessageId = 0;
2020
2121 /* Maps messages to when they were sent. */