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@224:9ea8925c61e0, 2016-10-18 (annotated)
- Committer:
- davidjhoward
- Date:
- Tue Oct 18 12:02:42 2016 +0000
- Revision:
- 224:9ea8925c61e0
- Parent:
- 199:d65ed41d4dd4
- Child:
- 225:11e39a2f3785
minor changes
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 | 199:d65ed41d4dd4 | 29 | bool log_sent=false; | 
| davidjhoward | 199:d65ed41d4dd4 | 30 | |
| jmarkel44 | 0:65cfa4873284 | 31 | while ( true ) { | 
| davidjhoward | 199:d65ed41d4dd4 | 32 | |
| davidjhoward | 199:d65ed41d4dd4 | 33 | std::ostringstream log_event; | 
| davidjhoward | 60:96e17fb215a6 | 34 | |
| davidjhoward | 60:96e17fb215a6 | 35 | curr_sec = time(0); | 
| davidjhoward | 60:96e17fb215a6 | 36 | ts = localtime(&curr_sec); | 
| davidjhoward | 60:96e17fb215a6 | 37 | // printf("curr_sec=%ld, min=%d (last=%d)\r\n", curr_sec, ts->tm_min, last_min ); | 
| davidjhoward | 224:9ea8925c61e0 | 38 | if( ((ts->tm_min%15) == 0) && (ts->tm_min != last_min) ) { | 
| davidjhoward | 60:96e17fb215a6 | 39 | last_min = ts->tm_min; | 
| davidjhoward | 199:d65ed41d4dd4 | 40 | |
| davidjhoward | 125:f11cc566d073 | 41 | log_event << "\"lr\":["; | 
| davidjhoward | 61:ae6dd6692c7d | 42 | std::map<std::string, ModbusRegister>::iterator iter; | 
| davidjhoward | 61:ae6dd6692c7d | 43 | for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) { | 
| davidjhoward | 199:d65ed41d4dd4 | 44 | |
| davidjhoward | 125:f11cc566d073 | 45 | log_event << "{\"t\":"<< "\"" << iter->first.c_str() << "\"," << "\"v\":"<< "\"" << iter->second.float_value<< "\"},"; | 
| davidjhoward | 199:d65ed41d4dd4 | 46 | log_sent = false; | 
| davidjhoward | 199:d65ed41d4dd4 | 47 | if( log_event.str().size() >= 150 ) { | 
| davidjhoward | 199:d65ed41d4dd4 | 48 | std::string str = log_event.str(); | 
| davidjhoward | 199:d65ed41d4dd4 | 49 | str.erase( str.size() - 1 ); | 
| davidjhoward | 199:d65ed41d4dd4 | 50 | str.append("]"); | 
| davidjhoward | 199:d65ed41d4dd4 | 51 | // printf("%s:%d: Logging %s : len=%d\r\n", __func__, __LINE__, str.c_str(), str.length() ); | 
| davidjhoward | 199:d65ed41d4dd4 | 52 | LiveDataLoggerApi( str.c_str() ); | 
| davidjhoward | 199:d65ed41d4dd4 | 53 | log_event.str(""); | 
| davidjhoward | 199:d65ed41d4dd4 | 54 | log_event.clear(); | 
| davidjhoward | 199:d65ed41d4dd4 | 55 | log_event << "\"lr\":["; | 
| davidjhoward | 199:d65ed41d4dd4 | 56 | log_sent = true; | 
| davidjhoward | 199:d65ed41d4dd4 | 57 | } | 
| davidjhoward | 61:ae6dd6692c7d | 58 | } | 
| davidjhoward | 199:d65ed41d4dd4 | 59 | if( log_sent == false ) { | 
| davidjhoward | 199:d65ed41d4dd4 | 60 | std::string str = log_event.str(); | 
| davidjhoward | 199:d65ed41d4dd4 | 61 | str.erase( str.size() - 1 ); | 
| davidjhoward | 199:d65ed41d4dd4 | 62 | str.append("]"); | 
| davidjhoward | 199:d65ed41d4dd4 | 63 | if( str.length() > 10 ) { | 
| davidjhoward | 199:d65ed41d4dd4 | 64 | // printf("%s:%d: Logging %s : len=%d\r\n", __func__, __LINE__, str.c_str(), str.length() ); | 
| davidjhoward | 199:d65ed41d4dd4 | 65 | LiveDataLoggerApi( str.c_str() ); | 
| davidjhoward | 199:d65ed41d4dd4 | 66 | } | 
| davidjhoward | 199:d65ed41d4dd4 | 67 | } | 
| davidjhoward | 58:a4422d19b2ea | 68 | } | 
| davidjhoward | 199:d65ed41d4dd4 | 69 | |
| davidjhoward | 78:5a2e019036a4 | 70 | Thread::wait(5000); | 
| jmarkel44 | 0:65cfa4873284 | 71 | } | 
| jmarkel44 | 0:65cfa4873284 | 72 | } | 
