4545#include "gyrosensor.h"
4646#include "gpspositionsensor.h"
4747#include "gpstime.h"
48+ #include "airspeedstate.h"
4849#include "homelocation.h"
4950#include "positionstate.h"
5051#include "systemalarms.h"
@@ -451,6 +452,25 @@ uint16_t build_GAM_message(struct hott_gam_message *msg)
451452 msg -> current = scale_float2uword (current , 10 , 0 );
452453 msg -> capacity = scale_float2uword (energy , 0.1f , 0 );
453454
455+ // simulate individual cell voltage
456+ uint8_t cell_voltage = (telestate -> Battery .Voltage > 0 ) ? scale_float2uint8 (telestate -> Battery .Voltage / telestate -> Battery .NbCells , 50 , 0 ) : 0 ;
457+ msg -> cell1 = (telestate -> Battery .NbCells >= 1 ) ? cell_voltage : 0 ;
458+ msg -> cell2 = (telestate -> Battery .NbCells >= 2 ) ? cell_voltage : 0 ;
459+ msg -> cell3 = (telestate -> Battery .NbCells >= 3 ) ? cell_voltage : 0 ;
460+ msg -> cell4 = (telestate -> Battery .NbCells >= 4 ) ? cell_voltage : 0 ;
461+ msg -> cell5 = (telestate -> Battery .NbCells >= 5 ) ? cell_voltage : 0 ;
462+ msg -> cell6 = (telestate -> Battery .NbCells >= 6 ) ? cell_voltage : 0 ;
463+
464+ msg -> min_cell_volt = cell_voltage ;
465+ msg -> min_cell_volt_num = telestate -> Battery .NbCells ;
466+
467+ // apply main voltage to batt1 voltage
468+ msg -> batt1_voltage = msg -> voltage ;
469+
470+ // AirSpeed
471+ float airspeed = (telestate -> Airspeed .TrueAirspeed > 0 ) ? telestate -> Airspeed .TrueAirspeed : 0 ;
472+ msg -> speed = scale_float2uword (airspeed , MS_TO_KMH , 0 );
473+
454474 // pressure kPa to 0.1Bar
455475 msg -> pressure = scale_float2uint8 (telestate -> Baro .Pressure , 0.1f , 0 );
456476
@@ -492,9 +512,26 @@ uint16_t build_EAM_message(struct hott_eam_message *msg)
492512 float voltage = (telestate -> Battery .Voltage > 0 ) ? telestate -> Battery .Voltage : 0 ;
493513 float current = (telestate -> Battery .Current > 0 ) ? telestate -> Battery .Current : 0 ;
494514 float energy = (telestate -> Battery .ConsumedEnergy > 0 ) ? telestate -> Battery .ConsumedEnergy : 0 ;
495- msg -> voltage = scale_float2uword (voltage , 10 , 0 );
496- msg -> current = scale_float2uword (current , 10 , 0 );
497- msg -> capacity = scale_float2uword (energy , 0.1f , 0 );
515+ msg -> voltage = scale_float2uword (voltage , 10 , 0 );
516+ msg -> current = scale_float2uword (current , 10 , 0 );
517+ msg -> capacity = scale_float2uword (energy , 0.1f , 0 );
518+
519+ // simulate individual cell voltage
520+ uint8_t cell_voltage = (telestate -> Battery .Voltage > 0 ) ? scale_float2uint8 (telestate -> Battery .Voltage / telestate -> Battery .NbCells , 50 , 0 ) : 0 ;
521+ msg -> cell1_H = (telestate -> Battery .NbCells >= 1 ) ? cell_voltage : 0 ;
522+ msg -> cell2_H = (telestate -> Battery .NbCells >= 2 ) ? cell_voltage : 0 ;
523+ msg -> cell3_H = (telestate -> Battery .NbCells >= 3 ) ? cell_voltage : 0 ;
524+ msg -> cell4_H = (telestate -> Battery .NbCells >= 4 ) ? cell_voltage : 0 ;
525+ msg -> cell5_H = (telestate -> Battery .NbCells >= 5 ) ? cell_voltage : 0 ;
526+ msg -> cell6_H = (telestate -> Battery .NbCells >= 6 ) ? cell_voltage : 0 ;
527+ msg -> cell7_H = (telestate -> Battery .NbCells >= 7 ) ? cell_voltage : 0 ;
528+
529+ // apply main voltage to batt1 voltage
530+ msg -> batt1_voltage = msg -> voltage ;
531+
532+ // AirSpeed
533+ float airspeed = (telestate -> Airspeed .TrueAirspeed > 0 ) ? telestate -> Airspeed .TrueAirspeed : 0 ;
534+ msg -> speed = scale_float2uword (airspeed , MS_TO_KMH , 0 );
498535
499536 // temperatures
500537 msg -> temperature1 = scale_float2uint8 (telestate -> Gyro .temperature , 1 , OFFSET_TEMPERATURE );
@@ -597,6 +634,9 @@ void update_telemetrydata()
597634 if (GPSPositionSensorHandle () != NULL ) {
598635 GPSPositionSensorGet (& telestate -> GPS );
599636 }
637+ if (AirspeedStateHandle () != NULL ) {
638+ AirspeedStateGet (& telestate -> Airspeed );
639+ }
600640 if (GPSTimeHandle () != NULL ) {
601641 GPSTimeGet (& telestate -> GPStime );
602642 }
@@ -646,8 +686,9 @@ void update_telemetrydata()
646686 // calculate altitude relative to start position
647687 telestate -> altitude = - telestate -> Position .Down ;
648688
649- // check and set min/max values when armed.
650- if (telestate -> FlightStatus .Armed == FLIGHTSTATUS_ARMED_ARMED ) {
689+ // check and set min/max values when armed
690+ // and without receiver input for standalone board used as sensor
691+ if ((telestate -> FlightStatus .Armed == FLIGHTSTATUS_ARMED_ARMED ) || ((telestate -> SysAlarms .Alarm .Attitude == SYSTEMALARMS_ALARM_OK ) && (telestate -> SysAlarms .Alarm .Receiver != SYSTEMALARMS_ALARM_OK ))) {
651692 if (telestate -> min_altitude > telestate -> altitude ) {
652693 telestate -> min_altitude = telestate -> altitude ;
653694 }
@@ -774,10 +815,12 @@ void update_telemetrydata()
774815 */
775816uint8_t generate_warning ()
776817{
818+ bool gps_ok = (telestate -> SysAlarms .Alarm .GPS == SYSTEMALARMS_ALARM_OK );
819+
777820 // set warning tone with hardcoded priority
778821 if ((telestate -> Settings .Warning .MinSpeed == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
779- (telestate -> Settings .Limit .MinSpeed > telestate -> GPS .Groundspeed * MS_TO_KMH )) {
780- return HOTT_TONE_A ; // maximum speed
822+ (telestate -> Settings .Limit .MinSpeed > telestate -> GPS .Groundspeed * MS_TO_KMH ) && gps_ok ) {
823+ return HOTT_TONE_A ; // minimum speed
781824 }
782825 if ((telestate -> Settings .Warning .NegDifference2 == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
783826 (telestate -> Settings .Limit .NegDifference2 > telestate -> climbrate3s )) {
@@ -788,7 +831,7 @@ uint8_t generate_warning()
788831 return HOTT_TONE_C ; // sink rate 1s
789832 }
790833 if ((telestate -> Settings .Warning .MaxDistance == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
791- (telestate -> Settings .Limit .MaxDistance < telestate -> homedistance )) {
834+ (telestate -> Settings .Limit .MaxDistance < telestate -> homedistance ) && gps_ok ) {
792835 return HOTT_TONE_D ; // maximum distance
793836 }
794837 if ((telestate -> Settings .Warning .MinSensor1Temp == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
@@ -808,7 +851,7 @@ uint8_t generate_warning()
808851 return HOTT_TONE_I ; // maximum temperature sensor 2
809852 }
810853 if ((telestate -> Settings .Warning .MaxSpeed == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
811- (telestate -> Settings .Limit .MaxSpeed < telestate -> GPS .Groundspeed * MS_TO_KMH )) {
854+ (telestate -> Settings .Limit .MaxSpeed < telestate -> GPS .Groundspeed * MS_TO_KMH ) && gps_ok ) {
812855 return HOTT_TONE_L ; // maximum speed
813856 }
814857 if ((telestate -> Settings .Warning .PosDifference2 == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
0 commit comments