mirror of https://github.com/rusefi/RomRaider.git
Handle short and longer header format and check request packet size limit
This commit is contained in:
parent
575d8a2921
commit
0c6d0b39c6
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||||
* Copyright (C) 2006-2018 RomRaider.com
|
* Copyright (C) 2006-2019 RomRaider.com
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -129,7 +129,10 @@ public final class NCSProtocol implements ProtocolNCS {
|
||||||
@Override
|
@Override
|
||||||
public byte[] constructLoadAddressRequest(byte[][] addresses) {
|
public byte[] constructLoadAddressRequest(byte[][] addresses) {
|
||||||
checkNotNullOrEmpty(addresses, "addresses");
|
checkNotNullOrEmpty(addresses, "addresses");
|
||||||
// len 0xac 0x81 fld_typ address1 [[fld_typ address2] ... [fld_typ addressN]] checksum
|
// short header - false, length encoded into lower 5 bits of first byte
|
||||||
|
// 0x8Len 0x10 0xFC 0xac 0x81 fld_typ address1 [[fld_typ address2] ... [fld_typ addressN]] checksum
|
||||||
|
// short header - true
|
||||||
|
// Len 0xac 0x81 fld_typ address1 [[fld_typ address2] ... [fld_typ addressN]] checksum
|
||||||
return buildLoadAddrRequest(true, addresses);
|
return buildLoadAddrRequest(true, addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||||
* Copyright (C) 2006-2018 RomRaider.com
|
* Copyright (C) 2006-2019 RomRaider.com
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,12 +26,9 @@ import static com.romraider.io.protocol.ncs.iso14230.NCSProtocol.NCS_NRC;
|
||||||
import static com.romraider.io.protocol.ncs.iso14230.NCSProtocol.READ_LOAD_RESPONSE;
|
import static com.romraider.io.protocol.ncs.iso14230.NCSProtocol.READ_LOAD_RESPONSE;
|
||||||
import static com.romraider.io.protocol.ncs.iso14230.NCSProtocol.RESPONSE_NON_DATA_BYTES;
|
import static com.romraider.io.protocol.ncs.iso14230.NCSProtocol.RESPONSE_NON_DATA_BYTES;
|
||||||
import static com.romraider.io.protocol.ncs.iso14230.NCSProtocol.READ_SID_GRP_RESPONSE;
|
import static com.romraider.io.protocol.ncs.iso14230.NCSProtocol.READ_SID_GRP_RESPONSE;
|
||||||
import static com.romraider.util.ByteUtil.asUnsignedInt;
|
|
||||||
import static com.romraider.util.HexUtil.asHex;
|
import static com.romraider.util.HexUtil.asHex;
|
||||||
import static com.romraider.util.ParamChecker.checkNotNullOrEmpty;
|
import static com.romraider.util.ParamChecker.checkNotNullOrEmpty;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import com.romraider.logger.ecu.comms.manager.PollingState;
|
import com.romraider.logger.ecu.comms.manager.PollingState;
|
||||||
import com.romraider.logger.ecu.exception.InvalidResponseException;
|
import com.romraider.logger.ecu.exception.InvalidResponseException;
|
||||||
|
|
||||||
|
@ -58,10 +55,17 @@ public final class NCSResponseProcessor {
|
||||||
assertNrc((byte) (response[2] + 0x40), response[1], response[2], response[3],
|
assertNrc((byte) (response[2] + 0x40), response[1], response[2], response[3],
|
||||||
"Request type not supported");
|
"Request type not supported");
|
||||||
}
|
}
|
||||||
|
if ((response[0] & (byte)0x80) == (byte)0x80) { // long header
|
||||||
|
assertOneOf(new byte[]{ECU_ID_SID_RESPONSE, LOAD_ADDRESS_RESPONSE,
|
||||||
|
READ_LOAD_RESPONSE, READ_SID_GRP_RESPONSE},
|
||||||
|
response[3], "Invalid response code");
|
||||||
|
}
|
||||||
|
else { // short header
|
||||||
assertOneOf(new byte[]{ECU_ID_SID_RESPONSE, LOAD_ADDRESS_RESPONSE,
|
assertOneOf(new byte[]{ECU_ID_SID_RESPONSE, LOAD_ADDRESS_RESPONSE,
|
||||||
READ_LOAD_RESPONSE, READ_SID_GRP_RESPONSE},
|
READ_LOAD_RESPONSE, READ_SID_GRP_RESPONSE},
|
||||||
response[1], "Invalid response code");
|
response[1], "Invalid response code");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final static byte[] extractResponseData(byte[] response) {
|
public final static byte[] extractResponseData(byte[] response) {
|
||||||
checkNotNullOrEmpty(response, "response");
|
checkNotNullOrEmpty(response, "response");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||||
* Copyright (C) 2006-2018 RomRaider.com
|
* Copyright (C) 2006-2019 RomRaider.com
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -23,6 +23,8 @@ import static com.romraider.util.HexUtil.asHex;
|
||||||
import static com.romraider.util.ParamChecker.checkNotNull;
|
import static com.romraider.util.ParamChecker.checkNotNull;
|
||||||
import static com.romraider.util.ThreadUtil.sleep;
|
import static com.romraider.util.ThreadUtil.sleep;
|
||||||
import static org.apache.log4j.Logger.getLogger;
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
|
import static com.romraider.io.protocol.ncs.iso14230.NCSProtocol.SID_21;
|
||||||
|
import static com.romraider.io.protocol.ncs.iso14230.NCSProtocol.SID_22;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -202,13 +204,13 @@ public final class NCSLoggerConnection implements LoggerConnection {
|
||||||
|
|
||||||
if (queries.size() != queryCount
|
if (queries.size() != queryCount
|
||||||
|| pollState.isNewQuery()) {
|
|| pollState.isNewQuery()) {
|
||||||
// max data bytes 255 including TX loopback
|
// max data bytes 63 when length encoded into format byte
|
||||||
int dataLength = 0;
|
int dataLength = 0;
|
||||||
for (EcuQuery query : queries) {
|
for (EcuQuery query : queries) {
|
||||||
dataLength += query.getBytes().length;
|
dataLength += calcLength(query.getBytes());
|
||||||
}
|
}
|
||||||
// if length is too big then notify user to un-select some parameters
|
// if length is too big then notify user to un-select some parameters
|
||||||
if (dataLength > 60) {
|
if (dataLength > 56) {
|
||||||
throw new SerialCommunicationException(
|
throw new SerialCommunicationException(
|
||||||
"Request message too large, un-select some parameters");
|
"Request message too large, un-select some parameters");
|
||||||
}
|
}
|
||||||
|
@ -216,7 +218,10 @@ public final class NCSLoggerConnection implements LoggerConnection {
|
||||||
LOGGER.debug(String.format("Mode:%s %s Load address request ---> %s",
|
LOGGER.debug(String.format("Mode:%s %s Load address request ---> %s",
|
||||||
pollState.getCurrentState(), module, asHex(request)));
|
pollState.getCurrentState(), module, asHex(request)));
|
||||||
|
|
||||||
final byte[] response = new byte[4];
|
byte[] response = new byte[4]; // short header response
|
||||||
|
if ((request[0] & (byte)0x80) == (byte)0x80) {
|
||||||
|
response = new byte[6]; // long header response
|
||||||
|
}
|
||||||
manager.send(request, response, pollState);
|
manager.send(request, response, pollState);
|
||||||
LOGGER.debug(String.format("Mode:%s %s Load address response <--- %s",
|
LOGGER.debug(String.format("Mode:%s %s Load address response <--- %s",
|
||||||
pollState.getCurrentState(), module, asHex(response)));
|
pollState.getCurrentState(), module, asHex(response)));
|
||||||
|
@ -259,4 +264,14 @@ public final class NCSLoggerConnection implements LoggerConnection {
|
||||||
public void sendAddressWrites(Map<EcuQuery, byte[]> writeQueries, Module module) {
|
public void sendAddressWrites(Map<EcuQuery, byte[]> writeQueries, Module module) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int calcLength(byte[] address) {
|
||||||
|
switch (address[0]) {
|
||||||
|
case SID_21:
|
||||||
|
case SID_22:
|
||||||
|
return 3;
|
||||||
|
default:
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue