37 #include "flighttelemetrystats.h"
38 #include "gcstelemetrystats.h"
39 #include "modulesettings.h"
48 #ifndef TELEM_QUEUE_SIZE
53 #define TELEM_QUEUE_SIZE 60
56 #ifndef TELEM_STACK_SIZE
57 #define TELEM_STACK_SIZE 624
61 #define MAX_QUEUE_SIZE TELEM_QUEUE_SIZE
62 #define STACK_SIZE_BYTES TELEM_STACK_SIZE
63 #define TASK_PRIORITY_RX PIOS_THREAD_PRIO_NORMAL
64 #define TASK_PRIORITY_TX PIOS_THREAD_PRIO_NORMAL
67 #define STATS_UPDATE_PERIOD_MS 1753
68 #define CONNECTION_TIMEOUT_MS 8000
69 #define USB_ACTIVITY_TIMEOUT_MS 6000
71 #define MAX_ACKS_PENDING 3
72 #define MAX_REQS_PENDING 5
73 #define ACK_TIMEOUT_MS 250
159 GCSTelemetryStatsConnectQueue(telem_state.
queue);
161 struct pios_thread *telemetryTxTaskHandle;
162 struct pios_thread *telemetryRxTaskHandle;
170 TaskMonitorAdd(TASKINFO_RUNNING_TELEMETRYTX, telemetryTxTaskHandle);
171 TaskMonitorAdd(TASKINFO_RUNNING_TELEMETRYRX, telemetryRxTaskHandle);
183 if (FlightTelemetryStatsInitialize() == -1 ||
184 GCSTelemetryStatsInitialize() == -1) {
224 UAVObjMetadata metadata;
252 UAVObjMetadata metadata;
269 switch (updateMode) {
291 metadata.telemetryUpdatePeriod);
313 DEBUG_PRINTF(3,
"telem: abandoning ack wait for %d/%d\n",
323 DEBUG_PRINTF(3,
"telem: abandoning ack wait for %d/%d\n",
358 bool did_something =
false;
367 did_something =
true;
372 return did_something;
414 DEBUG_PRINTF(3,
"telem: blocking because acks are full\n");
455 if (offset >= size) {
459 uint32_t remaining = size -
offset;
461 if (len > remaining) {
503 if (i < MAX_REQS_PENDING) {
537 if (obj_id != other_obj_id) {
543 DEBUG_PRINTF(3,
"telem: Got ack for %d/%d\n", obj_id, inst_id);
550 DEBUG_PRINTF(3,
"telem: Got UNEXPECTED ack for %d/%d\n", obj_id, inst_id);
560 }
else if (ev->
obj == GCSTelemetryStatsHandle()) {
566 int32_t success = -1;
568 UAVObjMetadata metadata;
661 telem_t telem = parameters;
691 if (retval ==
true) {
704 telem_t telem = parameters;
712 uint8_t serial_data[16];
713 uint16_t bytes_to_process;
718 serial_data,
sizeof(serial_data), 100);
720 if (bytes_to_process > 0) {
722 serial_data, bytes_to_process);
724 #if defined(PIOS_COM_TELEM_USB)
764 int32_t updatePeriodMs)
785 FlightTelemetryStatsData flightStats;
786 GCSTelemetryStatsData gcsStats;
787 FlightTelemetryStatsGet(&flightStats);
788 GCSTelemetryStatsGet(&gcsStats);
789 if (flightStats.Status != FLIGHTTELEMETRYSTATS_STATUS_CONNECTED || gcsStats.Status != GCSTELEMETRYSTATS_STATUS_CONNECTED) {
800 FlightTelemetryStatsData flightStats;
801 GCSTelemetryStatsData gcsStats;
803 uint8_t connectionTimeout;
810 FlightTelemetryStatsGet(&flightStats);
811 GCSTelemetryStatsGet(&gcsStats);
814 if (flightStats.Status == FLIGHTTELEMETRYSTATS_STATUS_CONNECTED) {
820 flightStats.RxFailures += utalkStats.
rxErrors;
821 flightStats.TxFailures += telem->
tx_errors;
826 flightStats.RxDataRate = 0;
827 flightStats.TxDataRate = 0;
828 flightStats.RxFailures = 0;
829 flightStats.TxFailures = 0;
830 flightStats.TxRetries = 0;
841 connectionTimeout = 1;
843 connectionTimeout = 0;
848 if (flightStats.Status == FLIGHTTELEMETRYSTATS_STATUS_DISCONNECTED) {
850 if (gcsStats.Status == GCSTELEMETRYSTATS_STATUS_HANDSHAKEREQ) {
851 flightStats.Status = FLIGHTTELEMETRYSTATS_STATUS_HANDSHAKEACK;
853 }
else if (flightStats.Status == FLIGHTTELEMETRYSTATS_STATUS_HANDSHAKEACK) {
855 if (gcsStats.Status == GCSTELEMETRYSTATS_STATUS_CONNECTED) {
856 flightStats.Status = FLIGHTTELEMETRYSTATS_STATUS_CONNECTED;
857 }
else if (gcsStats.Status == GCSTELEMETRYSTATS_STATUS_DISCONNECTED) {
858 flightStats.Status = FLIGHTTELEMETRYSTATS_STATUS_DISCONNECTED;
860 }
else if (flightStats.Status == FLIGHTTELEMETRYSTATS_STATUS_CONNECTED) {
861 if (gcsStats.Status != GCSTELEMETRYSTATS_STATUS_CONNECTED || connectionTimeout) {
862 flightStats.Status = FLIGHTTELEMETRYSTATS_STATUS_DISCONNECTED;
867 flightStats.Status = FLIGHTTELEMETRYSTATS_STATUS_DISCONNECTED;
872 if (flightStats.Status == FLIGHTTELEMETRYSTATS_STATUS_CONNECTED) {
875 AlarmsSet(SYSTEMALARMS_ALARM_TELEMETRY, SYSTEMALARMS_ALARM_ERROR);
880 FlightTelemetryStatsSet(&flightStats);
884 FlightTelemetryStatsUpdated();
896 ModuleSettingsTelemetrySpeedGet(&speed);
902 #if defined(PIOS_COM_TELEM_USB)
911 static volatile uint32_t usb_last_active;
919 if (usb_last_active) {
933 #endif // PIOS_COM_TELEM_USB
940 #if defined(PIOS_COM_TELEM_USB)
int32_t PIOS_FLASH_find_partition_id(enum pios_flash_partition_labels label, uintptr_t *partition_id)
uint32_t PIOS_Thread_Systime(void)
UAVObjHandle UAVObjGetByID(uint32_t id)
struct pios_queue * PIOS_Queue_Create(size_t queue_length, size_t item_size)
static void updateObject(telem_t telem, UAVObjHandle obj, int32_t eventType)
static void registerObjectShim(UAVObjHandle obj)
bool UAVObjIsMetaobject(UAVObjHandle obj)
#define STATS_UPDATE_PERIOD_MS
#define CONNECTION_TIMEOUT_MS
int32_t EventPeriodicQueueCreate(UAVObjEvent *ev, struct pios_queue *queue, uint16_t periodMs)
int32_t UAVTalkSendNack(UAVTalkConnection connectionHandle, uint32_t objId, uint16_t instId)
static void ackCallback(void *ctx, uint32_t obj_id, uint16_t inst_id)
void UAVTalkGetStats(UAVTalkConnection connection, UAVTalkStats *stats)
static uintptr_t getComPort()
int32_t PIOS_FLASH_get_partition_size(uintptr_t partition_id, uint32_t *partition_size)
static void processObjEvent(telem_t telem, UAVObjEvent *ev)
#define UAVOBJ_ALL_INSTANCES
static void gcsTelemetryStatsUpdated()
static void update_object_instances(uint32_t obj_id, uint32_t inst_id)
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
UAVTalkConnection uavTalkCon
int32_t UAVObjConnectQueueThrottled(UAVObjHandle obj_handle, struct pios_queue *queue, uint8_t eventMask, uint16_t interval)
bool PIOS_Queue_Receive(struct pios_queue *queuep, void *itemp, uint32_t timeout_ms)
void UAVTalkProcessInputStream(UAVTalkConnection connectionHandle, uint8_t *rxbytes, int numbytes)
#define PIOS_COM_TELEM_USB
#define DEBUG_PRINTF(level,...)
bool PIOS_Mutex_Unlock(struct pios_mutex *mtx)
static void reqCallback(void *ctx, uint32_t obj_id, uint16_t inst_id)
struct pios_mutex * PIOS_Mutex_Create(void)
struct pios_mutex * reqack_mutex
static void addAckPending(telem_t telem, UAVObjHandle obj, uint16_t inst_id)
uint8_t UAVObjGetTelemetryAcked(const UAVObjMetadata *dataOut)
void PIOS_HAL_ConfigureSerialSpeed(uintptr_t com_id, HwSharedSpeedBpsOptions speed)
uint8_t data[XFER_BYTES_PER_PACKET]
static void updateSettings()
volatile bool rx_inhibited
#define PIOS_COM_TELEM_SER
UAVTalkConnection UAVTalkInitialize(void *ctx, UAVTalkOutputCb outputStream, UAVTalkAckCb ackCallback, UAVTalkReqCb reqCallback, UAVTalkFileCb fileCallback)
static bool processUsbActivity(bool seen_active)
#define MODULE_HIPRI_INITCALL(ifn, sfn)
struct pending_req reqs[MAX_REQS_PENDING]
uint32_t UAVObjGetID(UAVObjHandle obj)
int32_t PIOS_FLASH_end_transaction(uintptr_t partition_id)
static void ackResendOrTimeout(telem_t telem, int idx)
uint16_t PIOS_COM_ReceiveBuffer(uintptr_t com_id, uint8_t *buf, uint16_t buf_len, uint32_t timeout_ms)
static void telemetryRxTask(void *parameters)
#define EV_MASK_ALL_UPDATES
int32_t TelemetryInitialize(void)
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
static int32_t transmitData(void *ctx, uint8_t *data, int32_t length)
Event dispatcher, distributes object events as callbacks. Alternative to using tasks and queues...
#define USB_ACTIVITY_TIMEOUT_MS
UAVObjUpdateMode UAVObjGetTelemetryUpdateMode(const UAVObjMetadata *dataOut)
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
static int32_t fileReqCallback(void *ctx, uint8_t *buf, uint32_t file_id, uint32_t offset, uint32_t len)
int32_t EventPeriodicQueueUpdate(UAVObjEvent *ev, struct pios_queue *queue, uint16_t periodMs)
struct telemetry_state * telem_t
void UAVObjUnblockThrottle(struct ObjectEventEntryThrottled *throttled)
bool PIOS_Thread_Period_Elapsed(const uint32_t prev_systime, const uint32_t increment_ms)
Determine if a period has elapsed since a datum.
uint16_t PIOS_COM_GetNumReceiveBytesPending(uintptr_t com_id)
uint32_t time_of_last_update
Tracking statistics for a UAVTalk connection.
static void updateTelemetryStats(telem_t telem)
void PIOS_Thread_Sleep(uint32_t time_ms)
int32_t TelemetryStart(void)
PIOS_COM_SendBuffer(shub_global->frsky_port, shub_global->serial_buf, msg_length)
int32_t UAVObjConnectQueue(UAVObjHandle obj_handle, struct pios_queue *queue, uint8_t eventMask)
static void registerObject(telem_t telem, UAVObjHandle obj)
static bool ackHousekeeping(telem_t telem)
int32_t UAVObjGetMetadata(UAVObjHandle obj_handle, UAVObjMetadata *dataOut)
int32_t UAVTalkSendObject(UAVTalkConnection connection, UAVObjHandle obj, uint16_t instId, uint8_t acked)
UAVObjHandle UAVObjGetLinkedObj(UAVObjHandle obj)
struct pios_queue * queue
Includes PiOS and core architecture components.
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm)
uint16_t UAVObjGetNumInstances(UAVObjHandle obj)
int32_t PIOS_FLASH_read_data(uintptr_t partition_id, uint32_t offset, uint8_t *data, uint16_t len)
int32_t PIOS_FLASH_start_transaction(uintptr_t partition_id)
void telemetry_set_inhibit(bool inhibit)
static int32_t setUpdatePeriod(telem_t telem, UAVObjHandle obj, int32_t updatePeriodMs)
volatile bool request_inhibit
volatile bool tx_inhibited
static bool sendRequestedObjs(telem_t telem)
struct ObjectEventEntryThrottled * throttle
#define PIOS_Assert(test)
void UAVObjRegisterNewInstanceCB(new_uavo_instance_cb_t callback)
static void telemetryTxTask(void *parameters)
struct pios_semaphore * access_sem
Include file of the UAVTalk library.
static struct telemetry_state telem_state
struct pending_ack acks[MAX_ACKS_PENDING]
#define PIOS_MUTEX_TIMEOUT_MAX
bool PIOS_COM_Available(uintptr_t com_id)
bool PIOS_Mutex_Lock(struct pios_mutex *mtx, uint32_t timeout_ms)
void UAVObjIterate(void(*iterator)(UAVObjHandle obj))