1、调焦界面加入显示马达位置的功能;
2、添加配置文件的功能,写入自动调焦参数和轨道电机参数;
This commit is contained in:
358
HPPA/hppaConfigFile.cpp
Normal file
358
HPPA/hppaConfigFile.cpp
Normal file
@ -0,0 +1,358 @@
|
||||
//
|
||||
// Created by tangchao on 2023/3/25.
|
||||
//
|
||||
|
||||
#include "hppaConfigFile.h"
|
||||
|
||||
Configfile::Configfile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Configfile::setConfigfilePath(string configfilePath)
|
||||
{
|
||||
m_configfilePath = configfilePath;
|
||||
}
|
||||
|
||||
bool Configfile::isConfigfileExist()
|
||||
{
|
||||
QFileInfo info(QString::fromStdString(m_configfilePath));
|
||||
|
||||
return info.exists();
|
||||
}
|
||||
|
||||
bool Configfile::parseConfigfile()
|
||||
{
|
||||
// Read the file. If there is an error, report it and exit.
|
||||
try
|
||||
{
|
||||
cfg.readFile(m_configfilePath);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(const FileIOException &fioex)
|
||||
{
|
||||
std::cerr << "I/O error while reading file." << std::endl;
|
||||
return false;
|
||||
}
|
||||
catch(const ParseException &pex)
|
||||
{
|
||||
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
|
||||
<< " - " << pex.getError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Configfile::getPositionRestriction(int& max, int& min)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& autoFocus = root["autoFocus"];
|
||||
int count = autoFocus.getLength();
|
||||
|
||||
const Setting& positionRestriction = autoFocus["PositionRestriction"];
|
||||
string name = positionRestriction.getName();
|
||||
|
||||
if (!(positionRestriction.lookupValue("max", max)
|
||||
&& positionRestriction.lookupValue("min", min)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getTuningStepSize(int& coarse, int& fine)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& autoFocus = root["autoFocus"];
|
||||
int count = autoFocus.getLength();
|
||||
|
||||
const Setting& TuningStepSize = autoFocus["TuningStepSize"];
|
||||
string name = TuningStepSize.getName();
|
||||
|
||||
if (!(TuningStepSize.lookupValue("coarse", coarse)
|
||||
&& TuningStepSize.lookupValue("fine", fine)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getFitParams(float& fa, float& fb)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& autoFocus = root["autoFocus"];
|
||||
int count = autoFocus.getLength();
|
||||
|
||||
const Setting& FitParams = autoFocus["FitParams"];
|
||||
string name = FitParams.getName();
|
||||
|
||||
if (!(FitParams.lookupValue("fa", fa)
|
||||
&& FitParams.lookupValue("fb", fb)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getAutoFocusRange(int& max, int& min)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& autoFocus = root["autoFocus"];
|
||||
int count = autoFocus.getLength();
|
||||
|
||||
const Setting& AutoFocusRange = autoFocus["AutoFocusRange"];
|
||||
string name = AutoFocusRange.getName();
|
||||
|
||||
if (!(AutoFocusRange.lookupValue("max", max)
|
||||
&& AutoFocusRange.lookupValue("min", min)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getXMotorParm(float& StepAnglemar, float& Lead, int& SubdivisionMultiples, float& ScaleFactor)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& motionPlatform = root["motionPlatform"];
|
||||
int count = motionPlatform.getLength();
|
||||
|
||||
const Setting& x = motionPlatform["x"];
|
||||
string name = x.getName();
|
||||
|
||||
if (!(x.lookupValue("StepAnglemar", StepAnglemar)
|
||||
&& x.lookupValue("Lead", Lead) && x.lookupValue("SubdivisionMultiples", SubdivisionMultiples)
|
||||
&& x.lookupValue("ScaleFactor", ScaleFactor)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getYMotorParm(float& StepAnglemar, float& Lead, int& SubdivisionMultiples, float& ScaleFactor)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting& motionPlatform = root["motionPlatform"];
|
||||
int count = motionPlatform.getLength();
|
||||
|
||||
const Setting& y = motionPlatform["y"];
|
||||
string name = y.getName();
|
||||
|
||||
if (!(y.lookupValue("StepAnglemar", StepAnglemar)
|
||||
&& y.lookupValue("Lead", Lead) && y.lookupValue("SubdivisionMultiples", SubdivisionMultiples)
|
||||
&& y.lookupValue("ScaleFactor", ScaleFactor)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const SettingNotFoundException& nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getSN(string &SN)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string SN_tem = cfg.lookup("SN");
|
||||
SN = SN_tem;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
cerr << "No 'spectralBin' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Configfile::createConfigFile()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace libconfig;
|
||||
|
||||
Config cfg;
|
||||
|
||||
Setting &root = cfg.getRoot();
|
||||
|
||||
// Add some settings to the configuration.
|
||||
Setting &SN = root.add("SN", Setting::TypeString) = "2004";
|
||||
|
||||
//autoFocus
|
||||
Setting & autoFocus = root.add("autoFocus", Setting::TypeGroup);
|
||||
Setting & PositionRestriction = autoFocus.add("PositionRestriction", Setting::TypeGroup);
|
||||
Setting& TuningStepSize = autoFocus.add("TuningStepSize", Setting::TypeGroup);
|
||||
Setting& FitParams = autoFocus.add("FitParams", Setting::TypeGroup);
|
||||
Setting& AutoFocusRange = autoFocus.add("AutoFocusRange", Setting::TypeGroup);
|
||||
|
||||
Setting & PositionRestriction_max = PositionRestriction.add("max", Setting::TypeInt) = 1000;
|
||||
Setting & PositionRestriction_min = PositionRestriction.add("min", Setting::TypeInt) = 120;
|
||||
Setting& TuningStepSize_coarse = TuningStepSize.add("coarse", Setting::TypeInt) = 10;
|
||||
Setting& TuningStepSize_fine = TuningStepSize.add("fine", Setting::TypeInt) = 2;
|
||||
Setting& FitParams_fa = FitParams.add("fa", Setting::TypeFloat) = 0.0017;
|
||||
Setting& FitParams_fb = FitParams.add("fb", Setting::TypeFloat) = 0.3277;
|
||||
Setting& AutoFocusRange_max = AutoFocusRange.add("max", Setting::TypeInt) = 688;
|
||||
Setting& AutoFocusRange_min = AutoFocusRange.add("min", Setting::TypeInt) = 144;
|
||||
|
||||
//motionPlatform
|
||||
Setting& motionPlatform = root.add("motionPlatform", Setting::TypeGroup);
|
||||
Setting& x = motionPlatform.add("x", Setting::TypeGroup);
|
||||
Setting& y = motionPlatform.add("y", Setting::TypeGroup);
|
||||
|
||||
Setting& x_StepAnglemar = x.add("StepAnglemar", Setting::TypeFloat) = 1.8;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Setting& x_Lead = x.add("Lead", Setting::TypeFloat) = 13.5;//<2F><><EFBFBD>̣<EFBFBD><CCA3><EFBFBD>λ<EFBFBD><CEBB>cm
|
||||
Setting& x_SubdivisionMultiples = x.add("SubdivisionMultiples", Setting::TypeInt) = 128;//ϸ<>ֱ<EFBFBD><D6B1><EFBFBD>
|
||||
Setting& x_ScaleFactor = x.add("ScaleFactor", Setting::TypeFloat) = 1.0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Setting& y_StepAnglemar = y.add("StepAnglemar", Setting::TypeFloat) = 1.8;
|
||||
Setting& y_Lead = y.add("Lead", Setting::TypeFloat) = 13.5;
|
||||
Setting& y_SubdivisionMultiples = y.add("SubdivisionMultiples", Setting::TypeInt) = 128;
|
||||
Setting& y_ScaleFactor = y.add("ScaleFactor", Setting::TypeFloat) = 0.2;
|
||||
|
||||
// Write out the new configuration.
|
||||
try
|
||||
{
|
||||
cfg.writeFile(m_configfilePath.c_str());
|
||||
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
|
||||
|
||||
}
|
||||
catch(const FileIOException &fioex)
|
||||
{
|
||||
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool 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 false;
|
||||
}
|
||||
catch(const ParseException &pex)
|
||||
{
|
||||
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
|
||||
<< " - " << pex.getError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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 false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user