Wireless interface using LoRa technology
Dependencies: AlohaTransceiver RingBuffer SX1276Lib_inAir SerialInterfaceProtocol mbed L3PDU
Diff: main.cpp
- Revision:
- 2:5a74ae8be594
- Parent:
- 1:101cf4fca4e5
- Child:
- 3:7bb50ee42cba
--- a/main.cpp Thu Jul 14 11:49:34 2016 +0000 +++ b/main.cpp Fri Jul 15 02:08:07 2016 +0000 @@ -15,6 +15,7 @@ AlohaTransceiver aloha; AlohaFrame txFrame; Timer timer; +InterruptIn button(USER_BUTTON); void serialInterruptHandler() { // Note: you need to actually read from the serial to clear the RX interrupt @@ -88,15 +89,16 @@ // stop the timer to measure round trip time timer.stop(); - printf("Received Frame\r\n"); - printf(" Type: 0x%x, PayloadLength: 0x%x\r\n", frame->getType(), frame->getPayloadLength()); - printf(" SrcAddr: 0x%x, DestAddr: 0x%x\r\n", frame->getSourceAddress(), frame->getDestinationAddress()); - printf(" FMF: 0x%x, SequenceID: 0x%x\r\n", frame->getFullMessageFlag(), frame->getSequenceID()); + printf("-----------------------------------------\r\n"); + printf(">Received Frame\r\n"); + printf("> Type: 0x%x, PayloadLength: 0x%x\r\n", frame->getType(), frame->getPayloadLength()); + printf("> SrcAddr: 0x%x, DestAddr: 0x%x\r\n", frame->getSourceAddress(), frame->getDestinationAddress()); + printf("> FMF: 0x%x, SequenceID: 0x%x\r\n", frame->getFullMessageFlag(), frame->getSequenceID()); for (uint8_t i = 0; i < frame->getPayloadLength(); i++) { - printf(" Payload[%d]: 0x%x\r\n", i, frame->getPayload(i)); + printf("> Payload[%d]: 0x%x\r\n", i, frame->getPayload(i)); } - printf(" CRC: 0x%x\r\n", frame->getCrc()); + printf("> CRC: 0x%x\r\n", frame->getCrc()); // decode payload (range test only) int8_t snr = (int8_t) frame->getPayload(0); @@ -106,13 +108,26 @@ int16_t rssi = (int16_t) (rssi_h << 8 | rssi_l); - printf("Base Station respond:\r\n"); - printf("Rssi: %d, Snr: %d\r\n", rssi, snr); - printf("Round trip time: %d ms\r\n", timer.read_ms()); - - + 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("> Round trip time: %d ms\r\n", timer.read_ms()); + printf("-----------------------------------------\r\n"); } +void automaticPacketTransmit() +{ + SerialInputBuffer.enqueue((uint8_t) '<'); + SerialInputBuffer.enqueue((uint8_t) '0'); + SerialInputBuffer.enqueue((uint8_t) '1'); + SerialInputBuffer.enqueue((uint8_t) '0'); + SerialInputBuffer.enqueue((uint8_t) '0'); + SerialInputBuffer.enqueue((uint8_t) 'f'); + SerialInputBuffer.enqueue((uint8_t) 'f'); + SerialInputBuffer.enqueue((uint8_t) '>'); +} + + int main() { // initialize radio module aloha.BoardInit(); @@ -126,6 +141,9 @@ // register callback functions for aloha transceiver aloha.registerType(AlohaFrame::Aloha_Data, AlohaDataHandler); + + // configure button interrupt + button.fall(automaticPacketTransmit); while(1) { SIP.poll();