44 #include "physical_constants.h"
45 #include "modulesettings.h"
46 #include "flightbatterysettings.h"
47 #include "flightbatterystate.h"
48 #include "gpsposition.h"
49 #include "airspeedactual.h"
50 #include "baroaltitude.h"
52 #include "positionactual.h"
53 #include "velocityactual.h"
54 #include "flightstatus.h"
56 #if defined(PIOS_INCLUDE_TARANIS_SPORT)
58 static void uavoTaranisTask(
void *parameters);
60 static bool frsky_encode_rssi(
struct frsky_settings *frsky, uint32_t *
value,
bool test_presence_only, uint32_t arg);
61 static bool frsky_encode_swr(
struct frsky_settings *frsky, uint32_t *
value,
bool test_presence_only, uint32_t arg);
62 static bool frsky_encode_battery(
struct frsky_settings *frsky, uint32_t *
value,
bool test_presence_only, uint32_t arg);
64 #define FRSKY_POLL_REQUEST 0x7e
65 #define FRSKY_MINIMUM_POLL_INTERVAL 10000
67 #define VOLT_RATIO (20)
70 FRSKY_STATE_WAIT_POLL_REQUEST,
71 FRSKY_STATE_WAIT_SENSOR_ID,
72 FRSKY_STATE_WAIT_TX_DONE,
92 struct frsky_sport_telemetry {
93 enum frsky_state
state;
94 int32_t scheduled_item;
95 uint32_t last_poll_time;
96 uint8_t ignore_rx_chars;
99 uint32_t item_last_triggered[
NELEMENTS(frsky_value_items)];
102 #define FRSKY_SPORT_BAUDRATE 57600
104 #if defined(PIOS_FRSKY_SPORT_TELEMETRY_STACK_SIZE)
105 #define STACK_SIZE_BYTES PIOS_FRSKY_SPORT_TELEMETRY_STACK_SIZE
107 #define STACK_SIZE_BYTES 672
109 #define TASK_PRIORITY PIOS_THREAD_PRIO_LOW
111 static struct pios_thread *uavoTaranisTaskHandle;
113 static struct frsky_sport_telemetry *frsky;
122 static bool frsky_encode_rssi(
struct frsky_settings *frsky, uint32_t *
value,
bool test_presence_only, uint32_t arg)
125 uint8_t local_link_quality = 0, local_link_connected = 0;
127 RFM22BStatusLinkStateGet(&local_link_connected);
128 RFM22BStatusLinkQualityGet(&local_link_quality);
130 RFM22BStatusData rfm22bStatus;
131 RFM22BStatusInstGet(1, &rfm22bStatus);
139 static bool frsky_encode_swr(
struct frsky_settings *frsky, uint32_t *
value,
bool test_presence_only, uint32_t arg)
145 static bool frsky_encode_battery(
struct frsky_settings *frsky, uint32_t *
value,
bool test_presence_only, uint32_t arg)
148 FlightBatteryStateVoltageGet(&voltage);
149 *value = (uint8_t) (voltage * VOLT_RATIO);
159 static void frsky_schedule_next_item(
void)
162 int32_t max_exp_time = INT32_MIN;
163 int32_t most_exp_item = -1;
164 for (i = 0; i <
NELEMENTS(frsky_value_items); i++) {
165 if (frsky_value_items[i].encode_value(&frsky->frsky_settings, 0,
true, frsky_value_items[i].
fn_arg)) {
168 if (exp_time > max_exp_time) {
169 max_exp_time = exp_time;
174 frsky->scheduled_item = most_exp_item;
180 static bool frsky_send_scheduled_item(
void)
182 int32_t item = frsky->scheduled_item;
183 if ((item >= 0) && (item <
NELEMENTS(frsky_value_items))) {
186 if (frsky_value_items[item].encode_value(&frsky->frsky_settings, &value,
false,
187 frsky_value_items[item].
fn_arg)) {
201 static int32_t uavoTaranisStart(
void)
206 uavoTaranisTask,
"uavoFrSKYSensorHubBridge",
209 uavoTaranisTaskHandle);
220 static int32_t uavoTaranisInitialize(
void)
227 frsky =
PIOS_malloc(
sizeof(
struct frsky_sport_telemetry));
229 memset(frsky, 0x00,
sizeof(
struct frsky_sport_telemetry));
233 if (FlightBatteryStateInitialize() == -1 \
234 || FlightStatusInitialize() == -1 \
235 || PositionActualInitialize() == -1 \
236 || VelocityActualInitialize()) {
244 frsky->state = FRSKY_STATE_WAIT_POLL_REQUEST;
246 frsky->ignore_rx_chars = 0;
247 frsky->scheduled_item = -1;
248 frsky->com = sport_com;
251 for (i = 0; i <
NELEMENTS(frsky_value_items); i++)
272 static
void uavoTaranisTask(
void *parameters)
279 for (uint32_t i = 0; i <
sizeof(frsky_value_items) /
sizeof(frsky_value_items[0]); i++) {
280 frsky->scheduled_item =
i;
281 frsky_send_scheduled_item();
292 frsky_schedule_next_item();
293 frsky_send_scheduled_item();
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)
uint32_t PIOS_DELAY_GetuS()
Query the Delay timer for the current uS.
bool frsky_encode_fuel(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
void * PIOS_malloc(size_t size)
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)
uint32_t PIOS_DELAY_GetuSSince(uint32_t t)
Calculate time in microseconds since a previous time.
#define MODULE_INITCALL(ifn, sfn)
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
int32_t frsky_send_frame(uintptr_t com, enum frsky_value_id id, uint32_t value, bool send_prelude)
bool frsky_encode_cells(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
void PIOS_Thread_Sleep(uint32_t time_ms)
bool frsky_encode_altitude(struct frsky_settings *frsky, uint32_t *value, bool test_presence_only, uint32_t arg)
Includes PiOS and core architecture components.
#define PIOS_COM_FRSKY_SPORT
int32_t PIOS_COM_ChangeBaud(uintptr_t com_id, uint32_t baud)