Browse Source

Added alerts notification and clearance in the main core function

tags/v1.2.0
Bertrand Lemasle 6 years ago
parent
commit
8d51ceb975
2 changed files with 33 additions and 1 deletions
  1. +31
    -1
      GpsTracker/Core.cpp
  2. +2
    -0
      GpsTracker/Core.h

+ 31
- 1
GpsTracker/Core.cpp View File

@@ -1,8 +1,10 @@
#include "Core.h" #include "Core.h"
#include "Config.h" #include "Config.h"
#include "Flash.h" #include "Flash.h"
#include "Alerts.h"


#define LOGGER_NAME "Core" #define LOGGER_NAME "Core"
#define SMS_BUFFER_SIZE 100


using namespace utils; using namespace utils;


@@ -21,17 +23,45 @@ namespace core {


if (acquired) { if (acquired) {
positions::appendLast(metadata); positions::appendLast(metadata);
forceBackup = updateSleepTime(); forceBackup = updateSleepTime();

gps::preserveCurrentCoordinates(); gps::preserveCurrentCoordinates();
} }


notifyFailures(metadata);
alerts::clear(metadata);
positions::doBackup(forceBackup); positions::doBackup(forceBackup);


if (acquired) updateRtcTime(); if (acquired) updateRtcTime();
mainunit::deepSleep(sleepTime); mainunit::deepSleep(sleepTime);
} }


void notifyFailures(PositionEntryMetadata &metadata) {
uint8_t triggered = alerts::getTriggered(metadata);
uint8_t notified = 0;
SIM808RegistrationStatus networkStatus;
char buffer[SMS_BUFFER_SIZE] = "Alerts !\n";

if (!triggered) return;

network::powerOn();
networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS);

if (!network::isAvailable(networkStatus.stat)) return;

if (bitRead(triggered, ALERT_BATTERY_LEVEL_1) || bitRead(triggered, ALERT_BATTERY_LEVEL_2)) {
sprintf_P(buffer + strlen(buffer), PSTR(" - Battery at %d%%.\n"), metadata.batteryLevel);
}
if (bitRead(triggered, ALERT_RTC_TEMPERATURE_FAILURE)) {
sprintf_P(buffer + strlen(buffer), PSTR(" - Temperature is %.2f°C. Backup battery failure ?\n"), metadata.batteryLevel);
}

//TODO : send sms, return if failed
alerts::add(notified); //only add the successly notified failures
//TODO : network::powerOff(); count "handles" like for i2c ?
}

void updateRtcTime() { void updateRtcTime() {
tmElements_t time; tmElements_t time;
gps::getTime(time); gps::getTime(time);


+ 2
- 0
GpsTracker/Core.h View File

@@ -17,4 +17,6 @@ namespace core {
void updateRtcTime(); void updateRtcTime();
bool updateSleepTime(); bool updateSleepTime();
uint16_t mapSleepTime(uint8_t velocity); uint16_t mapSleepTime(uint8_t velocity);

void notifyFailures(PositionEntryMetadata &metadata);
} }

Loading…
Cancel
Save