mborgerson
Well-known member
After posting some example data logger code in other threads, I have decided to try to write a generic logger object which can become the basis of a data logger library.
One of the first things I need to figure out is how to have the logger object allocate it's own storage for the internal buffers and/or queues. The logical way is to have the logger object examine the user-defined storage structure size, then initialize queues and buffers and use 'new' inside the object to get the required memory from the heap. (Of course, the object will free that memory in the destructor.) I haven't explicitly used new/delete or malloc()/free() much at all in my embedded programming.
Some questions occur to me:
Are there limits on how much memory I should allocate in this fashion?
Is there a way to determine how much memory is available in the heap? (So I can set up a buffer that leaves some space for other parts of the program)
Can I add some code to make the SD Card look like a USB-connected device that can be used to upload the logged data from the SD card?
Here are some of the more complex public methods that I envision:
datalogger::InitStorage(uint16_t structsize, uint32_t collectionrate, uint16_t bufferMSec);
The user passes the size of their data structure, the collection rate and the number of milliseconds of buffer capacity. From those values the object calculates the amount of buffer memory that it requires. There will probably need to be some indicator of whether the memory allocation succeeded and how much memory was allocated.
datalogger::AttachCollector( void *aptr);
The user passes in a pointer to their data collection function. The function will be called from the internal IntervalTimer with a pointer parameter that the user typecasts to their structure type, then fills in the data to be saved. I envision some further questions about what devices can be used to do the collection, as the data is collected inside an interrupt handler.
datalogger:AttachDisplay(void *aptr);
The user passes in a pointer to a data display function. That function will be called when the user requests a display of the logged data. The user will write a function that does an appropriate display of the data. The user function will receive a pointer to the data to be displayed.
When I get a bit further along, I'll post some code showing the header file for the class.
One of the first things I need to figure out is how to have the logger object allocate it's own storage for the internal buffers and/or queues. The logical way is to have the logger object examine the user-defined storage structure size, then initialize queues and buffers and use 'new' inside the object to get the required memory from the heap. (Of course, the object will free that memory in the destructor.) I haven't explicitly used new/delete or malloc()/free() much at all in my embedded programming.
Some questions occur to me:
Are there limits on how much memory I should allocate in this fashion?
Is there a way to determine how much memory is available in the heap? (So I can set up a buffer that leaves some space for other parts of the program)
Can I add some code to make the SD Card look like a USB-connected device that can be used to upload the logged data from the SD card?
Here are some of the more complex public methods that I envision:
datalogger::InitStorage(uint16_t structsize, uint32_t collectionrate, uint16_t bufferMSec);
The user passes the size of their data structure, the collection rate and the number of milliseconds of buffer capacity. From those values the object calculates the amount of buffer memory that it requires. There will probably need to be some indicator of whether the memory allocation succeeded and how much memory was allocated.
datalogger::AttachCollector( void *aptr);
The user passes in a pointer to their data collection function. The function will be called from the internal IntervalTimer with a pointer parameter that the user typecasts to their structure type, then fills in the data to be saved. I envision some further questions about what devices can be used to do the collection, as the data is collected inside an interrupt handler.
datalogger:AttachDisplay(void *aptr);
The user passes in a pointer to a data display function. That function will be called when the user requests a display of the logged data. The user will write a function that does an appropriate display of the data. The user function will receive a pointer to the data to be displayed.
When I get a bit further along, I'll post some code showing the header file for the class.
Last edited: