Hi all,
I'd like to keep an internal logfile for debug events that I trigger on different parts of the program. The log would be kept in RAM so it can be retrieved at any time later either through serial or via the LCD. I think 100 lines of 40 characters each would be enough ~ so about 4KBytes allocated to this purpose.
What would be the most efficient way of doing this?
I was thinking using the circular buffer component and throw in the text in there. Then it would cycle without trouble. But how big can the Circular Buffer be actually, are there any limitations or issues? Would 4096 bytes cause any trouble?
Thanks for your thoughts.
Regards,
R
Event Log Embedded
-
- Posts: 54
- http://meble-kuchenne.info.pl
- Joined: Wed Sep 08, 2021 10:36 pm
- Has thanked: 26 times
- Been thanked: 11 times
-
- Valued Contributor
- Posts: 1462
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 136 times
- Been thanked: 713 times
Re: Event Log Embedded
I'd probably use an array of strings or even dynamically allocate memory. You need to allocate a block of memory using circular buffer or array (and thus a maximum number of entries) - dynamically allocated can have a maximum set or run until RAM runs out?
For ease of use I'd allow for several macros:
Log(string)
LogN(string, number)
LogNN(string, number, number)
etc as fitted needs and have a global constant (debug?) that if set to true allows the logging and if false turns it off..
Then you'll need a PrintLog or similar that dumps the output to UART or as required.. This may run at end of program or on a button press (be careful not to put too much code into the interrupt handler though)
Martin
For ease of use I'd allow for several macros:
Log(string)
LogN(string, number)
LogNN(string, number, number)
etc as fitted needs and have a global constant (debug?) that if set to true allows the logging and if false turns it off..
Then you'll need a PrintLog or similar that dumps the output to UART or as required.. This may run at end of program or on a button press (be careful not to put too much code into the interrupt handler though)
Martin
-
- Posts: 54
- Joined: Wed Sep 08, 2021 10:36 pm
- Has thanked: 26 times
- Been thanked: 11 times
Re: Event Log Embedded
Thanks Martin,
Yeah, I've allocated a Circular Buffer only for this purpose.
Only problem now when simulating is when I use the function GetString() and say read 30 characters, the string comes back OK, but the data in the buffer seems to be set back to 255 (empties the data on those 30 characters)
I want to keep the buffer intact at all times, when reading from it, not sure how this can be achieved...
Cheers,
R
Yeah, I've allocated a Circular Buffer only for this purpose.
Only problem now when simulating is when I use the function GetString() and say read 30 characters, the string comes back OK, but the data in the buffer seems to be set back to 255 (empties the data on those 30 characters)

I want to keep the buffer intact at all times, when reading from it, not sure how this can be achieved...
Cheers,
R
-
- Valued Contributor
- Posts: 1462
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 136 times
- Been thanked: 713 times
Re: Event Log Embedded
When you get data from a circular buffer it does empty it (it's intended as a buffer to an UART or similar) to make room for new data.
Can you post/PM your code - and I'll take a look or I can do a simple example using arrays that doesn't have this problem..
Martin
Can you post/PM your code - and I'll take a look or I can do a simple example using arrays that doesn't have this problem..
Martin
-
- Posts: 54
- Joined: Wed Sep 08, 2021 10:36 pm
- Has thanked: 26 times
- Been thanked: 11 times
Re: Event Log Embedded
Thanks Martin,
Yes arrays of strings are the way to go then, it's no problem I'll implement the log in this fashion, it's straightforward enough approach.
Cheers!
R
Yes arrays of strings are the way to go then, it's no problem I'll implement the log in this fashion, it's straightforward enough approach.
Cheers!
R