From 1cf542adcd8dd2fec3690720635940eef97a6efa Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Mon, 24 Jun 2019 14:47:14 +0100
Subject: [PATCH] Fix seriously nasty linking errors

---
 .gitignore                                         |  2 +-
 ...ustom.h.example => settings.custom.cpp.example} | 13 +++++++++++++
 iot/main/settings.custom.h                         | 14 ++++++++++++++
 iot/main/settings.h                                | 12 +++---------
 iot/main/{radio.cpp => transmission.cpp}           |  4 ++--
 iot/main/{radio.h => transmission.h}               |  4 ++--
 6 files changed, 35 insertions(+), 14 deletions(-)
 rename iot/main/{settings.custom.h.example => settings.custom.cpp.example} (71%)
 create mode 100644 iot/main/settings.custom.h
 rename iot/main/{radio.cpp => transmission.cpp} (98%)
 rename iot/main/{radio.h => transmission.h} (75%)

diff --git a/.gitignore b/.gitignore
index e1478a7..75bcb86 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
 config.custom.h
-settings.custom.h
+settings.custom.cpp
 
 Reports/*.pdf
 
diff --git a/iot/main/settings.custom.h.example b/iot/main/settings.custom.cpp.example
similarity index 71%
rename from iot/main/settings.custom.h.example
rename to iot/main/settings.custom.cpp.example
index 63bad2b..11fdf42 100644
--- a/iot/main/settings.custom.h.example
+++ b/iot/main/settings.custom.cpp.example
@@ -1,3 +1,9 @@
+#include <lmic.h>
+#include <hal/hal.h>
+#include <SPI.h>
+
+#include "settings.h"
+
 
 // LoRaWAN NwkSKey, network session key
 // This is the default Semtech key, which is used by the early prototype TTN
@@ -11,3 +17,10 @@ static const u1_t PROGMEM APPSKEY[16] = { ..... };
 
 // LoRaWAN end-device address (DevAddr)
 static const u4_t DEVADDR = 0x....; // <-- Change this address for every node!
+
+const lmic_pinmap lmic_pins = {
+	.nss = PIN_SPI_CS_RFM95,
+	.rxtx = LMIC_UNUSED_PIN,
+	.rst = 9,
+	.dio = {2, 6, 7},
+};
diff --git a/iot/main/settings.custom.h b/iot/main/settings.custom.h
new file mode 100644
index 0000000..28e4fee
--- /dev/null
+++ b/iot/main/settings.custom.h
@@ -0,0 +1,14 @@
+#include <lmic.h>
+#include <hal/hal.h>
+#include <SPI.h>
+
+/**
+ * Don't edit this file - you want to make a copy of settings.custom.cpp, call 
+ * it settings.cpp, and edit that instead.
+ */
+
+extern const PROGMEM u1_t NWKSKEY[16];
+extern const u1_t PROGMEM APPSKEY[16];
+extern const u4_t DEVADDR;
+
+extern const lmic_pinmap lmic_pins;
diff --git a/iot/main/settings.h b/iot/main/settings.h
index a93a3b3..4fa4001 100644
--- a/iot/main/settings.h
+++ b/iot/main/settings.h
@@ -8,8 +8,8 @@
 
 /*
  * This is the main settings file - customise it to match your setup.
- * Don't forget that you need to take a copy of settings.custom.h.example as
- * settings.custom.h, and fill in the private keys the program needs to talk 
+ * Don't forget that you need to take a copy of settings.custom.cpp.example as
+ * settings.custom.cpp, and fill in the private keys the program needs to talk 
  * over LORaWAN.
  */
 
@@ -34,13 +34,7 @@
 // The SPI chip-select pin for the RFM 95
 #define PIN_SPI_CS_RFM95	10
 
-// Pin mapping
-const lmic_pinmap lmic_pins = {
-	.nss = PIN_SPI_CS_RFM95,
-	.rxtx = LMIC_UNUSED_PIN,
-	.rst = 9,
-	.dio = {2, 6, 7},
-};
+// Pin mapping - see settings.custom.cpp
 
 
 /////////////////////////////////
diff --git a/iot/main/radio.cpp b/iot/main/transmission.cpp
similarity index 98%
rename from iot/main/radio.cpp
rename to iot/main/transmission.cpp
index 6f76a70..c7aa1c1 100644
--- a/iot/main/radio.cpp
+++ b/iot/main/transmission.cpp
@@ -10,7 +10,7 @@ static bool is_sending_complete = false;
 
 static osjob_t sendjob;
 
-void radio_init() {
+void transmit_init() {
 	// LMIC init
 	os_init();
 	// Reset the MAC state. Session and pending data transfers will be discarded.
@@ -66,7 +66,7 @@ void radio_init() {
  * @param data   The message to send.
  * @param length The length of the given message.
  */
-bool radio_send(uint8_t* data, int length) {
+bool transmit_send(uint8_t* data, int length) {
 	// Check if there is not a current TX/RX job running
 	if (LMIC.opmode & OP_TXRXPEND) {
 		Serial.println(F("OP_TXRXPEND: There's already a job running, not sending"));
diff --git a/iot/main/radio.h b/iot/main/transmission.h
similarity index 75%
rename from iot/main/radio.h
rename to iot/main/transmission.h
index 3f1db5e..38a9bc4 100644
--- a/iot/main/radio.h
+++ b/iot/main/transmission.h
@@ -3,11 +3,11 @@
 /**
  * Initialises the RFM95 LoRa radio.
  */
-void radio_init();
+void transmit_init();
 
 /**
  * Sends a specified message via LoRaWAN.
  * @param data   The message to send.
  * @param length The length of the given message.
  */
-bool radio_send(byte* data, int length);
+bool transmit_send(byte* data, int length);
