Increased Heartbeat timer; fixed pilot code. Needs testing.
Ben
11 years ago
Binary diff not shown
58 | 58 | public static final int FIRST_PULSE = 30000; |
59 | 59 | |
60 | 60 | /** 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; | |
62 | 62 | |
63 | 63 | /** Tag for logging */ |
64 | 64 | public static final String TAG = "chopper.Comm"; |
143 | 143 | Log.i(TAG, "Connection established"); |
144 | 144 | |
145 | 145 | /* Initializes heartbeat protocol */ |
146 | mHeartbeat.cancel(); | |
146 | 147 | mCountdown.purge(); |
148 | //mCountdown.cancel(); | |
149 | //mCountdown = new Timer(); | |
147 | 150 | mCountdown.schedule(mHeartbeat, FIRST_PULSE); |
148 | 151 | startReading(); |
149 | 152 | } |
246 | 249 | public void handleMessage(Message msg) { |
247 | 250 | switch (msg.what) { |
248 | 251 | 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 | |
251 | 253 | if (!mTextConn.isAlive()) {//a connection is being established |
254 | Log.i(TAG, "Making Text connection"); | |
252 | 255 | mTextConn = new Thread(mTextConnArg); |
253 | 256 | mTextConn.start(); //Try to connect |
254 | 257 | mTextConnLock.unlock(); |
256 | 259 | } |
257 | 260 | break; |
258 | 261 | case MAKE_DATA_CONN: |
259 | Log.i(TAG, "Making data connection"); | |
260 | 262 | if (mDataConnLock.tryLock()) { //if not, the thread is in the process of being created. No action necessary |
261 | 263 | if (!mDataConn.isAlive()) {//a connection is being established |
264 | Log.i(TAG, "Making data connection"); | |
262 | 265 | mDataConn = new Thread(mDataConnArg); |
263 | 266 | mDataConn.start(); //Try to connect |
264 | 267 | mDataConnLock.unlock(); |
359 | 362 | if (parts[1].equals("PULSE")) { |
360 | 363 | sendMessage(msg); |
361 | 364 | //Reset the heartbeat countdown |
365 | mHeartbeat.cancel(); | |
362 | 366 | mCountdown.purge(); |
367 | //mCountdown.cancel(); | |
368 | //mCountdown = new Timer(); | |
363 | 369 | mCountdown.schedule(mHeartbeat, PULSE_RATE); |
364 | 370 | return true; |
365 | 371 | } |