37 #if defined(PIOS_INCLUDE_HOTT)
44 #define STACK_SIZE_BYTES 700
45 #define TASK_PRIORITY PIOS_THREAD_PRIO_NORMAL
48 static struct pios_thread *uavoHoTTBridgeTaskHandle;
49 static uint32_t hott_port;
54 static void uavoHoTTBridgeTask(
void *parameters);
61 static uint8_t calc_checksum(uint8_t *
data, uint16_t size);
62 static uint8_t generate_warning();
63 static void update_telemetrydata();
74 static int32_t uavoHoTTBridgeStart(
void)
79 uavoHoTTBridgeTask,
"uavoHoTTBridge",
82 uavoHoTTBridgeTaskHandle);
93 static int32_t uavoHoTTBridgeInitialize(
void)
101 if (HoTTSettingsInitialize() == -1) {
109 if (telestate == NULL) {
124 static
void uavoHoTTBridgeTask(
void *parameters) {
125 uint8_t rx_buffer[2];
127 uint16_t message_size;
130 memset(telestate, 0,
sizeof(*telestate));
145 rx_buffer[1]= rx_buffer[0];
157 switch (rx_buffer[0]) {
179 switch (rx_buffer[0]) {
194 if (message_size > 0) {
200 for (
int i = 0;
i < message_size;
i++) {
222 update_telemetrydata();
224 if (telestate->
Settings.Sensor[HOTTSETTINGS_SENSOR_VARIO] == HOTTSETTINGS_SENSOR_DISABLED)
228 memset(msg, 0,
sizeof(*msg));
234 msg->
warning = generate_warning();
270 msg->
checksum = calc_checksum((uint8_t *)msg,
sizeof(*msg));
275 update_telemetrydata();
277 if (telestate->
Settings.Sensor[HOTTSETTINGS_SENSOR_GPS] == HOTTSETTINGS_SENSOR_DISABLED)
281 memset(msg, 0,
sizeof(*msg));
287 msg->
warning = generate_warning();
311 msg->
ascii5 = (telestate->
Home.Set ?
'H' :
'-');
320 switch (telestate->
GPS.Status) {
321 case GPSPOSITION_STATUS_FIX2D:
324 case GPSPOSITION_STATUS_FIX3D:
325 case GPSPOSITION_STATUS_DIFF3D:
331 switch (telestate->
SysAlarms.Alarm[SYSTEMALARMS_ALARM_GPS]) {
332 case SYSTEMALARMS_ALARM_UNINITIALISED:
337 case SYSTEMALARMS_ALARM_OK:
340 case SYSTEMALARMS_ALARM_WARNING:
343 case SYSTEMALARMS_ALARM_ERROR:
344 case SYSTEMALARMS_ALARM_CRITICAL:
363 msg->
msl = scale_float2uword(telestate->
GPS.Altitude, 1, 0);
368 msg->
checksum = calc_checksum((uint8_t *)msg,
sizeof(*msg));
373 update_telemetrydata();
375 if (telestate->
Settings.Sensor[HOTTSETTINGS_SENSOR_GAM] == HOTTSETTINGS_SENSOR_DISABLED)
379 memset(msg, 0,
sizeof(*msg));
385 msg->
warning = generate_warning();
413 float energy = (telestate->
Battery.ConsumedEnergy > 0) ? telestate->
Battery.ConsumedEnergy : 0;
414 msg->
voltage = scale_float2uword(voltage, 10, 0);
416 msg->
capacity = scale_float2uword(energy, 0.1, 0);
419 msg->
pressure = scale_float2uint8(telestate->
Baro.Pressure, 0.1, 0);
421 msg->
checksum = calc_checksum((uint8_t *)msg,
sizeof(*msg));
426 update_telemetrydata();
428 if (telestate->
Settings.Sensor[HOTTSETTINGS_SENSOR_EAM] == HOTTSETTINGS_SENSOR_DISABLED)
432 memset(msg, 0,
sizeof(*msg));
438 msg->
warning = generate_warning();
454 float voltage = (telestate->
Battery.Voltage > 0) ? telestate->
Battery.Voltage : 0;
456 float energy = (telestate->
Battery.ConsumedEnergy > 0) ? telestate->
Battery.ConsumedEnergy : 0;
457 msg->
voltage = scale_float2uword(voltage, 10, 0);
459 msg->
capacity = scale_float2uword(energy, 0.1, 0);
473 float flighttime = (telestate->
Battery.EstimatedFlightTime <= 5999) ? telestate->
Battery.EstimatedFlightTime : 5999;
477 msg->
checksum = calc_checksum((uint8_t *)msg,
sizeof(*msg));
482 update_telemetrydata();
484 if (telestate->
Settings.Sensor[HOTTSETTINGS_SENSOR_ESC] == HOTTSETTINGS_SENSOR_DISABLED)
488 memset(msg, 0,
sizeof(*msg));
498 float voltage = (telestate->
Battery.Voltage > 0) ? telestate->
Battery.Voltage : 0;
500 float max_current = (telestate->
Battery.PeakCurrent > 0) ? telestate->
Battery.PeakCurrent : 0;
501 float energy = (telestate->
Battery.ConsumedEnergy > 0) ? telestate->
Battery.ConsumedEnergy : 0;
504 msg->
max_current = scale_float2uword(max_current, 10, 0);
513 msg->
checksum = calc_checksum((uint8_t *)msg,
sizeof(*msg));
518 update_telemetrydata();
521 memset(msg, 0,
sizeof(*msg));
528 msg->
checksum = calc_checksum((uint8_t *)msg,
sizeof(*msg));
538 void update_telemetrydata () {
540 if (HoTTSettingsHandle() != NULL)
541 HoTTSettingsGet(&telestate->
Settings);
542 if (AttitudeActualHandle() != NULL)
543 AttitudeActualGet(&telestate->
Attitude);
544 if (BaroAltitudeHandle() != NULL)
545 BaroAltitudeGet(&telestate->
Baro);
546 if (FlightBatteryStateHandle() != NULL)
547 FlightBatteryStateGet(&telestate->
Battery);
548 if (FlightStatusHandle() != NULL)
550 if (GPSPositionHandle() != NULL)
551 GPSPositionGet(&telestate->
GPS);
552 if (GPSTimeHandle() != NULL)
553 GPSTimeGet(&telestate->
GPStime);
554 if (GyrosHandle() != NULL)
555 GyrosGet(&telestate->
Gyro);
556 if (HomeLocationHandle() != NULL)
557 HomeLocationGet(&telestate->
Home);
558 if (PositionActualHandle() != NULL)
559 PositionActualGet(&telestate->
Position);
560 if (SystemAlarmsHandle() != NULL)
562 if (VelocityActualHandle() != NULL)
563 VelocityActualGet(&telestate->
Velocity);
578 n += climbratesize - 1;
586 if ((telestate->
FlightStatus.Armed == FLIGHTSTATUS_ARMED_ARMING) || ((telestate->
last_armed != FLIGHTSTATUS_ARMED_ARMED) && (telestate->
FlightStatus.Armed == FLIGHTSTATUS_ARMED_ARMED))) {
596 if (telestate->
FlightStatus.Armed == FLIGHTSTATUS_ARMED_ARMED) {
610 const char *txt_unknown =
"unknown";
611 const char *txt_manual =
"Manual";
612 const char *txt_acro =
"Acro";
613 const char *txt_leveling =
"Leveling";
614 const char *txt_virtualbar =
"Virtualbar";
615 const char *txt_stabilized1 =
"Stabilized1";
616 const char *txt_stabilized2 =
"Stabilized2";
617 const char *txt_stabilized3 =
"Stabilized3";
618 const char *txt_autotune =
"Autotune";
619 const char *txt_altitudehold =
"AltitudeHold";
620 const char *txt_positionhold =
"PositionHold";
621 const char *txt_returntohome =
"ReturnToHome";
622 const char *txt_pathplanner =
"PathPlanner";
623 const char *txt_tabletcontrol =
"TabletCtrl";
624 const char *txt_failsafe =
"Failsafe";
625 const char *txt_disarmed =
"Disarmed";
626 const char *txt_arming =
"Arming";
627 const char *txt_armed =
"Armed";
629 const char *txt_flightmode;
631 case FLIGHTSTATUS_FLIGHTMODE_MANUAL:
632 txt_flightmode = txt_manual;
634 case FLIGHTSTATUS_FLIGHTMODE_ACRO:
635 txt_flightmode = txt_acro;
637 case FLIGHTSTATUS_FLIGHTMODE_LEVELING:
638 txt_flightmode = txt_leveling;
640 case FLIGHTSTATUS_FLIGHTMODE_VIRTUALBAR:
641 txt_flightmode = txt_virtualbar;
643 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED1:
644 txt_flightmode = txt_stabilized1;
646 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED2:
647 txt_flightmode = txt_stabilized2;
649 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED3:
650 txt_flightmode = txt_stabilized3;
652 case FLIGHTSTATUS_FLIGHTMODE_AUTOTUNE:
653 txt_flightmode = txt_autotune;
655 case FLIGHTSTATUS_FLIGHTMODE_ALTITUDEHOLD:
656 txt_flightmode = txt_altitudehold;
658 case FLIGHTSTATUS_FLIGHTMODE_POSITIONHOLD:
659 txt_flightmode = txt_positionhold;
661 case FLIGHTSTATUS_FLIGHTMODE_RETURNTOHOME:
662 txt_flightmode = txt_returntohome;
664 case FLIGHTSTATUS_FLIGHTMODE_PATHPLANNER:
665 txt_flightmode = txt_pathplanner;
667 case FLIGHTSTATUS_FLIGHTMODE_TABLETCONTROL:
668 txt_flightmode = txt_tabletcontrol;
670 case FLIGHTSTATUS_FLIGHTMODE_FAILSAFE:
671 txt_flightmode = txt_failsafe;
674 txt_flightmode = txt_unknown;
677 const char *txt_armstate;
679 case FLIGHTSTATUS_ARMED_DISARMED:
680 txt_armstate = txt_disarmed;
682 case FLIGHTSTATUS_ARMED_ARMING:
683 txt_armstate = txt_arming;
685 case FLIGHTSTATUS_ARMED_ARMED:
686 txt_armstate = txt_armed;
689 txt_armstate = txt_unknown;
698 uint8_t generate_warning() {
700 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MINSPEED] == HOTTSETTINGS_WARNING_ENABLED) &&
701 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MINSPEED] > telestate->
GPS.Groundspeed *
MS_TO_KMH))
704 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_NEGDIFFERENCE2] == HOTTSETTINGS_WARNING_ENABLED) &&
708 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_NEGDIFFERENCE1] == HOTTSETTINGS_WARNING_ENABLED) &&
712 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MAXDISTANCE] == HOTTSETTINGS_WARNING_ENABLED) &&
716 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MINSENSOR1TEMP] == HOTTSETTINGS_WARNING_ENABLED) &&
717 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MINSENSOR1TEMP] > telestate->
Gyro.temperature))
720 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MINSENSOR2TEMP] == HOTTSETTINGS_WARNING_ENABLED) &&
721 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MINSENSOR2TEMP] > telestate->
Baro.Temperature))
724 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MAXSENSOR1TEMP] == HOTTSETTINGS_WARNING_ENABLED) &&
725 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MAXSENSOR1TEMP] < telestate->
Gyro.temperature))
728 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MAXSENSOR2TEMP] == HOTTSETTINGS_WARNING_ENABLED) &&
729 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MAXSENSOR2TEMP] < telestate->
Baro.Temperature))
732 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MAXSPEED] == HOTTSETTINGS_WARNING_ENABLED) &&
733 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MAXSPEED] < telestate->
GPS.Groundspeed *
MS_TO_KMH))
736 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_POSDIFFERENCE2] == HOTTSETTINGS_WARNING_ENABLED) &&
740 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_POSDIFFERENCE1] == HOTTSETTINGS_WARNING_ENABLED) &&
744 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MINHEIGHT] == HOTTSETTINGS_WARNING_ENABLED) &&
745 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MINHEIGHT] > telestate->
altitude))
748 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MINPOWERVOLTAGE] == HOTTSETTINGS_WARNING_ENABLED) &&
749 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MINPOWERVOLTAGE] > telestate->
Battery.Voltage))
752 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MAXUSEDCAPACITY] == HOTTSETTINGS_WARNING_ENABLED) &&
753 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MAXUSEDCAPACITY] < telestate->
Battery.ConsumedEnergy))
756 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MAXCURRENT] == HOTTSETTINGS_WARNING_ENABLED) &&
757 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MAXCURRENT] < telestate->
Battery.Current))
760 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MAXPOWERVOLTAGE] == HOTTSETTINGS_WARNING_ENABLED) &&
761 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MAXPOWERVOLTAGE] < telestate->
Battery.Voltage))
764 if ((telestate->
Settings.Warning[HOTTSETTINGS_WARNING_MAXHEIGHT] == HOTTSETTINGS_WARNING_ENABLED) &&
765 (telestate->
Settings.Limit[HOTTSETTINGS_LIMIT_MAXHEIGHT] < telestate->
altitude))
769 if (telestate->
Settings.Warning[HOTTSETTINGS_WARNING_ALTITUDEBEEP] == HOTTSETTINGS_WARNING_ENABLED) {
774 if (((last < 20) && (actual >= 20)) || ((last > 20) && (actual <= 20)))
776 if (((last < 40) && (actual >= 40)) || ((last > 40) && (actual <= 40)))
778 if (((last < 60) && (actual >= 60)) || ((last > 60) && (actual <= 60)))
780 if (((last < 80) && (actual >= 80)) || ((last > 80) && (actual <= 80)))
782 if (((last < 100) && (actual >= 100)) || ((last > 100) && (actual <= 100)))
784 if (((last < 200) && (actual >= 200)) || ((last > 200) && (actual <= 200)))
786 if (((last < 400) && (actual >= 400)) || ((last > 400) && (actual <= 400)))
788 if (((last < 600) && (actual >= 600)) || ((last > 600) && (actual <= 600)))
790 if (((last < 800) && (actual >= 800)) || ((last > 800) && (actual <= 800)))
792 if (((last < 1000) && (actual >= 1000)) || ((last > 1000) && (actual <= 1000)))
803 uint8_t calc_checksum(uint8_t *
data, uint16_t size) {
805 for(
int i = 0;
i < size;
i++)
814 uint16_t temp = (uint16_t)roundf(value * scale + offset);
816 result = (uint8_t)temp & 0xff;
823 int8_t scale_float2int8(
float value,
float scale,
float offset) {
824 int8_t result = (int8_t)roundf(value * scale + offset);
831 uword_t scale_float2uword(
float value,
float scale,
float offset) {
832 uint16_t temp = (uint16_t)roundf(value * scale + offset);
834 result.
l = (uint8_t)temp & 0xff;
835 result.
h = (uint8_t)(temp >> 8) & 0xff;
845 uint32_t absvalue = abs(value);
846 uint16_t degrees = (absvalue / 10000000);
847 uint32_t seconds = (absvalue - degrees * 10000000) * 6;
848 uint16_t minutes = seconds / 1000000;
850 seconds = seconds / 100;
851 uint16_t degmin = degrees * 100 + minutes;
853 *dir = (value < 0) ? 1 : 0;
854 temp.
l = (uint8_t)degmin & 0xff;
855 temp.
h = (uint8_t)(degmin >> 8) & 0xff;
857 temp.
l = (uint8_t)seconds & 0xff;
858 temp.
h = (uint8_t)(seconds >> 8) & 0xff;
#define OFFSET_CLIMBRATE3S
uint32_t PIOS_Thread_Systime(void)
#define VARIO_INVERT_CR3S
#define VARIO_INVERT_CR10S
#define GAM_INVERT2_CURRENT
Main PiOS header to include all the compiled in PiOS options.
#define VARIO_INVERT_CR1S
bool PIOS_Modules_IsEnabled(enum pios_modules module)
PositionActualData Position
static float scale(float val, float inMin, float inMax, float outMin, float outMax)
sends telemery data on HoTT request
#define OFFSET_TEMPERATURE
void * PIOS_malloc(size_t size)
SystemAlarmsData SysAlarms
uint8_t max_temperatureESC
uint8_t data[XFER_BYTES_PER_PACKET]
HoTTSettingsData Settings
char statusline[statussize]
#define MODULE_INITCALL(ifn, sfn)
uint16_t PIOS_COM_ReceiveBuffer(uintptr_t com_id, uint8_t *buf, uint16_t buf_len, uint32_t timeout_ms)
#define HOTT_VARIO_TEXT_ID
#define EAM_INVERT_VOLTAGE
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
#define EAM_INVERT_CURRENT
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
FlightStatusData FlightStatus
#define EAM_INVERT_CAPACITY
uint8_t climbrate_pointer
AttitudeActualData Attitude
void PIOS_Thread_Sleep_Until(uint32_t *previous_ms, uint32_t increment_ms)
int32_t PIOS_COM_SendCharNonBlocking(uintptr_t com_id, char c)
int16_t climbratebuffer[climbratesize]
#define HOTT_MAX_MESSAGE_LENGTH
int snprintf(char *buf, size_t count, const char *format,...)
FlightBatteryStateData Battery
static uint32_t lastSysTime
uint8_t max_temperatureMOT
int32_t PIOS_COM_ChangeBaud(uintptr_t com_id, uint32_t baud)
VelocityActualData Velocity
#define GAM_INVERT2_VOLTAGE