Skip to content

Commit

Permalink
Made sending checksum in packets configurable, see #33
Browse files Browse the repository at this point in the history
  • Loading branch information
envy committed Mar 10, 2018
1 parent 119e80d commit bf97fc1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions esp-knx-ip-send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ void ESPKNXIP::send(address_t const &receiver, knx_command_type_t ct, uint8_t da
{
if (receiver.value == 0)
return;

#if SEND_CHECKSUM
uint32_t len = 6 + 2 + 8 + data_len + 1; // knx_pkt + cemi_msg + cemi_service + data + checksum
#else
uint32_t len = 6 + 2 + 8 + data_len; // knx_pkt + cemi_msg + cemi_service + data
#endif
DEBUG_PRINT(F("Creating packet with len "));
DEBUG_PRINTLN(len)
uint8_t buf[len];
Expand Down Expand Up @@ -49,14 +52,16 @@ void ESPKNXIP::send(address_t const &receiver, knx_command_type_t ct, uint8_t da
memcpy(cemi_data->data, data, data_len);
cemi_data->data[0] = (cemi_data->data[0] & 0x3F) | ((ct & 0x03) << 6);

#if SEND_CHECKSUM
// Calculate checksum, which is just XOR of all bytes
uint8_t cs = buf[0] ^ buf[1];
for (uint32_t i = 2; i < len - 1; ++i)
{
cs ^= buf[i];
}
buf[len - 1] = cs;

#endif

DEBUG_PRINT(F("Sending packet:"));
for (int i = 0; i < len; ++i)
{
Expand Down
1 change: 1 addition & 0 deletions esp-knx-ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// These values normally don't need adjustment
#define MULTICAST_PORT 3671 // [Default 3671]
#define MULTICAST_IP IPAddress(224, 0, 23, 12) // [Default IPAddress(224, 0, 23, 12)]
#define SEND_CHECKSUM 0

// Uncomment to enable printing out debug messages.
#define ESP_KNX_DEBUG
Expand Down

0 comments on commit bf97fc1

Please sign in to comment.