Skip to content

Commit

Permalink
Memory limit protection activated
Browse files Browse the repository at this point in the history
  • Loading branch information
miandehe committed Mar 16, 2016
1 parent 565a6af commit 6adbe11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions sck_beta_v0_9/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 19 additions & 10 deletions sck_beta_v0_9/SCKServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6adbe11

Please sign in to comment.