Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 137 additions & 16 deletions src/main/telemetry/hott.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
#include "telemetry/hott.h"
#include "telemetry/telemetry.h"

#ifdef USE_GPS
#include "fc/rc_modes.h"
#endif //USE_GPS

#if defined (USE_HOTT_TEXTMODE) && defined (USE_CMS)
#include "scheduler/scheduler.h"
#include "io/displayport_hott.h"
Expand All @@ -106,10 +110,10 @@ typedef enum {
HOTT_ENDING_TRANSMISSION
} hottState_e;

#define HOTT_MESSAGE_PREPARATION_FREQUENCY_5_HZ ((1000 * 1000) / 5)
#define HOTT_MESSAGE_PREPARATION_FREQUENCY_10_HZ ((1000 * 1000) / 10)
#define HOTT_RX_SCHEDULE 4000
#define HOTT_TX_SCHEDULE 5000
#define HOTT_TX_DELAY_US 2000
#define HOTT_TX_DELAY_US 600
#define MILLISECONDS_IN_A_SECOND 1000

static uint32_t rxSchedule = HOTT_RX_SCHEDULE;
Expand Down Expand Up @@ -227,27 +231,31 @@ void hottPrepareGPSResponse(HOTT_GPS_MSG_t *hottGPSMessage)
hottGPSMessage->gps_satelites = gpsSol.numSat;

// Report climb rate regardless of GPS fix
const int32_t climbrate = MAX(0, getEstimatedActualVelocity(Z) + 30000);
hottGPSMessage->climbrate_L = climbrate & 0xFF;
hottGPSMessage->climbrate_H = climbrate >> 8;

const int32_t climbrate3s = MAX(0, 3.0f * getEstimatedActualVelocity(Z) / 100 + 120);
hottGPSMessage->climbrate3s = climbrate3s & 0xFF;

const uint16_t encoded_climbrate = (uint16_t)(MAX(0, getEstimatedActualVelocity(Z) + 30000));
hottGPSMessage->climbrate_L = (uint8_t)(encoded_climbrate & 0x00FFU);
hottGPSMessage->climbrate_H = (uint8_t)(encoded_climbrate >> 8);
uint16_t encoded_climbrate3s = (uint16_t)(MAX(0, 3.0f * getEstimatedActualVelocity(Z) / 100 + 120));
if (encoded_climbrate3s > 255)
encoded_climbrate3s = HOTT_EAM_OFFSET_M3S;
hottGPSMessage->climbrate3s = (uint8_t)(encoded_climbrate3s);
#ifdef USE_GPS_FIX_ESTIMATION
if (!(STATE(GPS_FIX) || STATE(GPS_ESTIMATED_FIX)))
#else
if (!(STATE(GPS_FIX)))
#endif
{
hottGPSMessage->gps_fix_char = GPS_FIX_CHAR_NONE;
hottGPSMessage->free_char1 = 45; //"-";
hottGPSMessage->free_char2 = 45; //"-";
hottGPSMessage->free_char3 = 45; //"-";
return;
}

if (gpsSol.fixType == GPS_FIX_3D) {
hottGPSMessage->gps_fix_char = GPS_FIX_CHAR_3D;
} else {
hottGPSMessage->gps_fix_char = GPS_FIX_CHAR_2D;
hottGPSMessage->free_char3 = 50; //"2";
}

addGPSCoordinates(hottGPSMessage, gpsSol.llh.lat, gpsSol.llh.lon);
Expand All @@ -265,7 +273,119 @@ void hottPrepareGPSResponse(HOTT_GPS_MSG_t *hottGPSMessage)
hottGPSMessage->altitude_L = hottGpsAltitude & 0x00FF;
hottGPSMessage->altitude_H = hottGpsAltitude >> 8;

hottGPSMessage->home_direction = GPS_directionToHome;
hottGPSMessage->home_direction = GPS_directionToHome/2;

if (gpsSol.groundCourse < 0)
{
hottGPSMessage->flight_direction = gpsSol.groundCourse/20 + 180;
}
else
{
hottGPSMessage->flight_direction = gpsSol.groundCourse/20; //GPS_direction; //gpsSol.groundCourse
}

static uint8_t hrstSent = 0;
hottGPSMessage->free_char1 = 79; //"O";
hottGPSMessage->free_char2 = 75; //"K";
hottGPSMessage->free_char3 = 51; //"3"; 32 " "
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
if (ARMING_FLAG(ARMED))
{
hottGPSMessage->free_char1 = 65; //"A";
hottGPSMessage->free_char2 = 67; //"C";
hottGPSMessage->free_char3 = 82; //"R";
#ifdef USE_FW_AUTOLAND
if (FLIGHT_MODE(NAV_FW_AUTOLAND))
{
hottGPSMessage->free_char1 = 76; //"L";
hottGPSMessage->free_char2 = 78; //"N";
hottGPSMessage->free_char3 = 68; //"D";
} else
#endif
if (FLIGHT_MODE(FAILSAFE_MODE)) {
hottGPSMessage->free_char1 = 70; //"F";
hottGPSMessage->free_char2 = 83; //"S";
hottGPSMessage->free_char3 = 33; //"!";
} else if (IS_RC_MODE_ACTIVE(BOXHOMERESET) && hrstSent < 4 && !FLIGHT_MODE(NAV_RTH_MODE) && !FLIGHT_MODE(NAV_WP_MODE)) {
hottGPSMessage->free_char1 = 72; //"H";
hottGPSMessage->free_char2 = 82; //"R";
hottGPSMessage->free_char3 = 83; //"S";
hrstSent++;
} else if (FLIGHT_MODE(MANUAL_MODE)) {
hottGPSMessage->free_char1 = 77; //"M";
hottGPSMessage->free_char2 = 65; //"A";
hottGPSMessage->free_char3 = 78; //"N";
#ifdef USE_GEOZONE
} else if (FLIGHT_MODE(NAV_SEND_TO) && !FLIGHT_MODE(NAV_WP_MODE)) {
hottGPSMessage->free_char1 = 71; //"G";
hottGPSMessage->free_char2 = 69; //"E";
hottGPSMessage->free_char3 = 79; //"O";
#endif
} else if (FLIGHT_MODE(TURTLE_MODE)) {
hottGPSMessage->free_char1 = 84; //"T";
hottGPSMessage->free_char2 = 82; //"R";
hottGPSMessage->free_char3 = 84; //"T";
} else if (FLIGHT_MODE(NAV_RTH_MODE)) {
if (isWaypointMissionRTHActive())
{
hottGPSMessage->free_char1 = 87; //"W";
hottGPSMessage->free_char2 = 82; //"R";
hottGPSMessage->free_char3 = 72; //"H";
}
else
{
hottGPSMessage->free_char1 = 82; //"R";
hottGPSMessage->free_char2 = 84; //"T";
hottGPSMessage->free_char3 = 72; //"H";
};
} else if (FLIGHT_MODE(NAV_POSHOLD_MODE) && STATE(AIRPLANE)) {
hottGPSMessage->free_char1 = 76; //"L";
hottGPSMessage->free_char2 = 79; //"O";
hottGPSMessage->free_char3 = 84; //"T";
} else if (FLIGHT_MODE(NAV_POSHOLD_MODE)) {
hottGPSMessage->free_char1 = 72; //"H";
hottGPSMessage->free_char2 = 76; //"L";
hottGPSMessage->free_char3 = 68; //"D";
} else if (FLIGHT_MODE(NAV_COURSE_HOLD_MODE) && FLIGHT_MODE(NAV_ALTHOLD_MODE)) {
hottGPSMessage->free_char1 = 67; //"C";
hottGPSMessage->free_char2 = 82; //"R";
hottGPSMessage->free_char3 = 83; //"S";
} else if (FLIGHT_MODE(NAV_COURSE_HOLD_MODE)) {
hottGPSMessage->free_char1 = 67; //"C";
hottGPSMessage->free_char2 = 82; //"R";
hottGPSMessage->free_char3 = 72; //"H";
} else if (FLIGHT_MODE(NAV_WP_MODE)) {
hottGPSMessage->free_char1 = 87; //"W";
hottGPSMessage->free_char2 = 80; //"P";
hottGPSMessage->free_char3 = 32; //" ";
} else if (FLIGHT_MODE(NAV_ALTHOLD_MODE) && navigationRequiresAngleMode()) {
hottGPSMessage->free_char1 = 65; //"A";
hottGPSMessage->free_char2 = 72; //"H";
hottGPSMessage->free_char3 = 32; //" ";
} else if (FLIGHT_MODE(ANGLE_MODE)) {
hottGPSMessage->free_char1 = 65; //"A";
hottGPSMessage->free_char2 = 78; //"N";
hottGPSMessage->free_char3 = 71; //"G";
} else if (FLIGHT_MODE(HORIZON_MODE)) {
hottGPSMessage->free_char1 = 72; //"H";
hottGPSMessage->free_char2 = 79; //"O";
hottGPSMessage->free_char3 = 82; //"R";
} else if (FLIGHT_MODE(ANGLEHOLD_MODE)) {
hottGPSMessage->free_char1 = 65; //"A";
hottGPSMessage->free_char2 = 78; //"N";
hottGPSMessage->free_char3 = 72; //"H";
}
} else if (navConfig()->general.flags.extra_arming_safety && (!STATE(GPS_FIX) || !STATE(GPS_FIX_HOME))) {
hottGPSMessage->free_char1 = 87; //"W";
hottGPSMessage->free_char2 = 65; //"A";
hottGPSMessage->free_char3 = 73; //"I"; // Waiting for GPS lock
} else if (isArmingDisabled()) {
hottGPSMessage->free_char1 = 69; //"E";
hottGPSMessage->free_char2 = 82; //"R";
hottGPSMessage->free_char3 = 82; //"R";
hrstSent = 0;
}
if (!IS_RC_MODE_ACTIVE(BOXHOMERESET) && hrstSent > 0)
hrstSent = 0;
}
#endif

Expand Down Expand Up @@ -317,12 +437,13 @@ static inline void hottEAMUpdateAltitudeAndClimbrate(HOTT_EAM_MSG_t *hottEAMMess
hottEAMMessage->altitude_L = alt & 0xFF;
hottEAMMessage->altitude_H = alt >> 8;

const int32_t climbrate = MAX(0, (int32_t)(getEstimatedActualVelocity(Z) + 30000));
hottEAMMessage->climbrate_L = climbrate & 0xFF;
hottEAMMessage->climbrate_H = climbrate >> 8;

const int32_t climbrate3s = MAX(0, (int32_t)(3.0f * getEstimatedActualVelocity(Z) / 100 + 120));
hottEAMMessage->climbrate3s = climbrate3s & 0xFF;
const uint16_t encoded_climbrate = (uint16_t)(MAX(0, getEstimatedActualVelocity(Z) + 30000));
hottEAMMessage->climbrate_L = (uint8_t)(encoded_climbrate & 0x00FFU);
hottEAMMessage->climbrate_H = (uint8_t)(encoded_climbrate >> 8);
uint16_t encoded_climbrate3s = (uint16_t)(MAX(0, 3.0f * getEstimatedActualVelocity(Z) / 100 + 120));
if (encoded_climbrate3s > 255)
encoded_climbrate3s = HOTT_EAM_OFFSET_M3S;
hottEAMMessage->climbrate3s = (uint8_t)(encoded_climbrate3s);
}

void hottPrepareEAMResponse(HOTT_EAM_MSG_t *hottEAMMessage)
Expand Down