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();
    }
  }
Beispiel #2
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 #3
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);
   }
 }