Are there a way to know how much of the EEPROM memmory that is used?

狂风中的少年 提交于 2019-12-24 19:57:38

问题


I have looked trough the "logbook" and "datalogger" APIs and there are no way of telling that the data logger is almost full. I found the API call with the following path "/Mem/Logbook/IsFull". If I have understood it correct this will notify me when log is full and the datalogger has stopped logging.

So my question is: Are there a way to know how much of the memmory is currently in use so that I do a cleanup old data (need to do some calculations on them before they are deleted) before the EEPROM is full and the Datalogger stops recording?


回答1:


The data memory of Logbook/DataLogger is conceptually a ring buffer. That's why /Mem/DataLogger/IsFull always returns false on Movesense sensor (Suunto uses the same API in its watches where the situation is different). Therefore the sensor never stops recording, it just replaces oldest data with new.

Here are a couple of strategies that you could use:

Plan A:

  1. Create a new log (POST /Mem/Logbook/Entries => returns the logId for it)
  2. Start Logging (PUT /Mem/DataLogger/State: LOGGING)
  3. Every once in a while create a new log (POST /Mem/Logbook/Entries). Note: This can be done while logging is ongoing!
  4. When you want to know what is the status of the log, read /Mem/Logbook/Entries. When the oldest entry has completely been overwritten, it disappears from the list. Note: The GET /Entries is a heavy operation so you may not want to do it when the logger is running!

Plan B

Every now and then start a new log and process the previous one. That way the log never overwrites something you have not processed.

Plan C

(Note: This is low level and may break with some future Movesense sensor release)

GET the first 256 bytes of EEPROM chip #0 using the /Component/EEPROM API. This area contains a number of ExtflashChunkStorage::StorageHeader structs (see: ExtflashChunkStorage.h), rest is filled with 0xFF. The last StorageHeader before 0xFF is the current one. With that StorageHeader one can see where the ring buffer starts (firstChunk) and where next data is written (cursor). The difference of the two is the used memory. (Note: Since it is a ring buffer the difference can be negative. In that case add the "Size of Logbook area - 256" to it)

Full disclosure: I work for Movesense team



来源:https://stackoverflow.com/questions/51177842/are-there-a-way-to-know-how-much-of-the-eeprom-memmory-that-is-used

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!