Esempio n. 1
0
 public static NceMessage getWriteRegister(NceTrafficController tc, int reg, int val) {
   // not supported by USB connected to SB3 or PH
   if (tc.getUsbSystem() == NceTrafficController.USB_SYSTEM_SB3
       || tc.getUsbSystem() == NceTrafficController.USB_SYSTEM_SB5
       || tc.getUsbSystem() == NceTrafficController.USB_SYSTEM_TWIN
       || tc.getUsbSystem() == NceTrafficController.USB_SYSTEM_POWERHOUSE) {
     log.error("attempt to send unsupported binary command WRITE_REG_CMD to NCE USB");
     return null;
   }
   if (reg > 8) {
     log.error("register number too large: " + reg);
   }
   if (tc.getCommandOptions() >= NceTrafficController.OPTION_2006) {
     NceMessage m = new NceMessage(3);
     m.setBinary(true);
     m.setReplyLen(1);
     m.setOpCode(WRITE_REG_CMD);
     m.setElement(1, reg);
     m.setElement(2, val);
     m.setNeededMode(jmri.jmrix.AbstractMRTrafficController.PROGRAMINGMODE);
     m.setTimeout(NCE_PAGED_CV_TIMEOUT);
     return m;
   } else {
     NceMessage m = new NceMessage(6);
     m.setBinary(false);
     m.setOpCode('S');
     String s = "" + reg;
     m.setElement(1, s.charAt(s.length() - 1));
     m.setElement(2, ' ');
     m.addIntAsThree(val, 3);
     m.setNeededMode(jmri.jmrix.AbstractMRTrafficController.PROGRAMINGMODE);
     m.setTimeout(NCE_PAGED_CV_TIMEOUT);
     return m;
   }
 }
Esempio n. 2
0
 /**
  * write paged mode CV to programming track
  *
  * @param tc
  * @param cv
  * @param val
  */
 public static NceMessage getWritePagedCV(NceTrafficController tc, int cv, int val) {
   // test if supported on current connection
   if (tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_NONE
       && (tc.getCmdGroups() & NceTrafficController.CMDS_PROGTRACK)
           != NceTrafficController.CMDS_PROGTRACK) {
     log.error("attempt to send unsupported binary command WRITE_PAGED_CV_CMD to NCE USB");
     //			return null;
   }
   if (tc.getCommandOptions() >= NceTrafficController.OPTION_2006) {
     NceMessage m = new NceMessage(4);
     m.setBinary(true);
     m.setReplyLen(1);
     m.setOpCode(WRITE_PAGED_CV_CMD);
     m.setElement(1, cv >> 8);
     m.setElement(2, cv & 0xFF);
     m.setElement(3, val);
     m.setNeededMode(jmri.jmrix.AbstractMRTrafficController.PROGRAMINGMODE);
     m.setTimeout(NCE_PAGED_CV_TIMEOUT);
     return m;
   } else {
     NceMessage m = new NceMessage(8);
     m.setBinary(false);
     m.setOpCode('P');
     m.addIntAsThree(cv, 1);
     m.setElement(4, ' ');
     m.addIntAsThree(val, 5);
     m.setNeededMode(jmri.jmrix.AbstractMRTrafficController.PROGRAMINGMODE);
     m.setTimeout(NCE_PAGED_CV_TIMEOUT);
     return m;
   }
 }
Esempio n. 3
0
 public static NceMessage createAccySignalMacroMessage(
     NceTrafficController tc, int op, int addr, int data) {
   if (tc.getCommandOptions() < NceTrafficController.OPTION_2004) {
     log.error("Attempt to send NCE command to EPROM built before 2004");
   }
   NceMessage m = new NceMessage(5);
   m.setBinary(true);
   m.setReplyLen(1);
   m.setTimeout(SHORT_TIMEOUT);
   m.setOpCode(SEND_ACC_SIG_MACRO_CMD);
   m.setElement(1, (addr >> 8) & 0xFF);
   m.setElement(2, addr & 0xFF);
   m.setElement(3, op);
   m.setElement(4, data);
   return m;
 }
Esempio n. 4
0
  public static NceMessage queuePacketMessage(NceTrafficController tc, byte[] bytes) {
    // this command isn't supported by the NCE USB
    if (tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_NONE) {
      log.error("attempt to send unsupported queuePacketMessage to NCE USB");
      return null;
    }
    if (tc.getCommandOptions() >= NceTrafficController.OPTION_1999) {
      if (bytes.length < 3 || bytes.length > 6) {
        log.error(
            "Queue of NCE track packet too long:"
                + Integer.toString(bytes.length)
                + " packet :"
                + Arrays.toString(bytes));
      }
      NceMessage m = new NceMessage(1 + bytes.length);
      m.setBinary(true);
      m.setReplyLen(1);
      int i = 0; // counter to make it easier to format the message

      m.setElement(i++, QUEUEn_BYTES_CMD + bytes.length);
      for (int j = 0; j < bytes.length; j++) {
        m.setElement(i++, bytes[j] & 0xFF);
      }
      return m;
    } else {
      NceMessage m = new NceMessage(1 + 3 * bytes.length);
      m.setBinary(false);
      int i = 0; // counter to make it easier to format the message

      m.setElement(i++, 'Q'); // "S C02 " means sent it twice

      for (int j = 0; j < bytes.length; j++) {
        m.setElement(i++, ' ');
        m.addIntAsTwoHex(bytes[j] & 0xFF, i);
        i = i + 2;
      }
      return m;
    }
  }
Esempio n. 5
0
 public static NceMessage getWriteDirectCV(NceTrafficController tc, int cv, int val) {
   // not supported by USB connected to SB3 or PH
   if (tc.getUsbSystem() == NceTrafficController.USB_SYSTEM_SB3
       || tc.getUsbSystem() == NceTrafficController.USB_SYSTEM_SB5
       || tc.getUsbSystem() == NceTrafficController.USB_SYSTEM_TWIN
       || tc.getUsbSystem() == NceTrafficController.USB_SYSTEM_POWERHOUSE) {
     log.error("attempt to send unsupported binary command WRITE_DIR_CV_CMD to NCE USB");
     return null;
   }
   if (tc.getCommandOptions() < NceTrafficController.OPTION_2006) {
     log.error("getWriteDirectCV with option " + tc.getCommandOptions());
   }
   NceMessage m = new NceMessage(4);
   m.setBinary(true);
   m.setReplyLen(1);
   m.setOpCode(WRITE_DIR_CV_CMD);
   m.setElement(1, cv >> 8);
   m.setElement(2, cv & 0xFF);
   m.setElement(3, val);
   m.setNeededMode(jmri.jmrix.AbstractMRTrafficController.PROGRAMINGMODE);
   m.setTimeout(NCE_DIRECT_CV_TIMEOUT);
   return m;
 }
Esempio n. 6
0
 public static NceMessage createBinaryMessage(NceTrafficController tc, byte[] bytes) {
   if (tc.getCommandOptions() < NceTrafficController.OPTION_2004) {
     log.error("Attempt to send NCE command to EPROM built before 2004");
   }
   if (bytes.length < 1 || bytes.length > 20) {
     log.error("NCE command message length error:" + bytes.length);
   }
   NceMessage m = new NceMessage(bytes.length);
   m.setBinary(true);
   m.setReplyLen(1);
   m.setTimeout(SHORT_TIMEOUT);
   for (int j = 0; j < bytes.length; j++) {
     m.setElement(j, bytes[j] & 0xFF);
   }
   return m;
 }
Esempio n. 7
0
  public static NceMessage sendPacketMessage(NceTrafficController tc, byte[] bytes, int retries) {
    // this command isn't supported by the NCE USB
    if (tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_NONE) {
      log.error(
          "attempt to send unsupported sendPacketMessage to NCE USB cmd: 0x"
              + Integer.toHexString(SENDn_BYTES_CMD + bytes.length));
      return null;
    }
    if (tc.getCommandOptions() >= NceTrafficController.OPTION_1999) {
      if (bytes.length < 3 || bytes.length > 6) {
        log.error(
            "Send of NCE track packet too short or long:"
                + Integer.toString(bytes.length)
                + " packet:"
                + Arrays.toString(bytes));
      }
      NceMessage m = new NceMessage(2 + bytes.length);
      m.setBinary(true);
      m.setTimeout(SHORT_TIMEOUT);
      m.setReplyLen(1);
      int i = 0; // counter to make it easier to format the message

      m.setElement(i++, SENDn_BYTES_CMD + bytes.length);
      m.setElement(i++, retries); // send this many retries.
      for (int j = 0; j < bytes.length; j++) {
        m.setElement(i++, bytes[j] & 0xFF);
      }
      return m;
    } else {
      NceMessage m = new NceMessage(5 + 3 * bytes.length);
      m.setBinary(false);
      int i = 0; // counter to make it easier to format the message

      m.setElement(i++, 'S'); // "S C02 " means sent it twice
      m.setElement(i++, ' ');
      m.setElement(i++, 'C');
      m.setElement(i++, '0');
      m.setElement(i++, '2');

      for (int j = 0; j < bytes.length; j++) {
        m.setElement(i++, ' ');
        m.addIntAsTwoHex(bytes[j] & 0xFF, i);
        i = i + 2;
      }
      m.setTimeout(SHORT_TIMEOUT);
      return m;
    }
  }