Exemplo n.º 1
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();
  }
Exemplo n.º 2
0
 /**
  * Retrieve the text description for the most recent non-zero error and throw an exception.
  *
  * @param operation - string containing the name of the method for which the error occurred
  * @param status - the method's numeric error value
  * @exception J2534Exception on various non-zero return status
  * @see J2534_v0404
  */
 private static void handleError(String operation, int status) {
   ByteBuffer error = ByteBuffer.allocate(255);
   lib.PassThruGetLastError(error);
   String errString =
       String.format(
           "%s error [%d:%s], %s",
           operation, status, Status.get(status), Native.toString(error.array()));
   throw new J2534Exception(errString);
 }
Exemplo n.º 3
0
 /**
  * Configures various PassThru parameters.
  *
  * @param channelId - handle to the open communications channel
  * @param items - values of multiple parameters can be set in an array of ConfigItem
  */
 public void setConfig(int channelId, ConfigItem... items) {
   if (items.length == 0) return;
   SCONFIG[] sConfigs = sConfigs(items);
   SCONFIG_LIST list = sConfigList(sConfigs);
   NativeLong ioctlID = new NativeLong();
   ioctlID.setValue(IOCtl.SET_CONFIG.getValue());
   NativeLong ret = lib.PassThruIoctl(new NativeLong(channelId), ioctlID, list.getPointer(), null);
   if (ret.intValue() != Status.NOERROR.getValue())
     handleError("PassThruIoctl (SET_CONFIG)", ret.intValue());
 }
Exemplo n.º 4
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());
 }
Exemplo n.º 5
0
 /**
  * Retrieve various PassThru configuration parameters.
  *
  * @param channelId - handle to the open communications channel
  * @param parameters - values of multiple parameters can be retrieved by setting an array of
  *     integer parameter IDs
  * @return an array of <b>ConfigItem</b>
  * @see ConfigItem
  */
 public ConfigItem[] getConfig(int channelId, int... parameters) {
   if (parameters.length == 0) return new ConfigItem[0];
   SCONFIG[] sConfigs = sConfigs(parameters);
   SCONFIG_LIST input = sConfigList(sConfigs);
   NativeLong ioctlID = new NativeLong();
   ioctlID.setValue(IOCtl.GET_CONFIG.getValue());
   NativeLong ret =
       lib.PassThruIoctl(new NativeLong(channelId), ioctlID, input.getPointer(), null);
   if (ret.intValue() != Status.NOERROR.getValue())
     handleError("PassThruIoctl (GET_CONFIG)", ret.intValue());
   return configItems(input);
 }
Exemplo n.º 6
0
 /**
  * Establish a logical connection with a protocol channel of the specified device.
  *
  * @param deviceId - of PassThru device
  * @param flags - protocol specific options
  * @param baud - vehicle network communication rate
  * @return a handle to the open communications channel
  */
 public int connect(int deviceId, int flags, int baud) {
   NativeLongByReference pChannelID = new NativeLongByReference();
   NativeLong ret =
       lib.PassThruConnect(
           new NativeLong(deviceId),
           protocolID,
           new NativeLong(flags),
           new NativeLong(baud),
           pChannelID);
   if (ret.intValue() != Status.NOERROR.getValue()) handleError("PassThruConnect", ret.intValue());
   return pChannelID.getValue().intValue();
 }
Exemplo n.º 7
0
 /**
  * This function reads the battery voltage on pin 16 of the J2534 interface.
  *
  * @param channelId - handle to the open communications channel
  * @return battery voltage in VDC
  */
 public double getVbattery(int channelId) {
   NativeLongByReference vBatt = new NativeLongByReference();
   NativeLong ret =
       lib.PassThruIoctl(
           new NativeLong(channelId),
           new NativeLong(IOCtl.READ_VBATT.getValue()),
           null,
           vBatt.getPointer());
   if (ret.intValue() != Status.NOERROR.getValue()) handleError("PassThruIoctl", ret.intValue());
   LOGGER.trace("Ioctl result: " + vBatt.getValue().longValue());
   double response = vBatt.getValue().doubleValue() / 1000;
   return response;
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
0
 /**
  * Retrieve the PassThru device firmware version, DLL version, and the J2534 implementation
  * version.
  *
  * @param deviceId - of PassThru device
  * @return an instance of <b>Version</b>
  * @see Version
  */
 public Version readVersion(int deviceId) {
   ByteBuffer pFirmwareVersion = ByteBuffer.allocate(80);
   ByteBuffer pDllVersion = ByteBuffer.allocate(80);
   ByteBuffer pApiVersion = ByteBuffer.allocate(80);
   NativeLong ret =
       lib.PassThruReadVersion(
           new NativeLong(deviceId), pFirmwareVersion, pDllVersion, pApiVersion);
   if (ret.intValue() != Status.NOERROR.getValue())
     handleError("PassThruReadVersion", ret.intValue());
   return new Version(
       Native.toString(pFirmwareVersion.array()),
       Native.toString(pDllVersion.array()),
       Native.toString(pApiVersion.array()));
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
0
 /**
  * Close the PassThru device by ID.
  *
  * @param deviceId of PassThru device
  */
 public void close(int deviceId) {
   NativeLong ret = lib.PassThruClose(new NativeLong(deviceId));
   if (ret.intValue() != Status.NOERROR.getValue()) handleError("PassThruClose", ret.intValue());
 }
Exemplo n.º 12
0
 /**
  * Disconnect a previously opened communications channel.
  *
  * @param channelId - handle to the open communications channel
  */
 public void disconnect(int channelId) {
   NativeLong ret = lib.PassThruDisconnect(new NativeLong(channelId));
   if (ret.intValue() != Status.NOERROR.getValue())
     handleError("PassThruDisconnect", ret.intValue());
 }
Exemplo n.º 13
0
 /**
  * Stop the previously defined message filter by filter ID.
  *
  * @param channelId - handle to the open communications channel
  * @param msgId - ID of the filter to stop
  */
 public void stopMsgFilter(int channelId, int msgId) {
   NativeLong ret = lib.PassThruStopMsgFilter(new NativeLong(channelId), new NativeLong(msgId));
   if (ret.intValue() != Status.NOERROR.getValue())
     handleError("PassThruStopMsgFilter", ret.intValue());
 }
Exemplo n.º 14
0
 /**
  * Establish a connection and initialize the PassThru device.
  *
  * @return DeviceID of PassThru device
  */
 public int open() {
   NativeLongByReference pDeviceID = new NativeLongByReference();
   NativeLong ret = lib.PassThruOpen(null, pDeviceID);
   if (ret.intValue() != Status.NOERROR.getValue()) handleError("PassThruOpen", ret.intValue());
   return pDeviceID.getValue().intValue();
 }