Example #1
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;
    }
  }
Example #2
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;
    }
  }