diff --git a/collar.cpp b/collar.cpp index 4c52db2..91dc5da 100644 --- a/collar.cpp +++ b/collar.cpp @@ -27,7 +27,7 @@ static const u4_t DEVADDR = 0x260212B6; // } void debug_function(char *str) { - Serial.println(str); + // Serial.println(str); } @@ -68,7 +68,7 @@ float * const polyy = polyx + N_POLY_MAX; * of vertices * - https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html ***************************************************/ -const int pnpoly +inline const int pnpoly (const uint8_t nvert, const float *vertx, const float *verty, const float testx, const float testy) { uint8_t i, j, c = 0; @@ -85,7 +85,7 @@ const int pnpoly * - takes current GPS coordinates * - return 1 if in bounds ***************************************************/ -const int check_bounds(const float x, const float y) { +inline const int check_bounds(const float x, const float y) { return pnpoly(n_poly, polyx, polyy, x, y); } @@ -95,8 +95,6 @@ const int check_bounds(const float x, const float y) { * - loading arrays in nanopb does not appear * to work. ***************************************************/ -static volatile uint8_t data_available = 0; -static volatile uint8_t done_sending = 0; inline void import_protobuf(const uint8_t *protobuffer, const uint8_t size) { if(size != 122) { Serial.println("nmd"); @@ -108,25 +106,19 @@ inline void import_protobuf(const uint8_t *protobuffer, const uint8_t size) { if(isr>N_POLY_MAX) isr = 0; const uint8_t *ptr = protobuffer + 5; for(uint8_t i=0;i 0) { + while(available) { gps.encode(softserial_read()); available--; } } inline void on_start_gps() { - Serial.println("Starting gps"); state = WAIT_GPS; } inline void on_wait_gps() { - Serial.println("Waiting for gps"); if(gps.location.isValid()) { state = START_LORA; - Serial.println("end of gps"); } } @@ -222,8 +196,8 @@ inline void on_wait_gps() { #define FIELD_TWO_VARIANT 0x10 -const char oob[] = "OUT OF BOUNDS"; -const char inb[] = "IN BOUNDS"; +const char oob[] = " -OUT OF BOUNDS"; +const char inb[] = " -IN BOUNDS"; uint8_t buffer[] = { TYPE_STRING, PROTO_LEN, @@ -237,12 +211,11 @@ void on_start_lora() { void send_lora() { if (LMIC.opmode & OP_TXRXPEND) { Serial.print(" -cns"); - done_sending = 1; } else { const float latitude = gps.location.lat(); const float longitude = gps.location.lng(); if(n_poly>0) { - const uint8_t out_of_bounds = 0;//!check_bounds(latitude, longitude); + const uint8_t out_of_bounds = check_bounds(latitude, longitude); if(out_of_bounds) { Serial.println(oob); } else { @@ -268,13 +241,13 @@ void do_send(osjob_t* j){ #define TIMEOUT TX_INTERVAL * 2 * 1000UL void on_wait_lora() { - if(millis()- since > TX_INTERVAL*1000UL || done_sending) { + if(millis()- since > TX_INTERVAL*1000UL) { Serial.println(" -Lora Done Sending"); - done_sending = 0; state = START_GPS; } - if(millis()- since > TIMEOUT) { + if(millis() - since > TIMEOUT) { + Serial.println(" -Scheduling another job"); os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send); } } @@ -290,14 +263,12 @@ void loop() { Serial.print('.'); if(state == START_GPS) { - // softserial_init(); on_start_gps(); } else if(state == WAIT_GPS) { on_wait_gps(); } else if(state == START_LORA) { - // softserial_end(); on_start_lora(); } else if(state == WAIT_LORA) { @@ -306,23 +277,18 @@ void loop() { } else { // Serial.print('.'); } - if(data_available) { - Serial.println("Data available"); - for(uint8_t i=0;i