From dbcb499d7f5263df2ebe98e7642449fb9f5938db Mon Sep 17 00:00:00 2001 From: James Cotton Date: Mon, 6 Feb 2012 08:51:48 -0600 Subject: [PATCH] Add object to monitor the overo link status. Current just records the bytes/s being sent and the connected status (based on sending more than 500 bytes per second) --- flight/Modules/OveroSync/overosync.c | 30 +++++++++++++++++-- flight/Revolution/UAVObjects.inc | 1 + .../src/plugins/uavobjects/uavobjects.pro | 2 ++ shared/uavobjectdefinition/overosyncstats.xml | 12 ++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 shared/uavobjectdefinition/overosyncstats.xml diff --git a/flight/Modules/OveroSync/overosync.c b/flight/Modules/OveroSync/overosync.c index 38d257d8e..90f7e7807 100644 --- a/flight/Modules/OveroSync/overosync.c +++ b/flight/Modules/OveroSync/overosync.c @@ -32,6 +32,7 @@ #include "openpilot.h" #include "overosync.h" +#include "overosyncstats.h" // Private constants #define OVEROSYNC_PACKET_SIZE 256 @@ -68,6 +69,7 @@ struct overosync { xSemaphoreHandle transaction_lock; xSemaphoreHandle buffer_lock; volatile bool transaction_done; + uint32_t sent_bytes; uint32_t write_pointer; uint32_t sent_objects; uint32_t failed_objects; @@ -83,6 +85,11 @@ struct overosync *overosync; */ int32_t OveroSyncInitialize(void) { + if(pios_spi_overo_id == 0) + return -1; + + OveroSyncStatsInitialize(); + // Create object queues queue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(UAVObjEvent)); @@ -99,6 +106,9 @@ int32_t OveroSyncInitialize(void) */ int32_t OveroSyncStart(void) { + if(pios_spi_overo_id == 0) + return -1; + overosync = (struct overosync *) pvPortMalloc(sizeof(*overosync)); if(overosync == NULL) return -1; @@ -114,13 +124,13 @@ int32_t OveroSyncStart(void) overosync->active_transaction_id = 0; overosync->loading_transaction_id = 0; overosync->write_pointer = 0; + overosync->sent_bytes = 0; // Process all registered objects and connect queue for updates UAVObjIterate(®isterObject); // Start telemetry tasks - if(pios_spi_overo_id != 0) - xTaskCreate(overoSyncTask, (signed char *)"OveroSync", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &overoSyncTaskHandle); + xTaskCreate(overoSyncTask, (signed char *)"OveroSync", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &overoSyncTaskHandle); TaskMonitorAdd(TASKINFO_RUNNING_OVEROSYNC, overoSyncTaskHandle); @@ -167,6 +177,9 @@ static void overoSyncTask(void *parameters) transmitData(); + portTickType lastUpdateTime = xTaskGetTickCount(); + portTickType updateTime; + // Loop forever while (1) { // Wait for queue message @@ -177,6 +190,17 @@ static void overoSyncTask(void *parameters) //if(overosync->transaction_done) // transmitData(); + updateTime = xTaskGetTickCount(); + if(((portTickType) (updateTime - lastUpdateTime)) > 1000) { + // Update stats. This will trigger a local send event too + OveroSyncStatsData syncStats; + syncStats.Send = overosync->sent_bytes; + syncStats.Connected = syncStats.Send > 500 ? OVEROSYNCSTATS_CONNECTED_TRUE : OVEROSYNCSTATS_CONNECTED_FALSE; + OveroSyncStatsSet(&syncStats); + overosync->sent_bytes = 0; + lastUpdateTime = updateTime; + } + overosync_transfers++; } } @@ -233,7 +257,7 @@ static int32_t packData(uint8_t * data, int32_t length) overosync->write_pointer; memcpy(tx_buffer,data,length); overosync->write_pointer += length; - + overosync->sent_bytes += length; overosync->sent_objects++; xSemaphoreGive(overosync->buffer_lock); diff --git a/flight/Revolution/UAVObjects.inc b/flight/Revolution/UAVObjects.inc index 99c66962c..7a1b3e1a0 100644 --- a/flight/Revolution/UAVObjects.inc +++ b/flight/Revolution/UAVObjects.inc @@ -55,6 +55,7 @@ UAVOBJSRCFILENAMES += mixersettings UAVOBJSRCFILENAMES += mixerstatus UAVOBJSRCFILENAMES += nedaccel UAVOBJSRCFILENAMES += objectpersistence +UAVOBJSRCFILENAMES += overosyncstats UAVOBJSRCFILENAMES += positionactual UAVOBJSRCFILENAMES += positiondesired UAVOBJSRCFILENAMES += ratedesired diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro index 70937189b..d748a4301 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro @@ -37,6 +37,7 @@ HEADERS += $$UAVOBJECT_SYNTHETICS/accessorydesired.h \ $$UAVOBJECT_SYNTHETICS/systemstats.h \ $$UAVOBJECT_SYNTHETICS/systemalarms.h \ $$UAVOBJECT_SYNTHETICS/objectpersistence.h \ + $$UAVOBJECT_SYNTHETICS/overosyncstats.h \ $$UAVOBJECT_SYNTHETICS/systemsettings.h \ $$UAVOBJECT_SYNTHETICS/stabilizationsettings.h \ $$UAVOBJECT_SYNTHETICS/manualcontrolsettings.h \ @@ -90,6 +91,7 @@ SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \ $$UAVOBJECT_SYNTHETICS/systemstats.cpp \ $$UAVOBJECT_SYNTHETICS/systemalarms.cpp \ $$UAVOBJECT_SYNTHETICS/objectpersistence.cpp \ + $$UAVOBJECT_SYNTHETICS/overosyncstats.cpp \ $$UAVOBJECT_SYNTHETICS/systemsettings.cpp \ $$UAVOBJECT_SYNTHETICS/stabilizationsettings.cpp \ $$UAVOBJECT_SYNTHETICS/manualcontrolsettings.cpp \ diff --git a/shared/uavobjectdefinition/overosyncstats.xml b/shared/uavobjectdefinition/overosyncstats.xml new file mode 100644 index 000000000..8d719cffc --- /dev/null +++ b/shared/uavobjectdefinition/overosyncstats.xml @@ -0,0 +1,12 @@ + + + Maintains statistics on transfer rate to and from over + + + + + + + + +