38 #include "modulesettings.h"
40 #include "physical_constants.h"
41 #include "attitudeactual.h"
42 #include "baroaltitude.h"
43 #include "positionactual.h"
44 #include "velocityactual.h"
45 #include "flightbatterystate.h"
46 #include "flightbatterysettings.h"
48 #include "homelocation.h"
50 #include "flightstatus.h"
51 #include "airspeedactual.h"
53 #include "velocityactual.h"
54 #include "attitudeactual.h"
67 if (test_presence_only)
72 PositionActualDownGet(&down);
73 int32_t
alt = (int32_t)(-down * 100.0
f);
74 *value = (uint32_t) alt;
87 if (AttitudeActualHandle() == NULL)
90 if (test_presence_only)
93 AttitudeActualData attitude;
94 AttitudeActualGet(&attitude);
95 float hdg = (attitude.Yaw >= 0) ? attitude.Yaw : (attitude.Yaw + 360.0f);
96 *value = (uint32_t)(hdg * 100.0
f);
113 if (test_presence_only)
117 VelocityActualDownGet(&down);
118 int32_t vspeed = (int32_t)(-down * 100.0
f);
119 *value = (uint32_t) vspeed;
135 if (test_presence_only)
139 FlightBatteryStateCurrentGet(¤t);
140 int32_t current_frsky = (int32_t)(current * 10.0
f);
141 *value = (uint32_t) current_frsky;
155 if (FlightBatteryStateHandle() == NULL)
158 uint8_t cellCount = 0;
159 FlightBatteryStateDetectedCellCountGet(&cellCount);
165 if (test_presence_only)
169 FlightBatteryStateVoltageGet(&voltage);
171 uint32_t cell_voltage = (uint32_t)((voltage * 500.0
f) / frsky->
batt_cell_count);
172 *value = ((cell_voltage & 0xfff) << 8) | ((arg * 2) & 0x0f) | ((frsky->
batt_cell_count << 4) & 0xf0);
174 *value |= ((cell_voltage & 0xfff) << 20);
194 if (GPSPositionHandle() == NULL)
197 if (test_presence_only)
200 uint8_t hl_set = HOMELOCATION_SET_FALSE;
202 if (HomeLocationHandle())
203 HomeLocationSetGet(&hl_set);
207 case GPSPOSITION_STATUS_NOGPS:
210 case GPSPOSITION_STATUS_NOFIX:
213 case GPSPOSITION_STATUS_FIX2D:
216 case GPSPOSITION_STATUS_FIX3D:
217 case GPSPOSITION_STATUS_DIFF3D:
218 if (hl_set == HOMELOCATION_SET_TRUE)
227 *value = (uint32_t)t1;
243 if (GPSPositionHandle() == NULL)
246 if (test_presence_only)
249 uint32_t hdop = (uint32_t)(frsky->
gps_position.HDOP * 100.0f);
254 uint32_t vdop = (uint32_t)(frsky->
gps_position.VDOP * 100.0f);
259 *value = 256 * vdop + hdop;
275 if (test_presence_only)
279 float consumed_mahs = 0;
280 FlightBatteryStateConsumedEnergyGet(&consumed_mahs);
282 float fuel = (uint32_t)(100.0
f * (1.0
f - consumed_mahs / capacity));
284 *value = (uint32_t) fuel;
298 uint8_t accelDataSettings;
299 ModuleSettingsFrskyAccelDataGet(&accelDataSettings);
302 switch(accelDataSettings) {
303 case MODULESETTINGS_FRSKYACCELDATA_ACCELS: {
304 if (AccelsHandle() == NULL)
306 else if (test_presence_only)
326 case MODULESETTINGS_FRSKYACCELDATA_NEDACCELS: {
327 if (NedAccelHandle() == NULL)
329 else if (test_presence_only)
334 NedAccelNorthGet(&acc);
337 NedAccelEastGet(&acc);
340 NedAccelDownGet(&acc);
349 case MODULESETTINGS_FRSKYACCELDATA_NEDVELOCITY: {
350 if (VelocityActualHandle() == NULL)
352 else if (test_presence_only)
357 VelocityActualNorthGet(&acc);
360 VelocityActualEastGet(&acc);
363 VelocityActualDownGet(&acc);
372 if (AttitudeActualHandle() == NULL)
374 else if (test_presence_only)
379 AttitudeActualRollGet(&acc);
382 AttitudeActualPitchGet(&acc);
385 AttitudeActualYawGet(&acc);
394 int32_t frsky_acc = (int32_t) acc;
395 *value = (uint32_t) frsky_acc;
409 if (GPSPositionHandle() == NULL)
411 if (frsky->
gps_position.Status == GPSPOSITION_STATUS_NOFIX
412 || frsky->
gps_position.Status == GPSPOSITION_STATUS_NOGPS)
414 if (test_presence_only)
417 uint32_t frsky_coord = 0;
425 frsky_coord = 1 << 30;
430 frsky_coord = 2 << 30;
432 frsky_coord = 3 << 30;
435 frsky_coord |= (((uint64_t)coord * 6ull) / 100);
437 *value = frsky_coord;
450 if (GPSPositionHandle() == NULL)
452 if (frsky->
gps_position.Status != GPSPOSITION_STATUS_FIX3D
453 && frsky->
gps_position.Status != GPSPOSITION_STATUS_DIFF3D)
455 if (test_presence_only)
458 int32_t frsky_gps_alt = (int32_t)(frsky->
gps_position.Altitude * 100.0f);
459 *value = (uint32_t)frsky_gps_alt;
473 if (GPSPositionHandle() == NULL)
475 if (frsky->
gps_position.Status != GPSPOSITION_STATUS_FIX3D
476 && frsky->
gps_position.Status != GPSPOSITION_STATUS_DIFF3D)
478 if (test_presence_only)
481 int32_t frsky_speed = (int32_t)((frsky->
gps_position.Groundspeed / KNOTS2M_PER_SECOND) * 1000);
482 *value = frsky_speed;
495 if (GPSPositionHandle() == NULL || GPSTimeHandle() == NULL)
497 if (frsky->
gps_position.Status != GPSPOSITION_STATUS_FIX3D
498 && frsky->
gps_position.Status != GPSPOSITION_STATUS_DIFF3D)
500 if (test_presence_only)
503 GPSTimeData gps_time;
504 GPSTimeGet(&gps_time);
505 uint32_t frsky_time = 0;
509 frsky_time = 0x000000ff;
510 frsky_time |= gps_time.Day << 8;
511 frsky_time |= gps_time.Month << 16;
512 frsky_time |= (gps_time.Year % 100) << 24;
515 frsky_time |= gps_time.Second << 8;
516 frsky_time |= gps_time.Minute << 16;
517 frsky_time |= gps_time.Hour << 24;
538 if (FlightStatusHandle() == NULL)
540 if (test_presence_only)
543 FlightStatusData flight_status;
544 FlightStatusGet(&flight_status);
546 *value = (flight_status.Armed == FLIGHTSTATUS_ARMED_ARMED) ? 200 : 100;
547 *value += flight_status.FlightMode;
561 if (AirspeedActualHandle() == NULL)
563 if (test_presence_only)
566 AirspeedActualData airspeed;
567 AirspeedActualGet(&airspeed);
568 int32_t frsky_speed = (int32_t)((airspeed.TrueAirspeed / KNOTS2M_PER_SECOND) * 10);
569 *value = (uint32_t)frsky_speed;
588 if (byte == 0x7e || byte == 0x7d) {
590 obuff[1] = byte &= ~0x20;
Packs UAVObjects into FrSKY Smart Port frames.
bool frsky_encode_vario(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
bool frsky_encode_fuel(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
uint8_t frsky_insert_byte(uint8_t *obuff, uint16_t *chk, uint8_t byte)
bool frsky_encode_airspeed(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
bool frsky_encode_gps_alt(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
bool frsky_encode_gps_time(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
bool frsky_encode_acc(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
bool frsky_encode_current(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
bool frsky_encode_rpm(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
bool frsky_encode_gps_coord(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
bool frsky_encode_t2(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
float bound_min_max(float val, float min, float max)
Bound input value between min and max.
int32_t frsky_send_frame(uintptr_t com, enum frsky_value_id id, uint32_t value, bool send_prelude)
bool frsky_encode_gps_speed(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
FlightBatterySettingsData battery_settings
bool frsky_encode_cells(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
bool frsky_encode_t1(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
case MODULESETTINGS_FRSKYACCELDATA_ATTITUDEANGLES
PIOS_COM_SendBuffer(shub_global->frsky_port, shub_global->serial_buf, msg_length)
bool frsky_encode_altitude(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
GPSPositionData gps_position
bool frsky_encode_gps_course(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)