Skip to content

Commit

Permalink
introduce Knx namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
thelsing committed Aug 28, 2024
1 parent 628970a commit de6d638
Show file tree
Hide file tree
Showing 191 changed files with 24,456 additions and 23,883 deletions.
2 changes: 2 additions & 0 deletions examples/knx-linux-coupler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "fdsk.h"

using namespace Knx;

volatile sig_atomic_t loopActive = 1;
void signalHandler(int sig)
{
Expand Down
20 changes: 11 additions & 9 deletions examples/knx-usb/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ Adafruit_USBD_HID usb_hid;
// received data on interrupt OUT endpoint
void setReportCallback(uint8_t report_id, hid_report_type_t report_type, uint8_t const* data, uint16_t bufSize)
{
// we don't use multiple report and report ID
(void) report_id;
(void) report_type;
// we don't use multiple report and report ID
(void) report_id;
(void) report_type;

UsbTunnelInterface::receiveHidReport(data, bufSize);
}

bool sendHidReport(uint8_t* data, uint16_t length)
{
// We do not use reportId of the TinyUSB sendReport()-API here but instead provide it in the first byte of the buffer
// We do not use reportId of the TinyUSB sendReport()-API here but instead provide it in the first byte of the buffer
return usb_hid.sendReport(0, data, length);
}

Expand Down Expand Up @@ -68,15 +68,16 @@ void setup(void)
usb_hid.begin();

// wait until device mounted
while( !USBDevice.mounted() ) delay(1);
while ( !USBDevice.mounted() )
delay(1);

println("KNX USB Interface enabled.");

// read adress table, association table, groupobject table and parameters from eeprom
knx.readMemory();

if (knx.individualAddress() == 0)
knx.progMode(true);
knx.progMode(true);


if (knx.configured())
Expand All @@ -101,10 +102,11 @@ void loop(void)
knx.loop();

// only run the application code if the device was configured with ETS
if(!knx.configured())
if (!knx.configured())
return;

long now = millis();

if ((now - lastsend) < 3000)
return;

Expand All @@ -116,11 +118,11 @@ void loop(void)
output += ", " + String(temp);
output += ", " + String(humi);
Serial1.println(output);

if (sendCounter++ == cyclSend)
{
sendCounter = 0;

goTemperature.value(temp);
goHumidity.value(humi);
}
Expand Down
1 change: 1 addition & 0 deletions examples/knxPython/knxmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace py = pybind11;
#include "knx/platform/linux_platform.h"
#include "knx/ip/bau57B0.h"
#include "knx/interface_object/group_object_table_object.h"
using namespace Knx;

LinuxPlatform* platform = 0;
Bau57B0* bau = 0;
Expand Down
1 change: 1 addition & 0 deletions src/knx.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,4 @@ knx-->Platform
*/
#include "knx/knx_facade.h"
using namespace Knx;
89 changes: 47 additions & 42 deletions src/knx/application_layer/apdu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,63 @@
#include "../datalink_layer/cemi_frame.h"
#include "../bits.h"

APDU::APDU(uint8_t* data, CemiFrame& frame): _data(data), _frame(frame)
namespace Knx
{
}

ApduType APDU::type() const
{
uint16_t apci;
apci = getWord(_data);
popWord(apci, _data);
apci &= 0x3ff;
APDU::APDU(uint8_t* data, CemiFrame& frame): _data(data), _frame(frame)
{
}

if ((apci >> 6) < 11 && (apci >> 6) != 7) //short apci
apci &= 0x3c0;
ApduType APDU::type() const
{
uint16_t apci;
apci = getWord(_data);
popWord(apci, _data);
apci &= 0x3ff;

return (ApduType)apci;
}
if ((apci >> 6) < 11 && (apci >> 6) != 7) //short apci
apci &= 0x3c0;

void APDU::type(ApduType atype)
{
// ApduType is in big endian so convert to host first, pushWord converts back
pushWord((uint16_t)atype, _data);
}
return (ApduType)apci;
}

uint8_t* APDU::data()
{
return _data + 1;
}
void APDU::type(ApduType atype)
{
// ApduType is in big endian so convert to host first, pushWord converts back
pushWord((uint16_t)atype, _data);
}

CemiFrame& APDU::frame()
{
return _frame;
}
uint8_t* APDU::data()
{
return _data + 1;
}

uint8_t APDU::length() const
{
return _frame.npdu().octetCount();
}
CemiFrame& APDU::frame()
{
return _frame;
}

void APDU::printIt() const
{
#ifndef KNX_NO_PRINT
print("APDU: ");
print(enum_name(type()));
print(" ");
print(_data[0] & 0x3, HEX);
uint8_t APDU::length() const
{
return _frame.npdu().octetCount();
}

for (uint8_t i = 1; i < length() + 1; ++i)
void APDU::printIt() const
{
if (i)
print(" ");
#ifndef KNX_NO_PRINT
print("APDU: ");
print(enum_name(type()));
print(" ");
print(_data[0] & 0x3, HEX);

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

print(_data[i], HEX);
}

print(_data[i], HEX);
}
#endif
}
}
}
98 changes: 51 additions & 47 deletions src/knx/application_layer/apdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,55 @@

#include <string.h>

class CemiFrame;

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

public:
/**
* Get the type of the APDU.
*/
ApduType type() const;
/**
* Set the type of the APDU.
*/
void type(ApduType atype);
/**
* Get a pointer to the data.
*/
uint8_t* data();
/**
* Get the CemiFrame this APDU is part of.
*/
CemiFrame& frame();
/**
* Get the length of the APDU. (This is actually the octet count of the NPDU.)
*/
uint8_t length() const;
/**
* print APDU
*/
void printIt() const;

protected:
/**
* The constructor.
* @param data The data of the APDU. Encoding depends on the ::ApduType. The class doesn't
* take possession of this pointer.
* @param frame The CemiFrame this APDU is part of.
*/
APDU(uint8_t* data, CemiFrame& frame);

private:
uint8_t* _data = 0;
CemiFrame& _frame;
};

class CemiFrame;

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

public:
/**
* Get the type of the APDU.
*/
ApduType type() const;
/**
* Set the type of the APDU.
*/
void type(ApduType atype);
/**
* Get a pointer to the data.
*/
uint8_t* data();
/**
* Get the CemiFrame this APDU is part of.
*/
CemiFrame& frame();
/**
* Get the length of the APDU. (This is actually the octet count of the NPDU.)
*/
uint8_t length() const;
/**
* print APDU
*/
void printIt() const;

protected:
/**
* The constructor.
* @param data The data of the APDU. Encoding depends on the ::ApduType. The class doesn't
* take possession of this pointer.
* @param frame The CemiFrame this APDU is part of.
*/
APDU(uint8_t* data, CemiFrame& frame);

private:
uint8_t* _data = 0;
CemiFrame& _frame;
};
}
Loading

0 comments on commit de6d638

Please sign in to comment.