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@116:7337ed514891, 2016-09-22 (annotated)
- Committer:
- davidjhoward
- Date:
- Thu Sep 22 21:09:49 2016 +0000
- Revision:
- 116:7337ed514891
- Parent:
- 79:d6638c01eeec
- Child:
- 125:f11cc566d073
Write log to EEPROM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmarkel44 | 0:65cfa4873284 | 1 | /****************************************************************************** |
davidjhoward | 58:a4422d19b2ea | 2 | * |
jmarkel44 | 0:65cfa4873284 | 3 | * File: AnalyticsLogger.cpp |
jmarkel44 | 0:65cfa4873284 | 4 | * Desciption: source for the ICE Analytics Logger |
jmarkel44 | 0:65cfa4873284 | 5 | * |
jmarkel44 | 0:65cfa4873284 | 6 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 7 | #include "global.h" |
jmarkel44 | 0:65cfa4873284 | 8 | #include <stdio.h> |
jmarkel44 | 0:65cfa4873284 | 9 | #include "AnalyticsLogger.h" |
davidjhoward | 58:a4422d19b2ea | 10 | #include "eep.h" |
davidjhoward | 60:96e17fb215a6 | 11 | #include "rtc.h" |
jmarkel44 | 0:65cfa4873284 | 12 | |
jmarkel44 | 0:65cfa4873284 | 13 | /***************************************************************************** |
jmarkel44 | 0:65cfa4873284 | 14 | * Function: AnalyticsLogger |
davidjhoward | 58:a4422d19b2ea | 15 | * Description: entry point for the Analytics Logger |
jmarkel44 | 0:65cfa4873284 | 16 | * |
jmarkel44 | 0:65cfa4873284 | 17 | * @param (IN) args (user-defined arguments) |
jmarkel44 | 0:65cfa4873284 | 18 | * @return none |
jmarkel44 | 0:65cfa4873284 | 19 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 20 | void AnalyticsLogger(void const *args) |
jmarkel44 | 0:65cfa4873284 | 21 | { |
davidjhoward | 60:96e17fb215a6 | 22 | struct tm *ts; |
davidjhoward | 60:96e17fb215a6 | 23 | time_t curr_sec; |
davidjhoward | 60:96e17fb215a6 | 24 | char time_string[80]; |
davidjhoward | 60:96e17fb215a6 | 25 | int last_min=8; |
davidjhoward | 60:96e17fb215a6 | 26 | |
davidjhoward | 60:96e17fb215a6 | 27 | curr_sec = time(0); |
davidjhoward | 60:96e17fb215a6 | 28 | ts = localtime(&curr_sec); |
davidjhoward | 60:96e17fb215a6 | 29 | strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", ts); |
davidjhoward | 60:96e17fb215a6 | 30 | printf("\r\n%s has started at: %s\r\n", __func__, time_string); |
jmarkel44 | 0:65cfa4873284 | 31 | |
jmarkel44 | 0:65cfa4873284 | 32 | while ( true ) { |
davidjhoward | 60:96e17fb215a6 | 33 | |
davidjhoward | 60:96e17fb215a6 | 34 | curr_sec = time(0); |
davidjhoward | 60:96e17fb215a6 | 35 | ts = localtime(&curr_sec); |
davidjhoward | 60:96e17fb215a6 | 36 | // printf("curr_sec=%ld, min=%d (last=%d)\r\n", curr_sec, ts->tm_min, last_min ); |
davidjhoward | 60:96e17fb215a6 | 37 | if( ((ts->tm_min%15) == 0) && (ts->tm_min != last_min) ) { |
davidjhoward | 60:96e17fb215a6 | 38 | last_min = ts->tm_min; |
davidjhoward | 60:96e17fb215a6 | 39 | strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", ts); |
jmarkel44 | 77:43e0a3d9e536 | 40 | logInfo("%s logging at: %s\r\n", __func__, time_string); |
davidjhoward | 61:ae6dd6692c7d | 41 | |
davidjhoward | 61:ae6dd6692c7d | 42 | std::map<std::string, ModbusRegister>::iterator iter; |
davidjhoward | 61:ae6dd6692c7d | 43 | for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) { |
jmarkel44 | 77:43e0a3d9e536 | 44 | logInfo("Logging tag=%s, value=%2.2f\r\n", iter->first.c_str(), iter->second.float_value ); |
davidjhoward | 61:ae6dd6692c7d | 45 | } |
davidjhoward | 58:a4422d19b2ea | 46 | } |
davidjhoward | 78:5a2e019036a4 | 47 | |
davidjhoward | 78:5a2e019036a4 | 48 | Thread::wait(5000); |
jmarkel44 | 0:65cfa4873284 | 49 | } |
davidjhoward | 68:dbe39d83eb98 | 50 | } |
davidjhoward | 68:dbe39d83eb98 | 51 | |
davidjhoward | 68:dbe39d83eb98 | 52 | bool AnalyticsLoggerApi( std::string *log_string ) |
davidjhoward | 68:dbe39d83eb98 | 53 | { |
davidjhoward | 78:5a2e019036a4 | 54 | logInfo("%s:%d Sending Mail To AnalyticsLoggerMailbox", __func__, __LINE__); |
davidjhoward | 68:dbe39d83eb98 | 55 | AnalyticsLoggerReq_t *mail = AnalyticsLoggerMailBox.alloc(); |
davidjhoward | 68:dbe39d83eb98 | 56 | strncpy( mail->log_entry, log_string->c_str(), (sizeof(mail->log_entry)-1)); |
davidjhoward | 68:dbe39d83eb98 | 57 | AnalyticsLoggerMailBox.put(mail); |
davidjhoward | 68:dbe39d83eb98 | 58 | |
davidjhoward | 68:dbe39d83eb98 | 59 | return true; |
jmarkel44 | 0:65cfa4873284 | 60 | } |