示例#1
0
 // listen for turnouts, creating them as needed
 public void message(DCCppReply l) {
   if (log.isDebugEnabled()) {
     log.debug("recieved message: " + l.toString());
   }
   if (l.isTurnoutReply()) {
     // parse message type
     int addr = l.getTOIDInt();
     if (addr >= 0) {
       // check to see if the address has been operated before
       // continuing.
       if (log.isDebugEnabled()) {
         log.debug("message has address: " + addr);
       }
       // reach here for switch command; make sure we know
       // about this one
       String s = prefix + typeLetter() + addr;
       if (null == getBySystemName(s)) {
         // need to create a new one, and send the message on
         // to the newly created object.
         ((DCCppTurnout) provideTurnout(s)).initmessage(l);
       } else {
         // The turnout exists, forward this message to the
         // turnout
         ((DCCppTurnout) getBySystemName(s)).message(l);
       }
     }
   }
 }
示例#2
0
  // DCCppSensor test for incoming status message
  public void testDCCppSensorStatusMsg() {
    DCCppInterfaceScaffold xnis = new DCCppInterfaceScaffold(new DCCppCommandStation());
    Assert.assertNotNull("exists", xnis);

    DCCppSensor t = new DCCppSensor("DCCPPS04", xnis);
    DCCppReply m;

    // Verify this was created in UNKNOWN state
    Assert.assertTrue(t.getKnownState() == jmri.Sensor.UNKNOWN);

    // notify the Sensor that somebody else changed it...
    m = DCCppReply.parseDCCppReply("Q 4");
    t.message(m);
    Assert.assertEquals("Known state after activate ", jmri.Sensor.ACTIVE, t.getKnownState());

    m = DCCppReply.parseDCCppReply("q 4");
    t.message(m);

    Assert.assertEquals("Known state after inactivate ", jmri.Sensor.INACTIVE, t.getKnownState());
  }