How to efficiently store task information for a calendar year

I have an embedded system (MCU without any OS) that the end user should be able to determine the system level (scale: 0-100) for a year. As an example (time x day matrix):

| 1st Jan | 2nd Jan | 3rd Jan | .. | 31 Dec | 00:30 | 40 (%) | 40 | 45 | .. | 50 | 01:48 | 48 | 47 | 55 | .. | 33 | 02:26 | 64 | 64 | 60 | .. | 68 | .. | .. | .. | .. | .. | .. | 22:15 | 79 | 82 | 89 | .. | 100 | 23:37 | 100 | 100 | 97 | .. | 100 | 

I thought of storing the data as: time [in minutes], sysLevel so for the above table it would be something like this:

  typedef struct{ uint16_t minute; //scale: 0 - 1440 min uint8_t level; //scale 0 - 100 (%) }timeLevel_t; //3 byte 

then save every day as

 timeLevel_t firstJan[24] = { .. }; //it stores level changes, the array length doesn't have to be 24 timeLevel_t secJan[17] = { .. }; timeLevel_t thirdJan[20] = { .. }; ... 

(I will extract the data from the CSV file, which may be off topic, to consider it now on this issue).

In the worst case, the system will determine the definition of the task per hour, so the definition of timeLevel_t (3 bytes) for 24 hours will be 72 bytes per day, then the data for 365 days will be 26,280 bytes of data.

Would you suggest a more efficient memory storage algorithm for storing a calendar year (the program will update it every year to be reviewed on February 29)?

Moreover? Would it be better to make a 2-dimensional array for storing daily information on 1D, and timeLevel_t for another dimension?

+5
source share
1 answer

You will need to save additional information, such as # days / month or take 31 each, and spend a couple of bytes.

It all depends on your pain points. You can pack bytes more so as not to lose a bit, due to code complexity and computation time.

If the storage has an absolute premium, you can store everything in one huge 1D array and use extra bits for other things. For example, bit 11 may indicate β€œnext day”, bit 12 β€œnext month”, and then you can scan the array and find any day in the year. And you would have 4 more bits for various frauds.

Describe the problems more, please.

0
source

All Articles