Ejemplo n.º 1
0
 /**
  * Handle a request to change state by sending CBUS events.
  *
  * @param s new state value
  */
 protected void forwardCommandChangeToLayout(int s) {
   CanMessage m;
   if (s == Turnout.THROWN) {
     m = addrThrown.makeMessage();
     tc.sendCanMessage(m, this);
   } else if (s == Turnout.CLOSED) {
     m = addrClosed.makeMessage();
     tc.sendCanMessage(m, this);
   }
 }
Ejemplo n.º 2
0
 /**
  * Common initialization for both constructors.
  *
  * <p>
  */
 private void init(String address) {
   // build local addresses
   OlcbAddress a = new OlcbAddress(address);
   OlcbAddress[] v = a.split();
   if (v == null) {
     log.error("Did not find usable system name: " + address);
     return;
   }
   switch (v.length) {
     case 1:
       addrThrown = v[0];
       // need to complement here for addr 1
       // so address _must_ start with address + or -
       if (address.startsWith("+")) {
         addrClosed = new OlcbAddress("-" + address);
       } else if (address.startsWith("-")) {
         addrClosed = new OlcbAddress("+" + address);
       } else {
         log.error("can't make 2nd event from systemname " + address);
         return;
       }
       break;
     case 2:
       addrThrown = v[0];
       addrClosed = v[1];
       break;
     default:
       log.error("Can't parse OpenLCB Turnout system name: " + address);
       return;
   }
   // connect
   tc.addCanListener(this);
 }