mirror of
https://github.com/thelsing/knx.git
synced 2025-04-09 01:16:57 +02:00
Merge pull request #264 from OpenKNX/feature_activitycallback
Add activity callback function
This commit is contained in:
commit
7215f470af
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
@ -42,5 +54,8 @@ class DataLinkLayer
|
||||
Platform& _platform;
|
||||
#ifdef USE_CEMI_SERVER
|
||||
CemiServer* _cemiServer;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef KNX_ACTIVITYCALLBACK
|
||||
uint8_t _netIndex = 0;
|
||||
#endif
|
||||
};
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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)
|
||||
@ -67,6 +76,10 @@ 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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
@ -22,7 +22,9 @@ class TpUartDataLinkLayer : public DataLinkLayer
|
||||
|
||||
public:
|
||||
TpUartDataLinkLayer(DeviceObject& devObj, NetworkLayerEntity& netLayerEntity,
|
||||
Platform& platform, ITpUartCallBacks& cb);
|
||||
Platform& platform, ITpUartCallBacks& cb, DataLinkLayerCallbacks* dllcb = nullptr);
|
||||
|
||||
|
||||
|
||||
void loop();
|
||||
void enabled(bool value);
|
||||
@ -74,5 +76,6 @@ class TpUartDataLinkLayer : public DataLinkLayer
|
||||
void stopChip();
|
||||
|
||||
ITpUartCallBacks& _cb;
|
||||
DataLinkLayerCallbacks* _dllcb;
|
||||
};
|
||||
#endif
|
||||
|
@ -70,6 +70,9 @@ typedef uint8_t* (*SaveCallback)(uint8_t* buffer);
|
||||
typedef void (*IsrFunctionPtr)();
|
||||
typedef void (*ProgLedOnCallback)();
|
||||
typedef void (*ProgLedOffCallback)();
|
||||
#ifdef KNX_ACTIVITYCALLBACK
|
||||
typedef void (*ActivityCallback)(uint8_t info);
|
||||
#endif
|
||||
|
||||
template <class P, class B> class KnxFacade : private SaveRestore
|
||||
{
|
||||
@ -187,6 +190,21 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
||||
_progLedOnCallback = progLedOnCallback;
|
||||
}
|
||||
|
||||
#ifdef KNX_ACTIVITYCALLBACK
|
||||
/// @brief sets the Callback Function indicating sent or received telegrams
|
||||
/// @param activityCallback
|
||||
/// @details the info parameter
|
||||
void setActivityCallback(ActivityCallback activityCallback)
|
||||
{
|
||||
_activityCallback = activityCallback;
|
||||
}
|
||||
|
||||
void Activity(uint8_t info)
|
||||
{
|
||||
if(_activityCallback)
|
||||
_activityCallback(info);
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t buttonPin()
|
||||
{
|
||||
@ -414,6 +432,9 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
||||
B& _bau;
|
||||
ProgLedOnCallback _progLedOnCallback = 0;
|
||||
ProgLedOffCallback _progLedOffCallback = 0;
|
||||
#ifdef KNX_ACTIVITYCALLBACK
|
||||
ActivityCallback _activityCallback = 0;
|
||||
#endif
|
||||
uint32_t _ledPinActiveOn = KNX_LED_ACTIVE_ON;
|
||||
uint32_t _ledPin = KNX_LED;
|
||||
int32_t _buttonPin = KNX_BUTTON;
|
||||
|
Loading…
Reference in New Issue
Block a user