From a38c569cd00640436c2baa5fdc5b17e40e2cb904 Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Wed, 28 Sep 2011 22:09:19 +0300 Subject: [PATCH] HwSettings: move Telemetry and add GPS port speed to the HwSettings object TelemetrySettings object removed (saved 200+ bytes of RAM). Telemetry port speed moved to the HwSettings object. Added GPS port speed setting. GCS code updated to reflect changes and support both fields. --- flight/CopterControl/Makefile | 1 - flight/Modules/GPS/GPS.c | 64 ++ flight/Modules/Telemetry/telemetry.c | 57 +- .../src/plugins/config/cc_hw_settings.ui | 590 +++++++++--------- .../plugins/config/config_cc_hw_widget.cpp | 3 +- .../plugins/config/config_pro_hw_widget.cpp | 2 +- .../src/plugins/uavobjects/uavobjects.pro | 2 - shared/uavobjectdefinition/hwsettings.xml | 3 + .../uavobjectdefinition/telemetrysettings.xml | 10 - 9 files changed, 414 insertions(+), 318 deletions(-) delete mode 100644 shared/uavobjectdefinition/telemetrysettings.xml diff --git a/flight/CopterControl/Makefile b/flight/CopterControl/Makefile index 45371476e..06f21b509 100644 --- a/flight/CopterControl/Makefile +++ b/flight/CopterControl/Makefile @@ -162,7 +162,6 @@ SRC += $(OPUAVSYNTHDIR)/attitudeactual.c SRC += $(OPUAVSYNTHDIR)/manualcontrolcommand.c SRC += $(OPUAVSYNTHDIR)/i2cstats.c SRC += $(OPUAVSYNTHDIR)/watchdogstatus.c -SRC += $(OPUAVSYNTHDIR)/telemetrysettings.c SRC += $(OPUAVSYNTHDIR)/manualcontrolsettings.c SRC += $(OPUAVSYNTHDIR)/mixersettings.c SRC += $(OPUAVSYNTHDIR)/firmwareiapobj.c diff --git a/flight/Modules/GPS/GPS.c b/flight/Modules/GPS/GPS.c index 57d73fc6e..9334141dc 100644 --- a/flight/Modules/GPS/GPS.c +++ b/flight/Modules/GPS/GPS.c @@ -43,11 +43,15 @@ #include "gpssatellites.h" #include "WorldMagModel.h" #include "CoordinateConversions.h" +#include "hwsettings.h" + // **************** // Private functions static void gpsTask(void *parameters); +static void SettingsUpdatedCb(UAVObjEvent * ev); +static void updateSettings(); #ifdef PIOS_GPS_SETS_HOMELOCATION static void setHomeLocation(GPSPositionData * gpsData); @@ -116,7 +120,14 @@ int32_t GPSInitialize(void) #ifdef PIOS_GPS_SETS_HOMELOCATION HomeLocationInitialize(); #endif + HwSettingsInitialize(); + // Update GPS settings + updateSettings(); + + // Listen for settings updates, connect a callback function + HwSettingsConnectCallback(&SettingsUpdatedCb); + // TODO: Get gps settings object gpsPort = PIOS_COM_GPS; @@ -333,6 +344,59 @@ static void setHomeLocation(GPSPositionData * gpsData) // **************** +/** + * Settings callback, called each time the settings object is updated + */ +static void SettingsUpdatedCb(UAVObjEvent * ev) +{ + if (ev->obj == HwSettingsHandle()) + updateSettings(); +} + + +/** + * Update the GPS settings, called on startup and + * each time the settings object is updated + */ +static void updateSettings() +{ + // Set port + gpsPort = PIOS_COM_GPS; + + if (gpsPort) { + + // Retrieve settings + uint8_t speed; + HwSettingsGPSSpeedGet(&speed); + + // Set port speed + switch (speed) { + case HWSETTINGS_GPSSPEED_2400: + PIOS_COM_ChangeBaud(gpsPort, 2400); + break; + case HWSETTINGS_GPSSPEED_4800: + PIOS_COM_ChangeBaud(gpsPort, 4800); + break; + case HWSETTINGS_GPSSPEED_9600: + PIOS_COM_ChangeBaud(gpsPort, 9600); + break; + case HWSETTINGS_GPSSPEED_19200: + PIOS_COM_ChangeBaud(gpsPort, 19200); + break; + case HWSETTINGS_GPSSPEED_38400: + PIOS_COM_ChangeBaud(gpsPort, 38400); + break; + case HWSETTINGS_GPSSPEED_57600: + PIOS_COM_ChangeBaud(gpsPort, 57600); + break; + case HWSETTINGS_GPSSPEED_115200: + PIOS_COM_ChangeBaud(gpsPort, 115200); + break; + } + } +} + + /** * @} * @} diff --git a/flight/Modules/Telemetry/telemetry.c b/flight/Modules/Telemetry/telemetry.c index 25abf2c3a..ae989f738 100644 --- a/flight/Modules/Telemetry/telemetry.c +++ b/flight/Modules/Telemetry/telemetry.c @@ -34,7 +34,7 @@ #include "telemetry.h" #include "flighttelemetrystats.h" #include "gcstelemetrystats.h" -#include "telemetrysettings.h" +#include "hwsettings.h" // Private constants #define MAX_QUEUE_SIZE TELEM_QUEUE_SIZE @@ -65,7 +65,6 @@ static xTaskHandle telemetryTxTaskHandle; static xTaskHandle telemetryRxTaskHandle; static uint32_t txErrors; static uint32_t txRetries; -static TelemetrySettingsData settings; static uint32_t timeOfLastObjectUpdate; static UAVTalkConnection uavTalkCon; @@ -94,7 +93,7 @@ int32_t TelemetryStart(void) // Listen to objects of interest GCSTelemetryStatsConnectQueue(priorityQueue); - TelemetrySettingsConnectQueue(priorityQueue); + HwSettingsConnectQueue(priorityQueue); // Start telemetry tasks xTaskCreate(telemetryTxTask, (signed char *)"TelTx", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY_TX, &telemetryTxTaskHandle); @@ -121,7 +120,7 @@ int32_t TelemetryInitialize(void) FlightTelemetryStatsInitialize(); GCSTelemetryStatsInitialize(); - TelemetrySettingsInitialize(); + HwSettingsInitialize(); // Initialize vars timeOfLastObjectUpdate = 0; @@ -132,7 +131,7 @@ int32_t TelemetryInitialize(void) priorityQueue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(UAVObjEvent)); #endif - // Get telemetry settings object + // Update telemetry settings updateSettings(); // Initialise UAVTalk @@ -226,7 +225,7 @@ static void processObjEvent(UAVObjEvent * ev) updateTelemetryStats(); } else if (ev->obj == GCSTelemetryStatsHandle()) { gcsTelemetryStatsUpdated(); - } else if (ev->obj == TelemetrySettingsHandle()) { + } else if (ev->obj == HwSettingsHandle()) { updateSettings(); } else { // Only process event if connected to GCS or if object FlightTelemetryStats is updated @@ -514,22 +513,40 @@ static void updateTelemetryStats() */ static void updateSettings() { - // Set port - telemetryPort = PIOS_COM_TELEM_RF; + // Set port + telemetryPort = PIOS_COM_TELEM_RF; - // Retrieve settings - TelemetrySettingsGet(&settings); + if (telemetryPort) { - if (telemetryPort) { - // Set port speed - if (settings.Speed == TELEMETRYSETTINGS_SPEED_2400) PIOS_COM_ChangeBaud(telemetryPort, 2400); - else if (settings.Speed == TELEMETRYSETTINGS_SPEED_4800) PIOS_COM_ChangeBaud(telemetryPort, 4800); - else if (settings.Speed == TELEMETRYSETTINGS_SPEED_9600) PIOS_COM_ChangeBaud(telemetryPort, 9600); - else if (settings.Speed == TELEMETRYSETTINGS_SPEED_19200) PIOS_COM_ChangeBaud(telemetryPort, 19200); - else if (settings.Speed == TELEMETRYSETTINGS_SPEED_38400) PIOS_COM_ChangeBaud(telemetryPort, 38400); - else if (settings.Speed == TELEMETRYSETTINGS_SPEED_57600) PIOS_COM_ChangeBaud(telemetryPort, 57600); - else if (settings.Speed == TELEMETRYSETTINGS_SPEED_115200) PIOS_COM_ChangeBaud(telemetryPort, 115200); - } + // Retrieve settings + uint8_t speed; + HwSettingsTelemetrySpeedGet(&speed); + + // Set port speed + switch (speed) { + case HWSETTINGS_TELEMETRYSPEED_2400: + PIOS_COM_ChangeBaud(telemetryPort, 2400); + break; + case HWSETTINGS_TELEMETRYSPEED_4800: + PIOS_COM_ChangeBaud(telemetryPort, 4800); + break; + case HWSETTINGS_TELEMETRYSPEED_9600: + PIOS_COM_ChangeBaud(telemetryPort, 9600); + break; + case HWSETTINGS_TELEMETRYSPEED_19200: + PIOS_COM_ChangeBaud(telemetryPort, 19200); + break; + case HWSETTINGS_TELEMETRYSPEED_38400: + PIOS_COM_ChangeBaud(telemetryPort, 38400); + break; + case HWSETTINGS_TELEMETRYSPEED_57600: + PIOS_COM_ChangeBaud(telemetryPort, 57600); + break; + case HWSETTINGS_TELEMETRYSPEED_115200: + PIOS_COM_ChangeBaud(telemetryPort, 115200); + break; + } + } } /** diff --git a/ground/openpilotgcs/src/plugins/config/cc_hw_settings.ui b/ground/openpilotgcs/src/plugins/config/cc_hw_settings.ui index 2f849e66c..929c9053d 100644 --- a/ground/openpilotgcs/src/plugins/config/cc_hw_settings.ui +++ b/ground/openpilotgcs/src/plugins/config/cc_hw_settings.ui @@ -1,283 +1,307 @@ - - - CC_HW_Widget - - - - 0 - 0 - 517 - 487 - - - - Form - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - - - - :/configgadget/images/coptercontrol.svg - - - true - - - - - - - - - - - - - MainPort - - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - - - - - - - - - - - - - - FlexiPort - - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - RcvrPort - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - - - Telemetry speed: - - - - - - - Select the speed here. - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 75 - true - - - - - - - Qt::AutoText - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 75 - true - - - - Changes on this page only take effect after board reset or power cycle - - - true - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 32 - 32 - - - - - 32 - 32 - - - - - - - - :/core/images/helpicon.svg:/core/images/helpicon.svg - - - - 32 - 32 - - - - true - - - - - - - Send to OpenPilot but don't write in SD. -Beware of not locking yourself out! - - - true - - - - - - Apply - - - false - - - - - - - Applies and Saves all settings to SD. -Beware of not locking yourself out! - - - false - - - - - - Save - - - - - - - - - - - - - - - - + + + CC_HW_Widget + + + + 0 + 0 + 517 + 487 + + + + Form + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + :/configgadget/images/coptercontrol.svg + + + true + + + + + + + + + + + + + MainPort + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + + + + + + + + FlexiPort + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + RcvrPort + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + Telemetry speed: + + + + + + + + 55 + 0 + + + + GPS speed: + + + + + + + Select the speed here. + + + + + + + Select the speed here. + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 75 + true + + + + + + + Qt::AutoText + + + true + + + + + + + + 75 + true + + + + Changes on this page only take effect after board reset or power cycle + + + true + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + + :/core/images/helpicon.svg:/core/images/helpicon.svg + + + + 32 + 32 + + + + true + + + + + + + Send to OpenPilot but don't write in SD. +Beware of not locking yourself out! + + + true + + + + + + Apply + + + false + + + + + + + Applies and Saves all settings to SD. +Beware of not locking yourself out! + + + false + + + + + + Save + + + + + + + + + + + + + + + + diff --git a/ground/openpilotgcs/src/plugins/config/config_cc_hw_widget.cpp b/ground/openpilotgcs/src/plugins/config/config_cc_hw_widget.cpp index b6c543698..10476db26 100644 --- a/ground/openpilotgcs/src/plugins/config/config_cc_hw_widget.cpp +++ b/ground/openpilotgcs/src/plugins/config/config_cc_hw_widget.cpp @@ -40,10 +40,11 @@ ConfigCCHWWidget::ConfigCCHWWidget(QWidget *parent) : ConfigTaskWidget(parent) m_telemetry = new Ui_CC_HW_Widget(); m_telemetry->setupUi(this); setupButtons(m_telemetry->saveTelemetryToRAM,m_telemetry->saveTelemetryToSD); - addUAVObjectToWidgetRelation("TelemetrySettings","Speed",m_telemetry->telemetrySpeed); addUAVObjectToWidgetRelation("HwSettings","CC_FlexiPort",m_telemetry->cbFlexi); addUAVObjectToWidgetRelation("HwSettings","CC_MainPort",m_telemetry->cbTele); addUAVObjectToWidgetRelation("HwSettings","CC_RcvrPort",m_telemetry->cbRcvr); + addUAVObjectToWidgetRelation("HwSettings","TelemetrySpeed",m_telemetry->telemetrySpeed); + addUAVObjectToWidgetRelation("HwSettings","GPSSpeed",m_telemetry->gpsSpeed); connect(m_telemetry->cchwHelp,SIGNAL(clicked()),this,SLOT(openHelp())); enableControls(false); populateWidgets(); diff --git a/ground/openpilotgcs/src/plugins/config/config_pro_hw_widget.cpp b/ground/openpilotgcs/src/plugins/config/config_pro_hw_widget.cpp index e19be52ab..f81ba32ee 100644 --- a/ground/openpilotgcs/src/plugins/config/config_pro_hw_widget.cpp +++ b/ground/openpilotgcs/src/plugins/config/config_pro_hw_widget.cpp @@ -40,7 +40,7 @@ ConfigProHWWidget::ConfigProHWWidget(QWidget *parent) : ConfigTaskWidget(parent) m_telemetry->setupUi(this); setupButtons(m_telemetry->saveTelemetryToRAM,m_telemetry->saveTelemetryToSD); - addUAVObjectToWidgetRelation("TelemetrySettings","Speed",m_telemetry->telemetrySpeed); + addUAVObjectToWidgetRelation("HwSettings","TelemetrySpeed",m_telemetry->telemetrySpeed); enableControls(false); populateWidgets(); refreshWidgetsValues(); diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro index 63eefa5bf..511253626 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro @@ -36,7 +36,6 @@ HEADERS += $$UAVOBJECT_SYNTHETICS/accessorydesired.h \ $$UAVOBJECT_SYNTHETICS/systemstats.h \ $$UAVOBJECT_SYNTHETICS/systemalarms.h \ $$UAVOBJECT_SYNTHETICS/objectpersistence.h \ - $$UAVOBJECT_SYNTHETICS/telemetrysettings.h \ $$UAVOBJECT_SYNTHETICS/systemsettings.h \ $$UAVOBJECT_SYNTHETICS/stabilizationsettings.h \ $$UAVOBJECT_SYNTHETICS/manualcontrolsettings.h \ @@ -88,7 +87,6 @@ SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \ $$UAVOBJECT_SYNTHETICS/systemstats.cpp \ $$UAVOBJECT_SYNTHETICS/systemalarms.cpp \ $$UAVOBJECT_SYNTHETICS/objectpersistence.cpp \ - $$UAVOBJECT_SYNTHETICS/telemetrysettings.cpp \ $$UAVOBJECT_SYNTHETICS/systemsettings.cpp \ $$UAVOBJECT_SYNTHETICS/stabilizationsettings.cpp \ $$UAVOBJECT_SYNTHETICS/manualcontrolsettings.cpp \ diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index 34d18e797..4b600fd78 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -9,6 +9,9 @@ + + + diff --git a/shared/uavobjectdefinition/telemetrysettings.xml b/shared/uavobjectdefinition/telemetrysettings.xml deleted file mode 100644 index d19c03c55..000000000 --- a/shared/uavobjectdefinition/telemetrysettings.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - Select baud rate of telemetry. Warning - this must match your modem. - - - - - - -