lorawan: code sanitization

This commit is contained in:
Klaus K Wilting 2018-11-26 23:56:25 +01:00
parent dd9a493df3
commit e838b53e7a

View File

@ -9,44 +9,23 @@ static const char TAG[] = "lora";
osjob_t sendjob; osjob_t sendjob;
QueueHandle_t LoraSendQueue; QueueHandle_t LoraSendQueue;
namespace Arduino_LMIC { class cMyHalConfig_t : public Arduino_LMIC::HalConfiguration_t {
class HalConfiguration_ThisBoard_t : public HalConfiguration_t {
public: public:
enum DIGITAL_PINS : uint8_t { cMyHalConfig_t(){};
PIN_SX1276_NSS = LORA_CS,
PIN_SX1276_NRESET = LORA_RST,
PIN_SX1276_DIO0 = LORA_IRQ,
PIN_SX1276_DIO1 = LORA_IO1,
PIN_SX1276_DIO2 = LORA_IO2,
PIN_SX1276_ANT_SWITCH_RX = HalPinmap_t::UNUSED_PIN,
PIN_SX1276_ANT_SWITCH_TX_BOOST = HalPinmap_t::UNUSED_PIN,
PIN_SX1276_ANT_SWITCH_TX_RFO = HalPinmap_t::UNUSED_PIN,
PIN_VDD_BOOST_ENABLE = HalPinmap_t::UNUSED_PIN,
PIN_SX1276_MOSI = LORA_MOSI,
PIN_SX1276_MISO = LORA_MISO,
PIN_SX1276_SCK = LORA_SCK,
};
virtual void begin(void) override { virtual void begin(void) override {
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
} }
// virtual void end(void) override
// virtual ostime_t setModuleActive(bool state) override
}; };
static HalConfiguration_ThisBoard_t myConfig; cMyHalConfig_t myHalConfig{};
static const HalPinmap_t myPinmap = { // LMIC enhanced Pin mapping
.nss = HalConfiguration_ThisBoard_t::PIN_SX1276_NSS, const lmic_pinmap lmic_pins = {
.rxtx = HalConfiguration_ThisBoard_t::PIN_SX1276_ANT_SWITCH_RX, .nss = LORA_CS,
.rst = HalConfiguration_ThisBoard_t::PIN_SX1276_NRESET, .rxtx = LMIC_UNUSED_PIN,
.dio = {HalConfiguration_ThisBoard_t::PIN_SX1276_DIO0, .rst = LORA_RST,
HalConfiguration_ThisBoard_t::PIN_SX1276_DIO1, .dio = {LORA_IRQ, LORA_IO1, LORA_IO2},
HalConfiguration_ThisBoard_t::PIN_SX1276_DIO2},
// optional: set polarity of rxtx pin. // optional: set polarity of rxtx pin.
.rxtx_rx_active = 0, .rxtx_rx_active = 0,
// optional: set RSSI cal for listen-before-talk // optional: set RSSI cal for listen-before-talk
@ -57,11 +36,7 @@ static const HalPinmap_t myPinmap = {
.rssi_cal = 0, .rssi_cal = 0,
// optional: override LMIC_SPI_FREQ if non-zero // optional: override LMIC_SPI_FREQ if non-zero
.spi_freq = 0, .spi_freq = 0,
.pConfig = &myConfig}; .pConfig = &myHalConfig};
const HalPinmap_t *GetPinmap_ThisBoard(void) { return &myPinmap; }
} // namespace Arduino_LMIC
// DevEUI generator using devices's MAC address // DevEUI generator using devices's MAC address
void gen_lora_deveui(uint8_t *pdeveui) { void gen_lora_deveui(uint8_t *pdeveui) {
@ -400,14 +375,8 @@ esp_err_t lora_stack_init() {
ESP_LOGI(TAG, "Starting LMIC..."); ESP_LOGI(TAG, "Starting LMIC...");
const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard(); os_init(); // initialize lmic run-time environment on core 1
if (pPinMap == nullptr) { LMIC_reset(); // initialize lmic MAC
ESP_LOGE(TAG, "No device pinmap found. Aborting.");
return ESP_FAIL;
}
os_init_ex(pPinMap); // initialize lmic run-time environment on core 1
LMIC_reset(); // initialize lmic MAC
LMIC_setLinkCheckMode(0); LMIC_setLinkCheckMode(0);
// This tells LMIC to make the receive windows bigger, in case your clock is // This tells LMIC to make the receive windows bigger, in case your clock is
// faster or slower. This causes the transceiver to be earlier switched on, // faster or slower. This causes the transceiver to be earlier switched on,