dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Telemetry Module

Files

file  telemetry.c
 Telemetry module, handles telemetry and UAVObject updates.
 

Data Structures

struct  pending_ack
 
struct  pending_req
 
struct  telemetry_state
 

Macros

#define TELEM_QUEUE_SIZE   60
 
#define TELEM_STACK_SIZE   624
 
#define MAX_QUEUE_SIZE   TELEM_QUEUE_SIZE
 
#define STACK_SIZE_BYTES   TELEM_STACK_SIZE
 
#define TASK_PRIORITY_RX   PIOS_THREAD_PRIO_NORMAL
 
#define TASK_PRIORITY_TX   PIOS_THREAD_PRIO_NORMAL
 
#define MAX_RETRIES   2
 
#define STATS_UPDATE_PERIOD_MS   1753
 
#define CONNECTION_TIMEOUT_MS   8000
 
#define USB_ACTIVITY_TIMEOUT_MS   6000
 
#define MAX_ACKS_PENDING   3
 
#define MAX_REQS_PENDING   5
 
#define ACK_TIMEOUT_MS   250
 

Typedefs

typedef struct telemetry_statetelem_t
 

Functions

static void telemetryTxTask (void *parameters)
 
static void telemetryRxTask (void *parameters)
 
static int32_t transmitData (void *ctx, uint8_t *data, int32_t length)
 
static void addAckPending (telem_t telem, UAVObjHandle obj, uint16_t inst_id)
 
static void ackCallback (void *ctx, uint32_t obj_id, uint16_t inst_id)
 
static void reqCallback (void *ctx, uint32_t obj_id, uint16_t inst_id)
 
static void registerObject (telem_t telem, UAVObjHandle obj)
 
static void updateObject (telem_t telem, UAVObjHandle obj, int32_t eventType)
 
static int32_t setUpdatePeriod (telem_t telem, UAVObjHandle obj, int32_t updatePeriodMs)
 
static void processObjEvent (telem_t telem, UAVObjEvent *ev)
 
static void updateTelemetryStats (telem_t telem)
 
static void gcsTelemetryStatsUpdated ()
 
static void updateSettings ()
 
static uintptr_t getComPort ()
 
static void update_object_instances (uint32_t obj_id, uint32_t inst_id)
 
static bool processUsbActivity (bool seen_active)
 
static int32_t fileReqCallback (void *ctx, uint8_t *buf, uint32_t file_id, uint32_t offset, uint32_t len)
 
static void registerObjectShim (UAVObjHandle obj)
 
int32_t TelemetryStart (void)
 
int32_t TelemetryInitialize (void)
 
static void ackResendOrTimeout (telem_t telem, int idx)
 
static bool ackHousekeeping (telem_t telem)
 
static bool sendRequestedObjs (telem_t telem)
 
static void gcsTelemetryStatsUpdated (telem_t telem)
 
void telemetry_set_inhibit (bool inhibit)
 

Variables

static struct telemetry_state telem_state = { }
 

Detailed Description

Macro Definition Documentation

#define ACK_TIMEOUT_MS   250

Definition at line 73 of file telemetry.c.

#define CONNECTION_TIMEOUT_MS   8000

Definition at line 68 of file telemetry.c.

#define MAX_ACKS_PENDING   3

Definition at line 71 of file telemetry.c.

#define MAX_QUEUE_SIZE   TELEM_QUEUE_SIZE

Definition at line 61 of file telemetry.c.

#define MAX_REQS_PENDING   5

Definition at line 72 of file telemetry.c.

#define MAX_RETRIES   2

Definition at line 65 of file telemetry.c.

#define STACK_SIZE_BYTES   TELEM_STACK_SIZE

Definition at line 62 of file telemetry.c.

#define STATS_UPDATE_PERIOD_MS   1753

Definition at line 67 of file telemetry.c.

#define TASK_PRIORITY_RX   PIOS_THREAD_PRIO_NORMAL

Definition at line 63 of file telemetry.c.

#define TASK_PRIORITY_TX   PIOS_THREAD_PRIO_NORMAL

Definition at line 64 of file telemetry.c.

#define TELEM_QUEUE_SIZE   60

Definition at line 53 of file telemetry.c.

#define TELEM_STACK_SIZE   624

Definition at line 57 of file telemetry.c.

#define USB_ACTIVITY_TIMEOUT_MS   6000

Definition at line 69 of file telemetry.c.

Typedef Documentation

typedef struct telemetry_state* telem_t

Definition at line 113 of file telemetry.c.

Function Documentation

static void ackCallback ( void *  ctx,
uint32_t  obj_id,
uint16_t  inst_id 
)
static

Callback for when we receive an ack.

Parameters
[in]ctxCallback context (telemetry subsystem handle)
[in]obj_idThe object ID that we got an ack for.
[in]inst_idThe instance ID that we got an ack for.

Definition at line 520 of file telemetry.c.

static bool ackHousekeeping ( telem_t  telem)
static

Checks for expected-ack messages that need resend or expiration.

Parameters
[in]telemTelemetry subsystem handle

Definition at line 356 of file telemetry.c.

static void ackResendOrTimeout ( telem_t  telem,
int  idx 
)
static

Either expires or retransmits a message that expects ack.

Parameters
[in]telemTelemetry subsystem handle
[in]idxThe offset for "which ack" to do this for.

Definition at line 310 of file telemetry.c.

static void addAckPending ( telem_t  telem,
UAVObjHandle  obj,
uint16_t  inst_id 
)
static

Adds a message for which we want an ack. Can block if there are already too many ack-required things pending.

Parameters
[in]telemTelemetry subsystem handle
[in]objThe object for which we want to wait for an ack.
[in]inst_idThe instance ID of said object.
Todo:
Consider nicer wakeup mechanism here.

Definition at line 383 of file telemetry.c.

static int32_t fileReqCallback ( void *  ctx,
uint8_t *  buf,
uint32_t  file_id,
uint32_t  offset,
uint32_t  len 
)
static

Callback for when we receive a request for data. Converts a file id to the actual unit of information, and returns/copies it. Currently only operates on partitions.

Parameters
[in]ctxCallback context (telemetry subsystem handle)
[in]file_idThe requested file_id
[in]offsetThe offset of information requested
[in]lenThe maximum amount of information to return. A short read is permissable, as long as some bytes are returned.
Returns
The number of bytes filled, 0 on EOF, negative on error.

Definition at line 439 of file telemetry.c.

static void gcsTelemetryStatsUpdated ( )
static
static void gcsTelemetryStatsUpdated ( telem_t  telem)
static

Called each time the GCS telemetry stats object is updated. Trigger a flight telemetry stats update if a connection is not yet established.

Definition at line 780 of file telemetry.c.

static uintptr_t getComPort ( )
static

Determine input/output com port as highest priority available

Definition at line 938 of file telemetry.c.

static void processObjEvent ( telem_t  telem,
UAVObjEvent ev 
)
static

Processes queue events

Definition at line 556 of file telemetry.c.

static bool processUsbActivity ( bool  seen_active)
static
static void registerObject ( telem_t  telem,
UAVObjHandle  obj 
)
static

Register a new object, adds object to local list and connects the queue depending on the object's telemetry settings.

Parameters
[in]objObject to connect

Definition at line 217 of file telemetry.c.

static void registerObjectShim ( UAVObjHandle  obj)
static

Definition at line 138 of file telemetry.c.

static void reqCallback ( void *  ctx,
uint32_t  obj_id,
uint16_t  inst_id 
)
static

Callback for when a telemetry session requests data

Parameters
[in]ctxCallback context (telemetry subsystem handle)
[in]obj_idThe object ID that we got a req for.
[in]inst_idThe instance ID that we got a req for.

Definition at line 488 of file telemetry.c.

static bool sendRequestedObjs ( telem_t  telem)
static

Definition at line 603 of file telemetry.c.

static int32_t setUpdatePeriod ( telem_t  telem,
UAVObjHandle  obj,
int32_t  updatePeriodMs 
)
static

Set update period of object (it must be already setup for periodic updates)

Parameters
[in]objThe object to update
[in]updatePeriodMsThe update period in ms, if zero then periodic updates are disabled
Returns
0 Success
-1 Failure

Definition at line 763 of file telemetry.c.

void telemetry_set_inhibit ( bool  inhibit)
Todo:
Consider nulling out flighttelemetrystats conn state.

Definition at line 981 of file telemetry.c.

int32_t TelemetryInitialize ( void  )

Initialise the telemetry module

Returns
-1 if initialisation failed
0 on success

Definition at line 181 of file telemetry.c.

static void telemetryRxTask ( void *  parameters)
static

Telemetry transmit task. Processes queue events and periodic updates.

Definition at line 702 of file telemetry.c.

int32_t TelemetryStart ( void  )

Initialise the telemetry module

Returns
-1 if initialisation failed
0 on success

Definition at line 147 of file telemetry.c.

static void telemetryTxTask ( void *  parameters)
static

Telemetry transmit task

Definition at line 659 of file telemetry.c.

static int32_t transmitData ( void *  ctx,
uint8_t *  data,
int32_t  length 
)
static

Transmit data buffer to the modem or USB port.

Parameters
[in]dataData buffer to send
[in]lengthLength of buffer
Returns
-1 on failure
number of bytes transmitted on success

Definition at line 744 of file telemetry.c.

static void update_object_instances ( uint32_t  obj_id,
uint32_t  inst_id 
)
static

New UAVO object instance callback This is called from the uavobjectmanager

Parameters
[in]obj_idThe id of the object which had a new instance created
[in]inst_idthe instance ID that was created
Todo:
just send the new instance, reqack.

Definition at line 976 of file telemetry.c.

static void updateObject ( telem_t  telem,
UAVObjHandle  obj,
int32_t  eventType 
)
static

Update object's queue connections and timer, depending on object's settings

Parameters
[in]objObject to updates

Definition at line 250 of file telemetry.c.

static void updateSettings ( )
static

Update the telemetry settings, called on startup.

Definition at line 891 of file telemetry.c.

static void updateTelemetryStats ( telem_t  telem)
static

Update telemetry statistics and handle connection handshake

Definition at line 797 of file telemetry.c.

Variable Documentation

struct telemetry_state telem_state = { }
static

Definition at line 111 of file telemetry.c.