![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Wireless interface using LoRa technology
Dependencies: AlohaTransceiver RingBuffer SX1276Lib_inAir SerialInterfaceProtocol mbed L3PDU
Diff: main.cpp
- Revision:
- 3:7bb50ee42cba
- Parent:
- 2:5a74ae8be594
- Child:
- 4:9151697dfa70
diff -r 5a74ae8be594 -r 7bb50ee42cba main.cpp --- a/main.cpp Fri Jul 15 02:08:07 2016 +0000 +++ b/main.cpp Sun Jul 17 11:24:04 2016 +0000 @@ -72,16 +72,134 @@ memset(buffer, 0x0, sizeof(buffer)); txFrame.serialize(buffer); + aloha.send(buffer, 20); - aloha.send(buffer, 20); + seqid += 1; // start the timer to measure round trip time timer.reset(); timer.start(); - seqid += 1; + return 0; +} + +int configureRadio(uint8_t *payload, uint8_t payload_length, uint8_t *response, uint8_t *response_length) +{ + // read settings from radio +#if USE_MODEM_LORA == 1 + AlohaTransceiver::LoRaSettings_t *settings = aloha.getSettings(); +#elif USE_MODEM_FSK == 1 + AlohaTransceiver::FskSettings_t *settings = aloha.getSettings(); +#else + #error "Please define a modem in the compiler options." +#endif + + if (payload_length < 2) + { + sprintf((char *) response, "Wrong Payload Length\r\n"); + *response_length = 22; + return 1; + } + + // true is set, false is get + bool isSet = (bool) payload[0]; + uint8_t idx = payload[1]; + + switch(idx) + { + case 0x00: // Power + { + if (isSet) + { + int8_t Power = (int8_t) payload[2]; + settings->Power = Power; + + return 0; + } + else + { + response[0] = (uint8_t) settings->Power; + *response_length = 1; - return 0; + return 0; + } + } + + case 0x01: // Bandwidth + { + if (isSet) + { + uint32_t Bandwidth = (payload[4]) | + (payload[3] << 8) | + (payload[2] << 16) | + (payload[1] << 24); + settings->Bandwidth = Bandwidth; + + return 0; + } + else + { + response[3] = (uint8_t) (settings->Bandwidth); + response[2] = (uint8_t) (settings->Bandwidth >> 8); + response[1] = (uint8_t) (settings->Bandwidth >> 16); + response[0] = (uint8_t) (settings->Bandwidth >> 24); + *response_length = 4; + + return 0; + } + + } + + case 0x02: // Daterate + { + if (isSet) + { + uint32_t Datarate = (payload[4]) | + (payload[3] << 8) | + (payload[2] << 16) | + (payload[1] << 24); + settings->Datarate = Datarate; + + return 0; + } + else + { + response[3] = (uint8_t) (settings->Datarate); + response[2] = (uint8_t) (settings->Datarate >> 8); + response[1] = (uint8_t) (settings->Datarate >> 16); + response[0] = (uint8_t) (settings->Datarate >> 24); + *response_length = 4; + + return 0; + } + } + + case 0x03: // Coderate + { + if (isSet) + { + uint8_t Coderate = payload[1]; + settings->Coderate = Coderate; + + return 0; + } + else + { + response[0] = (uint8_t) settings->Coderate; + *response_length = 1; + + return 0; + } + } + + default: + { + break; + } + } + + + return 0; } void AlohaDataHandler(AlohaFrame *frame) @@ -108,9 +226,9 @@ int16_t rssi = (int16_t) (rssi_h << 8 | rssi_l); - printf(">Decoded Message:\r\n"); - printf("> Base Station::Rssi: %d, Snr: %d\r\n", rssi, snr); - printf("> Terminal: Rssi: %d, Snr: %d\r\n", aloha.getRssi(), aloha.getSnr()); + printf(">About this transmission:\r\n"); + printf("> Base Station:: Rssi: %d, Snr: %d\r\n", rssi, snr); + printf("> Terminal:: Rssi: %d, Snr: %d\r\n", aloha.getRssi(), aloha.getSnr()); printf("> Round trip time: %d ms\r\n", timer.read_ms()); printf("-----------------------------------------\r\n"); } @@ -130,7 +248,9 @@ int main() { // initialize radio module - aloha.BoardInit(); + aloha.boardInit(); + aloha.updateSettings(); + aloha.enable(); // attach serial interrupt handler pc.attach(&serialInterruptHandler); @@ -138,6 +258,7 @@ // register callback functions for SIP SIP.registerCommand(0x00, toggleChecksum); SIP.registerCommand(0x01, sendMessage); + SIP.registerCommand(0x02, configureRadio); // register callback functions for aloha transceiver aloha.registerType(AlohaFrame::Aloha_Data, AlohaDataHandler);