Testing basic mdot with external Interrupt
Dependencies: libmDot mbed-rtos mbed-src
Fork of mDot_test_rx by
LoRaWAN Network Configuration
For DevEUI, AppEUI, AppKey configuration to specific network, please see lines 10 to 18.
If using with an 8 channel gateway define config_frequency_sub_band at line 16. Setting config_frequency_sub_band to '1' will limit the device to using just the first eight (8) channels starting at 902.3 MHz.
Free Running vs Interrupt
At line 117 you can change the program from waiting for external interrupts to free-running by changing msg_rdy to be equal to 'true'.
main.cpp@0:e17e5a07892d, 2015-06-26 (annotated)
- Committer:
- mfiore
- Date:
- Fri Jun 26 17:39:51 2015 +0000
- Revision:
- 0:e17e5a07892d
- Child:
- 1:8295b8c0d802
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:e17e5a07892d | 1 | #include "mbed.h" |
mfiore | 0:e17e5a07892d | 2 | #include "mDot.h" |
mfiore | 0:e17e5a07892d | 3 | #include "MTSLog.h" |
mfiore | 0:e17e5a07892d | 4 | #include "MTSText.h" |
mfiore | 0:e17e5a07892d | 5 | #include <string> |
mfiore | 0:e17e5a07892d | 6 | #include <vector> |
mfiore | 0:e17e5a07892d | 7 | |
mfiore | 0:e17e5a07892d | 8 | using namespace mts; |
mfiore | 0:e17e5a07892d | 9 | |
mfiore | 0:e17e5a07892d | 10 | static std::string config_network_name = "<network name>"; |
mfiore | 0:e17e5a07892d | 11 | static std::string config_network_pass = "<network key>"; |
mfiore | 0:e17e5a07892d | 12 | static uint8_t config_frequency_sub_band = 1; |
mfiore | 0:e17e5a07892d | 13 | |
mfiore | 0:e17e5a07892d | 14 | int main() { |
mfiore | 0:e17e5a07892d | 15 | Serial debug(USBTX, USBRX); |
mfiore | 0:e17e5a07892d | 16 | debug.baud(460800); |
mfiore | 0:e17e5a07892d | 17 | |
mfiore | 0:e17e5a07892d | 18 | int32_t ret; |
mfiore | 0:e17e5a07892d | 19 | int32_t next_tx; |
mfiore | 0:e17e5a07892d | 20 | mDot* dot; |
mfiore | 0:e17e5a07892d | 21 | std::vector<uint8_t> send_data; |
mfiore | 0:e17e5a07892d | 22 | std::vector<uint8_t> recv_data; |
mfiore | 0:e17e5a07892d | 23 | uint8_t recv = 0; |
mfiore | 0:e17e5a07892d | 24 | uint8_t recv_mismatch = 0; |
mfiore | 0:e17e5a07892d | 25 | uint8_t send_failure = 0; |
mfiore | 0:e17e5a07892d | 26 | uint8_t iterations = 50; |
mfiore | 0:e17e5a07892d | 27 | |
mfiore | 0:e17e5a07892d | 28 | send_data.push_back(0x00); |
mfiore | 0:e17e5a07892d | 29 | send_data.push_back(0xFF); |
mfiore | 0:e17e5a07892d | 30 | send_data.push_back(0xFF); |
mfiore | 0:e17e5a07892d | 31 | send_data.push_back(0xFF); |
mfiore | 0:e17e5a07892d | 32 | send_data.push_back(0xFF); |
mfiore | 0:e17e5a07892d | 33 | send_data.push_back(0xFF); |
mfiore | 0:e17e5a07892d | 34 | send_data.push_back(0xFF); |
mfiore | 0:e17e5a07892d | 35 | send_data.push_back(0xFF); |
mfiore | 0:e17e5a07892d | 36 | |
mfiore | 0:e17e5a07892d | 37 | dot = mDot::getInstance(); |
mfiore | 0:e17e5a07892d | 38 | |
mfiore | 0:e17e5a07892d | 39 | dot->resetConfig(); |
mfiore | 0:e17e5a07892d | 40 | |
mfiore | 0:e17e5a07892d | 41 | while ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) { |
mfiore | 0:e17e5a07892d | 42 | logError("failed to set frequency sub band: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 0:e17e5a07892d | 43 | } |
mfiore | 0:e17e5a07892d | 44 | while ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) { |
mfiore | 0:e17e5a07892d | 45 | logError("failed to set network name: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 0:e17e5a07892d | 46 | } |
mfiore | 0:e17e5a07892d | 47 | while ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) { |
mfiore | 0:e17e5a07892d | 48 | logError("failed to set network password: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 0:e17e5a07892d | 49 | } |
mfiore | 0:e17e5a07892d | 50 | |
mfiore | 0:e17e5a07892d | 51 | logInfo("joining network"); |
mfiore | 0:e17e5a07892d | 52 | while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) { |
mfiore | 0:e17e5a07892d | 53 | logError("failed to join network: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 0:e17e5a07892d | 54 | wait_ms(dot->getNextTxMs() + 1); |
mfiore | 0:e17e5a07892d | 55 | } |
mfiore | 0:e17e5a07892d | 56 | logInfo("joined"); |
mfiore | 0:e17e5a07892d | 57 | |
mfiore | 0:e17e5a07892d | 58 | for (uint8_t i = 0; i < iterations; i++) { |
mfiore | 0:e17e5a07892d | 59 | send_data[0] = i; |
mfiore | 0:e17e5a07892d | 60 | if ((ret = dot->send(send_data)) != mDot::MDOT_OK) { |
mfiore | 0:e17e5a07892d | 61 | logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 0:e17e5a07892d | 62 | send_failure++; |
mfiore | 0:e17e5a07892d | 63 | } else { |
mfiore | 0:e17e5a07892d | 64 | logInfo("send data: %s", Text::bin2hexString(send_data).c_str()); |
mfiore | 0:e17e5a07892d | 65 | if ((ret = dot->recv(recv_data)) != mDot::MDOT_OK) { |
mfiore | 0:e17e5a07892d | 66 | logError("failed to recv: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 0:e17e5a07892d | 67 | } else { |
mfiore | 0:e17e5a07892d | 68 | logInfo("recv data: %s", Text::bin2hexString(recv_data).c_str()); |
mfiore | 0:e17e5a07892d | 69 | if (recv_data == send_data) { |
mfiore | 0:e17e5a07892d | 70 | recv++; |
mfiore | 0:e17e5a07892d | 71 | } else { |
mfiore | 0:e17e5a07892d | 72 | recv_mismatch++; |
mfiore | 0:e17e5a07892d | 73 | } |
mfiore | 0:e17e5a07892d | 74 | } |
mfiore | 0:e17e5a07892d | 75 | recv_data.clear(); |
mfiore | 0:e17e5a07892d | 76 | } |
mfiore | 0:e17e5a07892d | 77 | |
mfiore | 0:e17e5a07892d | 78 | next_tx = dot->getNextTxMs() + 1; |
mfiore | 0:e17e5a07892d | 79 | logInfo("waiting %ld ms to transmit again", next_tx); |
mfiore | 0:e17e5a07892d | 80 | wait_ms(next_tx); |
mfiore | 0:e17e5a07892d | 81 | } |
mfiore | 0:e17e5a07892d | 82 | |
mfiore | 0:e17e5a07892d | 83 | logInfo("Version: %s", dot->getId().c_str()); |
mfiore | 0:e17e5a07892d | 84 | logInfo("Recv: %d/%d", recv, iterations); |
mfiore | 0:e17e5a07892d | 85 | logInfo("Recv Mismatch: %d/%d", recv_mismatch, iterations); |
mfiore | 0:e17e5a07892d | 86 | logInfo("Send Failure: %d/%d", send_failure, iterations); |
mfiore | 0:e17e5a07892d | 87 | logInfo("Dropped: %d/%d", iterations - (recv + recv_mismatch + send_failure), iterations); |
mfiore | 0:e17e5a07892d | 88 | |
mfiore | 0:e17e5a07892d | 89 | return 0; |
mfiore | 0:e17e5a07892d | 90 | } |