works well
This commit is contained in:
36
collar.cpp
36
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<n_poly;i++) {
|
||||
// Serial.print('(');
|
||||
// Serial.print((int)(polyy[i]*100));
|
||||
// Serial.print(',');
|
||||
// Serial.print((int)(polyx[i]*100));
|
||||
// Serial.print(')');
|
||||
// Serial.print(',');
|
||||
// }
|
||||
// data_available = 0;
|
||||
// }
|
||||
}
|
||||
read_gps();
|
||||
os_runloop_once();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user