Protobuf + DB Queries

This commit is contained in:
Ryan Alder 2020-02-17 19:27:05 -08:00
parent 97dbf3facb
commit 927f3dc6c6
1 changed files with 21 additions and 4 deletions

25
main.c
View File

@ -21,6 +21,8 @@
#include <wiringPi.h>
#include <wiringPiSPI.h>
#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;
}