コード例 #1
0
 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;
   }
 }
コード例 #2
0
  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;
  }
コード例 #3
0
 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;
   }
 }
コード例 #4
0
 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");
     }
   }
 }