reduced size with config

This commit is contained in:
sessionm21 2020-05-15 22:20:43 +01:00
parent 9cbd23ef60
commit 5e8c891a60
5 changed files with 67 additions and 58 deletions

View File

@ -17,6 +17,7 @@ CFLAGS?=-Datmega328p\
-DARDUINO=200\
-DARDUINO_AVR_NANO\
-DARDUINO_ARCH_AVR\
-DARDUINO_LMIC_PROJECT_CONFIG_H=fenceless_lmic_config.h\
-Os\
-ffunction-sections\
-fdata-sections\
@ -35,6 +36,7 @@ CXXFLAGS?=-Datmega328p\
-DARDUINO=200\
-DARDUINO_AVR_NANO\
-DARDUINO_ARCH_AVR\
-DARDUINO_LMIC_PROJECT_CONFIG_H=fenceless_lmic_config.h\
-Os\
-ffunction-sections\
-fdata-sections\
@ -42,7 +44,7 @@ CXXFLAGS?=-Datmega328p\
-flto\
-fno-fat-lto-objects\
-fuse-linker-plugin\
-Wall
-Wall\
INC_DIRS?=-I./\
-I./$(ARDUINO_DIR)/libraries/SPI/src\
@ -57,7 +59,8 @@ INC_DIRS?=-I./\
-I./libraries/arduino-lmic/src/hal/\
-I./libraries/arduino-lmic/src/lmic/\
-I./libraries/arduino-lmic/src/aes/\
-I./libraries/AltSoftSerial/
-I./libraries/AltSoftSerial/\
-I./
SRC_FILES?=./$(ARDUINO_DIR)/cores/arduino/main.cpp\
./$(ARDUINO_DIR)/cores/arduino/wiring_digital.c\
@ -144,14 +147,13 @@ flash: $(OUT)$(NAME)
avrdude -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:$(OUT)$(NAME).hex:i
run: flash
screen /dev/ttyUSB0 4800
screen /dev/ttyUSB0
start: flash
systemctl start lora-gateway-bridge loraserver
stop:
avrdude -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:nothing.hex:i
systemctl stop lora-gateway-bridge loraserver
clean:
rm -r protobuf

View File

@ -28,12 +28,10 @@ void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }
static osjob_t sendjob;
static osjob_t gpsjob;
// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 10;
const unsigned GPS_INTERVAL = 1;
// Pin mapping for Adafruit Feather M0 LoRa
const lmic_pinmap lmic_pins = {
@ -50,6 +48,11 @@ const lmic_pinmap lmic_pins = {
***************************************************/
TinyGPSPlus gps;
uint8_t general_int;
#define isr general_int
#define timeout general_int
#define n_poly general_int
/****************************************************
* Track each pair of X and Y coordinates
* - arrays are used by the pnpoly function
@ -57,28 +60,7 @@ TinyGPSPlus gps;
const uint8_t N_POLY_MAX=10;
float polyx[N_POLY_MAX];
float polyy[N_POLY_MAX];
int n_poly=0;
/****************************************************
* Add a coordinate to the arrays
* - stores a total of N_POLY_MAX pairs
***************************************************/
const int push_vert(const float x, const float y) {
if(n_poly>N_POLY_MAX)
return 0;
polyx[n_poly]=x;
polyy[n_poly]=y;
n_poly++;
return 1;
}
/****************************************************
* 'Clear' pairs of coordinates
***************************************************/
void clear_verts() {
n_poly=0;
}
//int n_poly=0;
/****************************************************
* Check a pair of coordinates against two lists
* of vertices
@ -112,31 +94,28 @@ const int check_bounds(const float x, const float y) {
***************************************************/
void import_protobuf(const uint8_t *protobuffer, const uint32_t size) {
if(size != 122) {
Serial.println("Failed to decode");
Serial.println("nmd");
return;
}
Serial.println("Recieved valid protobuf data?");
uint32_t isr;
isr = 0;
isr = protobuffer[1];
if(isr>N_POLY_MAX) isr = N_POLY_MAX;
clear_verts();
if(isr>N_POLY_MAX) isr = 0;
const uint8_t *ptr = protobuffer + 5;
for(uint32_t i=0;i<isr;i++) {
float x,y;
memcpy(&x, ptr + i*12, 4);
memcpy(&y, ptr + i*12+5, 4);
push_vert(x, y);
for(uint8_t i=0;i<isr && i<N_POLY_MAX;i++) {
memcpy(&polyx[i], ptr + i*12, 4);
memcpy(&polyy[i], ptr + i*12+5, 4);
Serial.print((int)polyx[i]);
Serial.print(' ');
Serial.print((int)polyy[i]);
Serial.print('\n');
}
// n_poly = isr; - n_poly is isr
}
uint8_t is_sending = 0;
static volatile uint8_t is_sending = 0;
void onEvent (ev_t ev) {
// Serial.print(os_getTime());
// Serial.print(": ");
@ -165,47 +144,61 @@ void onEvent (ev_t ev) {
#define FIELD_TWO_FLOAT 0x15
#define FIELD_TWO_VARIANT 0x10
const char oob[] = "OUT OF BOUNDS";
const char inb[] = "IN BOUNDS";
uint8_t buffer[] = {
TYPE_STRING,
PROTO_LEN,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x48, 0x43,
FIELD_TWO_FLOAT, 0x00, 0x00, 0xc8, 0x42,
FIELD_TWO_VARIANT, 0};
FIELD_TWO_VARIANT, 0, 0};
void do_send(osjob_t* j){
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending"));
//Serial.println(F("OP_TXRXPEND, not sending"));
} else {
// prepare upstream data transmission at the next possible time.
// transmit on port 1 (the first parameter); you can use any value from 1 to 223 (others are reserved).
// don't request an ack (the last parameter, if not zero, requests an ack from the network).
// Remember, acks consume a lot of network resources; don't ask for an ack unless you really need it.
const float latitude = gps.location.lat();
const float latitude = gps.location.lat();
const float longitude = gps.location.lng();
const int oob = check_bounds(latitude, longitude);
if(n_poly>0) {
const uint8_t oob = !check_bounds(latitude, longitude);
if(oob) {
Serial.println(oob);
} else {
Serial.println(inb);
}
memcpy(buffer+13, (void*)&oob, 1);
} else {
const uint8_t oob = 0;
memcpy(buffer+13, (void*)&oob, 1);
}
memcpy(buffer+3, (void*)&latitude, 4);
memcpy(buffer+8, (void*)&longitude, 4);
memcpy(buffer+13, (void*)&oob, 1);
LMIC_setTxData2(1, buffer, sizeof(buffer), 0);
LMIC_setTxData2(1, buffer, sizeof(buffer)-2, 0);
}
}
void do_gps(osjob_t* j){
while(softserial_available()>0) {
#define GPS_MAX_ENCODES 60
void read_gps(){
timeout = 0;
while(softserial_available()>0 && timeout < GPS_MAX_ENCODES) {
gps.encode(softserial_read());
timeout ++;
}
if(!is_sending && gps.location.isValid()) {
Serial.println("gps");
is_sending = 1;
do_send(&sendjob);
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
}
os_setTimedCallback(&gpsjob, os_getTime()+sec2osticks(GPS_INTERVAL), do_gps);
}
void setup() {
Serial.begin(4800);
Serial.begin(9600);
softserial_init();
delay(100);
@ -237,10 +230,9 @@ void setup() {
// Set data rate and transmit power for uplink
LMIC_setDrTxpow(DR_SF7,14);
os_setTimedCallback(&gpsjob, os_getTime()+sec2osticks(GPS_INTERVAL), do_gps);
}
void loop() {
os_runloop_once();
os_runloop_once();
read_gps();
}

15
fenceless_lmic_config.h Normal file
View File

@ -0,0 +1,15 @@
// project-specific definitions
//#define CFG_eu868 1
#define CFG_us915 1
//#define CFG_au915 1
//#define CFG_as923 1
// #define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP /* for as923-JP */
//#define CFG_kr920 1
//#define CFG_in866 1
#define CFG_sx1276_radio 1
//#define LMIC_USE_INTERRUPTS
#define DISABLE_JOIN
#define DISABLE_PING
#define DISABLE_BEACONS
#define DISABLE_LMIC_FAILURE_TO
#define USE_IDEETRON_AES

Binary file not shown.

View File

@ -47,7 +47,7 @@ static uint8_t rx_bit = 0;
static uint16_t rx_target;
static volatile uint8_t rx_buffer_head;
static volatile uint8_t rx_buffer_tail;
#define RX_BUFFER_SIZE 80
#define RX_BUFFER_SIZE 30
static volatile uint8_t rx_buffer[RX_BUFFER_SIZE];
const static uint32_t cycles_per_bit = 1667UL;