Baseline for testing
Diff: EventLog.cpp
- Revision:
- 0:929bb73983c5
- Child:
- 1:aaddf80105fe
diff -r 000000000000 -r 929bb73983c5 EventLog.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EventLog.cpp Thu Jul 25 00:43:28 2019 +0000 @@ -0,0 +1,122 @@ + +#include "mbed.h" +#include "EventLog.h" + + +ESCM_EventLog::ESCM_EventLog() { + full_=false; + head_=0; + tail_=0; + +} + +ESCM_EventLog::~ESCM_EventLog() { +} + +void ESCM_EventLog::init() +{ + full_=false; + head_=0; + tail_=0; + + printf("Initializing Event Log\n\r"); + + memset ( events,0,sizeof(ESCM_Event)*MAX_EVENTS); +} + +int ESCM_EventLog::load() +{ +#if 1 + char * filename = "/local/event_log.bin"; + FILE *input = fopen(filename, "rb"); + if(input){ + + printf("Reading %s\n\r",filename ); + int size = MAX_EVENTS; + + fread(&size, sizeof(uint32_t),1,input); + + for (int i=0;i<MAX_EVENTS;i++) + { + printf("." ); + fread( &events[i].address, sizeof(uint32_t),1 , input); + fread( events[i].timeStr, sizeof(char) ,40, input); + } + fclose(input); + return 1; + } + else + { + printf("Could not Read %s\n\r",filename ); + return 0; + } +#endif +} + +void ESCM_EventLog::save() +{ +#if 1 + char * filename = "/local/event_log.bin"; + FILE *output = fopen(filename, "wb"); + + printf("Saving %s\n\r",filename ); + int size = MAX_EVENTS; + + fwrite(&size, sizeof(uint32_t),1,output); + + for (int i=0;i<MAX_EVENTS;i++) + { + printf("." ); + fwrite( &events[i].address, sizeof(uint32_t),1 , output); + fwrite( events[i].timeStr, sizeof(char) ,40, output); + } + fflush(output); + fclose(output); + +#endif + + printf("Done \n\r" ); +} + +void ESCM_EventLog::display(Serial *pc) +{ + int j = tail_; + int i = head_; + int count = 0 ; + + pc->printf("\n\r"); + pc->printf("-----------------------------\n\r"); + pc->printf("- Event Log \n\r"); + pc->printf("-----------------------------\n\r"); + pc->printf("%d %d %d \n\r", i,j, full_); + + + while ( count < size() ) + { + pc->printf("%02d > %02d :: %s\n\r", count, events[i].address, events[i].timeStr ); + if ( --i <= 0) { + i =( max_size_ - 1 ); + } + count++; + } + pc->printf("-----------------------------\n\r"); +} + +void ESCM_EventLog::add(int address) +{ + ESCM_Event newEvent; + newEvent.address = address; + sprintf ( newEvent.timeStr , "%s", "==="); + + put( newEvent ); +} + +void ESCM_EventLog::add(int address, char* timeStamp) +{ + ESCM_Event newEvent; + newEvent.address = address; + sprintf ( newEvent.timeStr , "%-16s", timeStamp); + + put( newEvent ); +} +