GrpcPrint/PrintS/Config/ConfigManager.cpp

665 lines
20 KiB
C++
Raw Normal View History

2024-03-19 17:45:12 +08:00
#include "ConfigManager.h"
#include "dao/MachineCfgDao.h"
//#include "../GTS/GTSController.h"
#include "../global.h"
#include "../Logger.h"
#include "../Registration/aes.hpp"
#include "../LanguageManager.h"
#include <sstream>
ConfigManager::ConfigManager()
:m_pDB(nullptr)
, m_pHbdLanguageDao(nullptr)
, m_pMachineCfgDao(nullptr)
, m_pBaseConfigDao(nullptr)
, m_pAxisConfigDao(nullptr)
, m_pIOCfgDao(nullptr)
,m_pCommunicationCfgDao(nullptr)
, m_pInfoTextDao(nullptr)
, m_pAlarmCfgDao(nullptr)
, m_IOCfgWrapper(nullptr)
, m_AlarmCfgWrapper(nullptr)
, m_pSystemBaseDao(nullptr)
, m_Machine(nullptr)
, m_pParamSetCfgDao(nullptr)
//,m_pLaserCfgDao(nullptr)
,m_PrepareJobCfgDao(nullptr)
, m_IOVersionDao(nullptr)
, m_ScannerControlCfgDao(nullptr)
//, m_pServoCfgDao(nullptr)
{
}
ConfigManager::~ConfigManager()
{
//if (m_pLaserCfgDao != nullptr)delete m_pLaserCfgDao;
if (m_ScannerControlCfgDao != nullptr)delete m_ScannerControlCfgDao;
if (m_pAlarmCfgDao != nullptr)delete m_pAlarmCfgDao;
if (m_pInfoTextDao != nullptr)delete m_pInfoTextDao;
if (m_pCommunicationCfgDao != nullptr)delete m_pCommunicationCfgDao;
if (m_pIOCfgDao != nullptr)delete m_pIOCfgDao;
if (m_pAxisConfigDao != nullptr)delete m_pAxisConfigDao;
if (m_pBaseConfigDao != nullptr)delete m_pBaseConfigDao;
if (m_Machine != nullptr)delete m_Machine;
if (m_pMachineCfgDao != nullptr)delete m_pMachineCfgDao;
if (m_pHbdLanguageDao != nullptr)delete m_pHbdLanguageDao;
if (m_pSystemBaseDao != nullptr)delete m_pSystemBaseDao;
if (m_pParamSetCfgDao != nullptr)delete m_pParamSetCfgDao;
if (m_PrepareJobCfgDao != nullptr)delete m_PrepareJobCfgDao;
if (m_IOVersionDao)delete m_IOVersionDao;
if (m_pDB)delete m_pDB;
for (map<int, HbdLanguage*>::iterator it = m_LanguageMap.begin(); it != m_LanguageMap.end(); it++) {
HbdLanguage* hbdl = it->second;
delete hbdl;
hbdl = NULL;
}
m_LanguageMap.clear();
for (map<short, AxisCfg*>::iterator it = m_AxisCfgs.begin(); it != m_AxisCfgs.end(); it++) {
AxisCfg* ac = it->second;
delete ac;
ac = NULL;
}
m_AxisCfgs.clear();
if (m_IOCfgWrapper != nullptr)delete m_IOCfgWrapper;
if (m_AlarmCfgWrapper != nullptr)delete m_AlarmCfgWrapper;
/*for (map<string, ComServerCfg*>::iterator it = m_ComServerCfgMap.begin(); it != m_ComServerCfgMap.end(); it++) {
ComServerCfg* csc = it->second;
delete csc;
csc = NULL;
}
m_ComServerCfgMap.clear();*/
for (auto pps : m_ParamSetCfg.ParamSetVec)
{
std::map<string, ParamSetCfg::LaserSet*>::iterator it;
for (it = pps->LaserSetMap.begin(); it != pps->LaserSetMap.end(); it++)
delete it->second;
pps->LaserSetMap.clear();
for (unsigned int i = 0; i < pps->PowderSets.size(); i++)
delete pps->PowderSets[i];
pps->PowderSets.clear();
delete pps;
}
m_ParamSetCfg.ParamSetVec.clear();
/*for (map<int, LaserCfg*>::iterator it = m_LaserCfgs.begin(); it != m_LaserCfgs.end(); it++) {
LaserCfg* cfg = it->second;
delete cfg;
cfg = NULL;
}
m_LaserCfgs.clear();*/
}
ConfigManager* ConfigManager::GetInstance()
{
static ConfigManager manager;
return &manager;
}
void ConfigManager::Init()
2024-03-19 17:45:12 +08:00
{
string databasepath = g_AppPath + "config.hbd";
m_pDB = new SQLite::Database(databasepath, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
m_pDB->exec("PRAGMA key = '!hbd_admin'");
m_pMachineCfgDao = new MachineCfgDao(m_pDB);
m_pMachineCfgDao->CreateTable();
m_pMachineCfgDao->Find(m_MachineCfg);
2024-05-30 11:18:10 +08:00
m_Machine = Machine::CreateInstance(m_MachineCfg.m_MachineType->GetValue());
2024-03-19 17:45:12 +08:00
/*m_AxisCfgs[GTS_AXIS_ID_MOLD] = new AxisCfg(GTS_AXIS_ID_MOLD);
m_AxisCfgs[GTS_AXIS_ID_POWDER] = new AxisCfg(GTS_AXIS_ID_POWDER);
m_AxisCfgs[GTS_AXIS_ID_ARM] = new AxisCfg(GTS_AXIS_ID_ARM);*/
2024-03-26 10:33:00 +08:00
m_LoadCfg = m_Machine->CreateLoadAxisCfg();
m_MoldCfg = m_Machine->CreateMoldAxisCfg();
//m_PowderCfg= m_Machine->CreatePowderAxisCfg();
m_ArmCfg = m_Machine->CreateArmAxisCfg();
m_SupplyCfg = m_Machine->CreateSupplyAxisCfg();
m_CleanCfg = m_Machine->CreateCleanAxisCfg();
2024-03-19 17:45:12 +08:00
m_EleCfg = m_Machine->CreateEleAxisCfg();
m_AxisCfgs[GTS_AXIS_ID_MOLD] = m_MoldCfg;
m_AxisCfgs[GTS_AXIS_ID_LOAD] = m_LoadCfg;
m_AxisCfgs[GTS_AXIS_ID_ARM] = m_ArmCfg;
m_AxisCfgs[GTS_AXIS_ID_SUPPLY] = m_SupplyCfg;
m_AxisCfgs[GTS_AXIS_ID_CLEAN] = m_CleanCfg;
m_AxisCfgs[GTS_AXIS_ID_ELE] = m_EleCfg;
//m_AxisCfgs[GTS_AXIS_ID_MOLD] = m_MoldCfg;
//m_AxisCfgs[GTS_AXIS_ID_POWDER] = m_PowderCfg;
//m_AxisCfgs[GTS_AXIS_ID_ARM] = m_ArmCfg;
m_IOCfgWrapper = new IOCfgWrapper();
m_AlarmCfgWrapper = new AlarmCfgWrapper();
2024-03-26 10:33:00 +08:00
2024-03-19 17:45:12 +08:00
m_pSystemBaseDao = new SystemBaseDao(m_pDB);
m_pHbdLanguageDao = new HbdLanguageDao(m_pDB);
2024-03-26 10:33:00 +08:00
2024-03-19 17:45:12 +08:00
m_pBaseConfigDao = new BaseConfigDao(m_pDB);
m_pAxisConfigDao = new AxisCfgDao(m_pDB);
m_pIOCfgDao = new IOCfgDao(m_pDB);
m_pCommunicationCfgDao = new CommunicationCfgDao(m_pDB);
//m_pComServerDao = new ComServerDao(m_pDB);
m_pInfoTextDao = new InfoTextDao(m_pDB);
m_pAlarmCfgDao = new AlarmCfgDao(m_pDB);
m_pParamSetCfgDao = new ParamSetCfgDao(m_pDB);
2024-03-26 10:33:00 +08:00
// m_pLaserCfgDao = new LaserCfgDao(m_pDB);
2024-03-19 17:45:12 +08:00
m_ScannerControlCfgDao = new ScannerControlCfgDao(m_pDB);
m_PrepareJobCfgDao = new PrepareJobCfgDao(m_pDB);
m_IOVersionDao = new IOVersionDao(m_pDB);
2024-03-26 10:33:00 +08:00
GenerateTable();
ReadConfig();
2024-03-19 17:45:12 +08:00
}
bool ConfigManager::InitFromSetup(void)
{
string databasepath = g_AppPath + "config.hbd";
WIN32_FIND_DATA FindFileData;
HANDLE handle = FindFirstFile(databasepath.c_str(), &FindFileData);
if (handle == INVALID_HANDLE_VALUE && __argc > 1) {
2024-03-19 17:45:12 +08:00
int cnt = __argc;
2024-05-30 11:18:10 +08:00
m_MachineCfg.m_MachineType->SetValue(stoi(__wargv[1]));
2024-03-19 17:45:12 +08:00
Init();
2024-05-30 11:18:10 +08:00
m_MachineCfg.m_MachineType->SetValue(stoi(__wargv[1]));
2024-03-19 17:45:12 +08:00
if (__argc > 2)
2024-05-30 11:18:10 +08:00
m_MachineCfg.m_IOVersion->SetValue(stoi(__wargv[2]));
2024-03-19 17:45:12 +08:00
SaveConfig();
return true;
}
else {
return false;
}
2024-03-19 17:45:12 +08:00
}
void ConfigManager::GenerateTable()
{
m_pSystemBaseDao->CreateTable();
m_pHbdLanguageDao->CreateTable();
// m_pMachineCfgDao->CreateTable();
m_pBaseConfigDao->CreateTable();
m_pAxisConfigDao->CreateTable();
m_pIOCfgDao->CreateTable();
m_pCommunicationCfgDao->CreateTable();
// m_pComServerDao->CreateTable();
m_pInfoTextDao->CreateTable();
m_pAlarmCfgDao->CreateTable();
m_pParamSetCfgDao->CreateTable();
//m_pLaserCfgDao->CreateTable();
m_ScannerControlCfgDao->CreateTable();
m_PrepareJobCfgDao->CreateTable();
m_IOVersionDao->CreateTable();
}
void ConfigManager::ReadConfig()
{
m_pSystemBaseDao->Find(m_SystemBaseCfg);
m_pHbdLanguageDao->Find(m_LanguageMap);
// m_pMachineCfgDao->Find(m_MachineCfg);
m_pBaseConfigDao->FindExtCfg(m_ExtCfg);
m_pBaseConfigDao->FindRunCfg(m_RunCfg);
m_pBaseConfigDao->FindFavoriteCfg(m_FavoriteCfg);
m_pBaseConfigDao->FindPowderEstimate(m_PowderEstimateCfg);
m_pBaseConfigDao->FindRecoatCheckCfg(m_RecoatCheckCfg);
m_pBaseConfigDao->FindParamLimitCfg(m_ParamLimitCfg);
m_pBaseConfigDao->FindCameraCalibrationCfg(m_CameraCalibrationCfg);
m_pBaseConfigDao->FindInfraredTempCfg(m_InfraredTempCfg);
m_pBaseConfigDao->FindUIShowCfg(m_UIShowCfg);
2024-03-19 17:45:12 +08:00
m_pAxisConfigDao->Find(m_AxisCfgs);
m_pIOCfgDao->Find(m_IOCfgWrapper);
m_IOCfgWrapper->Init();
//m_pComServerDao->Find(m_ComServerCfgMap);
2024-05-30 11:18:10 +08:00
m_pCommunicationCfgDao->Find(m_MachineCfg.m_MachineType->GetValue());
2024-03-19 17:45:12 +08:00
m_pAlarmCfgDao->Find();
//m_pAlarmCfgDao->FindStop(m_AlarmCfgWrapper);
//m_pAlarmCfgDao->FindPause(m_AlarmCfgWrapper);
//m_pAlarmCfgDao->FindWarn(m_AlarmCfgWrapper);
m_AlarmCfgWrapper->Init();
m_pParamSetCfgDao->Find(m_ParamSetCfg);
//m_pLaserCfgDao->FindCfg();
m_ScannerControlCfgDao->FindCfg();
2024-05-30 11:18:10 +08:00
m_PrepareJobCfgDao->Find(m_MachineCfg.m_MachineType->GetValue(), m_PrepareJobCfgs);
2024-03-19 17:45:12 +08:00
m_Machine->Init();
m_Machine->BindLaser();
m_IOVersionDao->Find(m_IOVersions);
//m_pAlarmCfgDao->CheckAlarmWithCfg();
2024-03-19 17:45:12 +08:00
//m_Machine->CheckAlarm();
}
void ConfigManager::SaveConfig()
{
if (!m_pDB)
return;
SQLite::Transaction transaction(*m_pDB);
m_pBaseConfigDao->SaveExtCfg(m_ExtCfg);
m_pBaseConfigDao->SaveRunCfg(m_RunCfg);
m_pBaseConfigDao->SaveFavoriteCfg(m_FavoriteCfg);
m_pBaseConfigDao->SavePowderEstimate(m_PowderEstimateCfg);
m_pBaseConfigDao->SaveRecoatCheckCfg(m_RecoatCheckCfg);
m_pBaseConfigDao->SaveParamLimitCfg(m_ParamLimitCfg);
m_pBaseConfigDao->SaveCameraCalibrationCfg(m_CameraCalibrationCfg);
m_pBaseConfigDao->SaveInfraredTempCfg(m_InfraredTempCfg);
m_pBaseConfigDao->SaveUIShowCfg(m_UIShowCfg);
2024-03-19 17:45:12 +08:00
m_pAxisConfigDao->Save(m_AxisCfgs);
m_pCommunicationCfgDao->Save();
//m_pComServerDao->Save(m_ComServerCfgMap);
m_pMachineCfgDao->Save(m_MachineCfg);
m_pAlarmCfgDao->Save();
m_pIOCfgDao->Save(m_IOCfgWrapper->m_IOCfgMap);
m_pParamSetCfgDao->Save(m_ParamSetCfg);
//m_pLaserCfgDao->Save();
m_ScannerControlCfgDao->Save();
2024-05-30 11:18:10 +08:00
m_PrepareJobCfgDao->Save(m_MachineCfg.m_MachineType->GetValue(), m_PrepareJobCfgs);
2024-03-19 17:45:12 +08:00
transaction.commit();
}
HbdLanguage* ConfigManager::GetLanguage(int id)
{
map<int, HbdLanguage*>::iterator it = m_LanguageMap.find(id);
if (it == m_LanguageMap.end())return NULL;
return m_LanguageMap[id];
}
void ConfigManager::GetDefaultText(map<string, string>& textmap)
{
textmap.clear();
m_pInfoTextDao->Find(textmap);
}
AxisCfg* ConfigManager::GetArmCfg() {
return m_ArmCfg;
}
AxisCfg* ConfigManager::GetMoldCfg() {
return m_MoldCfg;
}
AxisCfg* ConfigManager::GetLoadCfg() {
return m_LoadCfg;
}
AxisCfg* ConfigManager::GetSupplyCfg()
{
return m_SupplyCfg;
}
void ConfigManager::Export(string &content, string file_path)
{
if ((content.size() % 16) != 0)
{
2024-05-06 10:49:15 +08:00
size_t size = content.size();
2024-03-19 17:45:12 +08:00
size += 16 - (size % 16);
content.resize(size, '\0');
}
const uint8_t crypt_key[17] = "Zdcf&mZXfNZZJ%yn";
struct AES_ctx ctx;
AES_init_ctx(&ctx, crypt_key);
for (size_t i = 0; i < content.size() / 16; i++)
AES_ECB_encrypt(&ctx, (uint8_t *)&content[i * 16]);
std::FILE *file;
fopen_s(&file, file_path.c_str(), "wb");
fwrite(content.data(), sizeof(char), content.size(), file);
fclose(file);
}
void ConfigManager::Import(string &content, string file_path)
{
std::FILE *file;
fopen_s(&file, file_path.c_str(), "rb");
if (!file)
return;
fseek(file, 0, SEEK_END);
int buf_size;
int file_size = ftell(file);
if (file_size % 16 != 0)
buf_size = file_size + 16 - (file_size % 16);
else
buf_size = file_size;
char *buffer = new char[buf_size];
fseek(file, 0, SEEK_SET);
size_t ret_code = fread(buffer, sizeof(char), file_size, file);
fclose(file);
if (ret_code != file_size)
return;
const uint8_t crypt_key[17] = "Zdcf&mZXfNZZJ%yn";
struct AES_ctx ctx;
AES_init_ctx(&ctx, crypt_key);
for (int i = 0; i < buf_size / 16; i++)
AES_ECB_decrypt(&ctx, (uint8_t *)&buffer[i * 16]);
content = (char*)buffer;
}
void ConfigManager::Export(string file_path)
{
std::stringstream ss;
m_pAlarmCfgDao->Export( ss);
m_pBaseConfigDao->ExportExtCfg(m_ExtCfg, ss);
m_pBaseConfigDao->ExportRunCfg(m_RunCfg, ss);
m_pBaseConfigDao->ExportFavoriteCfg(m_FavoriteCfg, ss);
m_pBaseConfigDao->ExportPowderEstimate(m_PowderEstimateCfg, ss);
m_pBaseConfigDao->ExportRecoatCheckCfg(m_RecoatCheckCfg, ss);
m_pBaseConfigDao->ExportParamLimitCfg(m_ParamLimitCfg, ss);
m_pAxisConfigDao->Export(m_AxisCfgs, ss);
m_pCommunicationCfgDao->Export(ss);
m_pMachineCfgDao->Export(m_MachineCfg, ss);
m_pIOCfgDao->Export(m_IOCfgWrapper->m_IOCfgMap, ss);
m_pBaseConfigDao->ExportCameraCalibrationCfg(m_CameraCalibrationCfg, ss);
//m_pLaserCfgDao->Export(ss);
m_ScannerControlCfgDao->Export(ss);
//Export(ss.str(), file_path);
}
void ConfigManager::Import(string file_path)
{
string sql;
Import(sql, file_path);
/* std::stringstream ss(sql);
string cmd;
SQLite::Transaction transaction(*m_pDB);
while (getline(ss, cmd))
{
try {
m_pDB->exec(cmd);
}
catch (SQLite::Exception &e)
{
g_log->TraceError(g_LngManager->Log_DBError->ShowText(), e.what());
2024-03-19 17:45:12 +08:00
}
};
transaction.commit();
//g_StateManager->Stop();
m_pMachineCfgDao->Find(m_MachineCfg);
m_Machine = Machine::CreateInstance(m_MachineCfg.m_MachineType);
m_pBaseConfigDao->FindExtCfg(m_ExtCfg);
m_pBaseConfigDao->FindRunCfg(m_RunCfg);
m_pBaseConfigDao->FindFavoriteCfg(m_FavoriteCfg);
m_pBaseConfigDao->FindPowderEstimate(m_PowderEstimateCfg);
m_pBaseConfigDao->FindRecoatCheckCfg(m_RecoatCheckCfg);
m_pBaseConfigDao->FindParamLimitCfg(m_ParamLimitCfg);
m_pAxisConfigDao->Find(m_AxisCfgs);
m_pCommunicationCfgDao->Find(m_MachineCfg.m_MachineType);
m_pAlarmCfgDao->Find();
//m_pAlarmCfgDao->FindStop(m_AlarmCfgWrapper);
//m_pAlarmCfgDao->FindPause(m_AlarmCfgWrapper);
//m_pAlarmCfgDao->FindWarn(m_AlarmCfgWrapper);
m_AlarmCfgWrapper->Init();
m_pLaserCfgDao->FindCfg();
SaveConfig();
// g_StateManager->Start();*/
}
void ConfigManager::ExportPC(string file_path)
{
stringstream ss;
m_ScannerControlCfgDao->ExportAllPC(ss);
//Export(ss.str(), file_path);
}
void ConfigManager::ImportPC(string file_path)
{
string sql;
Import(sql, file_path);
m_ScannerControlCfgDao->ImportAllPc(sql);
}
void ConfigManager::ExportParamSet(string file_path)
{
std::stringstream sql;
m_pParamSetCfgDao->Export(m_ParamSetCfg, sql);
////Export(sql.str(), file_path);
}
void ConfigManager::ImportParamSet(string file_path)
{
string sql;
Import(sql, file_path);
m_pParamSetCfgDao->Import(m_ParamSetCfg, sql);
}
void ConfigManager::UpdateZeroOffset(int id, long value)
{
m_pAxisConfigDao->UpdateZeroOffset(id, value);
}
vector<IOVersion*>* ConfigManager::GetIOVersions(int machineid)
{
if (m_IOVersions.find(machineid) == m_IOVersions.end()) {
return NULL;
}
return m_IOVersions[machineid];
}
2024-06-04 17:49:56 +08:00
string ConfigManager::GetIOVersionStrs(int machineid) {
if (m_IOVersions.find(machineid) == m_IOVersions.end()) {
return "";
}
string result;
auto start = m_IOVersions[machineid]->begin();
while (start != m_IOVersions[machineid]->end()) {
result += (*start)->m_VersionCode;
++start;
}
return result;
}
2024-03-19 17:45:12 +08:00
void ConfigManager::DeleteMachineIO()
{
char buffer[256];
string strsql = "DELETE FROM %s WHERE %s=%d";
sprintf_s(buffer, sizeof(buffer), strsql.c_str(), IOCfg::TABLE_NAME.c_str(), IOCfg::FIELD_MACHINE_TYPE.c_str(), m_MachineCfg.m_MachineType);
m_pDB->exec(buffer);
2024-05-06 10:49:15 +08:00
}
void ConfigManager::SendCfgToClients() {
m_ParamLimitCfgNew.SetCfg(m_ParamLimitCfg);
m_ParamLimitCfgNew.SendToClients(PARAMLIMITCFGPARAM);
m_ExtCfgNew.SetCfg(m_ExtCfg);
m_ExtCfgNew.SendToClients(EXTCFGPARAM);
2024-05-28 18:07:35 +08:00
m_RunCfg.SendToClients(RUNCFGPARAM);
m_InfraredTempCfg.SendToClients(INFRAREDTEMPCFGPARAM);
2024-05-30 11:18:10 +08:00
m_MachineCfg.SendToClients(MACHINECFGPARAM);
2024-05-30 17:25:23 +08:00
m_FavoriteCfg.SendToClients(FAVORITECFGPARAM);
2024-05-31 11:49:20 +08:00
m_CameraCalibrationCfg.SendToClients(CAMERACALIBRATIONCFGPARAM);
m_UIShowCfg.SendToClients(UISHOWCFGPARAM);
m_RecoatCheckCfg.SendToClients(RECOATCHECKCFGPARAM);
m_PowderEstimateCfg.SendToClients(POWDERESTIMATECFGPARAM);
auto commuCfgitem = m_pCommunicationCfgDao->GetCommunicationCfg()->begin();
while (commuCfgitem != m_pCommunicationCfgDao->GetCommunicationCfg()->end()) {
commuCfgitem->second->SendToClients(COMMUNICATIONCFGPARAM);
++commuCfgitem;
}
int index = 0;
auto item = m_ScannerControlCfgDao->m_ScannerControlCfgMap.begin();
while (item != m_ScannerControlCfgDao->m_ScannerControlCfgMap.end()) {
//item->second->SendToClients();
++item;
}
2024-05-06 10:49:15 +08:00
m_MoldCfg->SendToClients(MOLDCFGPARAM);
m_LoadCfg->SendToClients(LOADCFGPARAM);
m_ArmCfg->SendToClients(ARMCFGPARAM);
m_SupplyCfg->SendToClients(SUPPLYCFGPARAM);
m_CleanCfg->SendToClients(CLEANCFGPARAM);
m_EleCfg->SendToClients(ELECFGPARAM);
}
2024-06-04 17:49:56 +08:00
void ConfigManager::CallFuncs(const ReadData& rd, const list<Item>& lst, ::stream::ResponseAny** response) {
stream::ComResponce result;
ConfigFunc cfunc = (ConfigFunc)ConverType::TryToI(rd.nameKey);
switch (cfunc)
{
case SAVECONFIG:
SaveConfig(); break;
case SAVEMACHINECONFIG:
SaveMachineConfig(); break;
case DELETEMACHINEIO:
DeleteMachineIO(); break;
case CONTROLRUN:
ControlRun(rd.its); break;
2024-06-04 17:49:56 +08:00
case IOVERSIONSTR:
if (lst.front().nameKey == "index") {
result.set_data(GetIOVersionStrs(ConverType::TryToI(lst.front().strValue)));
(*response)->mutable_data()->PackFrom(result);
}
printf("IOVERSIONSTR responded...\n");
break;
case REDTESTCFGSTART:
RedTestCfgStart(); break;
case REDTESTCFGSTOP:
RedTestCfgStop(); break;
2024-06-05 23:59:04 +08:00
//case FIXPOINTDAOADD:
// FixPointDaoAdd(lst); break;
//case FIXPOINTDAODEL:
// FixPointDaoDel(lst); break;
default:
break;
}
}
2024-06-05 23:59:04 +08:00
//void ConfigManager::FixPointDaoAdd(const list<Item>& lst) {
// int scannerIndex = -1;
// FixPointCfg* fpc = new FixPointCfg();
// for (auto it = lst.begin(); it != lst.end(); ++it) {
// if (it->nameKey == "index") scannerIndex = ConverType::TryToI(it->strValue);
// if (it->nameKey == "cno") fpc->m_Cno = ConverType::TryToI(it->strValue);
// if (it->nameKey == "pointX") fpc->m_PointX = ConverType::TryToF(it->strValue);
// if (it->nameKey == "pointY") fpc->m_PointY = ConverType::TryToF(it->strValue);
// if (it->nameKey == "duration") fpc->m_Duration = (unsigned int)ConverType::TryToI(it->strValue);
// }
//
// //if (GetFixPointDao()->Add(fpc)){
// // (*m_UIController.m_ScannerCtrl->GetScanners())[scannerIndex]->GetConfig()->m_FixPointWrapper.m_Cfgs->push_back(fpc);
// //}
//}
//
//void ConfigManager::FixPointDaoDel(const list<Item>& lst) {
//
//}
2024-05-06 10:49:15 +08:00
void ConfigManager::UpdateCfg(const ReadData& rd) {
2024-05-06 10:49:15 +08:00
switch (rd.dataType)
{
case PARAMLIMITCFG:
2024-05-09 12:49:18 +08:00
m_ParamLimitCfgNew.Update(rd, PARAMLIMITCFGPARAM);
2024-05-28 18:07:35 +08:00
m_ParamLimitCfgNew.UpdateCfg(m_ParamLimitCfg); break;
2024-05-06 10:49:15 +08:00
case EXTCFG:
2024-05-09 12:49:18 +08:00
m_ExtCfgNew.Update(rd, EXTCFGPARAM);
2024-05-28 18:07:35 +08:00
m_ExtCfgNew.UpdateCfg(m_ExtCfg); break;
case RUNCFG:
m_RunCfg.Update(rd, RUNCFGPARAM); break;
case INFRAREDTEMPCFG:
m_InfraredTempCfg.Update(rd, INFRAREDTEMPCFGPARAM); break;
2024-05-30 11:18:10 +08:00
case MACHINECFG:
m_MachineCfg.Update(rd, MACHINECFGPARAM); break;
2024-05-31 11:49:20 +08:00
case FAVORITECFG:
m_FavoriteCfg.UpdateSub(rd); break;
case CAMERACALIBRATIONCFG:
m_CameraCalibrationCfg.Update(rd, CAMERACALIBRATIONCFGPARAM); break;
case UISHOWCFG:
m_UIShowCfg.Update(rd, UISHOWCFGPARAM); break;
case RECOATCHECKCFG:
m_RecoatCheckCfg.Update(rd, RECOATCHECKCFGPARAM); break;
case POWDERESTIMATECFG:
m_PowderEstimateCfg.Update(rd,POWDERESTIMATECFGPARAM); break;
case COMMUNICATIONCFG:
2024-06-04 17:49:56 +08:00
UpdateCommunicationCfg(rd); break;
2024-05-06 10:49:15 +08:00
default:
break;
}
}
void ConfigManager::UpdateCommunicationCfg(const ReadData& rd) {
auto item = m_pCommunicationCfgDao->GetCommunicationCfg()->end();
size_t pos = rd.nameKey.find_first_of("_");
string clientCode = rd.nameKey.substr(pos + 1);
if (string::npos != pos && item != m_pCommunicationCfgDao->GetCommunicationCfg()->find(clientCode)) {
(*m_pCommunicationCfgDao->GetCommunicationCfg())[clientCode]->Update(rd, COMMUNICATIONCFGPARAM);
}
else {
printf("not find this [%s] param\n", rd.nameKey.data());
}
}
void ConfigManager::ControlRun(const list<Item>& its) {
bool enable = false;
string code;
auto item = its.begin();
while (item != its.end()) {
if (item->nameKey == "enable") enable = (bool)ConverType::TryToI(item->strValue);
if (item->nameKey == "code") code = item->strValue;
}
CommunicationCfg* cCfg = nullptr;
if (m_pCommunicationCfgDao->GetCommunicationCfg()->find(code) != m_pCommunicationCfgDao->GetCommunicationCfg()->end()) {
cCfg = (*m_pCommunicationCfgDao->GetCommunicationCfg())[code];
}
if(!cCfg) return;
if (m_ComRefCfg.find(cCfg) != m_ComRefCfg.end()) {
if (enable) {
m_ComRefCfg[cCfg]->CtrlStart();
}
else {
m_ComRefCfg[cCfg]->CtrlStop();
}
}
2024-06-04 17:49:56 +08:00
}
void ConfigManager::RedTestCfgStart() {
vector<ScannerControlCfg*>* laserCfg = ConfigManager::GetInstance()->GetMatchScannerControlCfg();
for (size_t cIndex = 0; cIndex < laserCfg->size(); cIndex++) {
ScannerControlCfg* lcfg = (*laserCfg)[cIndex];
if (lcfg->m_LaserEnable && lcfg->m_LaserEnable->IsActive()) {
lcfg->m_LaserEnable->SetActive(false);
}
if (lcfg->m_LaserRed && !lcfg->m_LaserRed->IsActive()) {
lcfg->m_LaserRed->SetActive(true);
}
}
}
void ConfigManager::RedTestCfgStop() {
vector<ScannerControlCfg*>* laserCfg = ConfigManager::GetInstance()->GetMatchScannerControlCfg();
for (size_t lrIndex = 0; lrIndex < laserCfg->size(); lrIndex++) {
ScannerControlCfg* lcfg = (*laserCfg)[lrIndex];
if (lcfg->m_LaserRed && lcfg->m_LaserRed->IsActive()) {
lcfg->m_LaserRed->SetActive(false);
}
}
}