Skip to content

Commit

Permalink
modbus.cpp, evse.cpp: Extend modbus error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dingo35 committed May 5, 2023
1 parent 741a16c commit 22c35f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 11 additions & 1 deletion SmartEVSE-3/src/evse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,17 @@ void MBhandleError(Error error, uint32_t token)
{
// ModbusError wraps the error code and provides a readable error message for it
ModbusError me(error);
_LOG_A("Error response: %02X - %s\n", error, (const char *)me);
uint8_t address, function;
uint16_t reg;
address = token >> 24;
function = (token >> 16);
reg = token & 0xFFFF;
if (LoadBl == 1 && address>=2 && address <=8 && function == 4 && reg == 0) { //master sends out messages to nodes 2-8, if no EVSE is connected with that address
//a timeout will be generated. This is legit!
_LOG_V("Error response: %02X - %s, address: %02x, function: %02x, reg: %04x.\n", error, (const char *)me, address, function, reg);
}
else
_LOG_A("Error response: %02X - %s, address: %02x, function: %02x, reg: %04x.\n", error, (const char *)me, address, function, reg);
}


Expand Down
18 changes: 14 additions & 4 deletions SmartEVSE-3/src/modbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ extern struct ModBus MB;
* @param uint16_t data
*/
void ModbusSend8(uint8_t address, uint8_t function, uint16_t reg, uint16_t data) {
// 0x12345678 is a token to keep track of modbus requests/responses. currently unused.
Error err = MBclient.addRequest(0x12345678, address, function, reg, data);
// 0x12345678 is a token to keep track of modbus requests/responses.
// token: first byte address, second byte function, third and fourth reg
uint32_t token;
token = reg;
token += address << 24;
token += function << 16;
Error err = MBclient.addRequest(token, address, function, reg, data);
if (err!=SUCCESS) {
ModbusError e(err);
_LOG_A("Error creating request: %02X - %s\n", (int)e, (const char *)e);
Expand Down Expand Up @@ -176,8 +181,13 @@ void ModbusWriteMultipleRequest(uint8_t address, uint16_t reg, uint16_t *values,
MB.RequestAddress = address;
MB.RequestFunction = 0x10;
MB.RequestRegister = reg;
// 0x12345678 is a token to keep track of modbus requests/responses. currently unused.
MBclient.addRequest(0x12345678, address, 0x10, reg, (uint16_t) count, count * 2u, values);
// 0x12345678 is a token to keep track of modbus requests/responses.
// token: first byte address, second byte function, third and fourth reg
uint32_t token;
token = reg;
token += address << 24;
token += 0x10 << 16;
MBclient.addRequest(token, address, 0x10, reg, (uint16_t) count, count * 2u, values);
_LOG_D("Sent packet");
uint16_t i;
char Str[MODBUS_SYS_CONFIG_COUNT * 5 + 10];
Expand Down

0 comments on commit 22c35f7

Please sign in to comment.