Skip to content

Commit 95aea4d

Browse files
authored
Pad page 12 (wmiMapPage) to match ini page size. This will place the "end of page" entity at the correct offset. (speeduino#1414)
1 parent 62aab4b commit 95aea4d

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

speeduino/pages.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ void setEntityValue(page_iterator_t &entity, uint16_t offset, byte value)
225225
// ========================= Static page size computation & checking ===================
226226

227227
// This will fail AND print the page number and required size
228-
template <uint8_t pageNum, uint16_t min>
228+
template <uint8_t pageNum, uint16_t pageSize>
229229
static inline void check_size(void) {
230-
static_assert(ini_page_sizes[pageNum] >= min, "Size is off!");
230+
static_assert(ini_page_sizes[pageNum] == pageSize, "Size is off!");
231231
}
232232

233233
// Since pages are a logical contiguous block, we can automatically compute the
@@ -301,6 +301,23 @@ static inline page_iterator_t create_raw_iterator(void *pBuffer, uint8_t pageNum
301301
} \
302302
DECLARE_NEXT_ENTITY_START(entityNum, blockSize)
303303

304+
// ========================= Empty entity processing ===================
305+
306+
static inline page_iterator_t create_empty_iterator(uint8_t pageNum, uint8_t index, uint16_t start, uint16_t size)
307+
{
308+
return page_iterator_t( NoEntity,
309+
entity_page_location_t(pageNum, index),
310+
entity_page_address_t(start, size));
311+
}
312+
313+
// If the offset is in range, create a "no entity"
314+
#define CHECK_NOENTITY(pageNum, offset, blockSize, entityNum) \
315+
if (offset < ENTITY_START_VAR(entityNum)+blockSize) \
316+
{ \
317+
return create_empty_iterator((pageNum), (entityNum), ENTITY_START_VAR(entityNum), (blockSize));\
318+
} \
319+
DECLARE_NEXT_ENTITY_START(entityNum, blockSize)
320+
304321
// ===============================================================================
305322

306323
// Does the heavy lifting of mapping page+offset to an entity
@@ -385,7 +402,8 @@ page_iterator_t map_page_offset_to_entity(uint8_t pageNumber, uint16_t offset)
385402
// LCOV_EXCL_BR_STOP
386403
CHECK_TABLE(wmiMapPage, offset, &vvt2Table, 1)
387404
CHECK_TABLE(wmiMapPage, offset, &dwellTable, 2)
388-
END_OF_PAGE(wmiMapPage, 3)
405+
CHECK_NOENTITY(wmiMapPage, offset, 8U, 3)
406+
END_OF_PAGE(wmiMapPage, 4)
389407
}
390408

391409
case ignMap2Page:

test/test_pages/test_page.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <FastCRC.h>
21
#include <unity.h>
32
#include "pages.h"
43
#include "../test_utils.h"

0 commit comments

Comments
 (0)