Fork to see if I can get working

Dependencies:   BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated

Fork of xDotBridge_update_test20180823 by Matt Briggs

Files at this revision

API Documentation at this revision

Comitter:
mbriggs_vortex
Date:
Sat Nov 18 15:50:10 2017 -0700
Parent:
88:2415b8ac4165
Child:
90:32f9d043561a
Commit message:
Updated bootloader. Fixed radio functions calls.

Changed in this revision

bootloader/xDotBootloader.bin Show annotated file Show diff for this revision Revisions of this file
bootloader/xDotBootloader_v1_00_20171118.bin Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/CommProtocolPeerBrute.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/dot_util.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/main.cpp Show annotated file Show diff for this revision Revisions of this file
Binary file bootloader/xDotBootloader.bin has changed
Binary file bootloader/xDotBootloader_v1_00_20171118.bin has changed
--- a/xDotBridge/src/CommProtocolPeerBrute.cpp	Thu Nov 16 18:10:53 2017 -0700
+++ b/xDotBridge/src/CommProtocolPeerBrute.cpp	Sat Nov 18 15:50:10 2017 -0700
@@ -9,6 +9,7 @@
 #include "dot_util.h"
 #include "util.h"
 #include "MyLog.h"
+#include "ChannelPlan.h"
 
 // wireless bridge protocol
 const uint8_t TX_PWR = 20; // 20 dBm
@@ -78,33 +79,36 @@
     uint8_t tx_datarate;
     uint32_t tx_frequency;
     uint8_t frequency_band = dot->getFrequencyBand();
-//    switch (frequency_band) {
-//        case mDot::FB_EU868:
-//            // 250kHz channels achieve higher throughput
-//            // DR6 : SF7 @ 250kHz
-//            // DR0 - DR5 (125kHz channels) available but much slower
-//            tx_frequency = 869850000;
-//            tx_datarate = mDot::DR6;
-//            // the 869850000 frequency is 100% duty cycle if the total power is under 7 dBm - tx power 4 + antenna gain 3 = 7
-//            tx_power = 4;
-//            break;
-//        case mDot::FB_US915:
-//        case mDot::FB_AU915:
-//        default:
-//            // 500kHz channels achieve highest throughput
-//            // DR8 : SF12 @ 500kHz
-//            // DR9 : SF11 @ 500kHz
-//            // DR10 : SF10 @ 500kHz
-//            // DR11 : SF9 @ 500kHz
-//            // DR12 : SF8 @ 500kHz
-//            // DR13 : SF7 @ 500kHz
-//            // DR0 - DR3 (125kHz channels) available but much slower
-//            tx_frequency = 915500000;
-//            tx_datarate = mDot::DR13;
-//            // 915 bands have no duty cycle restrictions, set tx power to max
-//            tx_power = 20;
-//            break;
-//    }
+    switch (frequency_band) {
+		case lora::ChannelPlan::EU868_OLD:
+		case lora::ChannelPlan::EU868:
+            // 250kHz channels achieve higher throughput
+            // DR6 : SF7 @ 250kHz
+            // DR0 - DR5 (125kHz channels) available but much slower
+            tx_frequency = 869850000;
+            tx_datarate = mDot::DR6;
+            // the 869850000 frequency is 100% duty cycle if the total power is under 7 dBm - tx power 4 + antenna gain 3 = 7
+            tx_power = 4;
+            break;
+        case lora::ChannelPlan::US915_OLD:
+        case lora::ChannelPlan::US915:
+        case lora::ChannelPlan::AU915_OLD:
+        case lora::ChannelPlan::AU915:
+        default:
+            // 500kHz channels achieve highest throughput
+            // DR8 : SF12 @ 500kHz
+            // DR9 : SF11 @ 500kHz
+            // DR10 : SF10 @ 500kHz
+            // DR11 : SF9 @ 500kHz
+            // DR12 : SF8 @ 500kHz
+            // DR13 : SF7 @ 500kHz
+            // DR0 - DR3 (125kHz channels) available but much slower
+            tx_frequency = 915500000;
+            tx_datarate = mDot::DR13;
+            // 915 bands have no duty cycle restrictions, set tx power to max
+            tx_power = 20;
+            break;
+    }
     // in PEER_TO_PEER mode there is no join request/response transaction
     // as long as both Dots are configured correctly, they should be able to communicate
 
@@ -145,33 +149,36 @@
     uint8_t tx_datarate;
     uint32_t tx_frequency;
     uint8_t frequency_band = dot->getFrequencyBand();
-//    switch (frequency_band) {
-//        case mDot::FB_EU868:
-//            // 250kHz channels achieve higher throughput
-//            // DR6 : SF7 @ 250kHz
-//            // DR0 - DR5 (125kHz channels) available but much slower
-//            tx_frequency = 869850000;
-//            tx_datarate = mDot::DR6;
-//            // the 869850000 frequency is 100% duty cycle if the total power is under 7 dBm - tx power 4 + antenna gain 3 = 7
-//            tx_power = 4;
-//            break;
-//        case mDot::FB_US915:
-//        case mDot::FB_AU915:
-//        default:
-//            // 500kHz channels achieve highest throughput
-//            // DR8 : SF12 @ 500kHz
-//            // DR9 : SF11 @ 500kHz
-//            // DR10 : SF10 @ 500kHz
-//            // DR11 : SF9 @ 500kHz
-//            // DR12 : SF8 @ 500kHz
-//            // DR13 : SF7 @ 500kHz
-//            // DR0 - DR3 (125kHz channels) available but much slower
-//            tx_frequency = 915500000;
-//            tx_datarate = mDot::DR13;
-//            // 915 bands have no duty cycle restrictions, set tx power to max
-//            tx_power = 20;
-//            break;
-//    }
+    switch (frequency_band) {
+		case lora::ChannelPlan::EU868_OLD:
+		case lora::ChannelPlan::EU868:
+            // 250kHz channels achieve higher throughput
+            // DR6 : SF7 @ 250kHz
+            // DR0 - DR5 (125kHz channels) available but much slower
+            tx_frequency = 869850000;
+            tx_datarate = mDot::DR6;
+            // the 869850000 frequency is 100% duty cycle if the total power is under 7 dBm - tx power 4 + antenna gain 3 = 7
+            tx_power = 4;
+            break;
+        case lora::ChannelPlan::US915_OLD:
+        case lora::ChannelPlan::US915:
+        case lora::ChannelPlan::AU915_OLD:
+        case lora::ChannelPlan::AU915:
+        default:
+            // 500kHz channels achieve highest throughput
+            // DR8 : SF12 @ 500kHz
+            // DR9 : SF11 @ 500kHz
+            // DR10 : SF10 @ 500kHz
+            // DR11 : SF9 @ 500kHz
+            // DR12 : SF8 @ 500kHz
+            // DR13 : SF7 @ 500kHz
+            // DR0 - DR3 (125kHz channels) available but much slower
+            tx_frequency = 915500000;
+            tx_datarate = mDot::DR13;
+            // 915 bands have no duty cycle restrictions, set tx power to max
+            tx_power = 20;
+            break;
+    }
     update_peer_to_peer_config(pair_network_address, pair_network_session_key, pair_data_session_key, tx_frequency, tx_datarate, tx_power);
     dot->saveConfig(); // This is required for network settings to apply
     return cmdSuccess;
@@ -537,9 +544,10 @@
     myLogInfo("version ------------------ %s", dot->getId().c_str());
     myLogInfo("device ID/EUI ------------ %s", mts::Text::bin2hexString(dot->getDeviceId()).c_str());
     myLogInfo("frequency band ----------- %s", mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str());
-//    if (dot->getFrequencySubBand() != mDot::FB_EU868) {
-//        myLogInfo("frequency sub band ------- %u", dot->getFrequencySubBand());
-//    }
+    if ((dot->getFrequencySubBand() != lora::ChannelPlan::EU868_OLD)
+     || (dot->getFrequencySubBand() != lora::ChannelPlan::EU868)) {
+        myLogInfo("frequency sub band ------- %u", dot->getFrequencySubBand());
+    }
     myLogInfo("public network ----------- %s", dot->getPublicNetwork() ? "on" : "off");
     myLogInfo("=========================");
     myLogInfo("credentials configuration");
--- a/xDotBridge/src/dot_util.cpp	Thu Nov 16 18:10:53 2017 -0700
+++ b/xDotBridge/src/dot_util.cpp	Sat Nov 18 15:50:10 2017 -0700
@@ -1,4 +1,5 @@
 #include "dot_util.h"
+#include "ChannelPlan.h"
 #if defined(TARGET_XDOT_L151CC)
 #include "xdot_low_power.h"
 #endif
@@ -20,9 +21,10 @@
     logInfo("version ------------------ %s", dot->getId().c_str());
     logInfo("device ID/EUI ------------ %s", mts::Text::bin2hexString(dot->getDeviceId()).c_str());
     logInfo("frequency band ----------- %s", mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str());
-//    if (dot->getFrequencySubBand() != mDot::FB_EU868) {
-//        logInfo("frequency sub band ------- %u", dot->getFrequencySubBand());
-//    }
+    if ((dot->getFrequencySubBand() != lora::ChannelPlan::EU868_OLD)
+	 || (dot->getFrequencySubBand() != lora::ChannelPlan::EU868)) {
+        logInfo("frequency sub band ------- %u", dot->getFrequencySubBand());
+    }
     logInfo("public network ----------- %s", dot->getPublicNetwork() ? "on" : "off");
     logInfo("=========================");
     logInfo("credentials configuration");
--- a/xDotBridge/src/main.cpp	Thu Nov 16 18:10:53 2017 -0700
+++ b/xDotBridge/src/main.cpp	Sat Nov 18 15:50:10 2017 -0700
@@ -19,7 +19,7 @@
 
 #define RX_SEQ_LOG 1
 
-const float BridgeVersion = 99.99;
+const float BridgeVersion = 1.01;
 
 // 232 Pins
 const PinName SER_TERM_TX = UART_TX;
@@ -27,51 +27,9 @@
 
 #ifndef __TEST__ // Exclude code for tests
 Serial pc(USBTX, USBRX);
-//RawSerial outPc(UART_TX, UART_RX);
-//Serial *outPc;
 BufferedSerial *outPc;
 InterruptIn uart1RxIntIn (SER_TERM_RX);
 
-//// Serial interrupts / buffer code
-//const int buffer_size = 255;
-//// might need to increase buffer size for high baud rates
-//char tx_buffer[buffer_size+1];
-//char rx_buffer[buffer_size+1];
-//// Circular buffer pointers
-//// volatile makes read-modify-write atomic
-//volatile int tx_in=0;
-//volatile int tx_out=0;
-//volatile int rx_in=0;
-//volatile int rx_out=0;
-//
-//// Interupt Routine to read in data from serial port
-//void Rx_interrupt() {
-//    led1=1;
-//// Loop just in case more than one character is in UART's receive FIFO buffer
-//// Stop if buffer full
-//    while ((outPc.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
-//        rx_buffer[rx_in] = outPc.getc();
-//// Uncomment to Echo to USB serial to watch data flow
-////        monitor_device.putc(rx_buffer[rx_in]);
-//        rx_in = (rx_in + 1) % buffer_size;
-//    }
-//    led1=0;
-//    return;
-//}
-//
-//// Interupt Routine to write out data to serial port
-//void Tx_interrupt() {
-//    led2=1;
-//// Loop to fill more than one character in UART's transmit FIFO buffer
-//// Stop if buffer empty
-//    while ((outPc.writeable()) && (tx_in != tx_out)) {
-//        outPc.putc(tx_buffer[tx_out]);
-//        tx_out = (tx_out + 1) % buffer_size;
-//    }
-//    led2=0;
-//    return;
-//}
-
 mDot* dot = NULL; // Used by dot-utils
 
 volatile bool uartRxFlag;
@@ -147,32 +105,6 @@
     }
     protocol->printDotConfig();
 
-    // save changes to configuration
-//    logInfo("saving configuration");
-//    core_util_critical_section_enter();
-//    bool dotConfigSaved = dot->saveConfig();
-//    core_util_critical_section_exit();
-//    if (!dotConfigSaved) {
-//        logError("failed to save configuration");
-//    }
-
-    // Setup programmable voltage detector
-    // PVD_LEVEL0 Falling 1.85
-    // PVD_LEVEL1 Falling 2.04
-    // PVD_LEVEL2 Falling 2.24
-    // PVD_LEVEL3 Falling 2.44
-    // PVD_LEVEL4 Falling 2.64
-    // PVD_LEVEL5 Falling 2.84
-    // PVD_LEVEL6 Falling 3.05
-//    PWR_PVDTypeDef pvdConfig;
-//    pvdConfig.Mode = PWR_PVD_MODE_NORMAL;
-//    pvdConfig.PVDLevel = PWR_PVDLEVEL_5;
-//
-//    HAL_PWR_ConfigPVD(&pvdConfig);
-//    HAL_PWR_EnablePVD();
-//    logInfo("Programmable Voltage Detector set for level: %d", pvdConfig.PVDLevel);
-//    // HAL_PWR_PVDCallback need to define this I think this will override the current implementation
-
     dot->setWakeMode(mDot::RTC_ALARM_OR_INTERRUPT);
     dot->setWakePin(GPIO0);
 //    dot->setWakePin(UART_RX);