From 35eef66bfeb686a463abf40688c5c46889b0ba09 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Mon, 15 Aug 2011 10:24:37 -0500 Subject: [PATCH 1/6] OP-557: Add a UAVO access method to erase the entire flash chip. Normally not needed by users because if too much changes I change the FS magic and trigger a wipe. Possibly the erase should require a particular "magic" object id value to execute? This would make it harder to do manually through UAVOs though. --- flight/Modules/System/systemmod.c | 5 +++++ flight/PiOS/Common/pios_flashfs_objlist.c | 13 +++++++++++++ flight/PiOS/inc/pios_flashfs_objlist.h | 3 ++- shared/uavobjectdefinition/objectpersistence.xml | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index f555d227f..e985da78d 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -230,6 +230,11 @@ static void objectUpdatedCb(UAVObjEvent * ev) || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjDeleteMetaobjects(); } + } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_FULLERASE) { + retval = -1; +#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) + retval = PIOS_FLASHFS_Format(); +#endif } if(retval == 0) { objper.Operation = OBJECTPERSISTENCE_OPERATION_COMPLETED; diff --git a/flight/PiOS/Common/pios_flashfs_objlist.c b/flight/PiOS/Common/pios_flashfs_objlist.c index 08fe640c9..2b2fe06fa 100644 --- a/flight/PiOS/Common/pios_flashfs_objlist.c +++ b/flight/PiOS/Common/pios_flashfs_objlist.c @@ -116,6 +116,19 @@ int32_t PIOS_FLASHFS_Init() return 0; } +/** + * @brief Erase the whole flash chip and create the file system + * @return 0 if successful, -1 if not + */ +int32_t PIOS_FLASHFS_Format() +{ + if(PIOS_Flash_W25X_EraseChip() != 0) + return -1; + if(PIOS_FLASHFS_ClearObjectTableHeader() != 0) + return -1; + return 0; +} + /** * @brief Erase the headers for all objects in the flash chip * @return 0 if successful, -1 if not diff --git a/flight/PiOS/inc/pios_flashfs_objlist.h b/flight/PiOS/inc/pios_flashfs_objlist.h index 945df4068..f5c22d973 100644 --- a/flight/PiOS/inc/pios_flashfs_objlist.h +++ b/flight/PiOS/inc/pios_flashfs_objlist.h @@ -32,6 +32,7 @@ #include "uavobjectmanager.h" int32_t PIOS_FLASHFS_Init(); +int32_t PIOS_FLASHFS_Format(); int32_t PIOS_FLASHFS_ObjSave(UAVObjHandle obj, uint16_t instId, uint8_t * data); int32_t PIOS_FLASHFS_ObjLoad(UAVObjHandle obj, uint16_t instId, uint8_t * data); -int32_t PIOS_FLASHFS_ObjDelete(UAVObjHandle obj, uint16_t instId); \ No newline at end of file +int32_t PIOS_FLASHFS_ObjDelete(UAVObjHandle obj, uint16_t instId); diff --git a/shared/uavobjectdefinition/objectpersistence.xml b/shared/uavobjectdefinition/objectpersistence.xml index 94076de9a..aa7a58e8c 100644 --- a/shared/uavobjectdefinition/objectpersistence.xml +++ b/shared/uavobjectdefinition/objectpersistence.xml @@ -1,7 +1,7 @@ Someone who knows please enter this - + From 33e61b4405b7f05fd00119fd16d0608bcc1689f1 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Mon, 15 Aug 2011 10:55:36 -0500 Subject: [PATCH 2/6] OP-557: Make the tools erase menu item attempt to perform a full format on the flash chip first, then fall back to erasing settings via the EraseSettings object persistence. The later only removes UAVO instances that the firmware is current aware of, so can create issues when jumping between versions. --- .../src/plugins/config/configplugin.cpp | 76 ++++++++++++------- .../src/plugins/config/configplugin.h | 1 + 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configplugin.cpp b/ground/openpilotgcs/src/plugins/config/configplugin.cpp index dced1c231..622b3db9b 100644 --- a/ground/openpilotgcs/src/plugins/config/configplugin.cpp +++ b/ground/openpilotgcs/src/plugins/config/configplugin.cpp @@ -30,7 +30,7 @@ #include #include #include - +#include "objectpersistence.h" ConfigPlugin::ConfigPlugin() { @@ -58,7 +58,7 @@ bool ConfigPlugin::initialize(const QStringList& args, QString *errMsg) "ConfigPlugin.EraseAll", QList() << Core::Constants::C_GLOBAL_ID); - cmd->action()->setText("Erase all settings from board..."); + cmd->action()->setText(tr("Erase all settings from board...")); ac->menu()->addSeparator(); ac->appendGroup("Utilities"); @@ -80,6 +80,17 @@ bool ConfigPlugin::initialize(const QStringList& args, QString *errMsg) return true; } +/** + * @brief Return handle to object manager + */ +UAVObjectManager * ConfigPlugin::getObjectManager() +{ + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager * objMngr = pm->getObject(); + Q_ASSERT(objMngr); + return objMngr; +} + void ConfigPlugin::extensionsInitialized() { cmd->action()->setEnabled(false); @@ -122,18 +133,19 @@ void ConfigPlugin::eraseAllSettings() return; settingsErased = false; - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager * objMngr = pm->getObject(); - Q_ASSERT(objMngr); - ObjectPersistence* objper = dynamic_cast( objMngr->getObject(ObjectPersistence::NAME) ); + ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager()); Q_ASSERT(objper); + connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *))); - ObjectPersistence::DataFields data; - data.Operation = ObjectPersistence::OPERATION_DELETE; - data.Selection = ObjectPersistence::SELECTION_ALLSETTINGS; + + ObjectPersistence::DataFields data = objper->getData(); + data.Operation = ObjectPersistence::OPERATION_FULLERASE; + + // No need for manual updated event, this is triggered by setData + // based on UAVO meta data objper->setData(data); objper->updated(); - QTimer::singleShot(1500,this,SLOT(eraseFailed())); + QTimer::singleShot(6000,this,SLOT(eraseFailed())); } @@ -141,37 +153,47 @@ void ConfigPlugin::eraseFailed() { if (settingsErased) return; - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager * objMngr = pm->getObject(); - Q_ASSERT(objMngr); - ObjectPersistence* objper = dynamic_cast( objMngr->getObject(ObjectPersistence::NAME)); - disconnect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *))); - QMessageBox msgBox; - msgBox.setText(tr("Error trying to erase settings.")); - msgBox.setInformativeText(tr("Power-cycle your board. Settings might be inconsistent.")); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); + + ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager()); + + ObjectPersistence::DataFields data = objper->getData(); + if(data.Operation == ObjectPersistence::OPERATION_FULLERASE) { + // First attempt via flash erase failed. Fall back on erase all settings + data.Operation = ObjectPersistence::OPERATION_DELETE; + data.Selection = ObjectPersistence::SELECTION_ALLSETTINGS; + objper->setData(data); + objper->updated(); + QTimer::singleShot(1500,this,SLOT(eraseFailed())); + } else { + disconnect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *))); + QMessageBox msgBox; + msgBox.setText(tr("Error trying to erase settings.")); + msgBox.setInformativeText(tr("Power-cycle your board after removing all blades. Settings might be inconsistent.")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.exec(); + } } void ConfigPlugin::eraseDone(UAVObject * obj) { QMessageBox msgBox; - ObjectPersistence* objper = dynamic_cast(sender()); - Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0); - QString tmp = obj->getField("Operation")->getValue().toString(); - if (obj->getField("Operation")->getValue().toString().compare(QString("Delete")) == 0 ) { + ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager()); + ObjectPersistence::DataFields data = objper->getData(); + Q_ASSERT(obj->getInstID() == objper->getInstID()); + + if(data.Operation != ObjectPersistence::OPERATION_COMPLETED) { return; } disconnect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *))); - if (obj->getField("Operation")->getValue().toString().compare(QString("Completed")) == 0) { + if (data.Operation == ObjectPersistence::OPERATION_COMPLETED) { settingsErased = true; msgBox.setText(tr("Settings are now erased.")); msgBox.setInformativeText(tr("Please now power-cycle your board to complete reset.")); } else { msgBox.setText(tr("Error trying to erase settings.")); - msgBox.setInformativeText(tr("Power-cycle your board. Settings might be inconsistent.")); + msgBox.setInformativeText(tr("Power-cycle your board after removing all blades. Settings might be inconsistent.")); } msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); diff --git a/ground/openpilotgcs/src/plugins/config/configplugin.h b/ground/openpilotgcs/src/plugins/config/configplugin.h index f4fa677de..7091ad460 100644 --- a/ground/openpilotgcs/src/plugins/config/configplugin.h +++ b/ground/openpilotgcs/src/plugins/config/configplugin.h @@ -48,6 +48,7 @@ public: ConfigPlugin(); ~ConfigPlugin(); + UAVObjectManager * getObjectManager(); void extensionsInitialized(); bool initialize(const QStringList & arguments, QString * errorString); void shutdown(); From 9bba1f7ae9a6f00779c76de5f246bdd3e4b447d4 Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Fri, 19 Aug 2011 18:36:30 +0200 Subject: [PATCH 3/6] Posix: fix object initialization where necessary --- flight/Modules/Guidance/guidance.c | 2 -- flight/Modules/ManualControl/manualcontrol.c | 3 +-- flight/OpenPilot/System/pios_board_posix.c | 2 ++ 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/flight/Modules/Guidance/guidance.c b/flight/Modules/Guidance/guidance.c index d1626923c..b90303928 100644 --- a/flight/Modules/Guidance/guidance.c +++ b/flight/Modules/Guidance/guidance.c @@ -100,8 +100,6 @@ int32_t GuidanceInitialize() GuidanceSettingsInitialize(); PositionDesiredInitialize(); - ManualControlCommandInitialize(); - FlightStatusInitialize(); NedAccelInitialize(); VelocityDesiredInitialize(); diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index bdd9f6b34..ba47fd64b 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -117,8 +117,7 @@ int32_t ManualControlInitialize() FlightStatusInitialize(); StabilizationDesiredInitialize(); - // ManualControlSettingsInitialize(); // this is initialized in - // pios_board.c + ManualControlSettingsInitialize(); return 0; } diff --git a/flight/OpenPilot/System/pios_board_posix.c b/flight/OpenPilot/System/pios_board_posix.c index 2285533aa..e1e8dcc54 100644 --- a/flight/OpenPilot/System/pios_board_posix.c +++ b/flight/OpenPilot/System/pios_board_posix.c @@ -30,6 +30,7 @@ #include #include "attituderaw.h" +#include "attitudeactual.h" #include "positionactual.h" #include "velocityactual.h" @@ -177,6 +178,7 @@ void PIOS_Board_Init(void) { // Initialize these here as posix has no AHRSComms AttitudeRawInitialize(); + AttitudeActualInitialize(); VelocityActualInitialize(); PositionActualInitialize(); From 5e4941f7cbecb2181f559fd12fa2489120573b1a Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Fri, 19 Aug 2011 18:41:59 +0200 Subject: [PATCH 4/6] PiOS.posix: make PiOS.posix bail in case of a Panic with an error message --- flight/PiOS.posix/posix/pios_debug.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/flight/PiOS.posix/posix/pios_debug.c b/flight/PiOS.posix/posix/pios_debug.c index f79f2e730..5956a9d04 100644 --- a/flight/PiOS.posix/posix/pios_debug.c +++ b/flight/PiOS.posix/posix/pios_debug.c @@ -79,8 +79,15 @@ void PIOS_DEBUG_Panic(const char *msg) PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_DEBUG, "\r%s @0x%x\r", msg, lr); #endif - // Stay put - while (1) ; + // tell the user whats going on on commandline too + fprintf(stderr,"CRITICAL ERROR: %s\n",msg); + + // this helps debugging: causing a div by zero allows a backtrace + // and/or ends execution + int b = 0; + int a = (2/b); + b=a; + } /** From 2062ec0aeb5342cee0c75b848b01cb6493fa275f Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Fri, 19 Aug 2011 19:52:27 +0200 Subject: [PATCH 5/6] AHRS_COM: Initialize transpherred objects before using them --- flight/Libraries/ahrs_comm_objects.c | 1 + 1 file changed, 1 insertion(+) diff --git a/flight/Libraries/ahrs_comm_objects.c b/flight/Libraries/ahrs_comm_objects.c index e43c380e4..5fc4f1b20 100644 --- a/flight/Libraries/ahrs_comm_objects.c +++ b/flight/Libraries/ahrs_comm_objects.c @@ -79,6 +79,7 @@ CREATEHANDLE(10, FirmwareIAPObj); static void ObjectUpdatedCb(UAVObjEvent * ev); #define ADDHANDLE(idx,obj) {\ + obj##Initialize();\ int n = idx;\ objectHandles[n].data = &obj;\ objectHandles[n].uavHandle = obj##Handle();\ From 85aef9c7b46caff6e6a7913fe32117f06b53cc17 Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Fri, 19 Aug 2011 20:20:44 +0200 Subject: [PATCH 6/6] OpenPilot: bugfix: Add GPS tx buffer by default (needed until GPS has been refactored to not send or only send when configured so) --- flight/OpenPilot/System/inc/pios_config.h | 1 + flight/OpenPilot/System/pios_board.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/flight/OpenPilot/System/inc/pios_config.h b/flight/OpenPilot/System/inc/pios_config.h index 4d561382e..4e6657cef 100644 --- a/flight/OpenPilot/System/inc/pios_config.h +++ b/flight/OpenPilot/System/inc/pios_config.h @@ -60,6 +60,7 @@ //#define PIOS_INCLUDE_HCSR04 #define PIOS_INCLUDE_OPAHRS #define PIOS_INCLUDE_COM +#define PIOS_INCLUDE_GPS #define PIOS_INCLUDE_SDCARD #define PIOS_INCLUDE_SETTINGS #define PIOS_INCLUDE_FREERTOS diff --git a/flight/OpenPilot/System/pios_board.c b/flight/OpenPilot/System/pios_board.c index fbc4419a1..f4ac5c367 100644 --- a/flight/OpenPilot/System/pios_board.c +++ b/flight/OpenPilot/System/pios_board.c @@ -525,6 +525,7 @@ static const struct pios_spektrum_cfg pios_spektrum_cfg = { #define PIOS_COM_TELEM_RF_TX_BUF_LEN 192 #define PIOS_COM_GPS_RX_BUF_LEN 96 +#define PIOS_COM_GPS_TX_BUF_LEN 96 #define PIOS_COM_TELEM_USB_RX_BUF_LEN 192 #define PIOS_COM_TELEM_USB_TX_BUF_LEN 192 @@ -1074,10 +1075,12 @@ void PIOS_Board_Init(void) { PIOS_Assert(0); } uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_GPS_RX_BUF_LEN); + uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_GPS_TX_BUF_LEN); PIOS_Assert(rx_buffer); + PIOS_Assert(tx_buffer); if (PIOS_COM_Init(&pios_com_gps_id, &pios_usart_com_driver, pios_usart_gps_id, rx_buffer, PIOS_COM_GPS_RX_BUF_LEN, - NULL, 0)) { + tx_buffer, PIOS_COM_GPS_TX_BUF_LEN)) { PIOS_Assert(0); } }