Page 1 of 1

Event Log Embedded

Posted: Sun Aug 28, 2022 9:11 am
by unity-control
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

Re: Event Log Embedded

Posted: Sun Aug 28, 2022 9:57 am
by mnfisher
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

Re: Event Log Embedded

Posted: Sun Aug 28, 2022 10:10 am
by unity-control
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

Re: Event Log Embedded

Posted: Sun Aug 28, 2022 10:19 am
by mnfisher
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

Re: Event Log Embedded

Posted: Sun Aug 28, 2022 10:43 am
by mnfisher
A simple demo using an array of strings...
LogDemo.fcfx
(14.18 KiB) Downloaded 66 times
Martin

Re: Event Log Embedded

Posted: Sun Aug 28, 2022 11:28 am
by unity-control
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