Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Committer:
davidjhoward
Date:
Mon Sep 19 21:20:43 2016 +0000
Revision:
79:d6638c01eeec
Parent:
77:43e0a3d9e536
Parent:
78:5a2e019036a4
Child:
116:7337ed514891
merge

Who changed what in which revision?

UserRevisionLine numberNew 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 68:dbe39d83eb98 10 #include "CloudDataLoggerApi.h"
davidjhoward 58:a4422d19b2ea 11 #include "eep.h"
davidjhoward 60:96e17fb215a6 12 #include "rtc.h"
jmarkel44 0:65cfa4873284 13
jmarkel44 0:65cfa4873284 14 /*****************************************************************************
jmarkel44 0:65cfa4873284 15 * Function: AnalyticsLogger
davidjhoward 58:a4422d19b2ea 16 * Description: entry point for the Analytics Logger
jmarkel44 0:65cfa4873284 17 *
jmarkel44 0:65cfa4873284 18 * @param (IN) args (user-defined arguments)
jmarkel44 0:65cfa4873284 19 * @return none
jmarkel44 0:65cfa4873284 20 *****************************************************************************/
jmarkel44 0:65cfa4873284 21 void AnalyticsLogger(void const *args)
jmarkel44 0:65cfa4873284 22 {
davidjhoward 60:96e17fb215a6 23 struct tm *ts;
davidjhoward 60:96e17fb215a6 24 time_t curr_sec;
davidjhoward 60:96e17fb215a6 25 char time_string[80];
davidjhoward 60:96e17fb215a6 26 int last_min=8;
davidjhoward 60:96e17fb215a6 27
davidjhoward 60:96e17fb215a6 28 curr_sec = time(0);
davidjhoward 60:96e17fb215a6 29 ts = localtime(&curr_sec);
davidjhoward 60:96e17fb215a6 30 strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", ts);
davidjhoward 60:96e17fb215a6 31 printf("\r\n%s has started at: %s\r\n", __func__, time_string);
jmarkel44 0:65cfa4873284 32
jmarkel44 0:65cfa4873284 33 while ( true ) {
davidjhoward 68:dbe39d83eb98 34
davidjhoward 68:dbe39d83eb98 35 if( CloudDataHandlerConnected == true )
davidjhoward 68:dbe39d83eb98 36 {
davidjhoward 68:dbe39d83eb98 37 // we are connected to the cloud, we don't save anything to EEPROM.
davidjhoward 78:5a2e019036a4 38 logInfo("%s:%d Not logging to EEPROM", __func__, __LINE__);
davidjhoward 68:dbe39d83eb98 39 Thread::wait(5000);
davidjhoward 68:dbe39d83eb98 40 continue;
davidjhoward 68:dbe39d83eb98 41 }
davidjhoward 68:dbe39d83eb98 42
davidjhoward 78:5a2e019036a4 43 osEvent evt = AnalyticsLoggerMailBox.get(50);
davidjhoward 58:a4422d19b2ea 44 if (evt.status == osEventMail) {
davidjhoward 58:a4422d19b2ea 45 AnalyticsLoggerReq_t *mail = (AnalyticsLoggerReq_t*)evt.value.p;
davidjhoward 58:a4422d19b2ea 46 logInfo("Analytics Logger Mail Received: Timestamp: %s, Entry: %s", mail->timestamp, mail->log_entry);
davidjhoward 58:a4422d19b2ea 47 AnalyticsLoggerMailBox.free(mail);
davidjhoward 78:5a2e019036a4 48 continue;
davidjhoward 60:96e17fb215a6 49 }
davidjhoward 60:96e17fb215a6 50
davidjhoward 60:96e17fb215a6 51 curr_sec = time(0);
davidjhoward 60:96e17fb215a6 52 ts = localtime(&curr_sec);
davidjhoward 60:96e17fb215a6 53 // printf("curr_sec=%ld, min=%d (last=%d)\r\n", curr_sec, ts->tm_min, last_min );
davidjhoward 60:96e17fb215a6 54 if( ((ts->tm_min%15) == 0) && (ts->tm_min != last_min) ) {
davidjhoward 60:96e17fb215a6 55 last_min = ts->tm_min;
davidjhoward 60:96e17fb215a6 56 strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", ts);
jmarkel44 77:43e0a3d9e536 57 logInfo("%s logging at: %s\r\n", __func__, time_string);
davidjhoward 61:ae6dd6692c7d 58
davidjhoward 61:ae6dd6692c7d 59 std::map<std::string, ModbusRegister>::iterator iter;
davidjhoward 61:ae6dd6692c7d 60 for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) {
jmarkel44 77:43e0a3d9e536 61 logInfo("Logging tag=%s, value=%2.2f\r\n", iter->first.c_str(), iter->second.float_value );
davidjhoward 61:ae6dd6692c7d 62 }
davidjhoward 58:a4422d19b2ea 63 }
davidjhoward 78:5a2e019036a4 64
davidjhoward 78:5a2e019036a4 65 Thread::wait(5000);
jmarkel44 0:65cfa4873284 66 }
davidjhoward 68:dbe39d83eb98 67 }
davidjhoward 68:dbe39d83eb98 68
davidjhoward 68:dbe39d83eb98 69 bool AnalyticsLoggerApi( std::string *log_string )
davidjhoward 68:dbe39d83eb98 70 {
davidjhoward 78:5a2e019036a4 71 logInfo("%s:%d Sending Mail To AnalyticsLoggerMailbox", __func__, __LINE__);
davidjhoward 68:dbe39d83eb98 72 AnalyticsLoggerReq_t *mail = AnalyticsLoggerMailBox.alloc();
davidjhoward 68:dbe39d83eb98 73 strncpy( mail->log_entry, log_string->c_str(), (sizeof(mail->log_entry)-1));
davidjhoward 68:dbe39d83eb98 74 AnalyticsLoggerMailBox.put(mail);
davidjhoward 68:dbe39d83eb98 75
davidjhoward 68:dbe39d83eb98 76 return true;
jmarkel44 0:65cfa4873284 77 }