From 1a377a0d6760a9f811d0de7782d0ef13282ec286 Mon Sep 17 00:00:00 2001 From: Jonathan Ma Date: Fri, 15 Mar 2024 20:04:14 -0400 Subject: [PATCH] Update downlink report --- src/ControlTasks/RadioControlTask.cpp | 33 +++++++++++++++++---------- src/ControlTasks/RadioControlTask.hpp | 2 +- src/constants.hpp | 2 ++ src/sfr.cpp | 5 ++++ src/sfr.hpp | 4 ++++ 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/ControlTasks/RadioControlTask.cpp b/src/ControlTasks/RadioControlTask.cpp index 0062b62..1bd7ea4 100644 --- a/src/ControlTasks/RadioControlTask.cpp +++ b/src/ControlTasks/RadioControlTask.cpp @@ -263,11 +263,16 @@ void RadioControlTask::execute() bool RadioControlTask::executeDownlink() { - uint16_t lat = map_range_16(sfr::gps::latitude * 10, constants::gps::lat_min, constants::gps::lat_max); - uint16_t lon = map_range_16(sfr::gps::longitude * 10, constants::gps::lon_min, constants::gps::lon_max); - uint16_t alt = map_range_16(sfr::gps::altitude / 10, constants::gps::alt_min, constants::gps::alt_max); + uint16_t lat = sfr::gps::latitude * 10; + uint16_t lon = sfr::gps::longitude * 10; + uint16_t alt = sfr::gps::altitude / 10; - uint8_t flags = ((sfr::radio::mode == radio_mode_type::listen) ? 0xF0 : 0x00) | (sfr::gps::valid_msg ? 0x0F : 0x00); + uint8_t flags = 0; + flags |= constants::radio::chipsat_id << 6; + flags |= sfr::gps::valid_msg << 5; // gps valid + flags |= sfr::imu::initialized << 4; // imu valid + flags |= sfr::gps::on << 3; // boot mode flag + flags |= (sfr::radio::mode == radio_mode_type::listen) << 2; // listen flag uint8_t dlink[] = { (uint8_t)(lat >> 8), (uint8_t)lat, @@ -280,6 +285,7 @@ bool RadioControlTask::executeDownlink() map_range(sfr::imu::acc_y, constants::imu::acc_min, constants::imu::acc_max), map_range(sfr::imu::acc_z, constants::imu::acc_min, constants::imu::acc_max), map_range(sfr::temperature::temp_c, constants::temperature::min, constants::temperature::max), + (uint8_t)(sfr::radio::valid_uplinks << 4 | (sfr::radio::invalid_uplinks & 0x0F)), flags}; #ifdef VERBOSE @@ -300,14 +306,14 @@ uint8_t RadioControlTask::map_range(float value, int min_val, int max_val) return (uint8_t)raw; } -uint16_t RadioControlTask::map_range_16(float value, int min_val, int max_val) -{ - long raw = map(value, min_val, max_val, 0, 65535); - Serial.println(raw); - raw = min(raw, 65535); - raw = max(raw, 0); - return (uint16_t)raw; -} +// uint16_t RadioControlTask::map_range_16(float value, int min_val, int max_val) +// { +// long raw = map(value, min_val, max_val, 0, 65535); +// Serial.println(raw); +// raw = min(raw, 65535); +// raw = max(raw, 0); +// return (uint16_t)raw; +// } void RadioControlTask::processUplink() { @@ -317,10 +323,12 @@ void RadioControlTask::processUplink() #ifdef VERBOSE Serial.println(F("No-Op Command")); #endif + sfr::radio::valid_uplinks++; break; case constants::opcodes::change_downlink_period: { // Change downlink period uint16_t combined = ((uint16_t)received[1] << 8) | received[2]; sfr::radio::downlink_period = combined * constants::time::one_second; + sfr::radio::valid_uplinks++; #ifdef VERBOSE Serial.print(F("Change Downlink Command: ")); Serial.println(combined); @@ -331,6 +339,7 @@ void RadioControlTask::processUplink() #ifdef VERBOSE Serial.println(F("Unknown Command")); #endif + sfr::radio::invalid_uplinks++; break; } } \ No newline at end of file diff --git a/src/ControlTasks/RadioControlTask.hpp b/src/ControlTasks/RadioControlTask.hpp index e69f1e9..93a11ac 100644 --- a/src/ControlTasks/RadioControlTask.hpp +++ b/src/ControlTasks/RadioControlTask.hpp @@ -19,7 +19,7 @@ class RadioControlTask bool receive(); bool executeDownlink(); uint8_t map_range(float value, int min, int max); - uint16_t map_range_16(float value, int min, int max); + // uint16_t map_range_16(float value, int min, int max); void processUplink(); uint8_t *received; }; diff --git a/src/constants.hpp b/src/constants.hpp index ace942d..04279d8 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -22,6 +22,8 @@ namespace constants { constexpr int pl = 8; constexpr int gn = 0; + constexpr int chipsat_id = 1; + } // namespace radio namespace imu { constexpr int gyro_min = -245; diff --git a/src/sfr.cpp b/src/sfr.cpp index 214bda6..850ce02 100644 --- a/src/sfr.cpp +++ b/src/sfr.cpp @@ -21,12 +21,14 @@ namespace sfr { namespace gps { float utc_time, latitude, longitude, altitude; bool valid_msg = false; + bool on = true; } // namespace gps namespace radio { sensor_init_mode_type init_mode = sensor_init_mode_type::init; radio_mode_type mode = radio_mode_type::init; uint8_t start_progress = 0; + uint32_t downlink_period = 10 * constants::time::one_second; uint32_t listen_period = 30 * constants::time::one_second; uint32_t command_wait_period = 30 * constants::time::one_second; @@ -34,6 +36,9 @@ namespace sfr { uint32_t listen_period_start; uint32_t command_wait_start; + uint8_t valid_uplinks = 0; + uint8_t invalid_uplinks = 0; + } // namespace radio }; // namespace sfr diff --git a/src/sfr.hpp b/src/sfr.hpp index cc2992f..bf202f4 100644 --- a/src/sfr.hpp +++ b/src/sfr.hpp @@ -38,6 +38,9 @@ namespace sfr { extern uint32_t listen_period_start; extern uint32_t command_wait_start; + extern uint8_t valid_uplinks; + extern uint8_t invalid_uplinks; + } // namespace radio namespace gps { extern float utc_time; @@ -47,6 +50,7 @@ namespace sfr { extern float altitude; extern bool valid_msg; + extern bool on; } // namespace gps }; // namespace sfr