public void checkMessage() { try { switch (message.charAt(0)) { case '#': processStatusMessage(); break; case 'n': messProc = new MessageProcessor(state.getSensorValues()); state.postSensorValues(messProc.processSensorArray(message)); state.distTimeStamp = new Date().getTime(); break; case 'o': messProc = new MessageProcessor(state.getSensorValues()); state.postSensorValues(messProc.processSensorArray(message)); state.lightTimeStamp = new Date().getTime(); break; case 't': messProc = new MessageProcessor(); state.postObjectPresent(messProc.processObjPresent(message)); state.objectTimeStamp = new Date().getTime(); break; case 'f': state.postResistivity(messProc.processResistivity(message)); break; } } catch (StringIndexOutOfBoundsException e) { return; } }
public String read() { try { inc = reader.readLine(); } catch (Exception e) { state.sessionStatus = ClientConfiguration.BROKEN; System.out.println("\nConnection Lost"); System.exit(0); } // System.out.println("returning string " + inc); return inc; }
public void processStatusMessage() { if (message.startsWith("#TIMEOUT")) { state.sessionStatus = ClientConfiguration.TIMEOUT; stop(); } else if (message.startsWith("#START")) { state.waitTime = "now"; state.sessionStatus = ClientConfiguration.RUNNING; } else if (message.startsWith("#WAIT")) { state.waitTime = "in " + message.substring(6); state.sessionStatus = ClientConfiguration.WAITING; } else if (message.startsWith("#STUCK")) { state.waitTime = "must wait until the Khepera is unstuck"; state.sessionStatus = ClientConfiguration.STUCK; } }
public void run() { while (true) { if (state.pendingCmd == true) { writeCmd = state.cmd; write(writeCmd); do { message = read(); } while (!checkLen()); checkMessage(); state.pendingCmd = false; } try { sleep(5); } catch (Exception e) { System.out.println("Exception in overall sleep of stateUpdater"); } } }