reduce footprint with KNX_NO_PRINT

This commit is contained in:
Thomas Kunze 2024-08-19 18:07:27 +02:00
parent 546300d705
commit 9294257985
34 changed files with 61 additions and 36 deletions

View File

@ -14,6 +14,7 @@ namespace py = pybind11;
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include "knx/bits.h"
#include "knx/platform/linux_platform.h" #include "knx/platform/linux_platform.h"
#include "knx/bau57B0.h" #include "knx/bau57B0.h"
#include "knx/group_object_table_object.h" #include "knx/group_object_table_object.h"

View File

@ -1,9 +1,9 @@
#include <cstring> #include <cstring>
#include "address_table_object.h" #include "address_table_object.h"
#include "bits.h"
#include "data_property.h" #include "data_property.h"
#include "util/logger.h" #include "util/logger.h"
#include "bits.h"
#define LOGGER Logger::logger("AddressTableObject") #define LOGGER Logger::logger("AddressTableObject")

View File

@ -42,6 +42,7 @@ uint8_t APDU::length() const
string APDU::toString() const string APDU::toString() const
{ {
#ifndef KNX_NO_PRINT
string value = "APDU: " + enum_name(type()) + " "; string value = "APDU: " + enum_name(type()) + " ";
value += byte2hex(_data[0] & 0x3); value += byte2hex(_data[0] & 0x3);
@ -54,4 +55,7 @@ string APDU::toString() const
} }
return value; return value;
#else
return "";
#endif
} }

View File

@ -5,9 +5,10 @@
#include "apdu.h" #include "apdu.h"
#include "bau.h" #include "bau.h"
#include "string.h" #include "string.h"
#include "bits.h"
#include <stdio.h> #include <stdio.h>
#include "util/logger.h" #include "util/logger.h"
#include "bits.h"
#define LOGGER Logger::logger("ApplicationLayer") #define LOGGER Logger::logger("ApplicationLayer")
const SecurityControl ApplicationLayer::noSecurity const SecurityControl ApplicationLayer::noSecurity

View File

@ -1,10 +1,10 @@
#include "application_program_object.h" #include "application_program_object.h"
#include "bits.h"
#include "data_property.h" #include "data_property.h"
#include "callback_property.h" #include "callback_property.h"
#include "dptconvert.h" #include "dptconvert.h"
#include <cstring> #include <cstring>
#include "util/logger.h" #include "util/logger.h"
#include "bits.h"
#define LOGGER Logger::logger("ApplicationProgramObject") #define LOGGER Logger::logger("ApplicationProgramObject")

View File

@ -1,8 +1,13 @@
#pragma once #pragma once
#include "table_object.h" #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 class ApplicationProgramObject : public TableObject
{ {
public: public:

View File

@ -1,9 +1,9 @@
#include <cstring> #include <cstring>
#include "association_table_object.h" #include "association_table_object.h"
#include "bits.h"
#include "data_property.h" #include "data_property.h"
#include "util/logger.h" #include "util/logger.h"
#include "bits.h"
#define LOGGER Logger::logger("AssociationTableObject") #define LOGGER Logger::logger("AssociationTableObject")

View File

@ -8,7 +8,7 @@ const uint8_t* popByte(uint8_t& b, const uint8_t* data)
return data; return data;
} }
#ifndef KNX_NO_PRINT
std::string byte2hex(const uint8_t byte) std::string byte2hex(const uint8_t byte)
{ {
const char* hex = "0123456789ABCDEF"; const char* hex = "0123456789ABCDEF";
@ -33,7 +33,6 @@ std::string array2hex(const uint8_t* value, size_t length)
return result; return result;
} }
#ifndef KNX_NO_PRINT
void printHex(const char* suffix, const uint8_t* data, size_t length, bool newline) void printHex(const char* suffix, const uint8_t* data, size_t length, bool newline)
{ {
print(suffix); print(suffix);

View File

@ -70,11 +70,10 @@
void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode); void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode);
#endif #endif
#ifndef KNX_NO_PRINT
std::string byte2hex(const uint8_t byte); std::string byte2hex(const uint8_t byte);
std::string word2hex(const uint16_t value); std::string word2hex(const uint16_t value);
std::string array2hex(const uint8_t* value, size_t length); std::string array2hex(const uint8_t* value, size_t length);
#ifndef KNX_NO_PRINT
void print(const char[]); void print(const char[]);
void print(char); void print(char);
void print(unsigned char, int = DEC); void print(unsigned char, int = DEC);
@ -103,6 +102,10 @@
#define print(...) do {} while(0) #define print(...) do {} while(0)
#define println(...) do {} while(0) #define println(...) do {} while(0)
#define printHex(...) do {} while(0) #define printHex(...) do {} while(0)
#define byte2hex(...) ""
#define word2hex(...) ""
#define array2hex(...) ""
#define enum_name(...) ""
#endif #endif
#ifdef KNX_ACTIVITYCALLBACK #ifdef KNX_ACTIVITYCALLBACK
@ -130,14 +133,6 @@ uint64_t sixBytesToUInt64(uint8_t* data);
uint16_t crc16Ccitt(uint8_t* input, uint16_t length); uint16_t crc16Ccitt(uint8_t* input, uint16_t length);
uint16_t crc16Dnp(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) #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 // 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 #undef max

View File

@ -402,6 +402,7 @@ bool CemiFrame::valid() const
std::string CemiFrame::toString() const std::string CemiFrame::toString() const
{ {
#ifndef KNX_NO_PRINT
std::string value = "DPDU:" + enum_name(frameType()) + " "; std::string value = "DPDU:" + enum_name(frameType()) + " ";
value += enum_name(systemBroadcast()) + " "; value += enum_name(systemBroadcast()) + " ";
value += enum_name(ack()) + " "; value += enum_name(ack()) + " ";
@ -416,4 +417,7 @@ std::string CemiFrame::toString() const
value += format_ga(destinationAddress()); value += format_ga(destinationAddress());
return value; return value;
#else
return "";
#endif
} }

View File

@ -1,11 +1,11 @@
#include "data_link_layer.h" #include "data_link_layer.h"
#include "bits.h"
#include "platform.h" #include "platform.h"
#include "device_object.h" #include "device_object.h"
#include "cemi_server.h" #include "cemi_server.h"
#include "cemi_frame.h" #include "cemi_frame.h"
#include "util/logger.h" #include "util/logger.h"
#include "bits.h"
#define LOGGER Logger::logger("DataLinkLayer") #define LOGGER Logger::logger("DataLinkLayer")

View File

@ -1,8 +1,8 @@
#include "group_object.h" #include "group_object.h"
#include "bits.h"
#include "string.h" #include "string.h"
#include "datapoint_types.h" #include "datapoint_types.h"
#include "group_object_table_object.h" #include "group_object_table_object.h"
#include "bits.h"
#ifdef SMALL_GROUPOBJECT #ifdef SMALL_GROUPOBJECT
GroupObjectUpdatedHandler GroupObject::_updateHandlerStatic = 0; GroupObjectUpdatedHandler GroupObject::_updateHandlerStatic = 0;

View File

@ -2,9 +2,9 @@
#include "group_object_table_object.h" #include "group_object_table_object.h"
#include "group_object.h" #include "group_object.h"
#include "bits.h"
#include "data_property.h" #include "data_property.h"
#include "util/logger.h" #include "util/logger.h"
#include "bits.h"
#define LOGGER Logger::logger("GroupObjectTableObject") #define LOGGER Logger::logger("GroupObjectTableObject")

View File

@ -2,6 +2,7 @@
#include "interface_object.h" #include "interface_object.h"
#include "data_property.h" #include "data_property.h"
#include "bits.h"
InterfaceObject::~InterfaceObject() InterfaceObject::~InterfaceObject()
{ {

View File

@ -4,7 +4,6 @@
#include "property.h" #include "property.h"
#include "save_restore.h" #include "save_restore.h"
#include "knx_types.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 for the type of an interface object. See Section 2.2 of knx:3/7/3 */
enum ObjectType enum ObjectType

View File

@ -1,4 +1,5 @@
#include "knx_ip_config_dib.h" #include "knx_ip_config_dib.h"
#include "../bits.h"
KnxIpConfigDIB::KnxIpConfigDIB(uint8_t* data, bool isCurrent) : KnxIpDIB(data) KnxIpConfigDIB::KnxIpConfigDIB(uint8_t* data, bool isCurrent) : KnxIpDIB(data)
{ {

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "knx_ip_dib.h" #include "knx_ip_dib.h"
#include "../bits.h"
#define LEN_IP_CONFIG_DIB 16 #define LEN_IP_CONFIG_DIB 16
#define LEN_IP_CURRENT_CONFIG_DIB 20 #define LEN_IP_CURRENT_CONFIG_DIB 20

View File

@ -1,4 +1,5 @@
#include "knx_ip_knx_addresses_dib.h" #include "knx_ip_knx_addresses_dib.h"
#include "../bits.h"
KnxIpKnxAddressesDIB::KnxIpKnxAddressesDIB(uint8_t* data) : KnxIpDIB(data) KnxIpKnxAddressesDIB::KnxIpKnxAddressesDIB(uint8_t* data) : KnxIpDIB(data)
{ {

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "knx_ip_dib.h" #include "knx_ip_dib.h"
#include "../bits.h"
class KnxIpKnxAddressesDIB : public KnxIpDIB class KnxIpKnxAddressesDIB : public KnxIpDIB
{ {

View File

@ -1,6 +1,8 @@
#include "knx_ip_search_response_extended.h" #include "knx_ip_search_response_extended.h"
#include "service_families.h" #include "service_families.h"
#include "../bits.h"
#define LEN_SERVICE_FAMILIES 2 #define LEN_SERVICE_FAMILIES 2
#if MASK_VERSION == 0x091A #if MASK_VERSION == 0x091A
#ifdef KNX_TUNNELING #ifdef KNX_TUNNELING

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "../platform.h" #include "../platform.h"
#include "../bits.h"
class KnxIpTunnelConnection class KnxIpTunnelConnection
{ {

View File

@ -1,6 +1,8 @@
#include "knx_ip_tunneling_info_dib.h" #include "knx_ip_tunneling_info_dib.h"
#include "service_families.h" #include "service_families.h"
#include "../bits.h"
KnxIpTunnelingInfoDIB::KnxIpTunnelingInfoDIB(uint8_t* data) : KnxIpDIB(data) KnxIpTunnelingInfoDIB::KnxIpTunnelingInfoDIB(uint8_t* data) : KnxIpDIB(data)
{ {
currentPos = data + 4; currentPos = data + 4;

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "knx_ip_dib.h" #include "knx_ip_dib.h"
#include "../bits.h"
#include "service_families.h" #include "service_families.h"
class KnxIpTunnelingInfoDIB : public KnxIpDIB class KnxIpTunnelingInfoDIB : public KnxIpDIB

View File

@ -1,5 +1,5 @@
#include "knx_types.h" #include "knx_types.h"
#ifndef KNX_NO_PRINT
const string enum_name(const LCCONFIG enum_val) const string enum_name(const LCCONFIG enum_val)
{ {
switch (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); return to_string(ga & 0xF800 >> 23) + "/" + to_string(ga & 0x70 >> 16) + "/" + to_string(ga & 0x00FF);
} }
#endif

View File

@ -2,8 +2,8 @@
#include "device_object.h" #include "device_object.h"
#include "tpdu.h" #include "tpdu.h"
#include "cemi_frame.h" #include "cemi_frame.h"
#include "bits.h"
#include "util/logger.h" #include "util/logger.h"
#include "bits.h"
#define LOGGER Logger::logger("NetworkLayerDevice") #define LOGGER Logger::logger("NetworkLayerDevice")

View File

@ -390,6 +390,11 @@ void println(unsigned int num, int base)
println(); println();
} }
void print(double num)
{
printf("%f", num);
}
void println(long num, int base) void println(long num, int base)
{ {
print(num, base); print(num, base);
@ -527,7 +532,7 @@ uint8_t* CC1310Platform::getEepromBuffer(uint32_t size)
NVS_read(nvsHandle, 0, (void*) NVS_buffer, 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) if (NVS_buffer[i] != 0)
{ {

View File

@ -244,7 +244,7 @@ void Property::state(uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t
(void)resultData; (void)resultData;
resultLength = 0; resultLength = 0;
} }
#ifndef KNX_NO_PRINT
const string enum_name(const PropertyDataType enum_val) const string enum_name(const PropertyDataType enum_val)
{ {
switch (enum_val) switch (enum_val)
@ -863,3 +863,4 @@ const string enum_name(const AccessLevel enum_val)
return to_string(enum_val); return to_string(enum_val);
} }
#endif

View File

@ -4,7 +4,6 @@
#include <stdint.h> #include <stdint.h>
#include "knx_types.h" #include "knx_types.h"
#include "apdu.h" #include "apdu.h"
#include "bits.h"
#include "util/simple_map.h" #include "util/simple_map.h"
class DeviceObject; class DeviceObject;
@ -74,7 +73,6 @@ class SecureApplicationLayer : public ApplicationLayer
{ {
if ((cmpAddr.addrType == AddrType::unknown) || (addrType == AddrType::unknown)) if ((cmpAddr.addrType == AddrType::unknown) || (addrType == AddrType::unknown))
{ {
println("Unknown address type detected!");
return false; return false;
} }

View File

@ -120,6 +120,7 @@ CemiFrame& TPDU::frame()
const std::string TPDU::toString() const const std::string TPDU::toString() const
{ {
#ifndef KNX_NO_PRINT
std::string value = std::string("TPDU: ") + enum_name(type()) + " "; std::string value = std::string("TPDU: ") + enum_name(type()) + " ";
if (control()) if (control())
@ -129,4 +130,7 @@ const std::string TPDU::toString() const
value += "numbered sequence: " + to_string(sequenceNumber()); value += "numbered sequence: " + to_string(sequenceNumber());
return value; return value;
#else
return "";
#endif
} }

View File

@ -4,9 +4,9 @@
#include "network_layer.h" #include "network_layer.h"
#include "application_layer.h" #include "application_layer.h"
#include "platform.h" #include "platform.h"
#include "bits.h"
#include "util/logger.h" #include "util/logger.h"
#include <stdio.h> #include <stdio.h>
#include "bits.h"
#define LOGGER Logger::logger("TransportLayer") #define LOGGER Logger::logger("TransportLayer")

View File

@ -1,5 +1,7 @@
#include "logger.h" #include "logger.h"
#include "../bits.h"
Map<std::string, Logger::LogType, 64> Logger::_loggers; Map<std::string, Logger::LogType, 64> Logger::_loggers;
Logger Logger::_logger; Logger Logger::_logger;
@ -123,7 +125,7 @@ void Logger::log(LogType type, const char* format, va_list args)
println(); println();
#endif #endif
} }
#ifndef KNX_NO_PRINT
const std::string Logger::enum_name(LogType type) const std::string Logger::enum_name(LogType type)
{ {
switch (type) switch (type)
@ -149,3 +151,4 @@ const std::string Logger::enum_name(LogType type)
return std::to_string(type); return std::to_string(type);
} }
#endif

View File

@ -1,4 +1,3 @@
#include "../bits.h"
#include <stdarg.h> #include <stdarg.h>
#include <string> #include <string>
#include "simple_map.h" #include "simple_map.h"
@ -17,7 +16,7 @@ class Logger
void exception(const std::string message, ...); void exception(const std::string message, ...);
protected: protected:
Logger() {} 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; } void name(std::string value) { _name = value; }
private: private:
const std::string enum_name(LogType type); const std::string enum_name(LogType type);

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <stdint.h>
// Provides a simple unordered map which is based on two arrays of different data types, namely K and V. // 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. // 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. // Tracking of free/occupied slots in the arrays is realized by a bitmask of size uint64_t.

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "knx/bits.h"
#include "knx/util/logger.h" #include "knx/util/logger.h"
#include "knx/config.h" #include "knx/config.h"
#include "knx/bau.h" #include "knx/bau.h"
@ -10,6 +9,8 @@
#include "knx/bau2920.h" #include "knx/bau2920.h"
#include "knx/bau57B0.h" #include "knx/bau57B0.h"
#include "knx/bits.h"
#ifndef USERDATA_SAVE_SIZE #ifndef USERDATA_SAVE_SIZE
#define USERDATA_SAVE_SIZE 0 #define USERDATA_SAVE_SIZE 0
#endif #endif