Пример #1
0
 private PASSTHRU_MSG passThruMessage(byte... data) {
   PASSTHRU_MSG msg = passThruMessage();
   msg.dataSize = new NativeLong(data.length);
   arraycopy(data, 0, msg.data, 0, data.length);
   msg.write();
   return msg;
 }
Пример #2
0
  /**
   * Setup network protocol filter(s) to selectively restrict or limit messages received. Then purge
   * the PassThru device's receive buffer.
   *
   * @param channelId - handle to the open communications channel
   * @param mask - used to isolate the receive message header section(s) of interest
   * @param pattern - a message pattern to compare with the receive messages
   * @return the message filter ID to be used to later stop the filter
   */
  public int startPassMsgFilter(int channelId, byte mask, byte pattern) {
    PASSTHRU_MSG maskMsg = passThruMessage(mask);
    PASSTHRU_MSG patternMsg = passThruMessage(pattern);

    NativeLongByReference msgId = new NativeLongByReference();
    msgId.setValue(new NativeLong(0));
    NativeLong ret =
        lib.PassThruStartMsgFilter(
            new NativeLong(channelId),
            new NativeLong(Filter.PASS_FILTER.getValue()),
            maskMsg.getPointer(),
            patternMsg.getPointer(),
            null,
            msgId);
    if (ret.intValue() != Status.NOERROR.getValue())
      handleError("PassThruStartMsgFilter", ret.intValue());

    ret =
        lib.PassThruIoctl(
            new NativeLong(channelId),
            new NativeLong(IOCtl.CLEAR_RX_BUFFER.getValue()),
            null,
            null);
    if (ret.intValue() != Status.NOERROR.getValue())
      handleError("PassThruIoctl (CLEAR_RX_BUFFER)", ret.intValue());
    return msgId.getValue().intValue();
  }
Пример #3
0
 /**
  * Send a message through the existing communication channel to the vehicle.
  *
  * @param channelId - handle to the open communications channel
  * @param data - data bytes to be transmitted to the vehicle network
  * @param timeout - maximum time (in milliseconds) for write completion
  */
 public void writeMsg(int channelId, byte[] data, long timeout) {
   PASSTHRU_MSG msg = passThruMessage(data);
   LOGGER.trace("Write Msg: " + toString(msg));
   NativeLongByReference numMsg = new NativeLongByReference();
   numMsg.setValue(new NativeLong(1));
   NativeLong ret =
       lib.PassThruWriteMsgs(
           new NativeLong(channelId), msg.getPointer(), numMsg, new NativeLong(timeout));
   if (ret.intValue() != Status.NOERROR.getValue())
     handleError("PassThruWriteMsgs", ret.intValue());
 }
Пример #4
0
 private PASSTHRU_MSG doReadMsg(int channelId) {
   PASSTHRU_MSG msg = passThruMessage();
   NativeLongByReference pNumMsgs = new NativeLongByReference();
   pNumMsgs.setValue(new NativeLong(1));
   NativeLong status =
       lib.PassThruReadMsgs(
           new NativeLong(channelId), msg.getPointer(), pNumMsgs, new NativeLong(50));
   if (status.intValue() != Status.NOERROR.getValue()
       && status.intValue() != Status.ERR_TIMEOUT.getValue()
       && status.intValue() != Status.ERR_BUFFER_EMPTY.getValue())
     handleError("PassThruReadMsgs", status.intValue());
   msg.read();
   return msg;
 }
Пример #5
0
 /**
  * This function performs an ISO14230 fast initialization sequence.
  *
  * @param channelId - handle to the open communications channel
  * @param input - start message to be transmitted to the vehicle network
  * @return response - response upon a successful initialization
  */
 public byte[] fastInit(int channelId, byte[] input) {
   PASSTHRU_MSG inMsg = passThruMessage(input);
   PASSTHRU_MSG outMsg = passThruMessage();
   LOGGER.trace("Ioctl inMsg: " + toString(inMsg));
   NativeLong ret =
       lib.PassThruIoctl(
           new NativeLong(channelId),
           new NativeLong(IOCtl.FAST_INIT.value),
           inMsg.getPointer(),
           outMsg.getPointer());
   if (ret.intValue() != Status.NOERROR.getValue()) handleError("PassThruIoctl", ret.intValue());
   outMsg.read();
   LOGGER.trace("Ioctl outMsg: " + toString(outMsg));
   byte[] response = new byte[outMsg.dataSize.intValue()];
   arraycopy(outMsg.data, 0, response, 0, outMsg.dataSize.intValue());
   return response;
 }
Пример #6
0
 private PASSTHRU_MSG passThruMessage() {
   PASSTHRU_MSG msg = new PASSTHRU_MSG();
   msg.txFlags = new NativeLong(0);
   msg.protocolID = protocolID;
   return msg;
 }