From bf97fc13e463004c8efa58070d71a64f72c85190 Mon Sep 17 00:00:00 2001 From: Nico Weichbrodt Date: Sat, 10 Mar 2018 14:52:59 +0100 Subject: [PATCH] Made sending checksum in packets configurable, see #33 --- esp-knx-ip-send.cpp | 9 +++++++-- esp-knx-ip.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/esp-knx-ip-send.cpp b/esp-knx-ip-send.cpp index e02cc82..26301ee 100644 --- a/esp-knx-ip-send.cpp +++ b/esp-knx-ip-send.cpp @@ -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]; @@ -49,6 +52,7 @@ 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) @@ -56,7 +60,8 @@ void ESPKNXIP::send(address_t const &receiver, knx_command_type_t ct, uint8_t da cs ^= buf[i]; } buf[len - 1] = cs; - +#endif + DEBUG_PRINT(F("Sending packet:")); for (int i = 0; i < len; ++i) { diff --git a/esp-knx-ip.h b/esp-knx-ip.h index 35ccc9f..f01323c 100644 --- a/esp-knx-ip.h +++ b/esp-knx-ip.h @@ -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