Beispiel #1
0
 /**
  * Apparently the binary "exitProgrammingMode" command can crash the command station if the EPROM
  * was built before 2006. This method uses a state flag ({@link
  * NceTrafficController#getNceProgMode}) to detect whether a command to enter program mode has
  * been generated, and presumably sent, when using the later EPROMS. *
  */
 public static NceMessage getExitProgMode(NceTrafficController tc) {
   NceMessage m = new NceMessage(1);
   if (tc.getCommandOptions() >= NceTrafficController.OPTION_2006) {
     // Sending exit programming mode binary can crash pre 2006 EPROMs
     // assumption is that program mode hasn't been entered, so exit without
     // sending command
     if (tc.getNceProgMode() == false) {
       return null;
     }
     // 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 EXIT_PROG_CMD to NCE USB");
       //    			return null;
     }
     tc.setNceProgMode(false);
     m.setBinary(true);
     m.setReplyLen(1);
     m.setOpCode(EXIT_PROG_CMD);
     m.setTimeout(SHORT_TIMEOUT);
   } else {
     m.setBinary(false);
     m.setOpCode('X');
     m.setTimeout(SHORT_TIMEOUT);
   }
   return m;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 private void issueClockStart() {
   byte[] cmd = jmri.jmrix.nce.NceBinaryCommand.accStartClock();
   NceMessage cmdNce =
       jmri.jmrix.nce.NceMessage.createBinaryMessage(tc, cmd, CMD_CLOCK_SET_REPLY_SIZE);
   waiting++;
   waitingForCmdStart = true;
   tc.sendNceMessage(cmdNce, this);
 }
Beispiel #4
0
 @SuppressWarnings("unused")
 private void issueClock1224(boolean mode) {
   byte[] cmd = jmri.jmrix.nce.NceBinaryCommand.accSetClock1224(mode);
   NceMessage cmdNce =
       jmri.jmrix.nce.NceMessage.createBinaryMessage(tc, cmd, CMD_CLOCK_SET_REPLY_SIZE);
   waiting++;
   waitingForCmd1224 = true;
   tc.sendNceMessage(cmdNce, this);
 }
Beispiel #5
0
 private void issueClockRatio(int r) {
   log.debug("sending ratio " + r + " to nce cmd station");
   byte[] cmd = jmri.jmrix.nce.NceBinaryCommand.accSetClockRatio(r);
   NceMessage cmdNce =
       jmri.jmrix.nce.NceMessage.createBinaryMessage(tc, cmd, CMD_CLOCK_SET_REPLY_SIZE);
   waiting++;
   waitingForCmdRatio = true;
   tc.sendNceMessage(cmdNce, this);
 }
Beispiel #6
0
 private void issueReadOnlyRequest() {
   if (!waitingForCmdRead) {
     byte[] cmd = jmri.jmrix.nce.NceBinaryCommand.accMemoryRead(CS_CLOCK_MEM_ADDR);
     NceMessage cmdNce = jmri.jmrix.nce.NceMessage.createBinaryMessage(tc, cmd, CS_CLOCK_MEM_SIZE);
     waiting++;
     waitingForCmdRead = true;
     tc.sendNceMessage(cmdNce, this);
     //			log.debug("issueReadOnlyRequest at " + internalClock.getTime());
   }
 }
Beispiel #7
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;
 }
Beispiel #8
0
 private void issueClockSetMem(int hh, int mm, int ss) {
   byte[] cmd =
       jmri.jmrix.nce.NceBinaryCommand.accMemoryWriteN(CS_CLOCK_MEM_ADDR + CS_CLOCK_SECONDS, 3);
   cmd[4] = (byte) ss;
   cmd[5] = (byte) mm;
   cmd[6] = (byte) hh;
   NceMessage cmdNce =
       jmri.jmrix.nce.NceMessage.createBinaryMessage(tc, cmd, CMD_MEM_SET_REPLY_SIZE);
   waiting++;
   waitingForCmdTime = true;
   tc.sendNceMessage(cmdNce, this);
 }
Beispiel #9
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;
    }
  }
Beispiel #10
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;
 }
Beispiel #11
0
 /**
  * enter programming track mode
  *
  * @param tc
  */
 public static NceMessage getProgMode(NceTrafficController tc) {
   // 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 ENTER_PROG_CMD to NCE USB");
     //			return null;
   }
   NceMessage m = new NceMessage(1);
   if (tc.getCommandOptions() >= NceTrafficController.OPTION_2006) {
     tc.setNceProgMode(true);
     m.setBinary(true);
     m.setReplyLen(1);
     m.setOpCode(ENTER_PROG_CMD);
     m.setTimeout(SHORT_TIMEOUT);
   } else {
     m.setBinary(false);
     m.setOpCode('M');
     m.setTimeout(SHORT_TIMEOUT);
   }
   return m;
 }
Beispiel #12
0
 public static NceMessage getKillMain(NceTrafficController tc) {
   // this command isn't supported by the NCE USB
   if (tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_NONE) {
     log.error("attempt to send unsupported binary command KILL_MAIN_CMD to NCE USB");
     return null;
   }
   NceMessage m = new NceMessage(1);
   if (tc.getCommandOptions() >= NceTrafficController.OPTION_1999) {
     m.setBinary(true);
     m.setReplyLen(1);
     m.setOpCode(KILL_MAIN_CMD);
   } else {
     m.setBinary(false);
     m.setOpCode('K');
   }
   return m;
 }
Beispiel #13
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;
    }
  }
Beispiel #14
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;
   }
 }
Beispiel #15
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;
   }
 }