Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into rp2040_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Ing-Dom committed Jan 14, 2024
2 parents 6297397 + c8685fa commit 17ff6eb
Show file tree
Hide file tree
Showing 27 changed files with 380 additions and 33 deletions.
20 changes: 20 additions & 0 deletions src/esp32_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,32 @@ Esp32Platform::Esp32Platform()
: ArduinoPlatform(&KNX_SERIAL)
#endif
{
#ifdef KNX_UART_RX_PIN
_rxPin = KNX_UART_RX_PIN;
#endif
#ifdef KNX_UART_TX_PIN
_txPin = KNX_UART_TX_PIN;
#endif
}

Esp32Platform::Esp32Platform(HardwareSerial* s) : ArduinoPlatform(s)
{
}

void Esp32Platform::knxUartPins(int8_t rxPin, int8_t txPin)
{
_rxPin = rxPin;
_txPin = txPin;
}

// ESP specific uart handling with pins
void Esp32Platform::setupUart()
{
_knxSerial->begin(19200, SERIAL_8E1, _rxPin, _txPin);
while (!_knxSerial)
;
}

uint32_t Esp32Platform::currentIpAddress()
{
return WiFi.localIP();
Expand Down
6 changes: 6 additions & 0 deletions src/esp32_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Esp32Platform : public ArduinoPlatform
Esp32Platform();
Esp32Platform(HardwareSerial* s);

// uart
void knxUartPins(int8_t rxPin, int8_t txPin);
void setupUart() override;

// ip stuff
uint32_t currentIpAddress() override;
uint32_t currentSubnetMask() override;
Expand All @@ -36,6 +40,8 @@ class Esp32Platform : public ArduinoPlatform
void commitToEeprom();
private:
WiFiUDP _udp;
int8_t _rxPin = -1;
int8_t _txPin = -1;
};

#endif
10 changes: 5 additions & 5 deletions src/knx/application_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ void ApplicationLayer::systemNetworkParameterReadResponse(Priority priority, Hop
void ApplicationLayer::domainAddressSerialNumberReadResponse(Priority priority, HopCountType hopType, const SecurityControl &secCtrl, const uint8_t* rfDoA,
const uint8_t* knxSerialNumber)
{
CemiFrame frame(11);
CemiFrame frame(13);
APDU& apdu = frame.apdu();
apdu.type(DomainAddressSerialNumberResponse);

Expand All @@ -567,19 +567,19 @@ void ApplicationLayer::domainAddressSerialNumberReadResponse(Priority priority,

//TODO: ApplicationLayer::IndividualAddressSerialNumberWriteRequest()
//TODO: ApplicationLayer::IndividualAddressSerialNumberReadRequest()
void ApplicationLayer::IndividualAddressSerialNumberReadResponse(Priority priority, HopCountType hopType, const SecurityControl &secCtrl, const uint8_t* rfDoA,
void ApplicationLayer::IndividualAddressSerialNumberReadResponse(Priority priority, HopCountType hopType, const SecurityControl &secCtrl, const uint8_t* domainAddress,
const uint8_t* knxSerialNumber)
{
CemiFrame frame(13);
CemiFrame frame(11);
APDU& apdu = frame.apdu();
apdu.type(IndividualAddressSerialNumberResponse);

uint8_t* data = apdu.data() + 1;

memcpy(data, knxSerialNumber, 6);
memcpy(data + 6, rfDoA, 6);
memcpy(data + 6, domainAddress, 2);

//apdu.printPDU();
//apdu.printPDU();

dataBroadcastRequest(AckDontCare, hopType, SystemPriority, apdu, secCtrl);
}
Expand Down
2 changes: 1 addition & 1 deletion src/knx/application_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ApplicationLayer
uint8_t* testResult, uint16_t testResultLength);
void domainAddressSerialNumberReadResponse(Priority priority, HopCountType hopType, const SecurityControl& secCtrl, const uint8_t* rfDoA,
const uint8_t* knxSerialNumber);
void IndividualAddressSerialNumberReadResponse(Priority priority, HopCountType hopType, const SecurityControl& secCtrl, const uint8_t* rfDoA,
void IndividualAddressSerialNumberReadResponse(Priority priority, HopCountType hopType, const SecurityControl& secCtrl, const uint8_t* domainAddress,
const uint8_t* knxSerialNumber);
#pragma endregion

Expand Down
3 changes: 2 additions & 1 deletion src/knx/bau07B0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ using namespace std;

Bau07B0::Bau07B0(Platform& platform)
: BauSystemBDevice(platform),
_dlLayer(_deviceObj, _netLayer.getInterface(), _platform, (ITpUartCallBacks&) *this)
_dlLayer(_deviceObj, _netLayer.getInterface(), _platform, (ITpUartCallBacks&) *this, (DataLinkLayerCallbacks*) this),
DataLinkLayerCallbacks()
#ifdef USE_CEMI_SERVER
, _cemiServer(*this)
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/knx/bau07B0.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "cemi_server.h"
#include "cemi_server_object.h"

class Bau07B0 : public BauSystemBDevice, public ITpUartCallBacks
class Bau07B0 : public BauSystemBDevice, public ITpUartCallBacks, public DataLinkLayerCallbacks
{
public:
Bau07B0(Platform& platform);
Expand Down
5 changes: 3 additions & 2 deletions src/knx/bau091A.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Bau091A::Bau091A(Platform& platform)
: BauSystemBCoupler(platform),
_routerObj(memory()),
_ipParameters(_deviceObj, platform),
_dlLayerPrimary(_deviceObj, _ipParameters, _netLayer.getPrimaryInterface(), _platform),
_dlLayerSecondary(_deviceObj, _netLayer.getSecondaryInterface(), platform, (ITpUartCallBacks&) *this)
_dlLayerPrimary(_deviceObj, _ipParameters, _netLayer.getPrimaryInterface(), _platform, (DataLinkLayerCallbacks*) this),
_dlLayerSecondary(_deviceObj, _netLayer.getSecondaryInterface(), platform, (ITpUartCallBacks&) *this, (DataLinkLayerCallbacks*) this),
DataLinkLayerCallbacks()
#ifdef USE_CEMI_SERVER
,
_cemiServer(*this)
Expand Down
2 changes: 1 addition & 1 deletion src/knx/bau091A.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "tpuart_data_link_layer.h"
#include "cemi_server_object.h"

class Bau091A : public BauSystemBCoupler, public ITpUartCallBacks
class Bau091A : public BauSystemBCoupler, public ITpUartCallBacks, public DataLinkLayerCallbacks
{
public:
Bau091A(Platform& platform);
Expand Down
5 changes: 1 addition & 4 deletions src/knx/bau27B0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ void Bau27B0::domainAddressSerialNumberReadIndication(Priority priority, HopCoun

void Bau27B0::individualAddressSerialNumberReadIndication(Priority priority, HopCountType hopType, const SecurityControl &secCtrl, uint8_t* knxSerialNumber)
{
// If the received serial number matches our serial number
// then send a response with the current RF domain address stored in the RF medium object and the serial number
if (!memcmp(knxSerialNumber, _deviceObj.propertyData(PID_SERIAL_NUMBER), 6))
_appLayer.IndividualAddressSerialNumberReadResponse(priority, hopType, secCtrl, _rfMediumObj.rfDomainAddress(), knxSerialNumber);
#pragma warning "individualAddressSerialNumberReadIndication is not available for rf"
}

void Bau27B0::domainAddressSerialNumberWriteLocalConfirm(Priority priority, HopCountType hopType, const SecurityControl &secCtrl, const uint8_t* rfDoA,
Expand Down
3 changes: 2 additions & 1 deletion src/knx/bau57B0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ using namespace std;
Bau57B0::Bau57B0(Platform& platform)
: BauSystemBDevice(platform),
_ipParameters(_deviceObj, platform),
_dlLayer(_deviceObj, _ipParameters, _netLayer.getInterface(), _platform)
_dlLayer(_deviceObj, _ipParameters, _netLayer.getInterface(), _platform, (DataLinkLayerCallbacks*) this),
DataLinkLayerCallbacks()
#ifdef USE_CEMI_SERVER
,
_cemiServer(*this)
Expand Down
2 changes: 1 addition & 1 deletion src/knx/bau57B0.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "ip_data_link_layer.h"
#include "cemi_server_object.h"

class Bau57B0 : public BauSystemBDevice
class Bau57B0 : public BauSystemBDevice, public DataLinkLayerCallbacks
{
public:
Bau57B0(Platform& platform);
Expand Down
2 changes: 1 addition & 1 deletion src/knx/bau_systemB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void BauSystemB::individualAddressSerialNumberReadIndication(Priority priority,
// An open medium BAU has to override this method and provide a proper domain address.
if (!memcmp(knxSerialNumber, _deviceObj.propertyData(PID_SERIAL_NUMBER), 6))
{
uint8_t emptyDomainAddress[6] = {0x00};
uint8_t emptyDomainAddress[2] = {0x00};
applicationLayer().IndividualAddressSerialNumberReadResponse(priority, hopType, secCtrl, emptyDomainAddress, knxSerialNumber);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/knx/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ void printHex(const char* suffix, const uint8_t *data, size_t length, bool newli
#define printHex(...) do {} while(0)
#endif

#ifdef KNX_ACTIVITYCALLBACK
#define KNX_ACTIVITYCALLBACK_DIR 0x00
#define KNX_ACTIVITYCALLBACK_DIR_RECV 0x00
#define KNX_ACTIVITYCALLBACK_DIR_SEND 0x01
#define KNX_ACTIVITYCALLBACK_IPUNICAST 0x02
#define KNX_ACTIVITYCALLBACK_NET 0x04
#endif

const uint8_t* popByte(uint8_t& b, const uint8_t* data);
const uint8_t* popWord(uint16_t& w, const uint8_t* data);
const uint8_t* popInt(uint32_t& i, const uint8_t* data);
Expand Down
15 changes: 15 additions & 0 deletions src/knx/data_link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@
#include "cemi_server.h"
#include "cemi_frame.h"


void DataLinkLayerCallbacks::activity(uint8_t info)
{
if(_activityCallback)
_activityCallback(info);
}

void DataLinkLayerCallbacks::setActivityCallback(ActivityCallback activityCallback)
{
_activityCallback = activityCallback;
}

DataLinkLayer::DataLinkLayer(DeviceObject& devObj, NetworkLayerEntity& netLayerEntity, Platform& platform) :
_deviceObject(devObj), _networkLayerEntity(netLayerEntity), _platform(platform)
{
#ifdef KNX_ACTIVITYCALLBACK
_netIndex = netLayerEntity.getEntityIndex();
#endif
}

#ifdef USE_CEMI_SERVER
Expand Down
17 changes: 16 additions & 1 deletion src/knx/data_link_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@

class Platform;

typedef void (*ActivityCallback)(uint8_t info);

class DataLinkLayerCallbacks
{
protected:
ActivityCallback _activityCallback = nullptr;
public:
virtual ~DataLinkLayerCallbacks() = default;
virtual void activity(uint8_t info);
virtual void setActivityCallback(ActivityCallback activityCallback);
};

class DataLinkLayer
{
public:
Expand Down Expand Up @@ -42,5 +54,8 @@ class DataLinkLayer
Platform& _platform;
#ifdef USE_CEMI_SERVER
CemiServer* _cemiServer;
#endif
#endif
#ifdef KNX_ACTIVITYCALLBACK
uint8_t _netIndex = 0;
#endif
};
26 changes: 23 additions & 3 deletions src/knx/ip_data_link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define MIN_LEN_CEMI 10

IpDataLinkLayer::IpDataLinkLayer(DeviceObject& devObj, IpParameterObject& ipParam,
NetworkLayerEntity &netLayerEntity, Platform& platform) : DataLinkLayer(devObj, netLayerEntity, platform), _ipParameters(ipParam)
NetworkLayerEntity &netLayerEntity, Platform& platform, DataLinkLayerCallbacks* dllcb) : DataLinkLayer(devObj, netLayerEntity, platform), _ipParameters(ipParam), _dllcb(dllcb)
{
}

Expand All @@ -30,6 +30,10 @@ bool IpDataLinkLayer::sendFrame(CemiFrame& frame)
if(isSendLimitReached())
return false;
bool success = sendBytes(packet.data(), packet.totalLength());
#ifdef KNX_ACTIVITYCALLBACK
if(_dllcb)
_dllcb->activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_SEND << KNX_ACTIVITYCALLBACK_DIR));
#endif
dataConReceived(frame, success);
return success;
}
Expand All @@ -51,6 +55,11 @@ void IpDataLinkLayer::loop()
|| buffer[1] != KNXIP_PROTOCOL_VERSION)
return;

#ifdef KNX_ACTIVITYCALLBACK
if(_dllcb)
_dllcb->activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_RECV << KNX_ACTIVITYCALLBACK_DIR));
#endif

uint16_t code;
popWord(code, buffer + 2);
switch ((KnxIpServiceType)code)
Expand All @@ -67,12 +76,23 @@ void IpDataLinkLayer::loop()
KnxIpSearchResponse searchResponse(_ipParameters, _deviceObject);

auto hpai = searchRequest.hpai();
#ifdef KNX_ACTIVITYCALLBACK
if(_dllcb)
_dllcb->activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_SEND << KNX_ACTIVITYCALLBACK_DIR) | (KNX_ACTIVITYCALLBACK_IPUNICAST));
#endif
_platform.sendBytesUniCast(hpai.ipAddress(), hpai.ipPortNumber(), searchResponse.data(), searchResponse.totalLength());
break;
}
case SearchRequestExt:
{
// FIXME, implement (not needed atm)
break;
}
default:
print("Unhandled service identifier: ");
println(code, HEX);
{
// print("Unhandled service identifier: ");
// println(code, HEX);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/knx/ip_data_link_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IpDataLinkLayer : public DataLinkLayer

public:
IpDataLinkLayer(DeviceObject& devObj, IpParameterObject& ipParam, NetworkLayerEntity& netLayerEntity,
Platform& platform);
Platform& platform, DataLinkLayerCallbacks* dllcb = nullptr);

void loop();
void enabled(bool value);
Expand All @@ -30,5 +30,6 @@ class IpDataLinkLayer : public DataLinkLayer
bool isSendLimitReached();

IpParameterObject& _ipParameters;
DataLinkLayerCallbacks* _dllcb;
};
#endif
3 changes: 2 additions & 1 deletion src/knx/ip_parameter_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ IpParameterObject::IpParameterObject(DeviceObject& deviceObject, Platform& platf
io->_deviceObject.individualAddress(getWord(data));
return 1;
}),
new DataProperty(PID_CURRENT_IP_ASSIGNMENT_METHOD, false, PDT_UNSIGNED_CHAR, 0, ReadLv3 | WriteLv3),
new DataProperty(PID_IP_ASSIGNMENT_METHOD, true, PDT_UNSIGNED_CHAR, 1, ReadLv3 | WriteLv3),
new DataProperty(PID_IP_CAPABILITIES, true, PDT_BITSET8, 1, ReadLv3 | WriteLv1),
new DataProperty(PID_IP_CAPABILITIES, true, PDT_BITSET8, 0, ReadLv3 | WriteLv1), // must be set by application due to capabilities of the used ip stack
new CallbackProperty<IpParameterObject>(this, PID_CURRENT_IP_ADDRESS, false, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv0,
[](IpParameterObject* io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t
{
Expand Down
2 changes: 2 additions & 0 deletions src/knx/knx_ip_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ enum KnxIpServiceType
ConnectionStateResponse = 0x208,
DisconnectRequest = 0x209,
DisconnectResponse = 0x20A,
SearchRequestExt = 0x20B,
SearchResponseExt = 0x20C,
DeviceConfigurationRequest = 0x310,
DeviceConfigurationAck = 0x311,
TunnelingRequest = 0x420,
Expand Down
5 changes: 5 additions & 0 deletions src/knx/network_layer_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ DptMedium NetworkLayerEntity::mediumType() const
return _dataLinkLayer->mediumType();
}

uint8_t NetworkLayerEntity::getEntityIndex()
{
return _entityIndex;
}

void NetworkLayerEntity::dataIndication(AckType ack, AddressType addrType, uint16_t destination, FrameFormat format, NPDU& npdu, Priority priority, uint16_t source)
{
_netLayer.dataIndication(ack, addrType, destination, format, npdu, priority, source, _entityIndex);
Expand Down
1 change: 1 addition & 0 deletions src/knx/network_layer_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class NetworkLayerEntity
DataLinkLayer& dataLinkLayer();

DptMedium mediumType() const;
uint8_t getEntityIndex();

// from data link layer
void dataIndication(AckType ack, AddressType addType, uint16_t destination, FrameFormat format, NPDU& npdu,
Expand Down
15 changes: 12 additions & 3 deletions src/knx/tpuart_data_link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,17 +537,22 @@ void TpUartDataLinkLayer::stopChip()
TpUartDataLinkLayer::TpUartDataLinkLayer(DeviceObject& devObj,
NetworkLayerEntity &netLayerEntity,
Platform& platform,
ITpUartCallBacks& cb)
ITpUartCallBacks& cb,
DataLinkLayerCallbacks* dllcb)
: DataLinkLayer(devObj, netLayerEntity, platform),
_cb(cb)
_cb(cb),
_dllcb(dllcb)
{
}

void TpUartDataLinkLayer::frameBytesReceived(uint8_t* buffer, uint16_t length)
{
//printHex("=>", buffer, length);
#ifdef KNX_ACTIVITYCALLBACK
if(_dllcb)
_dllcb->activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_RECV << KNX_ACTIVITYCALLBACK_DIR));
#endif
CemiFrame frame(buffer, length);

frameReceived(frame);
}

Expand Down Expand Up @@ -653,6 +658,10 @@ bool TpUartDataLinkLayer::sendSingleFrameByte()
if (_TxByteCnt >= _sendBufferLength)
{
_TxByteCnt = 0;
#ifdef KNX_ACTIVITYCALLBACK
if(_dllcb)
_dllcb->activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_SEND << KNX_ACTIVITYCALLBACK_DIR));
#endif
return false;
}
return true;
Expand Down
Loading

0 comments on commit 17ff6eb

Please sign in to comment.