Skip to content

Commit

Permalink
no more std::string
Browse files Browse the repository at this point in the history
  • Loading branch information
thelsing committed Aug 19, 2024
1 parent e0f0b49 commit 1b68cd0
Show file tree
Hide file tree
Showing 32 changed files with 293 additions and 232 deletions.
4 changes: 3 additions & 1 deletion examples/knx-cc1310/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ set(${PROJECT_NAME}_SOURCES
../../src/knx_facade.h
../../src/knx/platform/cc1310_platform.cpp
../../src/knx_facade.cpp
../../src/knx/knx_types.h
../../src/knx/knx_types.cpp
./RTT/SEGGER_RTT_Conf.h
./RTT/SEGGER_RTT_printf.c
./RTT/SEGGER_RTT.c
Expand All @@ -189,7 +191,7 @@ include_directories(
${SimpleLinkCC13X0SDK_INCLUDE_DIRS}
)

add_definitions(-DMASK_VERSION=0x27B0 -Wno-unknown-pragmas)
add_definitions(-DMASK_VERSION=0x27B0 -Wno-unknown-pragmas -DKNX_NO_PRINT)

add_executable(${PROJECT_NAME}
${${PROJECT_NAME}_SOURCES}
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ knx/tpdu.cpp
knx/tpdu.h
knx/tpuart_data_link_layer.cpp
knx/tpuart_data_link_layer.h
knx/tp_frame.cpp
knx/tp_frame.h
knx/transport_layer.cpp
knx/transport_layer.h
Expand Down
16 changes: 7 additions & 9 deletions src/knx/apdu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,20 @@ uint8_t APDU::length() const
return _frame.npdu().octetCount();
}

string APDU::toString() const
void APDU::printIt() const
{
#ifndef KNX_NO_PRINT
string value = std::string("APDU: ") + enum_name(type()) + " ";
value += byte2hex(_data[0] & 0x3);
print("APDU: ");
print(enum_name(type()));
print(" ");
print(_data[0] & 0x3, HEX);

for (uint8_t i = 1; i < length() + 1; ++i)
{
if (i)
value += " ";
print(" ");

value += byte2hex(_data[i]);
print(_data[i], HEX);
}

return value;
#else
return "";
#endif
}
8 changes: 4 additions & 4 deletions src/knx/apdu.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#pragma once

#include <stdint.h>
#include <string>
#include "util/logger.h"
#include "knx_types.h"

class CemiFrame;

/**
* This class represents an Application Protocol Data Unit. It is part of a CemiFrame.
*/
class APDU
class APDU : public IPrintable
{
friend class CemiFrame;

Expand All @@ -35,9 +35,9 @@ class APDU
*/
uint8_t length() const;
/**
* Convert APDU to string.
* print APDU
*/
std::string toString() const;
void printIt() const;

protected:
/**
Expand Down
18 changes: 9 additions & 9 deletions src/knx/application_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priori

void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu, const SecurityControl& secCtrl)
{
LOGGER.info("dataGroupIndication %s", apdu.toString().c_str());
LOGGER.info("dataGroupIndication ", apdu);

if (_assocTable == nullptr)
return;
Expand Down Expand Up @@ -92,7 +92,7 @@ void ApplicationLayer::dataGroupConfirm(AckType ack, HopCountType hopType, Prior

void ApplicationLayer::dataGroupConfirm(AckType ack, HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu, const SecurityControl& secCtrl, bool status)
{
LOGGER.info("dataGroupConfirm %s", apdu.toString().c_str());
LOGGER.info("dataGroupConfirm ", apdu);

switch (apdu.type())
{
Expand Down Expand Up @@ -130,7 +130,7 @@ void ApplicationLayer::dataBroadcastIndication(HopCountType hopType, Priority pr

void ApplicationLayer::dataBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, APDU& apdu, const SecurityControl& secCtrl)
{
LOGGER.info("dataBroadcastIndication %s", apdu.toString().c_str());
LOGGER.info("dataBroadcastIndication ", apdu);
uint8_t* data = apdu.data();

switch (apdu.type())
Expand Down Expand Up @@ -190,7 +190,7 @@ void ApplicationLayer::dataBroadcastConfirm(AckType ack, HopCountType hopType, P

void ApplicationLayer::dataBroadcastConfirm(AckType ack, HopCountType hopType, Priority priority, APDU& apdu, const SecurityControl& secCtrl, bool status)
{
LOGGER.info("dataBroadcastConfirm %s", apdu.toString().c_str());
LOGGER.info("dataBroadcastConfirm ", apdu);
uint8_t* data = apdu.data();

switch (apdu.type())
Expand Down Expand Up @@ -245,7 +245,7 @@ void ApplicationLayer::dataSystemBroadcastIndication(HopCountType hopType, Prior

void ApplicationLayer::dataSystemBroadcastIndication(HopCountType hopType, Priority priority, uint16_t source, APDU& apdu, const SecurityControl& secCtrl)
{
LOGGER.info("dataSystemBroadcastIndication %s", apdu.toString().c_str());
LOGGER.info("dataSystemBroadcastIndication ", apdu);
const uint8_t* data = apdu.data();

switch (apdu.type())
Expand Down Expand Up @@ -294,7 +294,7 @@ void ApplicationLayer::dataSystemBroadcastConfirm(HopCountType hopType, Priority

void ApplicationLayer::dataSystemBroadcastConfirm(HopCountType hopType, Priority priority, APDU& apdu, const SecurityControl& secCtrl, bool status)
{
LOGGER.info("dataSystemBroadcastConfirm %s", apdu.toString().c_str());
LOGGER.info("dataSystemBroadcastConfirm ", apdu);
const uint8_t* data = apdu.data();

switch (apdu.type())
Expand Down Expand Up @@ -1118,7 +1118,7 @@ void ApplicationLayer::userMemorySend(ApduType type, AckType ack, Priority prior

void ApplicationLayer::individualIndication(HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu, const SecurityControl& secCtrl)
{
LOGGER.info("individualIndication %s", apdu.toString().c_str());
LOGGER.info("individualIndication ", apdu);
uint8_t* data = apdu.data();

switch (apdu.type())
Expand Down Expand Up @@ -1374,13 +1374,13 @@ void ApplicationLayer::individualIndication(HopCountType hopType, Priority prior
}

default:
LOGGER.warning("Individual-indication: unhandled APDU-Type: %s", apdu.toString().c_str());
LOGGER.warning("Individual-indication: unhandled APDU-Type: ", apdu);
}
}

void ApplicationLayer::individualConfirm(AckType ack, HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu, const SecurityControl& secCtrl, bool status)
{
LOGGER.info("individualConfirm %s", apdu.toString().c_str());
LOGGER.info("individualConfirm ", apdu);
uint8_t* data = apdu.data();

switch (apdu.type())
Expand Down
24 changes: 1 addition & 23 deletions src/knx/bits.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdint.h>
#include "bits.h"
#include <cstring> // for memcpy()

Expand All @@ -9,29 +10,6 @@ const uint8_t* popByte(uint8_t& b, const uint8_t* data)
}

#ifndef KNX_NO_PRINT
std::string byte2hex(const uint8_t byte)
{
const char* hex = "0123456789ABCDEF";
char out[3] = {0};
out[0] = hex[(byte >> 4) & 0xF];
out[1] = hex[ byte & 0xF];
return std::string(out);
}

std::string word2hex(const uint16_t value)
{
return byte2hex((uint8_t) (value & 0xFF00) >> 8) + byte2hex((uint8_t) (value & 0xFF));
}

std::string array2hex(const uint8_t* value, size_t length)
{
std::string result("");

for (size_t i = 0; i < length; i++)
result += byte2hex(value[i]) + " ";

return result;
}

void printHex(const char* suffix, const uint8_t* data, size_t length, bool newline)
{
Expand Down
6 changes: 1 addition & 5 deletions src/knx/bits.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include <string>
#include <stdint.h>

#if defined(__linux__)
#include <arpa/inet.h>
Expand Down Expand Up @@ -71,9 +70,6 @@
#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);
void print(const char[]);
void print(char);
void print(unsigned char, int = DEC);
Expand Down
37 changes: 18 additions & 19 deletions src/knx/cemi_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,30 +400,29 @@ bool CemiFrame::valid() const
return true;
}

std::string CemiFrame::toString() const
void CemiFrame::printIt() const
{
#ifndef KNX_NO_PRINT
std::string value = std::string("DPDU:") + enum_name(frameType()) + " ";
value += enum_name(systemBroadcast());
value += " ";
value += enum_name(ack());
value += " ";
value += enum_name(repetition());
value += " ";
value += enum_name(priority());
value += " from ";
value += format_ia(sourceAddress());
value += " to ";
value += enum_name(addressType());
value += " ";
print("DPDU:");
print(enum_name(frameType()));
print(" ");
print(enum_name(systemBroadcast()));
print(" ");
print(enum_name(ack()));
print(" ");
print(enum_name(repetition()));
print(" ");
print(enum_name(priority()));
print(" from ");
print_ia(sourceAddress());
print(" to ");
print(enum_name(addressType()));
print(" ");

if (addressType() == AddressType::IndividualAddress)
value += format_ia(destinationAddress());
print_ia(destinationAddress());
else
value += format_ga(destinationAddress());
print_ga(destinationAddress());

return value;
#else
return "";
#endif
}
8 changes: 5 additions & 3 deletions src/knx/cemi_frame.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once

#include "knx_types.h"
#include "stdint.h"
#include <stdint.h>
#include "npdu.h"
#include "tpdu.h"
#include "apdu.h"
#include "config.h"
#include "util/logger.h"


#define NPDU_LPDU_DIFF 8
#define TPDU_NPDU_DIFF 1
Expand All @@ -16,7 +18,7 @@
// Mesg Code and additional info length
#define CEMI_HEADER_SIZE 2

class CemiFrame
class CemiFrame : public IPrintable
{
friend class DataLinkLayer;

Expand Down Expand Up @@ -72,7 +74,7 @@ class CemiFrame
uint8_t calcCrcTP(uint8_t* buffer, uint16_t len);
bool valid() const;

std::string toString() const;
void printIt() const;

private:
uint8_t buffer[0xff + NPDU_LPDU_DIFF] = {0}; //only valid of add info is zero
Expand Down
6 changes: 3 additions & 3 deletions src/knx/data_link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool DataLinkLayer::isTunnelAddress(uint16_t addr)
}
#endif

void DataLinkLayer::cddataRequestFromTunnel(CemiFrame& frame)
void DataLinkLayer::dataRequestFromTunnel(CemiFrame& frame)
{
_cemiServer->dataConfirmationToTunnel(frame);

Expand Down Expand Up @@ -161,7 +161,7 @@ void DataLinkLayer::frameReceived(CemiFrame& frame)
SystemBroadcast systemBroadcast = frame.systemBroadcast();


LOGGER.info("frameReceived %s", frame.toString().c_str());
LOGGER.info("frameReceived ", frame);


#ifdef USE_CEMI_SERVER
Expand Down Expand Up @@ -222,7 +222,7 @@ bool DataLinkLayer::sendTelegram(NPDU& npdu, AckType ack, uint16_t destinationAd
else
frame.frameType(format);

LOGGER.info("sendTelegram %s", frame.toString().c_str());
LOGGER.info("sendTelegram ", frame);

if (!frame.valid())
{
Expand Down
Loading

0 comments on commit 1b68cd0

Please sign in to comment.