Skip to content

Commit

Permalink
reduce footprint with KNX_NO_PRINT
Browse files Browse the repository at this point in the history
  • Loading branch information
thelsing committed Aug 19, 2024
1 parent 546300d commit 9294257
Show file tree
Hide file tree
Showing 34 changed files with 61 additions and 36 deletions.
1 change: 1 addition & 0 deletions examples/knxPython/knxmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace py = pybind11;
#include <vector>
#include <algorithm>

#include "knx/bits.h"
#include "knx/platform/linux_platform.h"
#include "knx/bau57B0.h"
#include "knx/group_object_table_object.h"
Expand Down
2 changes: 1 addition & 1 deletion src/knx/address_table_object.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <cstring>

#include "address_table_object.h"
#include "bits.h"
#include "data_property.h"
#include "util/logger.h"
#include "bits.h"

#define LOGGER Logger::logger("AddressTableObject")

Expand Down
4 changes: 4 additions & 0 deletions src/knx/apdu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -54,4 +55,7 @@ string APDU::toString() const
}

return value;
#else
return "";
#endif
}
3 changes: 2 additions & 1 deletion src/knx/application_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#include "apdu.h"
#include "bau.h"
#include "string.h"
#include "bits.h"
#include <stdio.h>
#include "util/logger.h"
#include "bits.h"

#define LOGGER Logger::logger("ApplicationLayer")

const SecurityControl ApplicationLayer::noSecurity
Expand Down
2 changes: 1 addition & 1 deletion src/knx/application_program_object.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "application_program_object.h"
#include "bits.h"
#include "data_property.h"
#include "callback_property.h"
#include "dptconvert.h"
#include <cstring>
#include "util/logger.h"
#include "bits.h"

#define LOGGER Logger::logger("ApplicationProgramObject")

Expand Down
7 changes: 6 additions & 1 deletion src/knx/application_program_object.h
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/knx/association_table_object.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <cstring>

#include "association_table_object.h"
#include "bits.h"
#include "data_property.h"
#include "util/logger.h"
#include "bits.h"

#define LOGGER Logger::logger("AssociationTableObject")

Expand Down
3 changes: 1 addition & 2 deletions src/knx/bits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand Down
15 changes: 5 additions & 10 deletions src/knx/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/knx/cemi_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) + " ";
Expand All @@ -416,4 +417,7 @@ std::string CemiFrame::toString() const
value += format_ga(destinationAddress());

return value;
#else
return "";
#endif
}
2 changes: 1 addition & 1 deletion src/knx/data_link_layer.cpp
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
2 changes: 1 addition & 1 deletion src/knx/group_object.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/knx/group_object_table_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions src/knx/interface_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "interface_object.h"
#include "data_property.h"
#include "bits.h"

InterfaceObject::~InterfaceObject()
{
Expand Down
1 change: 0 additions & 1 deletion src/knx/interface_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/knx/ip/knx_ip_config_dib.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "knx_ip_config_dib.h"
#include "../bits.h"

KnxIpConfigDIB::KnxIpConfigDIB(uint8_t* data, bool isCurrent) : KnxIpDIB(data)
{
Expand Down
1 change: 0 additions & 1 deletion src/knx/ip/knx_ip_config_dib.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/knx/ip/knx_ip_knx_addresses_dib.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "knx_ip_knx_addresses_dib.h"
#include "../bits.h"

KnxIpKnxAddressesDIB::KnxIpKnxAddressesDIB(uint8_t* data) : KnxIpDIB(data)
{
Expand Down
1 change: 0 additions & 1 deletion src/knx/ip/knx_ip_knx_addresses_dib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "knx_ip_dib.h"
#include "../bits.h"

class KnxIpKnxAddressesDIB : public KnxIpDIB
{
Expand Down
2 changes: 2 additions & 0 deletions src/knx/ip/knx_ip_search_response_extended.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/knx/ip/knx_ip_tunnel_connection.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "../platform.h"
#include "../bits.h"

class KnxIpTunnelConnection
{
Expand Down
2 changes: 2 additions & 0 deletions src/knx/ip/knx_ip_tunneling_info_dib.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/knx/ip/knx_ip_tunneling_info_dib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "knx_ip_dib.h"
#include "../bits.h"
#include "service_families.h"

class KnxIpTunnelingInfoDIB : public KnxIpDIB
Expand Down
3 changes: 2 additions & 1 deletion src/knx/knx_types.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "knx_types.h"

#ifndef KNX_NO_PRINT
const string enum_name(const LCCONFIG enum_val)
{
switch (enum_val)
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/knx/network_layer_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
7 changes: 6 additions & 1 deletion src/knx/platform/cc1310_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion src/knx/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -863,3 +863,4 @@ const string enum_name(const AccessLevel enum_val)

return to_string(enum_val);
}
#endif
2 changes: 0 additions & 2 deletions src/knx/secure_application_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <stdint.h>
#include "knx_types.h"
#include "apdu.h"
#include "bits.h"
#include "util/simple_map.h"

class DeviceObject;
Expand Down Expand Up @@ -74,7 +73,6 @@ class SecureApplicationLayer : public ApplicationLayer
{
if ((cmpAddr.addrType == AddrType::unknown) || (addrType == AddrType::unknown))
{
println("Unknown address type detected!");
return false;
}

Expand Down
4 changes: 4 additions & 0 deletions src/knx/tpdu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -129,4 +130,7 @@ const std::string TPDU::toString() const
value += "numbered sequence: " + to_string(sequenceNumber());

return value;
#else
return "";
#endif
}
2 changes: 1 addition & 1 deletion src/knx/transport_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "network_layer.h"
#include "application_layer.h"
#include "platform.h"
#include "bits.h"
#include "util/logger.h"
#include <stdio.h>
#include "bits.h"

#define LOGGER Logger::logger("TransportLayer")

Expand Down
5 changes: 4 additions & 1 deletion src/knx/util/logger.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "logger.h"

#include "../bits.h"

Map<std::string, Logger::LogType, 64> Logger::_loggers;
Logger Logger::_logger;

Expand Down Expand Up @@ -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)
Expand All @@ -149,3 +151,4 @@ const std::string Logger::enum_name(LogType type)

return std::to_string(type);
}
#endif
Loading

0 comments on commit 9294257

Please sign in to comment.