- added SMALL_GROUPOBJECT

This commit is contained in:
Waldemar Porscha 2021-02-08 18:10:43 +01:00
parent d7e5291387
commit cb19647673
3 changed files with 77 additions and 25 deletions

View File

@ -114,9 +114,13 @@ void BauSystemBDevice::updateGroupObject(GroupObject & go, uint8_t * data, uint8
memcpy(goData, data, length);
go.commFlag(Updated);
#ifdef SMALL_GROUPOBJECT
GroupObject::processClassCallback(go);
#else
GroupObjectUpdatedHandler handler = go.callback();
if (handler)
handler(go);
#endif
}
bool BauSystemBDevice::configured()

View File

@ -4,23 +4,30 @@
#include "datapoint_types.h"
#include "group_object_table_object.h"
#ifdef SMALL_GROUPOBJECT
GroupObjectUpdatedHandler GroupObject::_updateHandlerStatic = 0;
#endif
GroupObjectTableObject* GroupObject::_table = 0;
GroupObject::GroupObject()
{
_data = 0;
_commFlag = Ok;
_table = 0;
_dataLength = 0;
#ifndef SMALL_GROUPOBJECT
_updateHandler = 0;
#endif
}
GroupObject::GroupObject(const GroupObject& other)
{
_data = new uint8_t[other._dataLength];
_commFlag = other._commFlag;
_table = other._table;
_dataLength = other._dataLength;
_asap = other._asap;
#ifndef SMALL_GROUPOBJECT
_updateHandler = other._updateHandler;
#endif
memcpy(_data, other._data, _dataLength);
}
@ -175,6 +182,24 @@ size_t GroupObject::sizeInTelegram()
return asapValueSize(code);
}
#ifdef SMALL_GROUPOBJECT
GroupObjectUpdatedHandler GroupObject::classCallback()
{
return _updateHandlerStatic;
}
void GroupObject::classCallback(GroupObjectUpdatedHandler handler)
{
_updateHandlerStatic = handler;
}
void GroupObject::processClassCallback(GroupObject& ko)
{
if (_updateHandlerStatic != 0)
_updateHandlerStatic(ko);
}
#else
void GroupObject::callback(GroupObjectUpdatedHandler handler)
{
_updateHandler = handler;
@ -185,6 +210,7 @@ GroupObjectUpdatedHandler GroupObject::callback()
{
return _updateHandler;
}
#endif
void GroupObject::value(const KNXValue& value, const Dpt& type)
{
@ -205,7 +231,7 @@ bool GroupObject::tryValue(KNXValue& value, const Dpt& type)
return KNX_Decode_Value(_data, _dataLength, type, value);
}
#ifndef SMALL_GROUPOBJECT
void GroupObject::dataPointType(Dpt value)
{
_datapointType = value;
@ -240,7 +266,7 @@ void GroupObject::valueNoSend(const KNXValue& value)
{
valueNoSend(value, _datapointType);
}
#endif
void GroupObject::valueNoSend(const KNXValue& value, const Dpt& type)
{

View File

@ -133,6 +133,8 @@ class GroupObject
* (in german "KO-Nr")
*/
uint16_t asap();
#ifndef SMALL_GROUPOBJECT
/**
* register a callback for this group object. The registered callback will be called if the group object was changed from the bus.
*/
@ -141,16 +143,12 @@ class GroupObject
* returns the registered callback
*/
GroupObjectUpdatedHandler callback();
#endif
/**
* return the current value of the group object.
* @param type the datapoint type used for the conversion. If this doesn't fit to the group object the returned value is invalid.
*/
KNXValue value(const Dpt& type);
/**
* return the current value of the group object. The datapoint type must be set with dataPointType(). Otherwise the returned
* value is invalid.
*/
KNXValue value();
/**
* set the current value of the group object and changes the state of the group object to ::WriteRequest.
* @param value the value the group object is set to
@ -159,13 +157,6 @@ class GroupObject
* The parameters must fit the group object. Otherwise it will stay unchanged.
*/
void value(const KNXValue& value, const Dpt& type);
/**
* set the current value of the group object and changes the state of the group object to ::WriteRequest.
* @param value the value the group object is set to
*
* The parameters must fit the group object and dhe datapoint type must be set with dataPointType(). Otherwise it will stay unchanged.
*/
void value(const KNXValue& value);
/**
* set the current value of the group object.
* @param value the value the group object is set to
@ -174,13 +165,6 @@ class GroupObject
* The parameters must fit the group object. Otherwise it will stay unchanged.
*/
void valueNoSend(const KNXValue& value, const Dpt& type);
/**
* set the current value of the group object.
* @param value the value the group object is set to
*
* The parameters must fit the group object and dhe datapoint type must be set with dataPointType(). Otherwise it will stay unchanged.
*/
void valueNoSend(const KNXValue& value);
/**
* set the current value of the group object.
* @param value the value the group object is set to
@ -191,6 +175,27 @@ class GroupObject
* @returns true if the value of the group object was changed successfully.
*/
bool tryValue(KNXValue& value, const Dpt& type);
#ifndef SMALL_GROUPOBJECT
/**
* return the current value of the group object. The datapoint type must be set with dataPointType(). Otherwise the returned
* value is invalid.
*/
KNXValue value();
/**
* set the current value of the group object and changes the state of the group object to ::WriteRequest.
* @param value the value the group object is set to
*
* The parameters must fit the group object and dhe datapoint type must be set with dataPointType(). Otherwise it will stay unchanged.
*/
void value(const KNXValue& value);
/**
* set the current value of the group object.
* @param value the value the group object is set to
*
* The parameters must fit the group object and dhe datapoint type must be set with dataPointType(). Otherwise it will stay unchanged.
*/
void valueNoSend(const KNXValue& value);
/**
* set the current value of the group object.
* @param value the value the group object is set to
@ -209,15 +214,32 @@ class GroupObject
* sets the datapoint type of the group object.
*/
void dataPointType(Dpt value);
#else
/**
* Alternative callback processing: register one global callback for all group object.
* The registered callback will be called if any group object was changed from the bus.
* The callback method has to dispatch to the correct handler for this group object.
*/
static GroupObjectUpdatedHandler classCallback();
static void classCallback(GroupObjectUpdatedHandler handler);
static void processClassCallback(GroupObject& ko);
#endif
private:
// class members
static GroupObjectTableObject* _table;
#ifdef SMALL_GROUPOBJECT
static GroupObjectUpdatedHandler _updateHandlerStatic;
#endif
size_t asapValueSize(uint8_t code);
GroupObjectUpdatedHandler _updateHandler;
size_t goSize();
uint16_t _asap = 0;
ComFlag _commFlag = Ok;
uint8_t* _data = 0;
uint8_t _dataLength = 0;
GroupObjectTableObject* _table = 0;
#ifndef SMALL_GROUPOBJECT
GroupObjectUpdatedHandler _updateHandler;
Dpt _datapointType;
#endif
};