fix segment size in TableObject()

* save size after TableObject::allocTable() is called. Also change save() and restore() to save _size to flash. Modify saveSize()

* use _size to calculate crc value in CallbackProperty
This commit is contained in:
Julius Lipp 2021-04-12 22:55:34 +02:00
parent 1cadc320a5
commit 0fb3c704dc
2 changed files with 11 additions and 4 deletions

View File

@ -31,6 +31,8 @@ uint8_t* TableObject::save(uint8_t* buffer)
{ {
buffer = pushByte(_state, buffer); buffer = pushByte(_state, buffer);
buffer = pushInt(_size, buffer);
if (_data) if (_data)
buffer = pushInt(_memory.toRelative(_data), buffer); buffer = pushInt(_memory.toRelative(_data), buffer);
else else
@ -46,6 +48,8 @@ const uint8_t* TableObject::restore(const uint8_t* buffer)
buffer = popByte(state, buffer); buffer = popByte(state, buffer);
_state = (LoadState)state; _state = (LoadState)state;
buffer = popInt(_size, buffer);
uint32_t relativeAddress = 0; uint32_t relativeAddress = 0;
buffer = popInt(relativeAddress, buffer); buffer = popInt(relativeAddress, buffer);
@ -80,6 +84,8 @@ bool TableObject::allocTable(uint32_t size, bool doFill, uint8_t fillByte)
if (doFill) if (doFill)
memset(_data, fillByte, size); memset(_data, fillByte, size);
_size = size;
return true; return true;
} }
@ -229,7 +235,7 @@ void TableObject::errorCode(ErrorCode errorCode)
uint16_t TableObject::saveSize() uint16_t TableObject::saveSize()
{ {
return 5 + InterfaceObject::saveSize(); return 5 + InterfaceObject::saveSize() + sizeof(_size);
} }
void TableObject::initializeProperties(size_t propertiesSize, Property** properties) void TableObject::initializeProperties(size_t propertiesSize, Property** properties)
@ -272,13 +278,13 @@ void TableObject::initializeProperties(size_t propertiesSize, Property** propert
if (obj->_state != LS_LOADED) if (obj->_state != LS_LOADED)
return 0; // need to check return code for invalid return 0; // need to check return code for invalid
uint32_t segmentSize = obj->saveSize(); uint32_t segmentSize = obj->_size;
uint16_t crc16 = crc16Ccitt(obj->data(), segmentSize); uint16_t crc16 = crc16Ccitt(obj->data(), segmentSize);
pushInt(segmentSize, data); // Segment size pushInt(segmentSize, data); // Segment size
pushByte(0x00, data + 4); // CRC control byte -> 0: always valid pushByte(0x00, data + 4); // CRC control byte -> 0: always valid
pushByte(0xFF, data + 5); // Read access 4 bits + Write access 4 bits (unknown: value taken from real coupler device) pushByte(0xFF, data + 5); // Read access 4 bits + Write access 4 bits
pushWord(crc16, data + 6); // CRC-16 CCITT of filter table pushWord(crc16, data + 6); // CRC-16 CCITT of data
return 1; return 1;
}), }),

View File

@ -68,4 +68,5 @@ class TableObject: public InterfaceObject
LoadState _state = LS_UNLOADED; LoadState _state = LS_UNLOADED;
Memory& _memory; Memory& _memory;
uint8_t *_data = 0; uint8_t *_data = 0;
uint32_t _size = 0;
}; };