Default to a frame counter of 0

This commit is contained in:
Starbeamrainbowlabs 2019-07-02 14:07:11 +01:00
parent 3251a1d4a2
commit 135c7694f8
5 changed files with 29 additions and 19 deletions

View File

@ -19,7 +19,7 @@ GPSLocation gps_fetch() {
// The struct that will hold the result
GPSLocation result;
Serial.print(F("[gps] Working: "));
Serial.print(F("[gps] Working "));
uint32_t start = millis(), ms_last_update = millis();
uint8_t ticks = 0;
unsigned long fix_age = TinyGPS::GPS_INVALID_AGE;
@ -33,7 +33,7 @@ GPSLocation gps_fetch() {
gps.stats(&chars, &sentences, &failed_checksum);
if(millis() - start > 5000 && chars < 10) {
Serial.println(F("\n[error] GPS device init failed"));
Serial.println(F("\n[error/gps] Init failed"));
while(true) { delay(1); }
}
@ -57,11 +57,6 @@ GPSLocation gps_fetch() {
Serial.println();
ticks = 0;
}
// Serial.println(gps.location.lat());
// Serial.println(gps.location.lng());
// Serial.println(gps.date.year());
// Serial.println(gps.time.hour());
// Serial.println(gps.time.minute());
}
ms_last_update = millis();
continue;

View File

@ -60,16 +60,17 @@ void setup() {
const uint8_t* bytes_lat = reinterpret_cast<uint8_t const *>(&(gps_data.lat));
const uint8_t* bytes_lng = reinterpret_cast<uint8_t const *>(&(gps_data.lat));
for(int i = 0; i < sizeof(uint32_t); i++) {
message[i] = bytes_id[i];
}
// for(int i = 0; i < sizeof(uint32_t); i++) {
// }
// The size of a float == the size of a uint32_t
for(int i = 0; i < sizeof(float); i++) {
message[i] = bytes_id[i];
message[sizeof(uint32_t) + i] = bytes_lat[i];
message[sizeof(uint32_t) + sizeof(float) + i] = bytes_lng[i];
}
#ifdef ENABLE_RADIO
Serial.println(F("[main] Transmitting"));
// Serial.println(F("[main] Transmitting"));
transmit_init();
transmit_send(message, message_size);
#endif

View File

@ -6,8 +6,6 @@ void power_off() {
Serial.println(F("[power] Shutting down"));
// Serial.println(F("[power] Switching GPS module to standby"));
// power_gps_standby();
Serial.println(F("[power] Signalling TPL5111"));
pinMode(PIN_TPL_DONE, OUTPUT);
digitalWrite(PIN_TPL_DONE, HIGH);

View File

@ -8,6 +8,13 @@
// Global static variable that's used to detect when LMIC has finished doing it's thing
bool is_sending_complete = false;
void transmit_counter_save() {
store_eeprom_uint32_save(0, LMIC.seqnoUp);
store_eeprom_uint32_save(sizeof(uint32_t), LMIC.seqnoDn);
}
void transmit_init() {
Serial.println(F("[LMIC] Init"));
// LMIC init
@ -62,7 +69,11 @@ void transmit_init() {
// Restore the frame counters
LMIC.seqnoUp = store_eeprom_uint32_retrieve(0);
LMIC.seqnoDn = store_eeprom_uint32_retrieve(sizeof(uint32_t));
Serial.println(LMIC.seqnoUp);
// Serial.println(LMIC.seqnoUp);
if(LMIC.seqnoUp >= 4294967295) { // The default value
LMIC.seqnoUp = LMIC.seqnoDn = 0; // Reset to 0
transmit_counter_save();
}
}
/**
@ -78,7 +89,7 @@ bool transmit_send(uint8_t* data, int length) {
}
// Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, data, length, 0);
Serial.println(F("Packet queued"));
Serial.println(F("done"));
// Run the LMIC loop, but only until it's finished sending the packet
while (!is_sending_complete) {
@ -86,8 +97,7 @@ bool transmit_send(uint8_t* data, int length) {
}
// Persist the frame counters
store_eeprom_uint32_save(0, LMIC.seqnoUp);
store_eeprom_uint32_save(sizeof(uint32_t), LMIC.seqnoDn);
transmit_counter_save();
// Reset it for next time (just in case)
is_sending_complete = false;
@ -127,7 +137,7 @@ void onEvent (ev_t ev) {
Serial.println(F("EV_REJOIN_FAILED"));
break;*/
case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (incl. RX window wait)"));
Serial.println(F("EV_TXCOMPLETE incl. RX"));
if(LMIC.dataLen) {
// data received in rx slot after tx
Serial.print(F("Received: "));
@ -154,7 +164,8 @@ void onEvent (ev_t ev) {
Serial.println(F("EV_LINK_ALIVE"));
break;*/
default:
Serial.println(F("Unknown event"));
Serial.print(F("Unknown event "));
Serial.println(ev);
break;
}
}

View File

@ -1,5 +1,10 @@
#pragma once
/**
* Internal use only. Persists the LMIC frame counters to disk.
*/
void transmit_counter_save();
/**
* Initialises the RFM95 LoRa radio.
*/