program to test receiving packets from the gateway

Dependencies:   libmDot mbed-rtos mbed-src

Committer:
mfiore
Date:
Fri Jun 26 19:40:51 2015 +0000
Revision:
1:8295b8c0d802
Parent:
0:e17e5a07892d
Child:
2:aadbdfb6d517
make sure log level is set

Who changed what in which revision?

UserRevisionLine numberNew 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 1:8295b8c0d802 40
mfiore 1:8295b8c0d802 41 dot->setLogLevel(MTSLog::TRACE_LEVEL);
mfiore 0:e17e5a07892d 42
mfiore 0:e17e5a07892d 43 while ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 44 logError("failed to set frequency sub band: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 45 }
mfiore 0:e17e5a07892d 46 while ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 47 logError("failed to set network name: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 48 }
mfiore 0:e17e5a07892d 49 while ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 50 logError("failed to set network password: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 51 }
mfiore 0:e17e5a07892d 52
mfiore 0:e17e5a07892d 53 logInfo("joining network");
mfiore 0:e17e5a07892d 54 while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 55 logError("failed to join network: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 56 wait_ms(dot->getNextTxMs() + 1);
mfiore 0:e17e5a07892d 57 }
mfiore 0:e17e5a07892d 58 logInfo("joined");
mfiore 0:e17e5a07892d 59
mfiore 0:e17e5a07892d 60 for (uint8_t i = 0; i < iterations; i++) {
mfiore 0:e17e5a07892d 61 send_data[0] = i;
mfiore 0:e17e5a07892d 62 if ((ret = dot->send(send_data)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 63 logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 64 send_failure++;
mfiore 0:e17e5a07892d 65 } else {
mfiore 0:e17e5a07892d 66 logInfo("send data: %s", Text::bin2hexString(send_data).c_str());
mfiore 0:e17e5a07892d 67 if ((ret = dot->recv(recv_data)) != mDot::MDOT_OK) {
mfiore 0:e17e5a07892d 68 logError("failed to recv: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
mfiore 0:e17e5a07892d 69 } else {
mfiore 0:e17e5a07892d 70 logInfo("recv data: %s", Text::bin2hexString(recv_data).c_str());
mfiore 0:e17e5a07892d 71 if (recv_data == send_data) {
mfiore 0:e17e5a07892d 72 recv++;
mfiore 0:e17e5a07892d 73 } else {
mfiore 0:e17e5a07892d 74 recv_mismatch++;
mfiore 0:e17e5a07892d 75 }
mfiore 0:e17e5a07892d 76 }
mfiore 0:e17e5a07892d 77 recv_data.clear();
mfiore 0:e17e5a07892d 78 }
mfiore 0:e17e5a07892d 79
mfiore 0:e17e5a07892d 80 next_tx = dot->getNextTxMs() + 1;
mfiore 0:e17e5a07892d 81 logInfo("waiting %ld ms to transmit again", next_tx);
mfiore 0:e17e5a07892d 82 wait_ms(next_tx);
mfiore 0:e17e5a07892d 83 }
mfiore 0:e17e5a07892d 84
mfiore 0:e17e5a07892d 85 logInfo("Version: %s", dot->getId().c_str());
mfiore 0:e17e5a07892d 86 logInfo("Recv: %d/%d", recv, iterations);
mfiore 0:e17e5a07892d 87 logInfo("Recv Mismatch: %d/%d", recv_mismatch, iterations);
mfiore 0:e17e5a07892d 88 logInfo("Send Failure: %d/%d", send_failure, iterations);
mfiore 0:e17e5a07892d 89 logInfo("Dropped: %d/%d", iterations - (recv + recv_mismatch + send_failure), iterations);
mfiore 0:e17e5a07892d 90
mfiore 0:e17e5a07892d 91 return 0;
mfiore 0:e17e5a07892d 92 }