From 927f3dc6c614fc20ff2300b1d34139deceaea063 Mon Sep 17 00:00:00 2001 From: Ryan Alder Date: Mon, 17 Feb 2020 19:27:05 -0800 Subject: [PATCH] Protobuf + DB Queries --- main.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index f9bf4c0..ff65a34 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,8 @@ #include #include +#include "protobuf.h" +#include "database.h" // ############################################# // ############################################# @@ -148,6 +150,8 @@ typedef unsigned char byte; static const int CHANNEL = 0; +database_state db; + char message[256]; const char tok[2] = "|"; bool sx1272 = true; @@ -171,7 +175,7 @@ int RST = 0; sf_t sf = SF7; // Set center frequency -uint32_t freq = 915000000; // in Mhz! (868.1) +uint32_t freq = 915000000; // in Mhz! (915) byte hello[32] = "HELLO"; @@ -382,7 +386,14 @@ void receivepacket() { printf("Payload: %s\n", message); */ - printf("Received message: %s", message); + Fenceless__CollarResponse * m = decode_update(sizeof(message), (uint8_t*) message); + printf("Received message (x, y): "); + printf("%f ", m->loc->x); + printf("%f", m->loc->y); + + database_write_location(&db, 1, m->loc->x, m->loc->y); + + } // received a message } // dio0=1 @@ -446,7 +457,12 @@ void txlora(byte *frame, byte datalen) { } int main (int argc, char *argv[]) { - + if (argc != 2) { + printf("./a.out [Database Location]"); + return 1; + } else { + database_state_init(&db, argv[1]); + } wiringPiSetup () ; pinMode(ssPin, OUTPUT); pinMode(dio0, INPUT); @@ -466,6 +482,7 @@ int main (int argc, char *argv[]) { delay(1); } + database_state_free(&db); - return (0); + return 0; }