Browse Source

Implemented wait for network. Call backups directly to face what seems to be a segfault in positions::doBackup

tags/v1.2.0
Bertrand Lemasle 7 years ago
parent
commit
2c35fbe0f1
12 changed files with 97 additions and 21 deletions
  1. +11
    -6
      GpsTracker/Config.cpp
  2. +3
    -0
      GpsTracker/Config.h
  3. +1
    -0
      GpsTracker/GpsTracker.ino
  4. +0
    -1
      GpsTracker/Hardware.cpp
  5. +26
    -0
      GpsTracker/Network.cpp
  6. +4
    -0
      GpsTracker/Network.h
  7. +19
    -6
      GpsTracker/NetworkPositionsBackup.cpp
  8. +1
    -1
      GpsTracker/NetworkPositionsBackup.h
  9. +5
    -3
      GpsTracker/NetworkPositionsConfig.h
  10. +15
    -2
      GpsTracker/Positions.cpp
  11. +9
    -0
      GpsTracker/PositionsBackup.cpp
  12. +3
    -2
      GpsTracker/PositionsBackup.h

+ 11
- 6
GpsTracker/Config.cpp View File

@@ -20,8 +20,10 @@ namespace config {
} }


void write() { void write() {
VERBOSE_FORMAT("write", "%d, %s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);

VERBOSE_FORMAT("write", "%d, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
#if BACKUP_ENABLE_NETWORK
VERBOSE_FORMAT("write", "%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url);
#endif
hardware::i2c::powerOn(); hardware::i2c::powerOn();
int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value); int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value);
hardware::i2c::powerOff(); hardware::i2c::powerOff();
@@ -31,7 +33,10 @@ namespace config {
config_t get() { config_t get() {
if (value.seed == 0) details::read(); if (value.seed == 0) details::read();


VERBOSE_FORMAT("get", "%d, %s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
VERBOSE_FORMAT("get", "%d, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
#if BACKUP_ENABLE_NETWORK
VERBOSE_FORMAT("get", "%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url);
#endif
return value; return value;
} }


@@ -49,10 +54,10 @@ namespace config {
0xFFFF, 0xFFFF,
#if BACKUP_ENABLE_NETWORK #if BACKUP_ENABLE_NETWORK
{ {
POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD,
POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD,
0xFFFF, 0xFFFF,
POSITIONS_CONFIG_DEFAULT_APN,
POSITIONS_CONFIG_DEFAULT_URL,
POSITIONS_CONFIG_NET_DEFAULT_APN,
POSITIONS_CONFIG_NET_DEFAULT_URL,
}, },
#endif #endif
}; };


+ 3
- 0
GpsTracker/Config.h View File

@@ -19,6 +19,9 @@
#define GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS 10000 #define GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS 10000
#define GPS_DEFAULT_TOTAL_TIMEOUT_MS 180000 #define GPS_DEFAULT_TOTAL_TIMEOUT_MS 180000


#define NETWORK_DEFAULT_INTERMEDIATE_TIMEOUT_MS 2000
#define NETWORK_DEFAULT_TOTAL_TIMEOUT_MS 60000

struct sleepTimings_t { struct sleepTimings_t {
uint8_t speed; uint8_t speed;
uint16_t seconds; uint16_t seconds;


+ 1
- 0
GpsTracker/GpsTracker.ino View File

@@ -69,6 +69,7 @@ void loop() {
break; break;
case debug::GPSTRACKER_DEBUG_COMMAND::EEPROM_ADD_ENTRY: case debug::GPSTRACKER_DEBUG_COMMAND::EEPROM_ADD_ENTRY:
debug::addLastPositionToEeprom(); debug::addLastPositionToEeprom();
positions::doBackup();
break; break;
case debug::GPSTRACKER_DEBUG_COMMAND::SLEEP: case debug::GPSTRACKER_DEBUG_COMMAND::SLEEP:
mainunit::sleep(period_t::SLEEP_8S); mainunit::sleep(period_t::SLEEP_8S);


+ 0
- 1
GpsTracker/Hardware.cpp View File

@@ -66,7 +66,6 @@ namespace hardware {
VERBOSE("networkPowerOn"); VERBOSE("networkPowerOn");
powerOn(); powerOn();
device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::FULL); device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::FULL);
device.enableGprs(config::main::get().network.apn);
} }


void networkPowerOff() { void networkPowerOff() {


+ 26
- 0
GpsTracker/Network.cpp View File

@@ -1,8 +1,34 @@
#include "Config.h"
#include "Network.h" #include "Network.h"
#include "Hardware.h" #include "Hardware.h"
#include "MainUnit.h"

#define LOGGER_NAME "Network" #define LOGGER_NAME "Network"


namespace network { namespace network {


SIM808RegistrationStatus waitForRegistered(uint16_t timeout) {
SIM808RegistrationStatus currentStatus;

do {
currentStatus = hardware::sim808::device.getNetworkRegistrationStatus();
if (isAvailable(currentStatus.stat)) break;

mainunit::deepSleep(NETWORK_DEFAULT_INTERMEDIATE_TIMEOUT_MS / 1000);
timeout -= NETWORK_DEFAULT_INTERMEDIATE_TIMEOUT_MS;
} while (timeout > 1);

return currentStatus;
}

bool isAvailable(SIM808_NETWORK_REGISTRATION_STATE state) {
return state == SIM808_NETWORK_REGISTRATION_STATE::REGISTERED ||
state == SIM808_NETWORK_REGISTRATION_STATE::ROAMING;
}

bool enableGprs() {
return hardware::sim808::device.enableGprs(config::main::get().network.apn);
}
} }

+ 4
- 0
GpsTracker/Network.h View File

@@ -6,4 +6,8 @@ namespace network {


inline void powerOn() { hardware::sim808::networkPowerOn(); } inline void powerOn() { hardware::sim808::networkPowerOn(); }
inline void powerOff() { hardware::sim808::networkPowerOff(); } inline void powerOff() { hardware::sim808::networkPowerOff(); }

SIM808RegistrationStatus waitForRegistered(uint16_t timeout);
bool isAvailable(SIM808_NETWORK_REGISTRATION_STATE state);
bool enableGprs();
} }

+ 19
- 6
GpsTracker/NetworkPositionsBackup.cpp View File

@@ -5,14 +5,14 @@
#include "Positions.h" #include "Positions.h"
#include "Config.h" #include "Config.h"
#include "Hardware.h" #include "Hardware.h"
#include "Network.h"


#define LOGGER_NAME "Positions::backup::network" #define LOGGER_NAME "Positions::backup::network"
#define BUFFER_SIZE 160 #define BUFFER_SIZE 160
#define EXPECTED_HTTP_RESPONSE_CODE 201


namespace positions { namespace positions {
namespace backup { namespace backup {
namespace network {
namespace net {


namespace details { namespace details {


@@ -38,7 +38,7 @@ namespace positions {
buffer, buffer,
buffer, buffer,
BUFFER_SIZE BUFFER_SIZE
) == EXPECTED_HTTP_RESPONSE_CODE;
) == POSITIONS_CONFIG_NET_DEFAULT_EXPECTED_RESPONSE;
} }


void appendPositions(config_t &config) { void appendPositions(config_t &config) {
@@ -46,9 +46,22 @@ namespace positions {


uint16_t currentEntryIndex = config.network.lastSavedEntry + 1; uint16_t currentEntryIndex = config.network.lastSavedEntry + 1;
PositionEntry currentEntry; PositionEntry currentEntry;
SIM808RegistrationStatus networkStatus;


hardware::i2c::powerOn(); hardware::i2c::powerOn();
hardware::sim808::networkPowerOn();
network::powerOn();
networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS);

if (!network::isAvailable(networkStatus.stat)) {
VERBOSE_MSG("appendPositions", "network unavailable");
return;
}

if (!network::enableGprs()) {
VERBOSE_MSG("appendPositions", "gprs unavailable");
return;
}

do { do {
if (!positions::get(currentEntryIndex, currentEntry)) break; if (!positions::get(currentEntryIndex, currentEntry)) break;
if (!appendPosition(config, currentEntry)) break; if (!appendPosition(config, currentEntry)) break;
@@ -57,14 +70,14 @@ namespace positions {
config::main::set(config); config::main::set(config);


} while (positions::moveNext(currentEntryIndex)); } while (positions::moveNext(currentEntryIndex));
hardware::sim808::networkPowerOff();
network::powerOff();
hardware::i2c::powerOff(); hardware::i2c::powerOff();
} }


} }


void NetworkPositionsBackup::setup() { void NetworkPositionsBackup::setup() {
VERBOSE("backup");
VERBOSE("setup");
} }


void NetworkPositionsBackup::backup() { void NetworkPositionsBackup::backup() {


+ 1
- 1
GpsTracker/NetworkPositionsBackup.h View File

@@ -4,7 +4,7 @@


namespace positions { namespace positions {
namespace backup { namespace backup {
namespace network {
namespace net {


class NetworkPositionsBackup : public PositionsBackup { class NetworkPositionsBackup : public PositionsBackup {
private: private:


+ 5
- 3
GpsTracker/NetworkPositionsConfig.h View File

@@ -1,9 +1,11 @@
#pragma once #pragma once




#define POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD 10
#define POSITIONS_CONFIG_DEFAULT_APN "Vodafone"
#define POSITIONS_CONFIG_DEFAULT_URL "http://default.url"
#define POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD 2
#define POSITIONS_CONFIG_NET_DEFAULT_APN "Vodafone"
#define POSITIONS_CONFIG_NET_DEFAULT_URL "http://requestbin.fullcontact.com/16q71o61"
#define POSITIONS_CONFIG_NET_DEFAULT_EXPECTED_RESPONSE 201



struct networkConfig_t { struct networkConfig_t {
uint8_t saveThreshold; uint8_t saveThreshold;


+ 15
- 2
GpsTracker/Positions.cpp View File

@@ -43,6 +43,13 @@ namespace positions {
_backups[backupIdx] = new backup::sd::SdPositionsBackup(); _backups[backupIdx] = new backup::sd::SdPositionsBackup();
_backups[backupIdx++]->setup(); _backups[backupIdx++]->setup();
#endif #endif
#if BACKUP_ENABLE_NETWORK
_backups[backupIdx] = new backup::net::NetworkPositionsBackup();
_backups[backupIdx]->setup();
//_backups[backupIdx]->backup();
backupIdx++;

#endif
#endif #endif
} }


@@ -132,9 +139,15 @@ namespace positions {


void doBackup() { void doBackup() {
#ifdef BACKUPS_ENABLED #ifdef BACKUPS_ENABLED
for (int i = 0; i < BACKUPS_ENABLED; i++) {
VERBOSE_FORMAT("doBackup", "%d backups enabled", BACKUPS_ENABLED);

_backups[0]->backup();

/*for (int i = 0; i < BACKUPS_ENABLED; i++) {
VERBOSE_FORMAT("doBackup", "calling backup %d", i);
delay(1000);
_backups[i]->backup(); _backups[i]->backup();
}
}*/
#endif #endif
} }
} }

+ 9
- 0
GpsTracker/PositionsBackup.cpp View File

@@ -0,0 +1,9 @@
#include "PositionsBackup.h"

namespace positions {
namespace backup {

PositionsBackup::~PositionsBackup() {}

}
}

+ 3
- 2
GpsTracker/PositionsBackup.h View File

@@ -5,8 +5,9 @@ namespace positions {


class PositionsBackup { class PositionsBackup {
public: public:
virtual void setup();
virtual void backup();
~PositionsBackup();
virtual void setup()=0;
virtual void backup()=0;
}; };


} }

Loading…
Cancel
Save