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@125:f11cc566d073, 2016-09-23 (annotated)
- Committer:
- davidjhoward
- Date:
- Fri Sep 23 20:31:35 2016 +0000
- Revision:
- 125:f11cc566d073
- Parent:
- 116:7337ed514891
- Child:
- 177:9ec90c8e3ce1
more logging work
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> |
davidjhoward | 125:f11cc566d073 | 9 | #include <string> |
davidjhoward | 125:f11cc566d073 | 10 | #include <sstream> |
davidjhoward | 125:f11cc566d073 | 11 | #include <iostream> |
jmarkel44 | 0:65cfa4873284 | 12 | #include "AnalyticsLogger.h" |
davidjhoward | 125:f11cc566d073 | 13 | #include "LoggerApi.h" |
davidjhoward | 58:a4422d19b2ea | 14 | #include "eep.h" |
davidjhoward | 60:96e17fb215a6 | 15 | #include "rtc.h" |
jmarkel44 | 0:65cfa4873284 | 16 | |
jmarkel44 | 0:65cfa4873284 | 17 | /***************************************************************************** |
jmarkel44 | 0:65cfa4873284 | 18 | * Function: AnalyticsLogger |
davidjhoward | 58:a4422d19b2ea | 19 | * Description: entry point for the Analytics Logger |
jmarkel44 | 0:65cfa4873284 | 20 | * |
jmarkel44 | 0:65cfa4873284 | 21 | * @param (IN) args (user-defined arguments) |
jmarkel44 | 0:65cfa4873284 | 22 | * @return none |
jmarkel44 | 0:65cfa4873284 | 23 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 24 | void AnalyticsLogger(void const *args) |
jmarkel44 | 0:65cfa4873284 | 25 | { |
davidjhoward | 60:96e17fb215a6 | 26 | struct tm *ts; |
davidjhoward | 60:96e17fb215a6 | 27 | time_t curr_sec; |
davidjhoward | 60:96e17fb215a6 | 28 | int last_min=8; |
davidjhoward | 125:f11cc566d073 | 29 | |
jmarkel44 | 0:65cfa4873284 | 30 | while ( true ) { |
davidjhoward | 125:f11cc566d073 | 31 | |
davidjhoward | 125:f11cc566d073 | 32 | std::ostringstream log_event; |
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 | 125:f11cc566d073 | 37 | if( ((ts->tm_min%5) == 0) && (ts->tm_min != last_min) ) { |
davidjhoward | 60:96e17fb215a6 | 38 | last_min = ts->tm_min; |
davidjhoward | 61:ae6dd6692c7d | 39 | |
davidjhoward | 125:f11cc566d073 | 40 | log_event << "\"lr\":["; |
davidjhoward | 61:ae6dd6692c7d | 41 | std::map<std::string, ModbusRegister>::iterator iter; |
davidjhoward | 61:ae6dd6692c7d | 42 | for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) { |
davidjhoward | 125:f11cc566d073 | 43 | |
davidjhoward | 125:f11cc566d073 | 44 | log_event << "{\"t\":"<< "\"" << iter->first.c_str() << "\"," << "\"v\":"<< "\"" << iter->second.float_value<< "\"},"; |
davidjhoward | 61:ae6dd6692c7d | 45 | } |
davidjhoward | 125:f11cc566d073 | 46 | std::string str = log_event.str(); |
davidjhoward | 125:f11cc566d073 | 47 | str.erase( str.size() - 1 ); |
davidjhoward | 125:f11cc566d073 | 48 | str.append("]"); |
davidjhoward | 125:f11cc566d073 | 49 | // printf("Logging %s : len=%d\r\n", str.c_str(), str.length() ); |
davidjhoward | 125:f11cc566d073 | 50 | LiveDataLoggerApi( str.c_str() ); |
davidjhoward | 58:a4422d19b2ea | 51 | } |
davidjhoward | 78:5a2e019036a4 | 52 | |
davidjhoward | 78:5a2e019036a4 | 53 | Thread::wait(5000); |
jmarkel44 | 0:65cfa4873284 | 54 | } |
jmarkel44 | 0:65cfa4873284 | 55 | } |