示例#1
0
 /**
  * Retrieve a message through the existing communication channel from the vehicle.
  *
  * @param channelId - handle to the open communications channel
  * @param maxWait - maximum time (in milliseconds) for read completion
  * @return bytes read from the vehicle network
  */
 public byte[] readMsg(int channelId, long maxWait) {
   List<byte[]> responses = new ArrayList<byte[]>();
   long end = currentTimeMillis() + maxWait;
   do {
     PASSTHRU_MSG msg = doReadMsg(channelId);
     LOGGER.trace("Read Msg: " + toString(msg));
     if (isResponse(msg)) responses.add(data(msg));
     ThreadUtil.sleep(2);
   } while (currentTimeMillis() <= end);
   return concat(responses);
 }
示例#2
0
 /**
  * Retrieve the indicated number of messages through the existing communication channel from the
  * vehicle. If the number of messages can not be read before the timeout expires, throw an
  * exception.
  *
  * @param channelId - handle to the open communications channel
  * @param numMsg - number of valid messages to retrieve
  * @return bytes read from the vehicle network
  * @throws J2534Exception
  */
 public byte[] readMsg(int channelId, int numMsg, long timeout) {
   if (loopback) {
     numMsg++;
   }
   List<byte[]> responses = new ArrayList<byte[]>();
   long end = currentTimeMillis() + timeout;
   do {
     if (currentTimeMillis() >= end) {
       String errString =
           String.format("readMsg error: timeout expired waiting for %d more message(s)", numMsg);
       throw new J2534Exception(errString);
     }
     PASSTHRU_MSG msg = doReadMsg(channelId);
     LOGGER.trace("Read Msg: " + toString(msg));
     if (isResponse(msg)) {
       responses.add(data(msg));
       numMsg--;
     }
     ThreadUtil.sleep(2);
   } while (numMsg != 0);
   return concat(responses);
 }