45
45
#include "gyrosensor.h"
46
46
#include "gpspositionsensor.h"
47
47
#include "gpstime.h"
48
+ #include "airspeedstate.h"
48
49
#include "homelocation.h"
49
50
#include "positionstate.h"
50
51
#include "systemalarms.h"
@@ -451,6 +452,25 @@ uint16_t build_GAM_message(struct hott_gam_message *msg)
451
452
msg -> current = scale_float2uword (current , 10 , 0 );
452
453
msg -> capacity = scale_float2uword (energy , 0.1f , 0 );
453
454
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
+
454
474
// pressure kPa to 0.1Bar
455
475
msg -> pressure = scale_float2uint8 (telestate -> Baro .Pressure , 0.1f , 0 );
456
476
@@ -492,9 +512,26 @@ uint16_t build_EAM_message(struct hott_eam_message *msg)
492
512
float voltage = (telestate -> Battery .Voltage > 0 ) ? telestate -> Battery .Voltage : 0 ;
493
513
float current = (telestate -> Battery .Current > 0 ) ? telestate -> Battery .Current : 0 ;
494
514
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 );
498
535
499
536
// temperatures
500
537
msg -> temperature1 = scale_float2uint8 (telestate -> Gyro .temperature , 1 , OFFSET_TEMPERATURE );
@@ -597,6 +634,9 @@ void update_telemetrydata()
597
634
if (GPSPositionSensorHandle () != NULL ) {
598
635
GPSPositionSensorGet (& telestate -> GPS );
599
636
}
637
+ if (AirspeedStateHandle () != NULL ) {
638
+ AirspeedStateGet (& telestate -> Airspeed );
639
+ }
600
640
if (GPSTimeHandle () != NULL ) {
601
641
GPSTimeGet (& telestate -> GPStime );
602
642
}
@@ -646,8 +686,9 @@ void update_telemetrydata()
646
686
// calculate altitude relative to start position
647
687
telestate -> altitude = - telestate -> Position .Down ;
648
688
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 ))) {
651
692
if (telestate -> min_altitude > telestate -> altitude ) {
652
693
telestate -> min_altitude = telestate -> altitude ;
653
694
}
@@ -774,10 +815,12 @@ void update_telemetrydata()
774
815
*/
775
816
uint8_t generate_warning ()
776
817
{
818
+ bool gps_ok = (telestate -> SysAlarms .Alarm .GPS == SYSTEMALARMS_ALARM_OK );
819
+
777
820
// set warning tone with hardcoded priority
778
821
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
781
824
}
782
825
if ((telestate -> Settings .Warning .NegDifference2 == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
783
826
(telestate -> Settings .Limit .NegDifference2 > telestate -> climbrate3s )) {
@@ -788,7 +831,7 @@ uint8_t generate_warning()
788
831
return HOTT_TONE_C ; // sink rate 1s
789
832
}
790
833
if ((telestate -> Settings .Warning .MaxDistance == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
791
- (telestate -> Settings .Limit .MaxDistance < telestate -> homedistance )) {
834
+ (telestate -> Settings .Limit .MaxDistance < telestate -> homedistance ) && gps_ok ) {
792
835
return HOTT_TONE_D ; // maximum distance
793
836
}
794
837
if ((telestate -> Settings .Warning .MinSensor1Temp == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
@@ -808,7 +851,7 @@ uint8_t generate_warning()
808
851
return HOTT_TONE_I ; // maximum temperature sensor 2
809
852
}
810
853
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 ) {
812
855
return HOTT_TONE_L ; // maximum speed
813
856
}
814
857
if ((telestate -> Settings .Warning .PosDifference2 == HOTTBRIDGESETTINGS_WARNING_ENABLED ) &&
0 commit comments