Compare commits

..

No commits in common. "97dbf3facb76fedb5633c5e64b7aff845b702e56" and "19985b04c221441bfe461d694023d1cb76147c56" have entirely different histories.

5 changed files with 6 additions and 85 deletions

View File

@ -2,13 +2,13 @@
# Single lora testing app # Single lora testing app
CC=g++ CC=g++
CFLAGS=-c -Wall `pkg-config --cflags sqlite3 'libprotobuf-c >= 1.0.0'` CFLAGS=-c -Wall `pkg-config --cflags 'libprotobuf-c >= 1.0.0'`
LIBS=-lwiringPi -lprotobuf-c -lsqlite3 LIBS=-lwiringPi -lprotobuf-c
all: dragino_lora_app all: dragino_lora_app
dragino_lora_app: main.o protobuf.o message.pb-c.o database.o dragino_lora_app: main.o protobuf.o message.pb-c.o
$(CC) main.o protobuf.o database.o message.pb-c.o $(LIBS) -o dragino_lora_app $(CC) main.o protobuf.o message.pb-c.o $(LIBS) -o dragino_lora_app
main.o: main.c protobuf.h main.o: main.c protobuf.h
$(CC) $(CFLAGS) main.c $(CC) $(CFLAGS) main.c
@ -18,9 +18,6 @@ protobuf.o: message.pb-c.h protobuf.c protobuf.h
protobuf.h: message.pb-c.h protobuf.h: message.pb-c.h
database.o: database.c database.h
$(CC) $(CFLAGS) database.c -o database.o
message.pb-c.o: message.pb-c.h message.pb-c.c message.pb-c.o: message.pb-c.h message.pb-c.c
$(CC) $(CFLAGS) message.pb-c.c -o message.pb-c.o $(CC) $(CFLAGS) message.pb-c.c -o message.pb-c.o

View File

@ -1,53 +0,0 @@
#include "database.h"
#include <assert.h>
#include <stdio.h>
#include <stddef.h>
void database_state_init(struct database_state* s, const char* db_path) {
int return_code;
return_code = sqlite3_open_v2(db_path, &s->vm, SQLITE_OPEN_READWRITE, NULL);
assert(return_code == SQLITE_OK);
}
void database_state_free(struct database_state* s) {
sqlite3_close_v2(s->vm);
}
void database_write_active(struct database_state* s, int collar_id, int active_status) {
const char query[] = "UPDATE collar SET active=? WHERE id=?";
int return_code;
sqlite3_stmt* stmt;
return_code = sqlite3_prepare_v2(s->vm, query, sizeof(query), &stmt, NULL);
assert(return_code == SQLITE_OK);
return_code = sqlite3_bind_int(stmt, 1, active_status);
assert(return_code == SQLITE_OK);
return_code = sqlite3_bind_int(stmt, 2, collar_id);
assert(return_code == SQLITE_OK);
do {
return_code = sqlite3_step(stmt);
} while(return_code == SQLITE_ROW);
assert(return_code == SQLITE_DONE);
}
void database_write_location(struct database_state* s, int collar_id, double x, double y) {
const char query[] = "INSERT INTO data_point(collar_id, longitude, latitude, datetime)"
"VALUES (?, ?, ?, datetime('now'))";
int return_code;
sqlite3_stmt* stmt;
return_code = sqlite3_prepare_v2(s->vm, query, sizeof(query), &stmt, NULL);
assert(return_code == SQLITE_OK);
return_code = sqlite3_bind_int(stmt, 1, collar_id);
assert(return_code == SQLITE_OK);
return_code = sqlite3_bind_double(stmt, 2, x);
assert(return_code == SQLITE_OK);
return_code = sqlite3_bind_double(stmt, 3, y);
assert(return_code == SQLITE_OK);
do {
return_code = sqlite3_step(stmt);
} while(return_code == SQLITE_ROW);
assert(return_code == SQLITE_DONE);
}

View File

@ -1,14 +0,0 @@
#include <sqlite3.h>
extern "C" {
struct database_state {
sqlite3* vm;
};
void database_state_init(struct database_state* s, const char* db_path);
void database_state_free(struct database_state* s);
void database_write_active(struct database_state* s, int collar_id, int active_status);
void database_write_location(struct database_state* s, int collar_id, double x, double y);
}

View File

@ -3,8 +3,8 @@ syntax = "proto2";
package Fenceless; package Fenceless;
message Coordinate { message Coordinate {
required float x = 1; required double x = 1;
required float y = 2; required double y = 2;
} }
message CollarResponse { message CollarResponse {

View File

@ -1,9 +0,0 @@
#include "database.h"
int main() {
struct database_state state;
database_state_init(&state, "data.sqlite");
database_write_active(&state, 1, 1);
database_write_location(&state, 1, 5.0, 5.0);
database_state_free(&state);
}