コード例 #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");
  }
コード例 #2
0
  public Sample() {
    try {
      EventHeap eh = new EventHeap("localhost");
      Event e = new Event("MyEventType");
      e.addField("AGE", new Integer(27));
      e.addField("NAME", "Tico Ballagas");
      Event templates[] = new Event[1];
      templates[0] = e;

      // register for a specific event template
      // this will only be matched when EventType = MyEventType and Age = 27 and Name = Tico
      // Ballagas
      eh.registerForEvents(templates, this);

      // send an event - commented out for template demonstration
      // uncomment to see both templates match
      // eh.putEvent(e);

      Event template = new Event("MyEventType");
      template.addField("AGE", Integer.class, FieldValueTypes.FORMAL, FieldValueTypes.FORMAL);
      template.addField("NAME", String.class, FieldValueTypes.FORMAL, FieldValueTypes.FORMAL);

      // register for a generic event template
      // this template will be matched for any event that has EventType = MyEventType
      // and contains the Age and Name fields with correct type
      // the values of Age and Name can be any value
      // (run the c tutorial app as a test, waitForEvent should print and registerForEvents should
      // not)
      Event received = eh.waitForEvent(template);
      System.out.println("waitForEvent: " + received.getEventType());

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
 public boolean returnEvent(Event[] retEvents) {
   try {
     System.out.println("registerForEvents: " + retEvents[0].getEventType());
   } catch (Exception e) {
     e.printStackTrace();
   }
   return true;
 }
コード例 #4
0
  /*! This method is called whenever an event matching the template
  	is found on the event heap. This function decodes the events
  	of type "iStuffMobile" and issues corresponding high-level
  	commands to the "iStuff Mobile" mobile phone application.

  	\param retEvents as an Event array. The first element of the
  		   array is the matching event. Subsequent events in
  		   the array are the template events used for the match.

  	\return The function should return true if it wants to
  			continue recieving callbacks, and false if it is
  			done and doesn't want to recieve any more callbacks.
  */
  public boolean returnEvent(Event[] retEvents) {
    try {
      String currentProxyId = null;
      String command =
          retEvents[0].getPostValueString(
              "Command"); // get the value of Command field from the Event
      System.out.println("Received " + command);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    System.out.println("Waiting for event");
    return true;
  }
コード例 #5
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);
   }
 }