From cc953e1e964e288db2ba2c2d863e1954d8e011ed Mon Sep 17 00:00:00 2001 From: Scobber Date: Wed, 10 Jul 2019 22:32:44 +1000 Subject: [PATCH] add Cayenne LPP --- main/.vscode/arduino.json | 4 ++ main/.vscode/c_cpp_properties.json | 19 +++++++++ main/configuration.h | 2 +- main/dataformats.h | 68 ++++++++++++++++++++++++++++++ main/gps.ino | 25 ----------- main/main.ino | 3 +- 6 files changed, 93 insertions(+), 28 deletions(-) create mode 100644 main/.vscode/arduino.json create mode 100644 main/.vscode/c_cpp_properties.json create mode 100644 main/dataformats.h diff --git a/main/.vscode/arduino.json b/main/.vscode/arduino.json new file mode 100644 index 0000000..0980dd7 --- /dev/null +++ b/main/.vscode/arduino.json @@ -0,0 +1,4 @@ +{ + "board": "arduino:avr:yun", + "sketch": "main.ino" +} \ No newline at end of file diff --git a/main/.vscode/c_cpp_properties.json b/main/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..bf15620 --- /dev/null +++ b/main/.vscode/c_cpp_properties.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "C:\\Program Files (x86)\\Arduino\\tools\\**", + "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\**" + ], + "forcedInclude": [ + "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h" + ], + "intelliSenseMode": "msvc-x64", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe", + "cStandard": "c11", + "cppStandard": "c++17" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/main/configuration.h b/main/configuration.h index 2d066b2..31a4f35 100644 --- a/main/configuration.h +++ b/main/configuration.h @@ -26,7 +26,6 @@ along with this program. If not, see . #include #include - void ttn_register(void (*callback)(uint8_t message)); // ----------------------------------------------------------------------------- @@ -40,6 +39,7 @@ void ttn_register(void (*callback)(uint8_t message)); // Configuration // ----------------------------------------------------------------------------- +#define USE_CAYENNE #define DEBUG_PORT Serial // Serial debug port #define SERIAL_BAUD 115200 // Serial debug baud rate #define SLEEP_BETWEEN_MESSAGES 0 // Do sleep between messages diff --git a/main/dataformats.h b/main/dataformats.h new file mode 100644 index 0000000..0ddc888 --- /dev/null +++ b/main/dataformats.h @@ -0,0 +1,68 @@ +/* + +Packet Processor + +*/ + +#pragma once + + +#ifdef USE_CAYENNE + // CAYENNE DF + static uint8_t txBuffer[11] = {0x03, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + void buildPacket(uint8_t txBuffer[11]) + { + LatitudeBinary = ((_gps.location.lat() + 90) / 180.0) * 16777215; + LongitudeBinary = ((_gps.location.lng() + 180) / 360.0) * 16777215; + int32_t Height = gps.altitude.meters() * 100; + + sprintf(t, "Lat: %f", _gps.location.lat()); + Serial.println(t); + sprintf(t, "Lng: %f", _gps.location.lng()); + Serial.println(t); + sprintf(t, "Alt: %f", _gps.altitude.meters()); + Serial.println(t); + + txBuffer[2] = ( LatitudeBinary >> 16 ) & 0xFF; + txBuffer[3] = ( LatitudeBinary >> 8 ) & 0xFF; + txBuffer[4] = LatitudeBinary & 0xFF; + + txBuffer[5] = ( LongitudeBinary >> 16 ) & 0xFF; + txBuffer[6] = ( LongitudeBinary >> 8 ) & 0xFF; + txBuffer[7] = LongitudeBinary & 0xFF; + + txBuffer[8] = Height >> 16; + txBuffer[9] = Height >> 8; + txBuffer[10] = Height; + } +#else +uint8_t txBuffer[9]; + +void buildPacket(uint8_t txBuffer[9]) +{ + LatitudeBinary = ((_gps.location.lat() + 90) / 180.0) * 16777215; + LongitudeBinary = ((_gps.location.lng() + 180) / 360.0) * 16777215; + + sprintf(t, "Lat: %f", _gps.location.lat()); + Serial.println(t); + + sprintf(t, "Lng: %f", _gps.location.lng()); + Serial.println(t); + + txBuffer[0] = ( LatitudeBinary >> 16 ) & 0xFF; + txBuffer[1] = ( LatitudeBinary >> 8 ) & 0xFF; + txBuffer[2] = LatitudeBinary & 0xFF; + + txBuffer[3] = ( LongitudeBinary >> 16 ) & 0xFF; + txBuffer[4] = ( LongitudeBinary >> 8 ) & 0xFF; + txBuffer[5] = LongitudeBinary & 0xFF; + + altitudeGps = _gps.altitude.meters(); + txBuffer[6] = ( altitudeGps >> 8 ) & 0xFF; + txBuffer[7] = altitudeGps & 0xFF; + + hdopGps = _gps.hdop.value()/10; + txBuffer[8] = hdopGps & 0xFF; +} + +#endif diff --git a/main/gps.ino b/main/gps.ino index ed1e339..874ef09 100644 --- a/main/gps.ino +++ b/main/gps.ino @@ -63,29 +63,4 @@ static void gps_loop() { } } -void buildPacket(uint8_t txBuffer[9]) -{ - LatitudeBinary = ((_gps.location.lat() + 90) / 180.0) * 16777215; - LongitudeBinary = ((_gps.location.lng() + 180) / 360.0) * 16777215; - - sprintf(t, "Lat: %f", _gps.location.lat()); - Serial.println(t); - - sprintf(t, "Lng: %f", _gps.location.lng()); - Serial.println(t); - - txBuffer[0] = ( LatitudeBinary >> 16 ) & 0xFF; - txBuffer[1] = ( LatitudeBinary >> 8 ) & 0xFF; - txBuffer[2] = LatitudeBinary & 0xFF; - txBuffer[3] = ( LongitudeBinary >> 16 ) & 0xFF; - txBuffer[4] = ( LongitudeBinary >> 8 ) & 0xFF; - txBuffer[5] = LongitudeBinary & 0xFF; - - altitudeGps = _gps.altitude.meters(); - txBuffer[6] = ( altitudeGps >> 8 ) & 0xFF; - txBuffer[7] = altitudeGps & 0xFF; - - hdopGps = _gps.hdop.value()/10; - txBuffer[8] = hdopGps & 0xFF; -} diff --git a/main/main.ino b/main/main.ino index 328684b..60ba970 100644 --- a/main/main.ino +++ b/main/main.ino @@ -23,8 +23,7 @@ along with this program. If not, see . #include "configuration.h" #include - -uint8_t txBuffer[9]; +#include "dataformats.h" // Message counter, stored in RTC memory, survives deep sleep RTC_DATA_ATTR uint32_t count = 0;