mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
OP-4 Flight/Telemetry Create new objects to report statistics of the telemetry link (plus a few bug fixes, heap size was also increased)
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@515 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
6c4cd936e5
commit
89a6dd30d1
@ -135,6 +135,8 @@ SRC += $(OPUAVOBJ)/exampleobject2.c
|
||||
SRC += $(OPUAVOBJ)/examplesettings.c
|
||||
SRC += $(OPUAVOBJ)/settingspersistence.c
|
||||
SRC += $(OPUAVOBJ)/gpsobject.c
|
||||
SRC += $(OPUAVOBJ)/gcstelemetrystats.c
|
||||
SRC += $(OPUAVOBJ)/flighttelemetrystats.c
|
||||
|
||||
## PIOS Hardware (STM32F10x)
|
||||
SRC += $(PIOSSTM32F10X)/pios_sys.c
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
#include "openpilot.h"
|
||||
#include "flighttelemetrystats.h"
|
||||
|
||||
// Private constants
|
||||
#define MAX_QUEUE_SIZE 20
|
||||
@ -31,6 +32,7 @@
|
||||
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
|
||||
#define REQ_TIMEOUT_MS 250
|
||||
#define MAX_RETRIES 3
|
||||
#define STATS_UPDATE_PERIOD_MS 5000
|
||||
|
||||
// Private types
|
||||
|
||||
@ -39,6 +41,8 @@ static COMPortTypeDef telemetryPort;
|
||||
static xQueueHandle queue;
|
||||
static xTaskHandle telemetryTxTaskHandle;
|
||||
static xTaskHandle telemetryRxTaskHandle;
|
||||
static uint32_t txErrors;
|
||||
static uint32_t txRetries;
|
||||
|
||||
// Private functions
|
||||
static void telemetryTxTask(void* parameters);
|
||||
@ -56,6 +60,8 @@ static int32_t setUpdatePeriod(UAVObjHandle obj, int32_t updatePeriodMs);
|
||||
*/
|
||||
int32_t TelemetryInitialize(void)
|
||||
{
|
||||
UAVObjEvent ev;
|
||||
|
||||
// Create object queue
|
||||
queue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(UAVObjEvent));
|
||||
|
||||
@ -68,6 +74,12 @@ int32_t TelemetryInitialize(void)
|
||||
// Process all registered objects and connect queue for updates
|
||||
UAVObjIterate(®isterObject);
|
||||
|
||||
// Create periodic event that will be used to update the telemetry stats
|
||||
txErrors = 0;
|
||||
txRetries = 0;
|
||||
memset(&ev, 0, sizeof(UAVObjEvent));
|
||||
EventPeriodicQueueCreate(&ev, queue, STATS_UPDATE_PERIOD_MS);
|
||||
|
||||
// Start telemetry tasks
|
||||
xTaskCreate(telemetryTxTask, (signed char*)"TelemetryTx", STACK_SIZE, NULL, TASK_PRIORITY, &telemetryTxTaskHandle);
|
||||
xTaskCreate(telemetryRxTask, (signed char*)"TelemetryRx", STACK_SIZE, NULL, TASK_PRIORITY, &telemetryRxTaskHandle);
|
||||
@ -156,6 +168,8 @@ static void telemetryTxTask(void* parameters)
|
||||
UAVObjMetadata metadata;
|
||||
int32_t retries;
|
||||
int32_t success;
|
||||
UAVTalkStats utalkStats;
|
||||
FlightTelemetryStatsData stats;
|
||||
|
||||
// Loop forever
|
||||
while(1)
|
||||
@ -163,33 +177,75 @@ static void telemetryTxTask(void* parameters)
|
||||
// Wait for queue message
|
||||
if(xQueueReceive(queue, &ev, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
// Get object metadata
|
||||
UAVObjGetMetadata(ev.obj, &metadata);
|
||||
// Act on event
|
||||
retries = 0;
|
||||
success = -1;
|
||||
if(ev.event == EV_UPDATED || ev.event == EV_UPDATED_MANUAL)
|
||||
// Check if this is a periodic timer event (used to update stats)
|
||||
if (ev.obj == 0)
|
||||
{
|
||||
// Send update to GCS (with retries)
|
||||
while(retries < MAX_RETRIES && success == -1)
|
||||
{
|
||||
success = UAVTalkSendObject(ev.obj, ev.instId, metadata.telemetryAcked, REQ_TIMEOUT_MS); // call blocks until ack is received or timeout
|
||||
++retries;
|
||||
}
|
||||
// Get stats
|
||||
UAVTalkGetStats(&utalkStats);
|
||||
UAVTalkResetStats();
|
||||
|
||||
// Update stats object
|
||||
FlightTelemetryStatsGet(&stats);
|
||||
if (utalkStats.rxBytes > 0)
|
||||
{
|
||||
stats.Connected = FLIGHTTELEMETRYSTATS_CONNECTED_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
stats.Connected = FLIGHTTELEMETRYSTATS_CONNECTED_FALSE;
|
||||
}
|
||||
stats.RxDataRate = (float)utalkStats.rxBytes / ((float)STATS_UPDATE_PERIOD_MS/1000.0);
|
||||
stats.TxDataRate = (float)utalkStats.txBytes / ((float)STATS_UPDATE_PERIOD_MS/1000.0);
|
||||
stats.RxFailures += utalkStats.rxErrors;
|
||||
stats.TxFailures += txErrors;
|
||||
stats.TxRetries += txRetries;
|
||||
txErrors = 0;
|
||||
txRetries = 0;
|
||||
FlightTelemetryStatsSet(&stats);
|
||||
}
|
||||
else if(ev.event == EV_UPDATE_REQ)
|
||||
// This is an object update, handle based on event type
|
||||
else
|
||||
{
|
||||
// Request object update from GCS (with retries)
|
||||
while(retries < MAX_RETRIES && success == -1)
|
||||
// Get object metadata
|
||||
UAVObjGetMetadata(ev.obj, &metadata);
|
||||
// Act on event
|
||||
retries = 0;
|
||||
success = -1;
|
||||
if(ev.event == EV_UPDATED || ev.event == EV_UPDATED_MANUAL)
|
||||
{
|
||||
success = UAVTalkSendObjectRequest(ev.obj, ev.instId, REQ_TIMEOUT_MS); // call blocks until update is received or timeout
|
||||
++retries;
|
||||
// Send update to GCS (with retries)
|
||||
while(retries < MAX_RETRIES && success == -1)
|
||||
{
|
||||
success = UAVTalkSendObject(ev.obj, ev.instId, metadata.telemetryAcked, REQ_TIMEOUT_MS); // call blocks until ack is received or timeout
|
||||
++retries;
|
||||
}
|
||||
// Update stats
|
||||
txRetries += (retries-1);
|
||||
if ( success == -1 )
|
||||
{
|
||||
++txErrors;
|
||||
}
|
||||
}
|
||||
else if(ev.event == EV_UPDATE_REQ)
|
||||
{
|
||||
// Request object update from GCS (with retries)
|
||||
while(retries < MAX_RETRIES && success == -1)
|
||||
{
|
||||
success = UAVTalkSendObjectRequest(ev.obj, ev.instId, REQ_TIMEOUT_MS); // call blocks until update is received or timeout
|
||||
++retries;
|
||||
}
|
||||
// Update stats
|
||||
txRetries += (retries-1);
|
||||
if ( success == -1 )
|
||||
{
|
||||
++txErrors;
|
||||
}
|
||||
}
|
||||
// If this is a metaobject then make necessary telemetry updates
|
||||
if(UAVObjIsMetaobject(ev.obj))
|
||||
{
|
||||
updateObject(UAVObjGetLinkedObj(ev.obj)); // linked object will be the actual object the metadata are for
|
||||
}
|
||||
}
|
||||
// If this is a metaobject then make necessary telemetry updates
|
||||
if(UAVObjIsMetaobject(ev.obj))
|
||||
{
|
||||
updateObject(UAVObjGetLinkedObj(ev.obj)); // linked object will be the actual object the metadata are for
|
||||
}
|
||||
}
|
||||
}
|
||||
|
73
flight/OpenPilot/UAVObjects/flighttelemetrystats.c
Normal file
73
flight/OpenPilot/UAVObjects/flighttelemetrystats.c
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file flighttelemetrystats.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Implementation of the FlightTelemetryStats object. This file has been
|
||||
* automatically generated by the UAVObjectGenerator.
|
||||
*
|
||||
* @note Object definition file: flighttelemetrystats.xml.
|
||||
* This is an automatically generated file.
|
||||
* DO NOT modify manually.
|
||||
*
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "flighttelemetrystats.h"
|
||||
|
||||
// Private variables
|
||||
static UAVObjHandle handle;
|
||||
|
||||
/**
|
||||
* Initialize object.
|
||||
* \return 0 Success
|
||||
* \return -1 Failure
|
||||
*/
|
||||
int32_t FlightTelemetryStatsInitialize()
|
||||
{
|
||||
UAVObjMetadata metadata;
|
||||
|
||||
// Register object with the object manager
|
||||
handle = UAVObjRegister(FLIGHTTELEMETRYSTATS_OBJID, FLIGHTTELEMETRYSTATS_NAME, 0, FLIGHTTELEMETRYSTATS_ISSINGLEINST, FLIGHTTELEMETRYSTATS_ISSETTINGS, FLIGHTTELEMETRYSTATS_NUMBYTES);
|
||||
if (handle == 0) return -1;
|
||||
|
||||
// Initialize metadata
|
||||
metadata.telemetryAcked = 1;
|
||||
metadata.telemetryUpdateMode = UPDATEMODE_PERIODIC;
|
||||
metadata.telemetryUpdatePeriod = 5000;
|
||||
metadata.gcsTelemetryAcked = 1;
|
||||
metadata.gcsTelemetryUpdateMode = UPDATEMODE_NEVER;
|
||||
metadata.gcsTelemetryUpdatePeriod = 0;
|
||||
metadata.loggingUpdateMode = UPDATEMODE_PERIODIC;
|
||||
metadata.loggingUpdatePeriod = 5000;
|
||||
UAVObjSetMetadata(handle, &metadata);
|
||||
|
||||
// Done
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object handle
|
||||
*/
|
||||
UAVObjHandle FlightTelemetryStatsHandle()
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
73
flight/OpenPilot/UAVObjects/gcstelemetrystats.c
Normal file
73
flight/OpenPilot/UAVObjects/gcstelemetrystats.c
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file gcstelemetrystats.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Implementation of the GCSTelemetryStats object. This file has been
|
||||
* automatically generated by the UAVObjectGenerator.
|
||||
*
|
||||
* @note Object definition file: gcstelemetrystats.xml.
|
||||
* This is an automatically generated file.
|
||||
* DO NOT modify manually.
|
||||
*
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "gcstelemetrystats.h"
|
||||
|
||||
// Private variables
|
||||
static UAVObjHandle handle;
|
||||
|
||||
/**
|
||||
* Initialize object.
|
||||
* \return 0 Success
|
||||
* \return -1 Failure
|
||||
*/
|
||||
int32_t GCSTelemetryStatsInitialize()
|
||||
{
|
||||
UAVObjMetadata metadata;
|
||||
|
||||
// Register object with the object manager
|
||||
handle = UAVObjRegister(GCSTELEMETRYSTATS_OBJID, GCSTELEMETRYSTATS_NAME, 0, GCSTELEMETRYSTATS_ISSINGLEINST, GCSTELEMETRYSTATS_ISSETTINGS, GCSTELEMETRYSTATS_NUMBYTES);
|
||||
if (handle == 0) return -1;
|
||||
|
||||
// Initialize metadata
|
||||
metadata.telemetryAcked = 1;
|
||||
metadata.telemetryUpdateMode = UPDATEMODE_NEVER;
|
||||
metadata.telemetryUpdatePeriod = 0;
|
||||
metadata.gcsTelemetryAcked = 1;
|
||||
metadata.gcsTelemetryUpdateMode = UPDATEMODE_NEVER;
|
||||
metadata.gcsTelemetryUpdatePeriod = 0;
|
||||
metadata.loggingUpdateMode = UPDATEMODE_NEVER;
|
||||
metadata.loggingUpdatePeriod = 0;
|
||||
UAVObjSetMetadata(handle, &metadata);
|
||||
|
||||
// Done
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object handle
|
||||
*/
|
||||
UAVObjHandle GCSTelemetryStatsHandle()
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
78
flight/OpenPilot/UAVObjects/inc/flighttelemetrystats.h
Normal file
78
flight/OpenPilot/UAVObjects/inc/flighttelemetrystats.h
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file flighttelemetrystats.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Implementation of the FlightTelemetryStats object. This file has been
|
||||
* automatically generated by the UAVObjectGenerator.
|
||||
*
|
||||
* @note Object definition file: flighttelemetrystats.xml.
|
||||
* This is an automatically generated file.
|
||||
* DO NOT modify manually.
|
||||
*
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef FLIGHTTELEMETRYSTATS_H
|
||||
#define FLIGHTTELEMETRYSTATS_H
|
||||
|
||||
#include "openpilot.h"
|
||||
|
||||
// Object constants
|
||||
#define FLIGHTTELEMETRYSTATS_OBJID 766280320U
|
||||
#define FLIGHTTELEMETRYSTATS_NAME "FlightTelemetryStats"
|
||||
#define FLIGHTTELEMETRYSTATS_ISSINGLEINST 1
|
||||
#define FLIGHTTELEMETRYSTATS_ISSETTINGS 0
|
||||
#define FLIGHTTELEMETRYSTATS_NUMBYTES sizeof(FlightTelemetryStatsData)
|
||||
|
||||
// Object access macros
|
||||
#define FlightTelemetryStatsGet(dataOut) UAVObjGetData(FlightTelemetryStatsHandle(), dataOut)
|
||||
#define FlightTelemetryStatsSet(dataIn) UAVObjSetData(FlightTelemetryStatsHandle(), dataIn)
|
||||
#define FlightTelemetryStatsInstGet(instId, dataOut) UAVObjGetInstanceData(FlightTelemetryStatsHandle(), instId, dataOut)
|
||||
#define FlightTelemetryStatsInstSet(instId, dataIn) UAVObjSetInstanceData(FlightTelemetryStatsHandle(), instId, dataIn)
|
||||
#define FlightTelemetryStatsConnectQueue(queue) UAVObjConnectQueue(FlightTelemetryStatsHandle(), queue, EV_MASK_ALL_UPDATES)
|
||||
#define FlightTelemetryStatsConnectCallback(cb) UAVObjConnectCallback(FlightTelemetryStatsHandle(), cb, EV_MASK_ALL_UPDATES)
|
||||
#define FlightTelemetryStatsCreateInstance() UAVObjCreateInstance(FlightTelemetryStatsHandle())
|
||||
#define FlightTelemetryStatsRequestUpdate() UAVObjRequestUpdate(FlightTelemetryStatsHandle())
|
||||
#define FlightTelemetryStatsRequestInstUpdate(instId) UAVObjRequestInstanceUpdate(FlightTelemetryStatsHandle(), instId)
|
||||
#define FlightTelemetryStatsUpdated() UAVObjUpdated(FlightTelemetryStatsHandle())
|
||||
#define FlightTelemetryStatsInstUpdated(instId) UAVObjUpdated(FlightTelemetryStatsHandle(), instId)
|
||||
#define FlightTelemetryStatsGetMetadata(dataOut) UAVObjGetMetadata(FlightTelemetryStatsHandle(), dataOut)
|
||||
#define FlightTelemetryStatsSetMetadata(dataIn) UAVObjSetMetadata(FlightTelemetryStatsHandle(), dataIn)
|
||||
|
||||
// Object data
|
||||
typedef struct {
|
||||
uint8_t Connected;
|
||||
float TxDataRate;
|
||||
float RxDataRate;
|
||||
uint32_t TxFailures;
|
||||
uint32_t RxFailures;
|
||||
uint32_t TxRetries;
|
||||
|
||||
} __attribute__((packed)) FlightTelemetryStatsData;
|
||||
|
||||
// Enumeration types
|
||||
typedef enum { FLIGHTTELEMETRYSTATS_CONNECTED_TRUE=0, FLIGHTTELEMETRYSTATS_CONNECTED_FALSE=1, } FLIGHTTELEMETRYSTATSCONNECTEDEnum;
|
||||
|
||||
|
||||
// Generic interface functions
|
||||
int32_t FlightTelemetryStatsInitialize();
|
||||
UAVObjHandle FlightTelemetryStatsHandle();
|
||||
|
||||
#endif // FLIGHTTELEMETRYSTATS_H
|
78
flight/OpenPilot/UAVObjects/inc/gcstelemetrystats.h
Normal file
78
flight/OpenPilot/UAVObjects/inc/gcstelemetrystats.h
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file gcstelemetrystats.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Implementation of the GCSTelemetryStats object. This file has been
|
||||
* automatically generated by the UAVObjectGenerator.
|
||||
*
|
||||
* @note Object definition file: gcstelemetrystats.xml.
|
||||
* This is an automatically generated file.
|
||||
* DO NOT modify manually.
|
||||
*
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef GCSTELEMETRYSTATS_H
|
||||
#define GCSTELEMETRYSTATS_H
|
||||
|
||||
#include "openpilot.h"
|
||||
|
||||
// Object constants
|
||||
#define GCSTELEMETRYSTATS_OBJID 607270704U
|
||||
#define GCSTELEMETRYSTATS_NAME "GCSTelemetryStats"
|
||||
#define GCSTELEMETRYSTATS_ISSINGLEINST 1
|
||||
#define GCSTELEMETRYSTATS_ISSETTINGS 0
|
||||
#define GCSTELEMETRYSTATS_NUMBYTES sizeof(GCSTelemetryStatsData)
|
||||
|
||||
// Object access macros
|
||||
#define GCSTelemetryStatsGet(dataOut) UAVObjGetData(GCSTelemetryStatsHandle(), dataOut)
|
||||
#define GCSTelemetryStatsSet(dataIn) UAVObjSetData(GCSTelemetryStatsHandle(), dataIn)
|
||||
#define GCSTelemetryStatsInstGet(instId, dataOut) UAVObjGetInstanceData(GCSTelemetryStatsHandle(), instId, dataOut)
|
||||
#define GCSTelemetryStatsInstSet(instId, dataIn) UAVObjSetInstanceData(GCSTelemetryStatsHandle(), instId, dataIn)
|
||||
#define GCSTelemetryStatsConnectQueue(queue) UAVObjConnectQueue(GCSTelemetryStatsHandle(), queue, EV_MASK_ALL_UPDATES)
|
||||
#define GCSTelemetryStatsConnectCallback(cb) UAVObjConnectCallback(GCSTelemetryStatsHandle(), cb, EV_MASK_ALL_UPDATES)
|
||||
#define GCSTelemetryStatsCreateInstance() UAVObjCreateInstance(GCSTelemetryStatsHandle())
|
||||
#define GCSTelemetryStatsRequestUpdate() UAVObjRequestUpdate(GCSTelemetryStatsHandle())
|
||||
#define GCSTelemetryStatsRequestInstUpdate(instId) UAVObjRequestInstanceUpdate(GCSTelemetryStatsHandle(), instId)
|
||||
#define GCSTelemetryStatsUpdated() UAVObjUpdated(GCSTelemetryStatsHandle())
|
||||
#define GCSTelemetryStatsInstUpdated(instId) UAVObjUpdated(GCSTelemetryStatsHandle(), instId)
|
||||
#define GCSTelemetryStatsGetMetadata(dataOut) UAVObjGetMetadata(GCSTelemetryStatsHandle(), dataOut)
|
||||
#define GCSTelemetryStatsSetMetadata(dataIn) UAVObjSetMetadata(GCSTelemetryStatsHandle(), dataIn)
|
||||
|
||||
// Object data
|
||||
typedef struct {
|
||||
uint8_t Connected;
|
||||
float TxDataRate;
|
||||
float RxDataRate;
|
||||
uint32_t TxFailures;
|
||||
uint32_t RxFailures;
|
||||
uint32_t TxRetries;
|
||||
|
||||
} __attribute__((packed)) GCSTelemetryStatsData;
|
||||
|
||||
// Enumeration types
|
||||
typedef enum { GCSTELEMETRYSTATS_CONNECTED_TRUE=0, GCSTELEMETRYSTATS_CONNECTED_FALSE=1, } GCSTELEMETRYSTATSCONNECTEDEnum;
|
||||
|
||||
|
||||
// Generic interface functions
|
||||
int32_t GCSTelemetryStatsInitialize();
|
||||
UAVObjHandle GCSTelemetryStatsHandle();
|
||||
|
||||
#endif // GCSTELEMETRYSTATS_H
|
@ -31,6 +31,8 @@
|
||||
#include "exampleobject1.h"
|
||||
#include "exampleobject2.h"
|
||||
#include "examplesettings.h"
|
||||
#include "flighttelemetrystats.h"
|
||||
#include "gcstelemetrystats.h"
|
||||
#include "gpsobject.h"
|
||||
#include "settingspersistence.h"
|
||||
|
||||
@ -44,6 +46,8 @@ void UAVObjectsInitializeAll()
|
||||
ExampleObject1Initialize();
|
||||
ExampleObject2Initialize();
|
||||
ExampleSettingsInitialize();
|
||||
FlightTelemetryStatsInitialize();
|
||||
GCSTelemetryStatsInitialize();
|
||||
GpsObjectInitialize();
|
||||
SettingsPersistenceInitialize();
|
||||
|
||||
|
@ -33,11 +33,24 @@
|
||||
// Public types
|
||||
typedef int32_t (*UAVTalkOutputStream)(uint8_t* data, int32_t length);
|
||||
|
||||
typedef struct {
|
||||
uint32_t txBytes;
|
||||
uint32_t rxBytes;
|
||||
uint32_t txObjectBytes;
|
||||
uint32_t rxObjectBytes;
|
||||
uint32_t rxObjects;
|
||||
uint32_t txObjects;
|
||||
uint32_t txErrors;
|
||||
uint32_t rxErrors;
|
||||
} UAVTalkStats;
|
||||
|
||||
// Public functions
|
||||
int32_t UAVTalkInitialize(UAVTalkOutputStream outputStream);
|
||||
int32_t UAVTalkSetOutputStream(UAVTalkOutputStream outputStream);
|
||||
int32_t UAVTalkSendObject(UAVObjHandle obj, uint16_t instId, uint8_t acked, int32_t timeoutMs);
|
||||
int32_t UAVTalkSendObjectRequest(UAVObjHandle obj, uint16_t instId, int32_t timeoutMs);
|
||||
int32_t UAVTalkProcessInputStream(uint8_t rxbyte);
|
||||
void UAVTalkGetStats(UAVTalkStats* stats);
|
||||
void UAVTalkResetStats();
|
||||
|
||||
#endif // UAVTALK_H
|
||||
|
@ -51,6 +51,7 @@ static UAVObjHandle respObj;
|
||||
static uint16_t respInstId;
|
||||
static uint8_t rxBuffer[MAX_PACKET_LENGTH];
|
||||
static uint8_t txBuffer[MAX_PACKET_LENGTH];
|
||||
static UAVTalkStats stats;
|
||||
|
||||
// Private functions
|
||||
static uint16_t updateChecksum(uint16_t cs, uint8_t* data, int32_t length);
|
||||
@ -72,9 +73,41 @@ int32_t UAVTalkInitialize(UAVTalkOutputStream outputStream)
|
||||
lock = xSemaphoreCreateRecursiveMutex();
|
||||
vSemaphoreCreateBinary(respSema);
|
||||
xSemaphoreTake(respSema, 0); // reset to zero
|
||||
UAVTalkResetStats();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get communication statistics counters
|
||||
* @param[out] statsOut Statistics counters
|
||||
*/
|
||||
void UAVTalkGetStats(UAVTalkStats* statsOut)
|
||||
{
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(lock, portMAX_DELAY);
|
||||
|
||||
// Copy stats
|
||||
memcpy(statsOut, &stats, sizeof(UAVTalkStats));
|
||||
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the statistics counters.
|
||||
*/
|
||||
void UAVTalkResetStats()
|
||||
{
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(lock, portMAX_DELAY);
|
||||
|
||||
// Clear stats
|
||||
memset(&stats, 0, sizeof(UAVTalkStats));
|
||||
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request an update for the specified object, on success the object data would have been
|
||||
* updated by the GCS.
|
||||
@ -180,6 +213,7 @@ int32_t UAVTalkProcessInputStream(uint8_t rxbyte)
|
||||
static RxState state = STATE_SYNC;
|
||||
|
||||
// Receive state machine
|
||||
++stats.rxBytes;
|
||||
switch (state) {
|
||||
case STATE_SYNC:
|
||||
if ((rxbyte & TYPE_MASK) == TYPE_VER )
|
||||
@ -200,6 +234,7 @@ int32_t UAVTalkProcessInputStream(uint8_t rxbyte)
|
||||
if (obj == 0)
|
||||
{
|
||||
state = STATE_SYNC;
|
||||
++stats.rxErrors;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -218,6 +253,7 @@ int32_t UAVTalkProcessInputStream(uint8_t rxbyte)
|
||||
if (length >= MAX_PAYLOAD_LENGTH)
|
||||
{
|
||||
state = STATE_SYNC;
|
||||
++stats.rxErrors;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -281,8 +317,14 @@ int32_t UAVTalkProcessInputStream(uint8_t rxbyte)
|
||||
{
|
||||
xSemaphoreTakeRecursive(lock, portMAX_DELAY);
|
||||
receiveObject(type, obj, instId, rxBuffer, length);
|
||||
++stats.rxObjects;
|
||||
stats.rxObjectBytes += length;
|
||||
xSemaphoreGiveRecursive(lock);
|
||||
}
|
||||
else
|
||||
{
|
||||
++stats.rxErrors;
|
||||
}
|
||||
state = STATE_SYNC;
|
||||
}
|
||||
break;
|
||||
@ -392,10 +434,10 @@ static int32_t sendObject(UAVObjHandle obj, uint16_t instId, uint8_t type)
|
||||
uint32_t numInst;
|
||||
uint32_t n;
|
||||
|
||||
// If all instances are requested on a single instance object it is an error
|
||||
// If all instances are requested and this is a single instance object, force instance ID to zero
|
||||
if ( instId == UAVOBJ_ALL_INSTANCES && UAVObjIsSingleInstance(obj) )
|
||||
{
|
||||
return -1;
|
||||
instId = 0;
|
||||
}
|
||||
|
||||
// Process message type
|
||||
@ -507,6 +549,11 @@ static int32_t sendSingleObject(UAVObjHandle obj, uint16_t instId, uint8_t type)
|
||||
// Send buffer
|
||||
if (outStream!=NULL) (*outStream)(txBuffer, dataOffset+length+CHECKSUM_LENGTH);
|
||||
|
||||
// Update stats
|
||||
++stats.txObjects;
|
||||
stats.txBytes += dataOffset+length+CHECKSUM_LENGTH;
|
||||
stats.txObjectBytes += length;
|
||||
|
||||
// Done
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
|
||||
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )
|
||||
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 256 )
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 10 * 1024 ) )
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 20 * 1024 ) )
|
||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||
#define configUSE_TRACE_FACILITY 0
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user