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
Revision 123:ce602c91a9c3, committed 2016-09-23
- Comitter:
- davidjhoward
- Date:
- Fri Sep 23 15:25:06 2016 +0000
- Parent:
- 120:539b20bd3816
- Child:
- 124:48119db89152
- Commit message:
- continue work on logging
Changed in this revision
--- a/src/CloudDataHandler/CloudDataHandler.cpp Thu Sep 22 21:30:48 2016 +0000
+++ b/src/CloudDataHandler/CloudDataHandler.cpp Fri Sep 23 15:25:06 2016 +0000
@@ -11,7 +11,7 @@
void CloudDataHandler(void const *args)
{
int32_t ret;
- bool connected;
+ bool joined;
bool sent;
printf("\r%s has started...\n", __func__);
@@ -24,13 +24,13 @@
logInfo("network not joined, joining network");
if ((ret = GLOBAL_mdot->joinNetwork()) != mDot::MDOT_OK) {
logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
- connected = false;
+ joined = false;
}
} else {
- connected = true;
+ joined = true;
}
- sent = LogHandler( connected );
+ sent = LogHandler( joined );
if( sent == true ) {
// sent a packet, try to receive back.
logInfo("Sent to gateway: %s", tmp_buffer.c_str());
@@ -44,6 +44,6 @@
}
}
}
- Thread::wait(5000);
+ Thread::wait(10000);
}
}
\ No newline at end of file
--- a/src/CloudDataHandler/LogHandler.cpp Thu Sep 22 21:30:48 2016 +0000
+++ b/src/CloudDataHandler/LogHandler.cpp Fri Sep 23 15:25:06 2016 +0000
@@ -9,42 +9,73 @@
Mail<LoggerQueue_t, 16> LoggerQueue;
-size_t LoggerXmitLength = 128;
+size_t LoggerXmitLength = LOG_BYTES_PER_ENTRY;
-bool LogHandler( bool connected )
+bool LogHandler( bool joined )
{
int32_t ret;
+ char buffer[LOG_BYTES_PER_ENTRY];
std::string tmp_buffer;
+ bool log_in_eeprom=false;
+ bool log_to_send=false;
osEvent evt = LoggerQueue.get(50);
- if (evt.status != osEventMail) {
- tmp_buffer = "{\"mtype\":\"20\"}";
- } else {
- char buffer[128];
+ if( (evt.status == osEventMail) ) {
+ // pull the log event from the queue, even if we are not joined
LoggerQueue_t *LoggerEvent = (LoggerQueue_t*)evt.value.p;
logInfo("Log Msg Received: log entry: %s", LoggerEvent->log_entry);
- if( strlen(LoggerEvent->log_entry) >= LoggerXmitLength ) {
- memset(buffer, 0, sizeof(buffer));
- strncpy( buffer, LoggerEvent->log_entry, (LoggerXmitLength-1) );
+ strncpy( buffer, LoggerEvent->log_entry, (LoggerXmitLength-1) );
+ tmp_buffer.assign(buffer);
+ log_to_send = true;
+// printf("%s:%d: Found Log Event on LoggerQueue to send to cloud\r\n", __func__, __LINE__);
+ LoggerQueue.free(LoggerEvent);
+ }
+
+ if( (evt.status == osEventMail) && (joined == false) ) {
+ // if we pulled a log from the queue put it in the EEPROM
+ LogLocalApi( tmp_buffer.c_str() );
+// printf("%s:%d: Not Connected, Putting Logger event In EEPROM\r\n", __func__, __LINE__);
+ return false;
+ }
+
+ if( (evt.status != osEventMail) && joined == true) {
+ // nothing on the queue, see if there is anything in the EEPROM to send.
+ log_in_eeprom = LogLocalApi_PopEntry( buffer );
+ if( log_in_eeprom == true ) {
tmp_buffer.assign(buffer);
- } else {
- strncpy( buffer, LoggerEvent->log_entry, (LoggerXmitLength-1) );
- tmp_buffer.assign(buffer);
- LoggerQueue.free(LoggerEvent);
+ log_to_send = true;
+ // printf("%s:%d: Found Log Event in EEPROM to send to cloud\r\n", __func__, __LINE__);
+ }
+ else
+ {
+// printf("%s:%d: Nothing in EEPROM\r\n", __func__, __LINE__);
}
}
- if( connected == true ) {
+ if( log_to_send == false ) {
+ // no event log to send, send the heart beat message.
+// printf("%s:%d: No Log Event to send, attempt heart beat\r\n", __func__, __LINE__);
+ tmp_buffer = "{\"mtype\":\"20\"}";
+ }
+
+ if( joined == true ) {
std::vector<uint8_t> data(tmp_buffer.begin(), tmp_buffer.end());
if ((ret = GLOBAL_mdot->send(data)) == mDot::MDOT_OK) {
+// printf("%s:%d: Successful send to cloud\r\n", __func__, __LINE__);
return true;
}
- printf("failed to send, ret=%d, %s\r\n", ret, mDot::getReturnCodeString(ret).c_str());
+// printf("failed to send, ret=%d, %s\r\n", ret, mDot::getReturnCodeString(ret).c_str());
}
-
- printf("connected=%d\r\n",connected);
- // Store the log to local device
- LogLocalApi( tmp_buffer.c_str() );
+ if( log_to_send == true ) {
+ // We had a log event ready to send but didn't send it.
+ // Store it in the EEPROM for the next attempt.
+// printf("%s:%d: Could not send Log Event to cloud, store in EEPROM\r\n", __func__, __LINE__);
+ LogLocalApi( tmp_buffer.c_str() );
+ }
+ else
+ {
+// printf("%s:%d: Could not send to cloud, nothing to store in EEPROM\r\n", __func__, __LINE__);
+ }
return false;
}
\ No newline at end of file
--- a/src/CloudDataHandler/LogHandler.h Thu Sep 22 21:30:48 2016 +0000
+++ b/src/CloudDataHandler/LogHandler.h Fri Sep 23 15:25:06 2016 +0000
@@ -2,15 +2,16 @@
#define LOGHANDLER_H
#include "global.h"
+#include "LogLocalApi.h"
typedef struct logger_queue_t {
size_t position;
- char log_entry[128];
+ char log_entry[LOG_BYTES_PER_ENTRY];
} LoggerQueue_t;
extern Mail<LoggerQueue_t, 16> LoggerQueue;
-bool LogHandler( bool connected );
+bool LogHandler( bool joined );
#endif
--- a/src/CommandParser/cmd.cpp Thu Sep 22 21:30:48 2016 +0000
+++ b/src/CommandParser/cmd.cpp Fri Sep 23 15:25:06 2016 +0000
@@ -37,6 +37,7 @@
#include "ConfigurationHandler.h"
#include "ModbusMasterApi.h"
#include "LogLocalApi.h"
+#include "LoggerApi.h"
#include "OutputTask.h"
#include "mDot.h"
#include "rtos.h"
@@ -85,6 +86,7 @@
{"simin", "simulate input", cmd_simin },
{"deep", "dump EEP", cmd_deep },
{"peep", "push EEP", cmd_peep },
+ {"ins-log", "insert log event", cmd_inslog },
{NULL, NULL, NULL}
@@ -420,7 +422,7 @@
"\"halert\": \"115\","
"\"lalert\": \"85\", "
"\"hfs\": \"130\","
- "\"lfs\": \"70\", "
+ "\"lfs\": \"70\", "
"\"tol\": \"%s\" }", argv[2], argv[3], argv[4], argv[5], argv[6]
);
@@ -950,15 +952,12 @@
UNUSED(argc);
UNUSED(argv);
- char logString[128];
+ char logString[LOG_BYTES_PER_ENTRY];
LogLocalApi_PopEntry( logString );
- if( logString[0] != '\0' )
- {
+ if( logString[0] != '\0' ) {
printf("%s\r\n", logString );
- }
- else
- {
+ } else {
printf("%s\r\n", "No String Found" );
}
}
@@ -971,4 +970,18 @@
std::string logString = "This is a string to log";
LogLocalApi_PushEntry( logString.c_str() );
+}
+
+void cmd_inslog( int argc, char **argv )
+{
+ UNUSED(argc);
+ UNUSED(argv);
+
+ EventReasonStruct_t eventReason;
+ eventReason.eventReason = EVENT_REASON_AUTO;
+ eventReason.inputValue = 100.00;
+ strncpy(eventReason.inputTag, "i_stub01", sizeof(eventReason.inputTag) );
+ eventReason.outputValue = 0.0;
+ strncpy(eventReason.outputTag, "o_stub01", sizeof(eventReason.outputTag) );
+ EventLoggerApi( eventReason );
}
\ No newline at end of file
--- a/src/CommandParser/cmd.h Thu Sep 22 21:30:48 2016 +0000 +++ b/src/CommandParser/cmd.h Fri Sep 23 15:25:06 2016 +0000 @@ -61,5 +61,6 @@ void cmd_simin (int argc, char **argv); void cmd_deep (int argc, char **argv); void cmd_peep (int argc, char **argv); +void cmd_inslog (int argc, char **argv); #endif
--- a/src/Drivers/LogLocalApi.cpp Thu Sep 22 21:30:48 2016 +0000
+++ b/src/Drivers/LogLocalApi.cpp Fri Sep 23 15:25:06 2016 +0000
@@ -4,7 +4,7 @@
#include "global.h"
#include "eep.h"
-#define WAIT_TIME 1
+#define WAIT_TIME 5
void LogLocalApi( const char *logString )
{
@@ -25,18 +25,18 @@
unsigned char data1 = eep_get_byte(1, EEP_NBYT-2);
unsigned char data2 = eep_get_byte(1, EEP_NBYT-1);
- printf("read data0=0x%x, data1=0x%x, data2=0x%x\r\n", data0, data1, data2);
+// printf("read data0=0x%x, data1=0x%x, data2=0x%x\r\n", data0, data1, data2);
addr = ((data0<<16) & 0x03);
addr |= (data1<<8);
addr |= (data2);
dev = ((data0<<16) & 0x04);
- printf("start: device=%d, addr=0x%x\r\n", dev, addr);
+// printf("start: device=%d, addr=0x%x\r\n", dev, addr);
int len=strlen(logString);
- if( i >=LOG_BYTES_PER_ENTRY ) {
- logError("String too large");
+ if( len >=LOG_BYTES_PER_ENTRY ) {
+ logError("String too large, max=%d, len=%d", LOG_BYTES_PER_ENTRY, len );
return;
}
for( i=0,waddr=addr; i<=len; waddr++,i++ ) {
@@ -45,7 +45,7 @@
// printf("dev=%d, waddr=0x%x, wbyte=0x%x\r\n", dev, waddr, logString[i] );
}
waddr = addr + LOG_BYTES_PER_ENTRY;
- printf("final: device=%d, addr=0x%x, strlen=%d\r\n", dev, waddr, len);
+// printf("final: device=%d, addr=0x%x, strlen=%d\r\n", dev, waddr, len);
if( (waddr+127) >= EEP_NBYT ) {
if( dev == 0 )
@@ -56,7 +56,7 @@
data1 = (waddr&0x0000FF00)>>8;
data2 = (waddr&0x000000FF);
- printf("storing new address: data0=0x%x, data1=0x%x, data2=0x%x\r\n", data0, data1, data2);
+// printf("storing new address: data0=0x%x, data1=0x%x, data2=0x%x\r\n", data0, data1, data2);
eep_verbose = 0;
eep_set_byte(1, EEP_NBYT-3, data0);
@@ -68,21 +68,21 @@
eep_verbose = 0;
}
-void LogLocalApi_PopEntry( char *logString )
+bool LogLocalApi_PopEntry( char *logString )
{
unsigned long addr;
long raddr;
int dev;
int i;
-
- printf("%s\r\n", logString );
+
+ memset( logString, '\0', LOG_BYTES_PER_ENTRY );
// last 3 bytes of device 1 store next write address.
unsigned char data0 = eep_get_byte(1, EEP_NBYT-3);
unsigned char data1 = eep_get_byte(1, EEP_NBYT-2);
unsigned char data2 = eep_get_byte(1, EEP_NBYT-1);
- printf("read data0=0x%x, data1=0x%x, data2=0x%x\r\n", data0, data1, data2);
+// printf("read data0=0x%x, data1=0x%x, data2=0x%x\r\n", data0, data1, data2);
addr = ((data0<<16) & 0x03);
addr |= (data1<<8);
@@ -95,13 +95,12 @@
dev = 0;
raddr = LOG_END_OF_STORAGE - LOG_BYTES_PER_ENTRY;
} else {
- printf("already at first entry\r\n");
- memset( logString, '\0', LOG_BYTES_PER_ENTRY );
- return;
+// printf("already at first entry\r\n");
+ return false;
}
}
- printf("start: device=%d, addr=0x%x, raddr=0x%x\r\n", dev, addr, raddr);
+// printf("start: device=%d, addr=0x%x, raddr=0x%x\r\n", dev, addr, raddr);
for( i=0,raddr; i<=LOG_BYTES_PER_ENTRY; raddr++,i++ ) {
logString[i] = eep_get_byte(dev, raddr);
@@ -110,8 +109,7 @@
}
logString[LOG_BYTES_PER_ENTRY-1] = '\0';
raddr = addr - LOG_BYTES_PER_ENTRY;
- printf("final: raddr=0x%x, strlen=%d\r\n", raddr, strlen(logString));
-
+// printf("final: raddr=0x%x, strlen=%d\r\n", raddr, strlen(logString));
if( dev == 0 )
data0 = ((raddr&0x00030000)>>16);
@@ -120,7 +118,7 @@
data1 = (raddr&0x0000FF00)>>8;
data2 = (raddr&0x000000FF);
- printf("storing new address: data0=0x%x, data1=0x%x, data2=0x%x\r\n", data0, data1, data2);
+// printf("storing new address: data0=0x%x, data1=0x%x, data2=0x%x\r\n", data0, data1, data2);
eep_verbose = 0;
eep_set_byte(1, EEP_NBYT-3, data0);
@@ -130,4 +128,6 @@
eep_set_byte(1, EEP_NBYT-1, data2);
Thread::wait(WAIT_TIME);
eep_verbose = 0;
+
+ return true;
}
\ No newline at end of file
--- a/src/Drivers/LogLocalApi.h Thu Sep 22 21:30:48 2016 +0000 +++ b/src/Drivers/LogLocalApi.h Fri Sep 23 15:25:06 2016 +0000 @@ -4,12 +4,12 @@ #include <string.h> #include "eep.h" -#define LOG_BYTES_PER_ENTRY 128 +#define LOG_BYTES_PER_ENTRY 196 #define LOG_END_OF_STORAGE (EEP_NBYT - LOG_BYTES_PER_ENTRY) void LogLocalApi( const char *logString ); void LogLocalApi_PushEntry( const char *logString ); -void LogLocalApi_PopEntry( char *logString ); +bool LogLocalApi_PopEntry( char *logString ); #endif
--- a/src/ModbusMaster/ModbusMaster.cpp Thu Sep 22 21:30:48 2016 +0000
+++ b/src/ModbusMaster/ModbusMaster.cpp Fri Sep 23 15:25:06 2016 +0000
@@ -10,7 +10,6 @@
#include "BLEDataHandler.h"
#include "ModbusMaster.h"
#include "MbedJSONValue.h"
-#include "LoggerApi.h"
DigitalOut dout1(PC_1);
DigitalOut dout2(PA_1);
@@ -118,13 +117,6 @@
if( status == true ) {
ModbusRegisterMap[iter->first].float_value = float_value;
logInfo("Modbus Tag:%s value=%2.2f", iter->first.c_str(), float_value );
- EventReasonStruct_t eventReason;
- eventReason.eventReason = EVENT_REASON_AUTO;
- eventReason.inputValue = float_value;
- strncpy(eventReason.inputTag, iter->first.c_str(), sizeof(eventReason.inputTag) );
- eventReason.outputValue = 0.0;
- strncpy(eventReason.outputTag, "o_rly1", sizeof(eventReason.outputTag) );
- EventLoggerApi( eventReason );
} else {
logInfo("Modbus Read Failed, tag=%s", iter->first.c_str() );
}
