From 6adbe11be7f4df7a0e51e9a303341fc3aea64a51 Mon Sep 17 00:00:00 2001 From: mdeheras Date: Wed, 16 Mar 2016 12:38:28 +0100 Subject: [PATCH] Memory limit protection activated --- sck_beta_v0_9/Constants.h | 2 ++ sck_beta_v0_9/SCKServer.cpp | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/sck_beta_v0_9/Constants.h b/sck_beta_v0_9/Constants.h index 556428a..e63aaeb 100644 --- a/sck_beta_v0_9/Constants.h +++ b/sck_beta_v0_9/Constants.h @@ -125,6 +125,8 @@ Internal EEPROM Memory Addresses */ +#define MAX_MEMORY 571 //Memory size + // SCK Configuration Parameters #define EE_ADDR_TIME_VERSION 0 //32BYTES #define EE_ADDR_TIME_UPDATE 32 //4BYTES Time between update and update of the sensors in seconds diff --git a/sck_beta_v0_9/SCKServer.cpp b/sck_beta_v0_9/SCKServer.cpp index 435e910..6391a9d 100644 --- a/sck_beta_v0_9/SCKServer.cpp +++ b/sck_beta_v0_9/SCKServer.cpp @@ -132,15 +132,25 @@ void SCKServer::json_update(uint16_t updates, long *value, char *time, boolean i void SCKServer::addFIFO(long *value, char *time) { - int eeaddress = base__.readData(EE_ADDR_NUMBER_WRITE_MEASURE, INTERNAL); - int i = 0; - for (i = 0; i<9; i++) - { - base__.writeData(eeaddress + i*4, value[i], EXTERNAL); - } - base__.writeData(eeaddress + i*4, 0, time, EXTERNAL); - eeaddress = eeaddress + (SENSORS)*4 + TIME_BUFFER_SIZE; - base__.writeData(EE_ADDR_NUMBER_WRITE_MEASURE, eeaddress, INTERNAL); + uint16_t updates = (base__.readData(EE_ADDR_NUMBER_WRITE_MEASURE, INTERNAL)-base__.readData(EE_ADDR_NUMBER_READ_MEASURE, INTERNAL))/((SENSORS)*4 + TIME_BUFFER_SIZE); + if (updates < MAX_MEMORY) + { + int eeaddress = base__.readData(EE_ADDR_NUMBER_WRITE_MEASURE, INTERNAL); + int i = 0; + for (i = 0; i<9; i++) + { + base__.writeData(eeaddress + i*4, value[i], EXTERNAL); + } + base__.writeData(eeaddress + i*4, 0, time, EXTERNAL); + eeaddress = eeaddress + (SENSORS)*4 + TIME_BUFFER_SIZE; + base__.writeData(EE_ADDR_NUMBER_WRITE_MEASURE, eeaddress, INTERNAL); + } + else + { + #if debugEnabled + if (!ambient__.debug_state()) Serial.println(F("Memory limit exceeded!!")); + #endif + } } void SCKServer::readFIFO() @@ -307,7 +317,6 @@ void SCKServer::send(boolean sleep, boolean *wait_moment, long *value, char *tim } else { - //value[8] = 0; //Wifi Nets if (base__.checkRTC()) base__.RTCtime(time); else time = "#"; addFIFO(value, time);