Skip to content

Commit 2bac1c8

Browse files
committed
Loosen the Data Recording buffer magic check, add versioning
Instead of checking the full 4 bytes as magic, use the last 12 bits for versioning in preparation to eventually be able to extend or change the memory layout.
1 parent d3f6747 commit 2bac1c8

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/data_recorder.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ void data_recorder_init(DataRecord *dr) {
4343
// fetch information about the data buffer, it's stored at the end of the
4444
// VESC interface memory area
4545
DataBufferInfo *buffer_info = (DataBufferInfo *) ((uint8_t *) VESC_IF + 2036);
46-
if (buffer_info->magic != 0xcafe1111) {
46+
47+
// Magic format: 0xcafe1XVM where X=ignored (reserved for future use),
48+
// V=major version (4 bits), M=minor version (4 bits)
49+
// we check that the base magic matches and the version is compatible
50+
const uint32_t magic_base = buffer_info->magic & 0xfffff000;
51+
const uint8_t magic_major = (buffer_info->magic >> 4) & 0x0f;
52+
const uint8_t magic_minor = buffer_info->magic & 0x0f;
53+
const uint8_t required_major = 1;
54+
const uint8_t required_minor = 1;
55+
if (magic_base != 0xcafe1000 || magic_major != required_major || magic_minor < required_minor) {
56+
if (buffer_info->magic != 0) {
57+
log_msg("Data Record incompatible magic: 0x%08x", buffer_info->magic);
58+
}
4759
dr->enabled = false;
4860
return;
4961
}

0 commit comments

Comments
 (0)