diff --git a/collar.cpp b/collar.cpp index 91dc5da..e3d1188 100644 --- a/collar.cpp +++ b/collar.cpp @@ -22,10 +22,6 @@ static osjob_t sendjob; static const u4_t DEVADDR = 0x260212B6; -// void printf(char *str) { -// Serial.println(str); -// } - void debug_function(char *str) { // Serial.println(str); } @@ -50,7 +46,6 @@ const lmic_pinmap lmic_pins = { ***************************************************/ TinyGPSPlus gps; - uint8_t general_int; volatile uint8_t n_poly; #define isr general_int @@ -63,6 +58,8 @@ const uint8_t N_POLY_MAX=10; float polyx[N_POLY_MAX*2+5]; float * const polyy = polyx + N_POLY_MAX; +void do_send(osjob_t* j); + /**************************************************** * Check a pair of coordinates against two lists * of vertices @@ -112,20 +109,15 @@ inline void import_protobuf(const uint8_t *protobuffer, const uint8_t size) { n_poly = isr; } -void do_send(osjob_t* j); - void onEvent (ev_t ev) { if(ev == EV_TXCOMPLETE) { if (LMIC.dataLen) { Serial.print(F(" -Received: ")); Serial.println(LMIC.dataLen); + import_protobuf(LMIC.frame + LMIC.dataBeg, LMIC.dataLen); } // Schedule next transmission os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send); - - if (LMIC.dataLen) { - import_protobuf(LMIC.frame + LMIC.dataBeg, LMIC.dataLen); - } } } @@ -195,7 +187,6 @@ inline void on_wait_gps() { #define FIELD_TWO_FLOAT 0x15 #define FIELD_TWO_VARIANT 0x10 - const char oob[] = " -OUT OF BOUNDS"; const char inb[] = " -IN BOUNDS"; uint8_t buffer[] = { @@ -215,7 +206,7 @@ void send_lora() { const float latitude = gps.location.lat(); const float longitude = gps.location.lng(); if(n_poly>0) { - const uint8_t out_of_bounds = check_bounds(latitude, longitude); + const uint8_t out_of_bounds = !check_bounds(latitude, longitude); if(out_of_bounds) { Serial.println(oob); } else { @@ -232,7 +223,6 @@ void send_lora() { LMIC_setTxData2(1, buffer, sizeof(buffer)-1, 0); } since = millis(); - state = WAIT_LORA; } void do_send(osjob_t* j){ @@ -243,7 +233,6 @@ void do_send(osjob_t* j){ void on_wait_lora() { if(millis()- since > TX_INTERVAL*1000UL) { Serial.println(" -Lora Done Sending"); - state = START_GPS; } if(millis() - since > TIMEOUT) { @@ -253,7 +242,6 @@ void on_wait_lora() { } #define LOOP_LATENCY_MS 200L - uint32_t time_last = 0; void loop() { uint32_t time = millis(); @@ -274,21 +262,7 @@ void loop() { else if(state == WAIT_LORA) { on_wait_lora(); } - } else { - // Serial.print('.'); - } - // if(data_available) { - // Serial.println("Data available"); - // for(uint8_t i=0;i +#include +#include +#include + +#define TYPE_STRING 0x0A +#define TYPE_VARIANT 0x10 +#define PROTO_LEN 0x0A +#define FIELD_ONE_FLOAT 0x0D +#define FIELD_TWO_FLOAT 0x15 +#define FIELD_TWO_VARIANT 0x10 + +typedef struct { + float x,y; +} coord; +int main() +{ + uint8_t send_buffer[] = { + TYPE_STRING, + PROTO_LEN, + FIELD_ONE_FLOAT, 0x00, 0x00, 0x48, 0x43, + FIELD_TWO_FLOAT, 0x00, 0x00, 0xc8, 0x42, + FIELD_TWO_VARIANT, 0}; + printf("SIZEOF : %d\n", sizeof(send_buffer)); + + + printf("Testing encode:"); + float latitude = 200; + float longitude = 100; + + uint8_t buffer[14] = { + TYPE_STRING, + PROTO_LEN, + FIELD_ONE_FLOAT, 0x00, 0x00, 0x48, 0x43, + FIELD_TWO_FLOAT, 0x00, 0x00, 0xc8, 0x42, + FIELD_TWO_VARIANT, 0}; + memcpy(buffer+3, (void*)&latitude, 4); + memcpy(buffer+8, (void*)&longitude, 4); + + for(int i=0;i>(8*i)); + } + printf("\n"); + // memcpy(coordinates[0].x, buffer0 + i+0+7, 4); + // memcpy(coordinates[0].y, buffer0 + i+5+7, 4); + + // memcpy(coordinates[1].x, buffer0 + i+12+7, 4); + // memcpy(coordinates[1].y, buffer0 + i+17+7, 4); + // + // memcpy(coordinates[2].x, buffer0 + i+24+7, 4); + // memcpy(coordinates[2].y, buffer0 + i+29+7, 4); + + + + return 0; +}