Skip to content

Commit

Permalink
Update downlink report
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanjma committed Mar 16, 2024
1 parent 2d1a973 commit 1a377a0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
33 changes: 21 additions & 12 deletions src/ControlTasks/RadioControlTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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()
{
Expand All @@ -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);
Expand All @@ -331,6 +339,7 @@ void RadioControlTask::processUplink()
#ifdef VERBOSE
Serial.println(F("Unknown Command"));
#endif
sfr::radio::invalid_uplinks++;
break;
}
}
2 changes: 1 addition & 1 deletion src/ControlTasks/RadioControlTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/sfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@ 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;
uint32_t downlink_period_start;
uint32_t listen_period_start;
uint32_t command_wait_start;

uint8_t valid_uplinks = 0;
uint8_t invalid_uplinks = 0;

} // namespace radio

}; // namespace sfr
4 changes: 4 additions & 0 deletions src/sfr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,6 +50,7 @@ namespace sfr {
extern float altitude;

extern bool valid_msg;
extern bool on;
} // namespace gps

}; // namespace sfr
Expand Down

0 comments on commit 1a377a0

Please sign in to comment.