Commit b2b422c3 authored by Don Gagne's avatar Don Gagne

parent 9eb431f5
......@@ -18,16 +18,17 @@
QGC_LOGGING_CATEGORY(QGCSerialPortInfoLog, "QGCSerialPortInfoLog")
bool QGCSerialPortInfo::_jsonLoaded = false;
const char* QGCSerialPortInfo::_jsonFileTypeValue = "USBBoardInfo";
const char* QGCSerialPortInfo::_jsonBoardInfoKey = "boardInfo";
const char* QGCSerialPortInfo::_jsonBoardFallbackKey = "boardFallback";
const char* QGCSerialPortInfo::_jsonVendorIDKey = "vendorID";
const char* QGCSerialPortInfo::_jsonProductIDKey = "productID";
const char* QGCSerialPortInfo::_jsonBoardClassKey = "boardClass";
const char* QGCSerialPortInfo::_jsonNameKey = "name";
const char* QGCSerialPortInfo::_jsonRegExpKey = "regExp";
const char* QGCSerialPortInfo::_jsonAndroidOnlyKey = "androidOnly";
bool QGCSerialPortInfo::_jsonLoaded = false;
const char* QGCSerialPortInfo::_jsonFileTypeValue = "USBBoardInfo";
const char* QGCSerialPortInfo::_jsonBoardInfoKey = "boardInfo";
const char* QGCSerialPortInfo::_jsonBoardDescriptionFallbackKey = "boardDescriptionFallback";
const char* QGCSerialPortInfo::_jsonBoardManufacturerFallbackKey = "boardManufacturerFallback";
const char* QGCSerialPortInfo::_jsonVendorIDKey = "vendorID";
const char* QGCSerialPortInfo::_jsonProductIDKey = "productID";
const char* QGCSerialPortInfo::_jsonBoardClassKey = "boardClass";
const char* QGCSerialPortInfo::_jsonNameKey = "name";
const char* QGCSerialPortInfo::_jsonRegExpKey = "regExp";
const char* QGCSerialPortInfo::_jsonAndroidOnlyKey = "androidOnly";
const QGCSerialPortInfo::BoardClassString2BoardType_t QGCSerialPortInfo::_rgBoardClass2BoardType[] = {
{ "Pixhawk", QGCSerialPortInfo::BoardTypePixhawk },
......@@ -37,8 +38,9 @@ const QGCSerialPortInfo::BoardClassString2BoardType_t QGCSerialPortInfo::_rgBoar
{ "OpenPilot", QGCSerialPortInfo::BoardTypeOpenPilot },
};
QList<QGCSerialPortInfo::BoardInfo_t> QGCSerialPortInfo::_boardInfoList;
QList<QGCSerialPortInfo::BoardFallback_t> QGCSerialPortInfo::_boardFallbackList;
QList<QGCSerialPortInfo::BoardInfo_t> QGCSerialPortInfo::_boardInfoList;
QList<QGCSerialPortInfo::BoardRegExpFallback_t> QGCSerialPortInfo::_boardDescriptionFallbackList;
QList<QGCSerialPortInfo::BoardRegExpFallback_t> QGCSerialPortInfo::_boardManufacturerFallbackList;
QGCSerialPortInfo::QGCSerialPortInfo(void) :
QSerialPortInfo()
......@@ -90,8 +92,9 @@ void QGCSerialPortInfo::_loadJsonData(void)
// Validate root object keys
QList<JsonHelper::KeyValidateInfo> rootKeyInfoList = {
{ _jsonBoardInfoKey, QJsonValue::Array, true },
{ _jsonBoardFallbackKey, QJsonValue::Array, true },
{ _jsonBoardInfoKey, QJsonValue::Array, true },
{ _jsonBoardDescriptionFallbackKey, QJsonValue::Array, true },
{ _jsonBoardManufacturerFallbackKey, QJsonValue::Array, true },
};
if (!JsonHelper::validateKeys(json, rootKeyInfoList, errorString)) {
qWarning() << errorString;
......@@ -143,7 +146,7 @@ void QGCSerialPortInfo::_loadJsonData(void)
{ _jsonAndroidOnlyKey, QJsonValue::Bool, false },
};
QJsonArray rgBoardFallback = json[_jsonBoardFallbackKey].toArray();
QJsonArray rgBoardFallback = json[_jsonBoardDescriptionFallbackKey].toArray();
for (int i=0; i<rgBoardFallback.count(); i++) {
const QJsonValue& jsonValue = rgBoardFallback[i];
if (!jsonValue.isObject()) {
......@@ -157,17 +160,44 @@ void QGCSerialPortInfo::_loadJsonData(void)
return;
}
BoardFallback_t boardFallback;
boardFallback.regExp = fallbackObject[_jsonRegExpKey].toString();
BoardRegExpFallback_t boardFallback;
boardFallback.regExp = fallbackObject[_jsonRegExpKey].toString();
boardFallback.androidOnly = fallbackObject[_jsonAndroidOnlyKey].toBool(false);
boardFallback.boardType = _boardClassStringToType(fallbackObject[_jsonBoardClassKey].toString());
boardFallback.boardType = _boardClassStringToType(fallbackObject[_jsonBoardClassKey].toString());
if (boardFallback.boardType == BoardTypeUnknown) {
qWarning() << "Bad board class" << fallbackObject[_jsonBoardClassKey].toString();
return;
}
_boardFallbackList.append(boardFallback);
_boardDescriptionFallbackList.append(boardFallback);
}
rgBoardFallback = json[_jsonBoardManufacturerFallbackKey].toArray();
for (int i=0; i<rgBoardFallback.count(); i++) {
const QJsonValue& jsonValue = rgBoardFallback[i];
if (!jsonValue.isObject()) {
qWarning() << "Entry in boardFallback array is not object";
return;
}
QJsonObject fallbackObject = jsonValue.toObject();
if (!JsonHelper::validateKeys(fallbackObject, fallbackKeyInfoList, errorString)) {
qWarning() << errorString;
return;
}
BoardRegExpFallback_t boardFallback;
boardFallback.regExp = fallbackObject[_jsonRegExpKey].toString();
boardFallback.androidOnly = fallbackObject[_jsonAndroidOnlyKey].toBool(false);
boardFallback.boardType = _boardClassStringToType(fallbackObject[_jsonBoardClassKey].toString());
if (boardFallback.boardType == BoardTypeUnknown) {
qWarning() << "Bad board class" << fallbackObject[_jsonBoardClassKey].toString();
return;
}
_boardManufacturerFallbackList.append(boardFallback);
}
}
......@@ -176,7 +206,6 @@ QGCSerialPortInfo::BoardType_t QGCSerialPortInfo::_boardClassStringToType(const
for (size_t j=0; j<sizeof(_rgBoardClass2BoardType)/sizeof(_rgBoardClass2BoardType[0]); j++) {
if (boardClass == _rgBoardClass2BoardType[j].classString) {
return _rgBoardClass2BoardType[j].boardType;
break;
}
}
......@@ -204,16 +233,31 @@ bool QGCSerialPortInfo::getBoardInfo(QGCSerialPortInfo::BoardType_t& boardType,
}
if (boardType == BoardTypeUnknown) {
// Fall back to port name matching which could lead to incorrect board mapping. But in some cases the
// vendor and product id do not come through correctly so this is used as a last chance detection method.
for (int i=0; i<_boardFallbackList.count(); i++) {
const BoardFallback_t& boardFallback = _boardFallbackList[i];
// Fall back to port description matching and then manufactrure name matching
for (int i=0; i<_boardDescriptionFallbackList.count(); i++) {
const BoardRegExpFallback_t& boardFallback = _boardDescriptionFallbackList[i];
if (description().contains(QRegExp(boardFallback.regExp, Qt::CaseInsensitive))) {
#ifndef __android
if (boardFallback.androidOnly) {
continue;
}
#endif
boardType = boardFallback.boardType;
name = _boardTypeToString(boardType);
return true;
}
}
for (int i=0; i<_boardManufacturerFallbackList.count(); i++) {
const BoardRegExpFallback_t& boardFallback = _boardManufacturerFallbackList[i];
if (manufacturer().contains(QRegExp(boardFallback.regExp, Qt::CaseInsensitive))) {
#ifndef __android
if (boardFallback.androidOnly) {
continue;
}
#endif
boardType = boardFallback.boardType;
name = _boardTypeToString(boardType);
......
......@@ -68,7 +68,7 @@ private:
QString regExp;
BoardType_t boardType;
bool androidOnly;
} BoardFallback_t;
} BoardRegExpFallback_t;
static void _loadJsonData(void);
static BoardType_t _boardClassStringToType(const QString& boardClass);
......@@ -77,7 +77,8 @@ private:
static bool _jsonLoaded;
static const char* _jsonFileTypeValue;
static const char* _jsonBoardInfoKey;
static const char* _jsonBoardFallbackKey;
static const char* _jsonBoardDescriptionFallbackKey;
static const char* _jsonBoardManufacturerFallbackKey;
static const char* _jsonVendorIDKey;
static const char* _jsonProductIDKey;
static const char* _jsonBoardClassKey;
......@@ -87,6 +88,7 @@ private:
static const BoardClassString2BoardType_t _rgBoardClass2BoardType[BoardTypeUnknown];
static QList<BoardInfo_t> _boardInfoList;
static QList<BoardFallback_t> _boardFallbackList;
static QList<BoardRegExpFallback_t> _boardDescriptionFallbackList;
static QList<BoardRegExpFallback_t> _boardManufacturerFallbackList;
};
......@@ -20,8 +20,6 @@
{ "vendorID": 9900, "productID": 22, "boardClass": "Pixhawk", "name": "Crazyflie 2" },
{ "vendorID": 9900, "productID": 1, "boardClass": "Pixhawk", "name": "Omnibus F4 SD" },
{ "vendorID": 8137, "productID": 28, "boardClass": "Pixhawk", "name": "PX4 NXPHlite v3.x" },
{ "vendorID": 1155, "productID": 22336, "boardClass": "Pixhawk", "name": "ArduPilot ChibiOS" },
{ "vendorID": 4617, "productID": 22336, "boardClass": "Pixhawk", "name": "ArduPilot ChibiOS" },
{ "vendorID": 9900, "productID": 21, "boardClass": "PX4 Flow", "name": "PX4 Flow" },
......@@ -29,17 +27,17 @@
{ "vendorID": 1027, "productID": 24577, "boardClass": "SiK Radio", "name": "SiK Radio", "comment": "3DR Radio on FTDI" },
{ "vendorID": 4292, "productID": 60000, "boardClass": "SiK Radio", "name": "SiK Radio", "comment": "SILabs Radio" },
{ "vendorID": 5446, "productID": 424, "boardClass": "RTK GPS", "name": "U-blox RTK GPS", "comment": "U-blox RTK GPS (M8P)" },
{ "vendorID": 5446, "productID": 425, "boardClass": "RTK GPS", "name": "U-blox RTK GPS", "comment": "U-blox RTK GPS (F9P)" },
{ "vendorID": 1317, "productID": 42151, "boardClass": "RTK GPS", "name": "Trimble RTK GPS", "comment": "Trimble RTK GPS" },
{ "vendorID": 5418, "productID": 34240, "boardClass": "RTK GPS", "name": "Septentrio RTK GPS", "comment": "Septentrio RTK GPS" },
{ "vendorID": 5446, "productID": 424, "boardClass": "RTK GPS", "name": "U-blox RTK GPS", "comment": "U-blox RTK GPS (M8P)" },
{ "vendorID": 5446, "productID": 425, "boardClass": "RTK GPS", "name": "U-blox RTK GPS", "comment": "U-blox RTK GPS (F9P)" },
{ "vendorID": 1317, "productID": 42151, "boardClass": "RTK GPS", "name": "Trimble RTK GPS" },
{ "vendorID": 5418, "productID": 34240, "boardClass": "RTK GPS", "name": "Septentrio RTK GPS" },
{ "vendorID": 8352, "productID": 16732, "boardClass": "OpenPilot", "name": "OpenPilot OPLink" },
{ "vendorID": 8352, "productID": 16733, "boardClass": "OpenPilot", "name": "OpenPilot CC3D" },
{ "vendorID": 8352, "productID": 16734, "boardClass": "OpenPilot", "name": "OpenPilot Revolution" },
{ "vendorID": 8352, "productID": 16848, "boardClass": "OpenPilot", "name": "Taulabs Sparky2" }
],
"boardFallback": [
"boardDescriptionFallback": [
{ "regExp": "^PX4 FMU v5.x$", "boardClass": "Pixhawk" },
{ "regExp": "^PX4 BL FMU v5.x$", "boardClass": "Pixhawk" },
{ "regExp": "^PX4 FMU v4.x PRO$", "boardClass": "Pixhawk" },
......@@ -64,5 +62,11 @@
{ "regExp": "PX4.*Flow", "boardClass": "PX4 Flow" },
{ "regExp": "^FT231X USB UART$", "boardClass": "SiK Radio" },
{ "regExp": "USB UART$", "boardClass": "SiK Radio", "androidOnly": true, "comment": "Very broad fallback, too dangerous for non-android" }
],
"boardManufacturerFallback": [
{ "regExp": "^ArduPilot$", "boardClass": "Pixhawk" },
{ "regExp": "^Hex/ProfiCNC$", "boardClass": "Pixhawk" },
{ "regExp": "^Holybro$", "boardClass": "Pixhawk" }
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment