redesigned the activitycallback without using the facade and with a more flexible approach.

For performace reasons, the calls in the actual link layer is only activated when KNX_ACTIVITYCALLBACK is defined.

There is now a DataLinkLayerCallback class where a specific Bau *can* inherit from and - if the specific link layer supports it, pass itself to that linklayer(s).
This commit is contained in:
Ing-Dom 2023-12-25 16:34:40 +01:00
parent 53842ad0c5
commit 311abdd88f
12 changed files with 71 additions and 18 deletions

View File

@ -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
@ -150,4 +151,18 @@ bool Bau07B0::isAckRequired(uint16_t address, bool isGrpAddr)
return false;
}
// /// @brief sets the Callback Function indicating sent or received telegrams
// /// @param activityCallback
// /// @details the info parameter
// void Bau07B0::setActivityCallback(ActivityCallback activityCallback)
// {
// _activityCallback = activityCallback;
// }
// void Bau07B0::Activity(uint8_t info)
// {
// if(_activityCallback)
// _activityCallback(info);
// }
#endif

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -6,6 +6,18 @@
#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)
{

View File

@ -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:

View File

@ -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)
{
}
@ -31,7 +31,8 @@ bool IpDataLinkLayer::sendFrame(CemiFrame& frame)
return false;
bool success = sendBytes(packet.data(), packet.totalLength());
#ifdef KNX_ACTIVITYCALLBACK
knx.Activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_SEND << KNX_ACTIVITYCALLBACK_DIR));
if(_dllcb)
_dllcb->Activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_SEND << KNX_ACTIVITYCALLBACK_DIR));
#endif
dataConReceived(frame, success);
return success;
@ -55,7 +56,8 @@ void IpDataLinkLayer::loop()
return;
#ifdef KNX_ACTIVITYCALLBACK
knx.Activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_RECV << KNX_ACTIVITYCALLBACK_DIR));
if(_dllcb)
_dllcb->Activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_RECV << KNX_ACTIVITYCALLBACK_DIR));
#endif
uint16_t code;
@ -75,7 +77,8 @@ void IpDataLinkLayer::loop()
auto hpai = searchRequest.hpai();
#ifdef KNX_ACTIVITYCALLBACK
knx.Activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_SEND << KNX_ACTIVITYCALLBACK_DIR) | (KNX_ACTIVITYCALLBACK_IPUNICAST));
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;

View File

@ -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);
@ -30,5 +30,6 @@ class IpDataLinkLayer : public DataLinkLayer
bool isSendLimitReached();
IpParameterObject& _ipParameters;
DataLinkLayerCallbacks* _dllcb;
};
#endif

View File

@ -7,7 +7,6 @@
#include "device_object.h"
#include "address_table_object.h"
#include "cemi_frame.h"
#include "knx_facade.h"
#include <stdio.h>
#include <string.h>
@ -538,9 +537,11 @@ 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)
{
}
@ -548,7 +549,8 @@ void TpUartDataLinkLayer::frameBytesReceived(uint8_t* buffer, uint16_t length)
{
//printHex("=>", buffer, length);
#ifdef KNX_ACTIVITYCALLBACK
knx.Activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_RECV << KNX_ACTIVITYCALLBACK_DIR));
if(_dllcb)
_dllcb->Activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_RECV << KNX_ACTIVITYCALLBACK_DIR));
#endif
CemiFrame frame(buffer, length);
frameReceived(frame);
@ -657,7 +659,8 @@ bool TpUartDataLinkLayer::sendSingleFrameByte()
{
_TxByteCnt = 0;
#ifdef KNX_ACTIVITYCALLBACK
knx.Activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_SEND << KNX_ACTIVITYCALLBACK_DIR));
if(_dllcb)
_dllcb->Activity((_netIndex << KNX_ACTIVITYCALLBACK_NET) | (KNX_ACTIVITYCALLBACK_DIR_SEND << KNX_ACTIVITYCALLBACK_DIR));
#endif
return false;
}

View File

@ -21,8 +21,12 @@ class TpUartDataLinkLayer : public DataLinkLayer
using DataLinkLayer::_platform;
public:
// TpUartDataLinkLayer(DeviceObject& devObj, NetworkLayerEntity& netLayerEntity,
// Platform& platform, ITpUartCallBacks& cb);
TpUartDataLinkLayer(DeviceObject& devObj, NetworkLayerEntity& netLayerEntity,
Platform& platform, ITpUartCallBacks& cb);
Platform& platform, ITpUartCallBacks& cb, DataLinkLayerCallbacks* dllcb = nullptr);
void loop();
void enabled(bool value);
@ -74,5 +78,6 @@ class TpUartDataLinkLayer : public DataLinkLayer
void stopChip();
ITpUartCallBacks& _cb;
DataLinkLayerCallbacks* _dllcb;
};
#endif