SafeDetect
/
tx_serial_from_pi
this works for reading in data from pi via usb
Diff: main.cpp
- Revision:
- 103:d8e01f94dd43
- Parent:
- 102:630e8252eabf
- Child:
- 104:2b36fa37e411
--- a/main.cpp Tue Dec 10 04:04:03 2019 +0000 +++ b/main.cpp Tue Dec 10 06:05:28 2019 +0000 @@ -2,6 +2,8 @@ #include "dot_util.h" #include "RadioEvent.h" #include <stdlib.h> +#include <inttypes.h> + // setting must match settings on the gateway static std::string network_name = "LAleakers"; @@ -35,7 +37,7 @@ i2c.frequency(400000); - mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); + //mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); assert(plan); @@ -106,34 +108,62 @@ pc.printf("joining network\r"); } - if (dot->setTxDataRate(mDot::DR5) != mDot::MDOT_OK) { + printf("TX DR: %i\r", dot->getTxDataRate()); + + uint8_t max_dr = dot->getMaxDatarate(); + + printf("MAX DR: %i\r", max_dr); + + if (dot->setTxDataRate(max_dr) != mDot::MDOT_OK) { logError("failed to set TX datarate to DR1"); } - + pc.printf("TX DR: %i\r", dot->getTxDataRate()); + int ARR_SIZE = dot->getNextTxMaxSize(); + int t_size = 17; + ARR_SIZE -= t_size; + ARR_SIZE -= 5; // for the commas & colons in there + char arr[ARR_SIZE]; + char t_arr[t_size]; - char arr[10]; while (true) { - memset(arr, 0, 10); + //pc.printf("Max Payload: %i\n\r", dot->getNextTxMaxSize()); + memset(arr, 0, ARR_SIZE); + memset(t_arr, 0, t_size); + std::vector<uint8_t> tx_data; - tx_data.clear(); + tx_data.clear(); - pc.printf("Enter a message to TX: "); + uint64_t gps_t = dot->getGPSTime(); + printf("%llu \n", gps_t); + snprintf(t_arr, t_size,"T:%llu,", gps_t); + + //pc.printf("Enter a message to TX: "); char c = 'f'; - - for(int i = 0; i < 9 && c != '!'; i++){ + pc.printf("ready\n"); + //pc.printf("Your message: "); + for(int i = 0; i < ARR_SIZE && c != '!'; i++){ c = pc.getc(); + pc.printf("%c", c); arr[i] = c; } //pc.gets(arr, 9); - pc.printf("sending: %s\r", arr); + //pc.printf("sending: %s\r", arr); - for(int i = 0; arr[i] != '!'; i++) { + for(int i = 0; i < t_size && t_arr[i] != ','; i++) { + tx_data.push_back(t_arr[i]); + } + tx_data.push_back(','); + + for(int i = 0; arr[i] != '!' && i < ARR_SIZE; i++) { + if(arr[i] == '!'){ + break; + } tx_data.push_back(arr[i]); } send_data(tx_data); - pc.printf("message sent... \r"); + //pc.printf("message sent... \r"); } return 0; }