diff --git a/examples/knxPython/knxmodule.cpp b/examples/knxPython/knxmodule.cpp index aefb08b..1255d00 100644 --- a/examples/knxPython/knxmodule.cpp +++ b/examples/knxPython/knxmodule.cpp @@ -14,6 +14,7 @@ namespace py = pybind11; #include #include +#include "knx/bits.h" #include "knx/platform/linux_platform.h" #include "knx/bau57B0.h" #include "knx/group_object_table_object.h" diff --git a/src/knx/address_table_object.cpp b/src/knx/address_table_object.cpp index bf31bec..20cb22f 100644 --- a/src/knx/address_table_object.cpp +++ b/src/knx/address_table_object.cpp @@ -1,9 +1,9 @@ #include #include "address_table_object.h" -#include "bits.h" #include "data_property.h" #include "util/logger.h" +#include "bits.h" #define LOGGER Logger::logger("AddressTableObject") diff --git a/src/knx/apdu.cpp b/src/knx/apdu.cpp index 8b36a7f..7745a78 100644 --- a/src/knx/apdu.cpp +++ b/src/knx/apdu.cpp @@ -42,6 +42,7 @@ uint8_t APDU::length() const string APDU::toString() const { +#ifndef KNX_NO_PRINT string value = "APDU: " + enum_name(type()) + " "; value += byte2hex(_data[0] & 0x3); @@ -54,4 +55,7 @@ string APDU::toString() const } return value; +#else + return ""; +#endif } diff --git a/src/knx/application_layer.cpp b/src/knx/application_layer.cpp index a117f8a..4a3270b 100644 --- a/src/knx/application_layer.cpp +++ b/src/knx/application_layer.cpp @@ -5,9 +5,10 @@ #include "apdu.h" #include "bau.h" #include "string.h" -#include "bits.h" #include #include "util/logger.h" +#include "bits.h" + #define LOGGER Logger::logger("ApplicationLayer") const SecurityControl ApplicationLayer::noSecurity diff --git a/src/knx/application_program_object.cpp b/src/knx/application_program_object.cpp index c532d9a..477f79a 100644 --- a/src/knx/application_program_object.cpp +++ b/src/knx/application_program_object.cpp @@ -1,10 +1,10 @@ #include "application_program_object.h" -#include "bits.h" #include "data_property.h" #include "callback_property.h" #include "dptconvert.h" #include #include "util/logger.h" +#include "bits.h" #define LOGGER Logger::logger("ApplicationProgramObject") diff --git a/src/knx/application_program_object.h b/src/knx/application_program_object.h index 335fcb1..99b03d0 100644 --- a/src/knx/application_program_object.h +++ b/src/knx/application_program_object.h @@ -1,8 +1,13 @@ #pragma once #include "table_object.h" -#include "bits.h" +enum ParameterFloatEncodings +{ + Float_Enc_DPT9 = 0, // 2 Byte. See Chapter 3.7.2 section 3.10 (Datapoint Types 2-Octet Float Value) + Float_Enc_IEEE754Single = 1, // 4 Byte. C++ float + Float_Enc_IEEE754Double = 2, // 8 Byte. C++ double +}; class ApplicationProgramObject : public TableObject { public: diff --git a/src/knx/association_table_object.cpp b/src/knx/association_table_object.cpp index 9dd6f64..3d10096 100644 --- a/src/knx/association_table_object.cpp +++ b/src/knx/association_table_object.cpp @@ -1,9 +1,9 @@ #include #include "association_table_object.h" -#include "bits.h" #include "data_property.h" #include "util/logger.h" +#include "bits.h" #define LOGGER Logger::logger("AssociationTableObject") diff --git a/src/knx/bits.cpp b/src/knx/bits.cpp index 33a9180..50ff14c 100644 --- a/src/knx/bits.cpp +++ b/src/knx/bits.cpp @@ -8,7 +8,7 @@ const uint8_t* popByte(uint8_t& b, const uint8_t* data) return data; } - +#ifndef KNX_NO_PRINT std::string byte2hex(const uint8_t byte) { const char* hex = "0123456789ABCDEF"; @@ -33,7 +33,6 @@ std::string array2hex(const uint8_t* value, size_t length) return result; } -#ifndef KNX_NO_PRINT void printHex(const char* suffix, const uint8_t* data, size_t length, bool newline) { print(suffix); diff --git a/src/knx/bits.h b/src/knx/bits.h index 6bec014..00b4fca 100644 --- a/src/knx/bits.h +++ b/src/knx/bits.h @@ -70,11 +70,10 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode); #endif +#ifndef KNX_NO_PRINT std::string byte2hex(const uint8_t byte); std::string word2hex(const uint16_t value); std::string array2hex(const uint8_t* value, size_t length); - -#ifndef KNX_NO_PRINT void print(const char[]); void print(char); void print(unsigned char, int = DEC); @@ -103,6 +102,10 @@ #define print(...) do {} while(0) #define println(...) do {} while(0) #define printHex(...) do {} while(0) + #define byte2hex(...) "" + #define word2hex(...) "" + #define array2hex(...) "" + #define enum_name(...) "" #endif #ifdef KNX_ACTIVITYCALLBACK @@ -130,14 +133,6 @@ uint64_t sixBytesToUInt64(uint8_t* data); uint16_t crc16Ccitt(uint8_t* input, uint16_t length); uint16_t crc16Dnp(uint8_t* input, uint16_t length); -enum ParameterFloatEncodings -{ - Float_Enc_DPT9 = 0, // 2 Byte. See Chapter 3.7.2 section 3.10 (Datapoint Types 2-Octet Float Value) - Float_Enc_IEEE754Single = 1, // 4 Byte. C++ float - Float_Enc_IEEE754Double = 2, // 8 Byte. C++ double -}; - - #if defined(ARDUINO_ARCH_SAMD) // temporary undef until framework-arduino-samd > 1.8.9 is released. See https://github.com/arduino/ArduinoCore-samd/pull/399 for a PR should will probably address this #undef max diff --git a/src/knx/cemi_frame.cpp b/src/knx/cemi_frame.cpp index 9e64f4d..6a22aec 100644 --- a/src/knx/cemi_frame.cpp +++ b/src/knx/cemi_frame.cpp @@ -402,6 +402,7 @@ bool CemiFrame::valid() const std::string CemiFrame::toString() const { +#ifndef KNX_NO_PRINT std::string value = "DPDU:" + enum_name(frameType()) + " "; value += enum_name(systemBroadcast()) + " "; value += enum_name(ack()) + " "; @@ -416,4 +417,7 @@ std::string CemiFrame::toString() const value += format_ga(destinationAddress()); return value; +#else + return ""; +#endif } diff --git a/src/knx/data_link_layer.cpp b/src/knx/data_link_layer.cpp index ef8ce45..aec9b96 100644 --- a/src/knx/data_link_layer.cpp +++ b/src/knx/data_link_layer.cpp @@ -1,11 +1,11 @@ #include "data_link_layer.h" -#include "bits.h" #include "platform.h" #include "device_object.h" #include "cemi_server.h" #include "cemi_frame.h" #include "util/logger.h" +#include "bits.h" #define LOGGER Logger::logger("DataLinkLayer") diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index 8a69b7d..9e2058b 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -1,8 +1,8 @@ #include "group_object.h" -#include "bits.h" #include "string.h" #include "datapoint_types.h" #include "group_object_table_object.h" +#include "bits.h" #ifdef SMALL_GROUPOBJECT GroupObjectUpdatedHandler GroupObject::_updateHandlerStatic = 0; diff --git a/src/knx/group_object_table_object.cpp b/src/knx/group_object_table_object.cpp index e167921..044f097 100644 --- a/src/knx/group_object_table_object.cpp +++ b/src/knx/group_object_table_object.cpp @@ -2,9 +2,9 @@ #include "group_object_table_object.h" #include "group_object.h" -#include "bits.h" #include "data_property.h" #include "util/logger.h" +#include "bits.h" #define LOGGER Logger::logger("GroupObjectTableObject") diff --git a/src/knx/interface_object.cpp b/src/knx/interface_object.cpp index 93d5077..1b317d2 100644 --- a/src/knx/interface_object.cpp +++ b/src/knx/interface_object.cpp @@ -2,6 +2,7 @@ #include "interface_object.h" #include "data_property.h" +#include "bits.h" InterfaceObject::~InterfaceObject() { diff --git a/src/knx/interface_object.h b/src/knx/interface_object.h index fe9a371..9ea72e5 100644 --- a/src/knx/interface_object.h +++ b/src/knx/interface_object.h @@ -4,7 +4,6 @@ #include "property.h" #include "save_restore.h" #include "knx_types.h" -#include "bits.h" /** Enum for the type of an interface object. See Section 2.2 of knx:3/7/3 */ enum ObjectType diff --git a/src/knx/ip/knx_ip_config_dib.cpp b/src/knx/ip/knx_ip_config_dib.cpp index 0a56f06..fa3ac13 100644 --- a/src/knx/ip/knx_ip_config_dib.cpp +++ b/src/knx/ip/knx_ip_config_dib.cpp @@ -1,4 +1,5 @@ #include "knx_ip_config_dib.h" +#include "../bits.h" KnxIpConfigDIB::KnxIpConfigDIB(uint8_t* data, bool isCurrent) : KnxIpDIB(data) { diff --git a/src/knx/ip/knx_ip_config_dib.h b/src/knx/ip/knx_ip_config_dib.h index 9b64bf7..e85d525 100644 --- a/src/knx/ip/knx_ip_config_dib.h +++ b/src/knx/ip/knx_ip_config_dib.h @@ -1,6 +1,5 @@ #pragma once #include "knx_ip_dib.h" -#include "../bits.h" #define LEN_IP_CONFIG_DIB 16 #define LEN_IP_CURRENT_CONFIG_DIB 20 diff --git a/src/knx/ip/knx_ip_knx_addresses_dib.cpp b/src/knx/ip/knx_ip_knx_addresses_dib.cpp index 8e55394..c5239a3 100644 --- a/src/knx/ip/knx_ip_knx_addresses_dib.cpp +++ b/src/knx/ip/knx_ip_knx_addresses_dib.cpp @@ -1,4 +1,5 @@ #include "knx_ip_knx_addresses_dib.h" +#include "../bits.h" KnxIpKnxAddressesDIB::KnxIpKnxAddressesDIB(uint8_t* data) : KnxIpDIB(data) { diff --git a/src/knx/ip/knx_ip_knx_addresses_dib.h b/src/knx/ip/knx_ip_knx_addresses_dib.h index c24a5ac..e8ce38d 100644 --- a/src/knx/ip/knx_ip_knx_addresses_dib.h +++ b/src/knx/ip/knx_ip_knx_addresses_dib.h @@ -1,6 +1,5 @@ #pragma once #include "knx_ip_dib.h" -#include "../bits.h" class KnxIpKnxAddressesDIB : public KnxIpDIB { diff --git a/src/knx/ip/knx_ip_search_response_extended.cpp b/src/knx/ip/knx_ip_search_response_extended.cpp index db83559..4a56212 100644 --- a/src/knx/ip/knx_ip_search_response_extended.cpp +++ b/src/knx/ip/knx_ip_search_response_extended.cpp @@ -1,6 +1,8 @@ #include "knx_ip_search_response_extended.h" #include "service_families.h" +#include "../bits.h" + #define LEN_SERVICE_FAMILIES 2 #if MASK_VERSION == 0x091A #ifdef KNX_TUNNELING diff --git a/src/knx/ip/knx_ip_tunnel_connection.h b/src/knx/ip/knx_ip_tunnel_connection.h index c265447..65e0d0e 100644 --- a/src/knx/ip/knx_ip_tunnel_connection.h +++ b/src/knx/ip/knx_ip_tunnel_connection.h @@ -1,6 +1,5 @@ #pragma once #include "../platform.h" -#include "../bits.h" class KnxIpTunnelConnection { diff --git a/src/knx/ip/knx_ip_tunneling_info_dib.cpp b/src/knx/ip/knx_ip_tunneling_info_dib.cpp index 9b0197a..12a3bab 100644 --- a/src/knx/ip/knx_ip_tunneling_info_dib.cpp +++ b/src/knx/ip/knx_ip_tunneling_info_dib.cpp @@ -1,6 +1,8 @@ #include "knx_ip_tunneling_info_dib.h" #include "service_families.h" +#include "../bits.h" + KnxIpTunnelingInfoDIB::KnxIpTunnelingInfoDIB(uint8_t* data) : KnxIpDIB(data) { currentPos = data + 4; diff --git a/src/knx/ip/knx_ip_tunneling_info_dib.h b/src/knx/ip/knx_ip_tunneling_info_dib.h index 6e0b54c..623d6d9 100644 --- a/src/knx/ip/knx_ip_tunneling_info_dib.h +++ b/src/knx/ip/knx_ip_tunneling_info_dib.h @@ -1,6 +1,5 @@ #pragma once #include "knx_ip_dib.h" -#include "../bits.h" #include "service_families.h" class KnxIpTunnelingInfoDIB : public KnxIpDIB diff --git a/src/knx/knx_types.cpp b/src/knx/knx_types.cpp index 6049f38..404b1fc 100644 --- a/src/knx/knx_types.cpp +++ b/src/knx/knx_types.cpp @@ -1,5 +1,5 @@ #include "knx_types.h" - +#ifndef KNX_NO_PRINT const string enum_name(const LCCONFIG enum_val) { switch (enum_val) @@ -700,3 +700,4 @@ const string format_ga(uint16_t ga) { return to_string(ga & 0xF800 >> 23) + "/" + to_string(ga & 0x70 >> 16) + "/" + to_string(ga & 0x00FF); } +#endif \ No newline at end of file diff --git a/src/knx/network_layer_device.cpp b/src/knx/network_layer_device.cpp index 067d109..db38f78 100644 --- a/src/knx/network_layer_device.cpp +++ b/src/knx/network_layer_device.cpp @@ -2,8 +2,8 @@ #include "device_object.h" #include "tpdu.h" #include "cemi_frame.h" -#include "bits.h" #include "util/logger.h" +#include "bits.h" #define LOGGER Logger::logger("NetworkLayerDevice") diff --git a/src/knx/platform/cc1310_platform.cpp b/src/knx/platform/cc1310_platform.cpp index 3266927..17fda5a 100644 --- a/src/knx/platform/cc1310_platform.cpp +++ b/src/knx/platform/cc1310_platform.cpp @@ -390,6 +390,11 @@ void println(unsigned int num, int base) println(); } +void print(double num) +{ + printf("%f", num); +} + void println(long num, int base) { print(num, base); @@ -527,7 +532,7 @@ uint8_t* CC1310Platform::getEepromBuffer(uint32_t size) NVS_read(nvsHandle, 0, (void*) NVS_buffer, size); - for (int i = 0; i < size; i++) + for (uint32_t i = 0; i < size; i++) { if (NVS_buffer[i] != 0) { diff --git a/src/knx/property.cpp b/src/knx/property.cpp index 006907c..6584e3f 100644 --- a/src/knx/property.cpp +++ b/src/knx/property.cpp @@ -244,7 +244,7 @@ void Property::state(uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t (void)resultData; resultLength = 0; } - +#ifndef KNX_NO_PRINT const string enum_name(const PropertyDataType enum_val) { switch (enum_val) @@ -863,3 +863,4 @@ const string enum_name(const AccessLevel enum_val) return to_string(enum_val); } +#endif \ No newline at end of file diff --git a/src/knx/secure_application_layer.h b/src/knx/secure_application_layer.h index c162896..c60e93e 100644 --- a/src/knx/secure_application_layer.h +++ b/src/knx/secure_application_layer.h @@ -4,7 +4,6 @@ #include #include "knx_types.h" #include "apdu.h" -#include "bits.h" #include "util/simple_map.h" class DeviceObject; @@ -74,7 +73,6 @@ class SecureApplicationLayer : public ApplicationLayer { if ((cmpAddr.addrType == AddrType::unknown) || (addrType == AddrType::unknown)) { - println("Unknown address type detected!"); return false; } diff --git a/src/knx/tpdu.cpp b/src/knx/tpdu.cpp index 2fd400e..6c1d0e1 100644 --- a/src/knx/tpdu.cpp +++ b/src/knx/tpdu.cpp @@ -120,6 +120,7 @@ CemiFrame& TPDU::frame() const std::string TPDU::toString() const { +#ifndef KNX_NO_PRINT std::string value = std::string("TPDU: ") + enum_name(type()) + " "; if (control()) @@ -129,4 +130,7 @@ const std::string TPDU::toString() const value += "numbered sequence: " + to_string(sequenceNumber()); return value; +#else + return ""; +#endif } \ No newline at end of file diff --git a/src/knx/transport_layer.cpp b/src/knx/transport_layer.cpp index 8094967..98d1231 100644 --- a/src/knx/transport_layer.cpp +++ b/src/knx/transport_layer.cpp @@ -4,9 +4,9 @@ #include "network_layer.h" #include "application_layer.h" #include "platform.h" -#include "bits.h" #include "util/logger.h" #include +#include "bits.h" #define LOGGER Logger::logger("TransportLayer") diff --git a/src/knx/util/logger.cpp b/src/knx/util/logger.cpp index 59ef1fd..b1e0ab5 100644 --- a/src/knx/util/logger.cpp +++ b/src/knx/util/logger.cpp @@ -1,5 +1,7 @@ #include "logger.h" +#include "../bits.h" + Map Logger::_loggers; Logger Logger::_logger; @@ -123,7 +125,7 @@ void Logger::log(LogType type, const char* format, va_list args) println(); #endif } - +#ifndef KNX_NO_PRINT const std::string Logger::enum_name(LogType type) { switch (type) @@ -149,3 +151,4 @@ const std::string Logger::enum_name(LogType type) return std::to_string(type); } +#endif diff --git a/src/knx/util/logger.h b/src/knx/util/logger.h index 6fabb31..227d5ca 100644 --- a/src/knx/util/logger.h +++ b/src/knx/util/logger.h @@ -1,4 +1,3 @@ -#include "../bits.h" #include #include #include "simple_map.h" @@ -17,7 +16,7 @@ class Logger void exception(const std::string message, ...); protected: Logger() {} - virtual void log(LogType type, const char* format, va_list args); + void log(LogType type, const char* format, va_list args); void name(std::string value) { _name = value; } private: const std::string enum_name(LogType type); diff --git a/src/knx/util/simple_map.h b/src/knx/util/simple_map.h index c04a79f..658ba66 100644 --- a/src/knx/util/simple_map.h +++ b/src/knx/util/simple_map.h @@ -1,5 +1,7 @@ #pragma once +#include + // Provides a simple unordered map which is based on two arrays of different data types, namely K and V. // One array is used for the keys, the other array is used for the values. // Tracking of free/occupied slots in the arrays is realized by a bitmask of size uint64_t. diff --git a/src/knx_facade.h b/src/knx_facade.h index 09fe25c..67e95da 100644 --- a/src/knx_facade.h +++ b/src/knx_facade.h @@ -1,6 +1,5 @@ #pragma once -#include "knx/bits.h" #include "knx/util/logger.h" #include "knx/config.h" #include "knx/bau.h" @@ -10,6 +9,8 @@ #include "knx/bau2920.h" #include "knx/bau57B0.h" +#include "knx/bits.h" + #ifndef USERDATA_SAVE_SIZE #define USERDATA_SAVE_SIZE 0 #endif