diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp index 7f0703a4e..856fc6159 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp @@ -32,6 +32,8 @@ #include #include +#include +#include // ****************************** // constructor/destructor @@ -114,6 +116,34 @@ void UAVObjectUtilManager::transactionCompleted(UAVObject *obj, bool success) saveNextObject(); } +/** + * Get the UAV Board model, for anyone interested. Return format is: + * (Board Type << 8) + BoardRevision. + */ +int UAVObjectUtilManager::getBoardModel() +{ + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + if (!pm) + return 0; + UAVObjectManager *om = pm->getObject(); + if (!om) + return 0; + + UAVDataObject *obj = dynamic_cast(om->getObject(QString("FirmwareIAPObj"))); + // The code below will ask for the object update and wait for the updated to be received, + // or the timeout of the timer, set to 1 second. + QEventLoop loop; + connect(obj, SIGNAL(objectUpdated(UAVObject*)), &loop, SLOT(quit())); + QTimer::singleShot(1000, &loop, SLOT(quit())); // Create a timeout + obj->requestUpdate(); + loop.exec(); + + int boardType = (obj->getField("BoardType")->getValue().toInt()) << 8; + boardType += obj->getField("BoardRevision")->getValue().toInt(); + return boardType; +} + + // ****************************** // HomeLocation diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h index f4be46811..8a97b60dd 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h @@ -60,6 +60,8 @@ public: int getTelemetrySerialPortSpeed(QString &speed); int getTelemetrySerialPortSpeeds(QComboBox *comboBox); + int getBoardModel(); + private: QMutex *mutex;