Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
src/AnalyticsLogger/AnalyticsLogger.cpp
- Committer:
- jmarkel44
- Date:
- 2016-09-19
- Revision:
- 77:43e0a3d9e536
- Parent:
- 68:dbe39d83eb98
- Child:
- 79:d6638c01eeec
File content as of revision 77:43e0a3d9e536:
/****************************************************************************** * * File: AnalyticsLogger.cpp * Desciption: source for the ICE Analytics Logger * *****************************************************************************/ #include "global.h" #include <stdio.h> #include "AnalyticsLogger.h" #include "CloudDataLoggerApi.h" #include "eep.h" #include "rtc.h" /***************************************************************************** * Function: AnalyticsLogger * Description: entry point for the Analytics Logger * * @param (IN) args (user-defined arguments) * @return none *****************************************************************************/ void AnalyticsLogger(void const *args) { struct tm *ts; time_t curr_sec; char time_string[80]; int last_min=8; curr_sec = time(0); ts = localtime(&curr_sec); strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", ts); printf("\r\n%s has started at: %s\r\n", __func__, time_string); while ( true ) { if( CloudDataHandlerConnected == true ) { // we are connected to the cloud, we don't save anything to EEPROM. Thread::wait(5000); continue; } osEvent evt = AnalyticsLoggerMailBox.get(5000); if (evt.status == osEventMail) { AnalyticsLoggerReq_t *mail = (AnalyticsLoggerReq_t*)evt.value.p; logInfo("Analytics Logger Mail Received: Timestamp: %s, Entry: %s", mail->timestamp, mail->log_entry); AnalyticsLoggerMailBox.free(mail); break; } curr_sec = time(0); ts = localtime(&curr_sec); // printf("curr_sec=%ld, min=%d (last=%d)\r\n", curr_sec, ts->tm_min, last_min ); if( ((ts->tm_min%15) == 0) && (ts->tm_min != last_min) ) { last_min = ts->tm_min; strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", ts); logInfo("%s logging at: %s\r\n", __func__, time_string); std::map<std::string, ModbusRegister>::iterator iter; for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) { logInfo("Logging tag=%s, value=%2.2f\r\n", iter->first.c_str(), iter->second.float_value ); } } } } bool AnalyticsLoggerApi( std::string *log_string ) { logInfo("Sending Mail To AnalyticsLoggerMailbox"); AnalyticsLoggerReq_t *mail = AnalyticsLoggerMailBox.alloc(); strncpy( mail->log_entry, log_string->c_str(), (sizeof(mail->log_entry)-1)); AnalyticsLoggerMailBox.put(mail); return true; }