10 uint8_t TableObject::_tableUnloadCount = 0;
25 _staticTableAdr = staticTableAdr;
26 _staticTableSize = staticTableSize;
34 if (newState ==
LS_LOADED && _tableUnloadCount > 0)
37 if (_tableUnloadCount > 0)
56 if (newState == _state)
71 buffer =
pushInt(_size, buffer);
90 buffer =
popInt(_size, buffer);
92 uint32_t relativeAddress = 0;
93 buffer =
popInt(relativeAddress, buffer);
96 if (relativeAddress != 0)
105 uint32_t TableObject::tableReference()
110 bool TableObject::allocTable(uint32_t size,
bool doFill, uint8_t fillByte)
133 for (uint32_t i = 0; i < size; i++)
143 void TableObject::allocTableStatic()
145 if (_staticTableAdr && !_data)
148 _size = _staticTableSize;
149 _memory.addNewUsedBlock(_data, _size);
153 void TableObject::loadEvent(
const uint8_t* data)
159 loadEventUnloaded(
data);
163 loadEventLoading(
data);
167 loadEventLoaded(
data);
171 loadEventError(
data);
180 void TableObject::loadEventUnloaded(
const uint8_t* data)
182 uint8_t
event =
data[0];
202 void TableObject::loadEventLoading(
const uint8_t* data)
204 uint8_t
event =
data[0];
222 additionalLoadControls(
data);
231 void TableObject::loadEventLoaded(
const uint8_t* data)
233 uint8_t
event =
data[0];
251 if (!_staticTableAdr)
271 void TableObject::loadEventError(
const uint8_t* data)
273 uint8_t
event =
data[0];
293 void TableObject::additionalLoadControls(
const uint8_t* data)
302 size_t size = ((
data[2] << 24) | (
data[3] << 16) | (
data[4] << 8) |
data[5]);
303 bool doFill =
data[6] == 0x1;
304 uint8_t fillByte =
data[7];
306 if (!allocTable(size, doFill, fillByte))
335 [](
TableObject * obj, uint16_t start, uint8_t count, uint8_t*
data) -> uint8_t {
338 uint16_t currentNoOfElements = 1;
343 data[0] = obj->_state;
346 [](
TableObject * obj, uint16_t start, uint8_t count,
const uint8_t*
data) -> uint8_t {
347 obj->loadEvent(
data);
352 uint8_t ownPropertiesCount =
sizeof(ownProperties) /
sizeof(
Property*);
354 uint8_t propertyCount = propertiesSize /
sizeof(
Property*);
355 uint8_t allPropertiesCount = propertyCount + ownPropertiesCount;
357 Property* allProperties[allPropertiesCount];
358 memcpy(allProperties, properties, propertiesSize);
359 memcpy(allProperties + propertyCount, ownProperties,
sizeof(ownProperties));
364 initializeDynTableProperties(
sizeof(allProperties), allProperties);
367 void TableObject::initializeDynTableProperties(
size_t propertiesSize,
Property** properties)
372 [](
TableObject * obj, uint16_t start, uint8_t count, uint8_t*
data) -> uint8_t {
375 uint16_t currentNoOfElements = 1;
387 [](
TableObject * obj, uint16_t start, uint8_t count, uint8_t*
data) -> uint8_t {
391 uint32_t segmentSize = obj->_size;
404 uint8_t ownPropertiesCount =
sizeof(ownProperties) /
sizeof(
Property*);
406 uint8_t propertyCount = propertiesSize /
sizeof(
Property*);
407 uint8_t allPropertiesCount = propertyCount + ownPropertiesCount;
409 Property* allProperties[allPropertiesCount];
410 memcpy(allProperties, properties, propertiesSize);
411 memcpy(allProperties + propertyCount, ownProperties,
sizeof(ownProperties));
const uint8_t * popByte(uint8_t &b, const uint8_t *data)
uint8_t * pushInt(uint32_t i, uint8_t *data)
uint8_t * pushWord(uint16_t w, uint8_t *data)
uint8_t * pushByte(uint8_t b, uint8_t *data)
const uint8_t * popInt(uint32_t &i, const uint8_t *data)
uint16_t crc16Ccitt(uint8_t *input, uint16_t length)
uint8_t * save(uint8_t *buffer) override
This method is called when the object should save its state to the buffer.
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
virtual void state(PropertyID id, uint8_t *data, uint8_t length, uint8_t *resultData, uint8_t &resultLength)
Get state of a function property of the interface object.
virtual void initializeProperties(size_t propertiesSize, Property **properties)
Intializes the Property-array the the supplied values.
uint16_t saveSize() override
Property * property(PropertyID id)
Gets property with PropertyID id if it exists and nullptr otherwise.
void freeMemory(uint8_t *ptr)
uint8_t * toAbsolute(uint32_t relativeAddress)
uint32_t toRelative(uint8_t *absoluteAddress)
uint8_t * allocMemory(size_t size)
virtual uint8_t write(uint16_t start, uint8_t count, const uint8_t *data)=0
This class provides common functionality for interface objects that are configured by ETS with MemorW...
void initializeProperties(size_t propertiesSize, Property **properties) override
Intializes the Property-array the the supplied values.
LoadState loadState()
This method returns the LoadState of the interface object.
virtual ~TableObject()
The destructor.
static BeforeTablesUnloadCallback _beforeTablesUnload
static BeforeTablesUnloadCallback beforeTablesUnloadCallback()
uint8_t * data()
returns the internal data of the interface object.
virtual void beforeStateChange(LoadState &newState)
This method is called before the interface object enters a new LoadState.
void errorCode(ErrorCode errorCode)
Set the reason for a state change failure.
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
uint16_t saveSize() override
TableObject(Memory &memory, uint32_t staticTableAdr=0, uint32_t staticTableSize=0)
The constuctor.
uint8_t * save(uint8_t *buffer) override
This method is called when the object should save its state to the buffer.
@ LE_ADDITIONAL_LOAD_CONTROLS
@ E_MAX_TABLE_LENGTH_EXEEDED
@ PDT_CONTROL
length: 1 read, 10 write
@ PDT_GENERIC_08
length: 8
@ PDT_UNSIGNED_LONG
length: 4
void(* BeforeTablesUnloadCallback)()