From 84882c5edbaf0bd5c8f1137cd0b61973c48c713c Mon Sep 17 00:00:00 2001 From: tangchao0503 <735056338@qq.com> Date: Mon, 1 Aug 2022 19:10:25 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E3=80=81=E5=86=99=E3=80=81=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E7=B1=BBConfigfile=EF=BC=88=E4=BD=BF=E7=94=A8libconfi?= =?UTF-8?q?g.h++=EF=BC=89;=202=E3=80=81=E6=89=93=E5=BC=80=E7=9B=B8?= =?UTF-8?q?=E6=9C=BA=E6=97=B6=EF=BC=8C=E9=80=9A=E8=BF=87Configfile?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=92=8C=E8=A7=A3=E6=9E=90=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E5=B9=B6=E4=BD=BF=E7=94=A8=EF=BC=9B?= =?UTF-8?q?=203=E3=80=81=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=80=BB=E8=BE=91bug=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 10 +- Header_Files/configfile.h | 40 ++++++ Header_Files/ximeaimager.h | 4 + Source_Files/configfile.cpp | 240 +++++++++++++++++++++++++++++++++++ Source_Files/ximeaimager.cpp | 95 +++++++------- 记录-杂七杂八.txt | 3 + 6 files changed, 338 insertions(+), 54 deletions(-) create mode 100644 Header_Files/configfile.h create mode 100644 Source_Files/configfile.cpp create mode 100644 记录-杂七杂八.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 4da79a4..f8a38b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(Qt5 REQUIRED ${QT})# include_directories(.) -include_directories(../IrisXimeaImager) +include_directories(../IrisXimeaImager/Header_Files) include_directories(../ellipse_n_sdk/SoftwareDevelopment/sbgECom/src) #include_directories(/home/rock/tc_projects/ellipse_n_sdk/SoftwareDevelopment/sbgECom/src/) include_directories(../ellipse_n_sdk/SoftwareDevelopment/sbgECom/common) @@ -46,8 +46,12 @@ add_executable(${CMAKE_PROJECT_NAME} Source_Files/utility_tc.cpp Header_Files/utility_tc.h Source_Files/ximeaimager.cpp - Header_Files/ximeaimager.h) + Header_Files/ximeaimager.h + Source_Files/configfile.cpp + Header_Files/configfile.h) qt5_use_modules(${CMAKE_PROJECT_NAME} ${QT}) target_link_libraries(${CMAKE_PROJECT_NAME} - irisXimeaImager) + irisXimeaImager + libconfig.so + libconfig++.so) diff --git a/Header_Files/configfile.h b/Header_Files/configfile.h new file mode 100644 index 0000000..b5d2b5b --- /dev/null +++ b/Header_Files/configfile.h @@ -0,0 +1,40 @@ +// +// Created by tangchao on 2022/6/28. +// + +#ifndef XIMEAIMAGERECORDER_CONFIGFILE_H +#define XIMEAIMAGERECORDER_CONFIGFILE_H + +#include +#include +#include +#include + +using namespace std; +using namespace libconfig; + +class Configfile +{ + +public: + Configfile(); + void setConfigfilePath(string configfilePath); + int parseConfigfile(); + + bool getBin(int &bin); + bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety); + bool getGainOffset(float &gain, float &offset); + + int createConfigFile(); + int updateConfigFile(); + +private: + string m_configfilePath; + Config cfg; + + + +}; + + +#endif //XIMEAIMAGERECORDER_CONFIGFILE_H diff --git a/Header_Files/ximeaimager.h b/Header_Files/ximeaimager.h index 4e6708f..3aec613 100644 --- a/Header_Files/ximeaimager.h +++ b/Header_Files/ximeaimager.h @@ -29,6 +29,8 @@ #include #include +#include "configfile.h" + #include "irisximeaimager.h" #include "math.h" #include "utility_tc.h" @@ -102,6 +104,8 @@ private: return nanosecondSystem-TimeDifferenceBetweensOSAndSbg; } + Configfile m_configfile; + public slots: void openImger(); void closeImger(); diff --git a/Source_Files/configfile.cpp b/Source_Files/configfile.cpp new file mode 100644 index 0000000..1b968c3 --- /dev/null +++ b/Source_Files/configfile.cpp @@ -0,0 +1,240 @@ +// +// Created by tangchao on 2022/6/28. +// + +#include "Header_Files/configfile.h" + +Configfile::Configfile() +{ + +} + +void Configfile::setConfigfilePath(string configfilePath) +{ + m_configfilePath = configfilePath; +} + + +int Configfile::parseConfigfile() +{ + // Read the file. If there is an error, report it and exit. + try + { + cfg.readFile(m_configfilePath); + } + catch(const FileIOException &fioex) + { + std::cerr << "I/O error while reading file." << std::endl; + return(EXIT_FAILURE); + } + catch(const ParseException &pex) + { + std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() + << " - " << pex.getError() << std::endl; + return(EXIT_FAILURE); + } +} + +bool Configfile::getBin(int &bin) +{ + try + { + bin = cfg.lookup("bin"); + + return(EXIT_SUCCESS); + } + catch(const SettingNotFoundException &nfex) + { + cerr << "No 'bin' setting in configuration file." << endl; + return(EXIT_FAILURE); + } +} + +bool Configfile::getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety) +{ + const Setting& root = cfg.getRoot(); + + // Output a list of all books in the inventory. + try + { + const Setting &effective_window = root["effective_window"]; + int count = effective_window.getLength(); + + int bin; + getBin(bin); + + const Setting &window = effective_window[bin-1]; + string name = window.getName(); + + if(!(window.lookupValue("width", width) + && window.lookupValue("offsetx", offsetx) + && window.lookupValue("height", height) + && window.lookupValue("offsety", offsety))) + { + return(EXIT_FAILURE); + } + } + catch(const SettingNotFoundException &nfex) + { + // Ignore. + int a=1; + } + + return(EXIT_SUCCESS); +} + +bool Configfile::getGainOffset(float &gain, float &offset) +{ + const Setting& root = cfg.getRoot(); + + // Output a list of all books in the inventory. + try + { + const Setting &gainOffset = root["gainOffset"]; + int count = gainOffset.getLength(); + + int bin; + getBin(bin); + + const Setting &gainOffsetSetting = gainOffset[bin-1]; + string name = gainOffsetSetting.getName(); + + if(!(gainOffsetSetting.lookupValue("gain", gain) + && gainOffsetSetting.lookupValue("offset", offset))) + { + return(EXIT_FAILURE); + } + } + catch(const SettingNotFoundException &nfex) + { + // Ignore. + int a=1; + } + + return(EXIT_SUCCESS); +} + +int Configfile::createConfigFile() +{ + using namespace std; + using namespace libconfig; + + static const char *output_file = "ximea.cfg"; + Config cfg; + + Setting &root = cfg.getRoot(); + + // Add some settings to the configuration. + Setting &bin = root.add("bin", Setting::TypeInt) = 1; + Setting &SN = root.add("SN", Setting::TypeString) = "0098"; + + Setting &effective_window = root.add("effective_window", Setting::TypeGroup); + Setting &effective_windowBin1 = effective_window.add("bin1", Setting::TypeGroup); + Setting &effective_windowBin2 = effective_window.add("bin2", Setting::TypeGroup); + + effective_windowBin1.add("width", Setting::TypeInt) = 1; + effective_windowBin1.add("offsetx", Setting::TypeInt) = 2; + effective_windowBin1.add("height", Setting::TypeInt) = 3; + effective_windowBin1.add("offsety", Setting::TypeInt) = 4; + + effective_windowBin2.add("width", Setting::TypeInt) = 5; + effective_windowBin2.add("offsetx", Setting::TypeInt) = 6; + effective_windowBin2.add("height", Setting::TypeInt) = 7; + effective_windowBin2.add("offsety", Setting::TypeInt) = 8; + + Setting &gainOffset = root.add("gainOffset", Setting::TypeGroup); + Setting &gainOffsetBin1 = gainOffset.add("bin1", Setting::TypeGroup); + Setting &gainOffsetBin2 = gainOffset.add("bin2", Setting::TypeGroup); + + gainOffsetBin1.add("gain", Setting::TypeFloat) = 9.12; + gainOffsetBin1.add("offset", Setting::TypeFloat) = -10.2; + + gainOffsetBin2.add("gain", Setting::TypeFloat) = 11.789; + gainOffsetBin2.add("offset", Setting::TypeFloat) = -12.58; + + + // Write out the new configuration. + try + { + cfg.writeFile(output_file); + cerr << "New configuration successfully written to: " << output_file << endl; + + } + catch(const FileIOException &fioex) + { + cerr << "I/O error while writing file: " << output_file << endl; + return(EXIT_FAILURE); + } + + return(EXIT_SUCCESS); +} + +int Configfile::updateConfigFile() +{ + using namespace std; + using namespace libconfig; + + static const char *output_file = "updated.cfg"; + + Config cfg; + + cfg.setOptions(Config::OptionFsync + | Config::OptionSemicolonSeparators + | Config::OptionColonAssignmentForGroups + | Config::OptionOpenBraceOnSeparateLine); + + // Read the file. If there is an error, report it and exit. + try + { + cfg.readFile("example.cfg"); + } + catch(const FileIOException &fioex) + { + std::cerr << "I/O error while reading file." << std::endl; + return(EXIT_FAILURE); + } + catch(const ParseException &pex) + { + std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() + << " - " << pex.getError() << std::endl; + return(EXIT_FAILURE); + } + + // Find the 'movies' setting. Add intermediate settings if they don't yet + // exist. + Setting &root = cfg.getRoot(); + + if(! root.exists("inventory")) + root.add("inventory", Setting::TypeGroup); + + Setting &inventory = root["inventory"]; + + if(! inventory.exists("movies")) + inventory.add("movies", Setting::TypeList); + + Setting &movies = inventory["movies"]; + + // Create the new movie entry. + Setting &movie = movies.add(Setting::TypeGroup); + + movie.add("title", Setting::TypeString) = "Buckaroo Banzai"; + movie.add("media", Setting::TypeString) = "DVD"; + movie.add("price", Setting::TypeFloat) = 12.99; + movie.add("qty", Setting::TypeInt) = 20; + + // Write out the updated configuration. + try + { + cfg.writeFile(output_file); + cerr << "Updated configuration successfully written to: " << output_file + << endl; + + } + catch(const FileIOException &fioex) + { + cerr << "I/O error while writing file: " << output_file << endl; + return(EXIT_FAILURE); + } + + return(EXIT_SUCCESS); +} diff --git a/Source_Files/ximeaimager.cpp b/Source_Files/ximeaimager.cpp index a730e4b..e33cd49 100644 --- a/Source_Files/ximeaimager.cpp +++ b/Source_Files/ximeaimager.cpp @@ -8,6 +8,11 @@ XimeaImager::XimeaImager() m_iImagerState=100; //connect(this, SIGNAL(recordFinished()),this, SLOT()); + + m_configfile.setConfigfilePath("ximea.cfg"); + m_configfile.parseConfigfile(); + +// m_configfile.createConfigFile(); } void XimeaImager::openImger() @@ -24,40 +29,22 @@ void XimeaImager::openImger() //std::cout<<"XimeaImager::openImger111111111111111111111:正在打开相机!"<