#include "ConfigParser_DJI.h" ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////M300 ZZ_ConfigParser_M300RTK::ZZ_ConfigParser_M300RTK(QObject* parent /*= nullptr*/) { m_bInit = false; //return 0; } ZZ_ConfigParser_M300RTK::~ZZ_ConfigParser_M300RTK() { } int ZZ_ConfigParser_M300RTK::GetParams(AppRegInfo& struAppRegInfo, HardwareInfo& struHardwareInfo,UIConfig& struUIConfig) { Initialize("/home/DJI/Settings/"); LoadParams(); struAppRegInfo = m_struAppRegInfo; struHardwareInfo = m_struHardwareInfo; struUIConfig = m_struUIConfig; return 0; } int ZZ_ConfigParser_M300RTK::UpdateUIConfig(UIConfig struUIConfig) { m_pqfM300ConfigFiles[2]->setValue(QString("PSDK/CaptureMode"), struUIConfig.sCaptureMode); m_pqfM300ConfigFiles[2]->setValue(QString("PSDK/SamplingRate"), struUIConfig.sSamplingRate); m_pqfM300ConfigFiles[2]->setValue(QString("PSDK/DecisionHeight"), struUIConfig.sDecisionHeight); } int ZZ_ConfigParser_M300RTK::Initialize(QString qstrConfigFolderPath) { if (m_bInit) { return 0; } QDir qdConfigFiles(qstrConfigFolderPath); if (!qdConfigFiles.exists()) { qDebug() << "ZZ_ConfigParser_M300: Func Initialize. Dir not exists"; return 1; } qdConfigFiles.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); qdConfigFiles.setSorting(QDir::DirsFirst); QFileInfoList qfList = qdConfigFiles.entryInfoList(); if (qfList.size() < 1) { qDebug() << "ZZ_ConfigParser_M300:Func Initialize. Empty folder"; return 2; } int i = 0; int j = 0; do { QFileInfo qfInfo = qfList.at(i); bool bisDir = qfInfo.isDir(); if (bisDir) { continue; } else { if (qfInfo.fileName() == "AppInfoConfig.ini") { //QSettings qsTemp(qfInfo.filePath(), QSettings::Format::IniFormat); m_pqfM300ConfigFiles[0] = new QSettings(qfInfo.filePath(), QSettings::Format::IniFormat); qDebug() << qfInfo.filePath(); j++; } if (qfInfo.fileName() == "HardwareSettings.ini") { //m_qfM300ConfigFiles[1].setUserIniPath(qfInfo.filePath()); m_pqfM300ConfigFiles[1] = new QSettings(qfInfo.filePath(), QSettings::Format::IniFormat); qDebug() << qfInfo.filePath(); j++; } if (qfInfo.fileName() == "SystemSettings.ini") { m_pqfM300ConfigFiles[2] = new QSettings(qfInfo.filePath(), QSettings::Format::IniFormat); //m_qfM300ConfigFiles[2].setUserIniPath(qfInfo.filePath()); qDebug() << qfInfo.filePath(); j++; } //qDebug() << qfInfo.filePath() << ":" << qfInfo.fileName(); } ++i; } while (i < qfList.size()); if (j != 3) { qDebug() << "ZZ_ConfigParser_M300:Func Initialize. File count not match"; return 3; } m_bInit = true; return 0; } int ZZ_ConfigParser_M300RTK::LoadParams() { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QString qstrUSER_APP_NAME = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_APP_NAME"),"Error").toString(); qDebug() << qstrUSER_APP_NAME; if (qstrUSER_APP_NAME=="Error") { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_NAME not load"; return 1; } QString qstrUSER_APP_ID = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_APP_ID"), "Error").toString(); qDebug() << qstrUSER_APP_ID; if (qstrUSER_APP_ID == "Error") { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_ID not load"; return 1; } QString qstrUSER_APP_KEY = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_APP_KEY"), "Error").toString(); qDebug() << qstrUSER_APP_KEY; if (qstrUSER_APP_KEY == "Error") { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_KEY not load"; return 1; } QString qstrUSER_APP_LICENSE = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_APP_LICENSE"), "Error").toString(); qDebug() << qstrUSER_APP_LICENSE; if (qstrUSER_APP_LICENSE == "Error") { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_KEY not load"; return 1; } QString qstrUSER_DEVELOPER_ACCOUNT = m_pqfM300ConfigFiles[0]->value(QString("DJI/USER_DEVELOPER_ACCOUNT"), "Error").toString(); qDebug() << qstrUSER_DEVELOPER_ACCOUNT; if (qstrUSER_DEVELOPER_ACCOUNT == "Error") { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_APP_KEY not load"; return 1; } m_struAppRegInfo.qstrUserAppAcc = qstrUSER_DEVELOPER_ACCOUNT; m_struAppRegInfo.qstrUserAppID = qstrUSER_APP_ID; m_struAppRegInfo.qstrUserAppKey = qstrUSER_APP_KEY; m_struAppRegInfo.qstrUserAppLic = qstrUSER_APP_LICENSE; m_struAppRegInfo.qstrUserAppName = qstrUSER_APP_NAME; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QString qstrUSER_BAUD_RATE = m_pqfM300ConfigFiles[1]->value(QString("COMPORT/USER_BAUD_RATE"),"NULL").toString(); qDebug() << qstrUSER_BAUD_RATE; if (qstrUSER_BAUD_RATE == "NULL") { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.USER_BAUD_RATE not load"; return 1; } int iCONFIG_HARDWARE_CONNECTION = m_pqfM300ConfigFiles[1]->value(QString("ADV MODE/CONFIG_HARDWARE_CONNECTION"),10000).toInt(); qDebug() << iCONFIG_HARDWARE_CONNECTION; if (iCONFIG_HARDWARE_CONNECTION == 10000) { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.CONFIG_HARDWARE_CONNECTION not load"; return 1; } m_struHardwareInfo.enumHCM = HardwareConnectionMode(iCONFIG_HARDWARE_CONNECTION); m_struHardwareInfo.qstrBaudRate = qstrUSER_BAUD_RATE; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int iCaptureMode = m_pqfM300ConfigFiles[2]->value(QString("PSDK/CaptureMode"), -1).toInt(); qDebug() << iCaptureMode; if (iCaptureMode == -1) { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.CaptureMode not load"; return 1; } m_struUIConfig.sCaptureMode = (short)iCaptureMode; int iSamplingRate = m_pqfM300ConfigFiles[2]->value(QString("PSDK/SamplingRate"), -1).toInt(); qDebug() << iSamplingRate; if (iSamplingRate == -1) { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.SamplingRate not load"; return 1; } m_struUIConfig.sSamplingRate = (short)iSamplingRate; int iDecisionHeight = m_pqfM300ConfigFiles[2]->value(QString("PSDK/DecisionHeight"), -1).toInt(); qDebug() << iDecisionHeight; if (iDecisionHeight == -1) { qDebug() << "ZZ_ConfigParser_M300:Func LoadParams.DecisionHeight not load"; return 1; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////M350RTK ZZ_ConfigParser_M350RTK::ZZ_ConfigParser_M350RTK(QObject* parent) { m_bInit = false; } ZZ_ConfigParser_M350RTK::~ZZ_ConfigParser_M350RTK() { } int ZZ_ConfigParser_M350RTK::Initialize(QString qstrConfigFolderPath) { if (m_bInit) { return 0; } QDir qdConfigFiles(qstrConfigFolderPath); if (!qdConfigFiles.exists()) { qDebug() << "ZZ_ConfigParser_M350RTK: Func Initialize. Dir not exists"; return 1; } qdConfigFiles.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); qdConfigFiles.setSorting(QDir::DirsFirst); QFileInfoList qfList = qdConfigFiles.entryInfoList(); if (qfList.size() < 1) { qDebug() << "ZZ_ConfigParser_M350RTK:Func Initialize. Empty folder"; return 2; } int i = 0; int j = 0; do { QFileInfo qfInfo = qfList.at(i); bool bisDir = qfInfo.isDir(); if (bisDir) { continue; } else { if (qfInfo.fileName() == "AppInfoConfig.ini") { //QSettings qsTemp(qfInfo.filePath(), QSettings::Format::IniFormat); m_pqfM350ConfigFiles[0] = new QSettings(qfInfo.filePath(), QSettings::Format::IniFormat); qDebug() << qfInfo.filePath(); j++; } if (qfInfo.fileName() == "HardwareSettings.ini") { //m_qfM300ConfigFiles[1].setUserIniPath(qfInfo.filePath()); m_pqfM350ConfigFiles[1] = new QSettings(qfInfo.filePath(), QSettings::Format::IniFormat); qDebug() << qfInfo.filePath(); j++; } //qDebug() << qfInfo.filePath() << ":" << qfInfo.fileName(); } ++i; } while (i < qfList.size()); if (j != 2) { qDebug() << "ZZ_ConfigParser_M350RTK:Func Initialize. File count not match"; return 3; } m_bInit = true; return 0; } int ZZ_ConfigParser_M350RTK::LoadParams() { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QString qstrUSER_APP_NAME = m_pqfM350ConfigFiles[0]->value(QString("DJI/USER_APP_NAME"), "Error").toString(); qDebug() << qstrUSER_APP_NAME; if (qstrUSER_APP_NAME == "Error") { qDebug() << "ZZ_ConfigParser_M350RTK:Func LoadParams.USER_APP_NAME not load"; return 1; } QString qstrUSER_APP_ID = m_pqfM350ConfigFiles[0]->value(QString("DJI/USER_APP_ID"), "Error").toString(); qDebug() << qstrUSER_APP_ID; if (qstrUSER_APP_ID == "Error") { qDebug() << "ZZ_ConfigParser_M350RTK:Func LoadParams.USER_APP_ID not load"; return 1; } QString qstrUSER_APP_KEY = m_pqfM350ConfigFiles[0]->value(QString("DJI/USER_APP_KEY"), "Error").toString(); qDebug() << qstrUSER_APP_KEY; if (qstrUSER_APP_KEY == "Error") { qDebug() << "ZZ_ConfigParser_M350RTK:Func LoadParams.USER_APP_KEY not load"; return 1; } QString qstrUSER_APP_LICENSE = m_pqfM350ConfigFiles[0]->value(QString("DJI/USER_APP_LICENSE"), "Error").toString(); qDebug() << qstrUSER_APP_LICENSE; if (qstrUSER_APP_LICENSE == "Error") { qDebug() << "ZZ_ConfigParser_M350RTK:Func LoadParams.USER_APP_KEY not load"; return 1; } QString qstrUSER_DEVELOPER_ACCOUNT = m_pqfM350ConfigFiles[0]->value(QString("DJI/USER_DEVELOPER_ACCOUNT"), "Error").toString(); qDebug() << qstrUSER_DEVELOPER_ACCOUNT; if (qstrUSER_DEVELOPER_ACCOUNT == "Error") { qDebug() << "ZZ_ConfigParser_M350RTK:Func LoadParams.USER_APP_KEY not load"; return 1; } m_struAppRegInfo.qstrUserAppAcc = qstrUSER_DEVELOPER_ACCOUNT; m_struAppRegInfo.qstrUserAppID = qstrUSER_APP_ID; m_struAppRegInfo.qstrUserAppKey = qstrUSER_APP_KEY; m_struAppRegInfo.qstrUserAppLic = qstrUSER_APP_LICENSE; m_struAppRegInfo.qstrUserAppName = qstrUSER_APP_NAME; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QString qstrUSER_BAUD_RATE = m_pqfM350ConfigFiles[1]->value(QString("COMPORT/USER_BAUD_RATE"), "NULL").toString(); qDebug() << qstrUSER_BAUD_RATE; if (qstrUSER_BAUD_RATE == "NULL") { qDebug() << "ZZ_ConfigParser_M350RTK:Func LoadParams.USER_BAUD_RATE not load"; return 1; } int iCONFIG_HARDWARE_CONNECTION = m_pqfM350ConfigFiles[1]->value(QString("ADV MODE/CONFIG_HARDWARE_CONNECTION"), 10000).toInt(); qDebug() << iCONFIG_HARDWARE_CONNECTION; if (iCONFIG_HARDWARE_CONNECTION == 10000) { qDebug() << "ZZ_ConfigParser_M350RTK:Func LoadParams.CONFIG_HARDWARE_CONNECTION not load"; return 1; } m_struHardwareInfo.enumHCM = HardwareConnectionMode(iCONFIG_HARDWARE_CONNECTION); m_struHardwareInfo.qstrBaudRate = qstrUSER_BAUD_RATE; QString qstrWindSensorPort = m_pqfM350ConfigFiles[1]->value(QString("SENSOR/WIND"), "NULL").toString(); qDebug() << qstrWindSensorPort; if (qstrWindSensorPort == "NULL") { qDebug() << "ZZ_ConfigParser_M350RTK:Func LoadParams.qstrWindSensorPort not load"; return 1; } QString qstrGasSensorPort = m_pqfM350ConfigFiles[1]->value(QString("SENSOR/GAS"), "NULL").toString(); qDebug() << qstrGasSensorPort; if (qstrGasSensorPort == "NULL") { qDebug() << "ZZ_ConfigParser_M350RTK:Func LoadParams.qstrGasSensorPort not load"; return 1; } m_struSensorPortInfo.qstrGasSensorPort = qstrGasSensorPort; m_struSensorPortInfo.qstrWindSensorPort = qstrWindSensorPort; return 0; } int ZZ_ConfigParser_M350RTK::GetParams(AppRegInfo& struAppRegInfo, HardwareInfo& struHardwareInfo, SensorPort& struSensorPortInfo) { Initialize("/home/DJI/Settings/"); LoadParams(); struAppRegInfo = m_struAppRegInfo; struHardwareInfo = m_struHardwareInfo; struSensorPortInfo = m_struSensorPortInfo; return 0; }