Beispiel #1
0
  /*! This method runs all the time and listens to data from the SK6 and posts the data through
  	events to the event heap
  */
  public void run() {
    String data;
    String[] tokens;
    Integer value;
    Event e;

    System.out.println("Bluetooth thread, waiting for data");
    while (running == true) {
      try {
        if (inBufReader.ready()) {
          data = inBufReader.readLine();
          tokens = data.split(",");
          e = new Event("Shake");
          e.addField("ProxyID", proxyID);
          e.setPostValue("TimeToLive", new Integer(50)); // set time to live to 50 msec
          e.setPostValue("Sensor", tokens[0]);
          for (int i = 1; i < tokens.length; i++) {
            if (tokens[i].startsWith("+")) { // eliminate Number format exception
              value = new Integer(tokens[i].substring(1));
            } else {
              value = new Integer(tokens[i]);
            }
            e.setPostValue("Data" + i, value);
          }
          eventHeap.putEvent(e);
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
    System.out.println("out of run");
  }
Beispiel #2
0
 public Shake(String ip, String proxyID, String cmprt) {
   try {
     eventHeap = new EventHeap(ip);
     template = new Event[1];
     template[0] = new Event("Shake"); // the Events to be fetched should be of type Shake
     template[0].addField(
         "Command",
         String.class,
         FieldValueTypes.FORMAL,
         FieldValueTypes
             .FORMAL); // the events to be fetched should have a field Command of an Integer value
     // type
     this.proxyID = proxyID;
     this.comPort = cmprt;
     initSerial();
     eventHeap.registerForEvents(template, this); // register to receive events of type template
   } catch (Exception ex) {
     ex.printStackTrace();
     System.exit(-1);
   }
 }