#include "ComServer.h" #include "../global.h" ComServer::ComServer() :m_TempCtrlClient(nullptr) , m_LaserChillerClient(nullptr) //, m_PurifierChillerClient(nullptr) ,m_UPSClient(nullptr) ,m_OxygenClient(nullptr) , m_SimpleSupplyClient(nullptr) //,m_PowderCarClient(nullptr) , m_PowerMeterClient(nullptr) , m_ScannerPowerClient(nullptr) { m_AlarmCfgWrapper = ConfigManager::GetInstance()->GetAlarmCfg(); } ComServer::~ComServer() { if (m_TempCtrlClient != nullptr) m_TempCtrlClient->SetRunFlag(false); if (m_PowerMeterClient != nullptr) m_PowerMeterClient->SetRunFlag(false); if (m_ScannerPowerClient)m_ScannerPowerClient->SetRunFlag(false); for (size_t i = 0; i < m_LaserClients.size(); i++) { m_LaserClients[i]->SetRunFlag(false); } if(m_OxygenClient)m_OxygenClient->SetRunFlag(false); if (m_LaserChillerClient)m_LaserChillerClient->SetRunFlag(false); //if (m_PurifierChillerClient)m_PurifierChillerClient->SetRunFlag(false); if (m_UPSClient)m_UPSClient->SetRunFlag(false); if (m_SimpleSupplyClient)m_SimpleSupplyClient->SetRunFlag(false); //if (m_PowderCarClient)m_PowderCarClient->SetRunFlag(false); if (m_TempCtrlClient)delete m_TempCtrlClient; if(m_OxygenClient)delete m_OxygenClient; if (m_UPSClient)delete m_UPSClient; if (m_LaserChillerClient)delete m_LaserChillerClient; //if (m_PurifierChillerClient)delete m_PurifierChillerClient; if (m_SimpleSupplyClient)delete m_SimpleSupplyClient; //if (m_PowderCarClient)delete m_PowderCarClient; if (m_ScannerPowerClient)delete m_ScannerPowerClient; if (m_PowerMeterClient)delete m_PowerMeterClient; for (size_t i = 0; i < m_LaserClients.size(); i++) { delete m_LaserClients[i]; } m_LaserClients.clear(); } void ComServer::Init() { m_MachineCfg = ConfigManager::GetInstance()->GetMachineCfg(); m_ExtCfg = ConfigManager::GetInstance()->GetExtCfg(); m_Machine = ConfigManager::GetInstance()->GetMachine(); WORD wVersionRequested = MAKEWORD(2, 2); CSocketHandle::InitLibrary(wVersionRequested); //map* cfgs = ConfigManager::GetInstance()->GetComCfg(); map* communicationCfg = ConfigManager::GetInstance()->GetCommunicationCfg(); if (communicationCfg->find("PLATE_TEMP") != communicationCfg->end()) { m_TempCtrlClient = new TempCtrlClient((*communicationCfg)["PLATE_TEMP"]); m_TempCtrlClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_TempCtrlClient->GetConfig(), m_TempCtrlClient); } if (communicationCfg->find("OXYGEN") != communicationCfg->end()) { m_OxygenClient= new OxygenClient((*communicationCfg)["OXYGEN"]); m_OxygenClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_OxygenClient->GetConfig(), m_OxygenClient); } if (communicationCfg->find("LASER_CHILLER") != communicationCfg->end()) { m_LaserChillerClient = new ChillerClient((*communicationCfg)["LASER_CHILLER"],&m_ExtCfg->m_LaserChillerType); m_LaserChillerClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_LaserChillerClient->GetConfig(), m_LaserChillerClient); } /*if (communicationCfg->find("PURIFIER_CHILLER") != communicationCfg->end()) { m_PurifierChillerClient = new ChillerClient((*communicationCfg)["PURIFIER_CHILLER"],&m_ExtCfg->m_PurifierChillerType); m_PurifierChillerClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_PurifierChillerClient->GetConfig(), m_PurifierChillerClient); }*/ if (communicationCfg->find("UPS") != communicationCfg->end()) { m_UPSClient = new UPSClient((*communicationCfg)["UPS"]); m_UPSClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_UPSClient->GetConfig(), m_UPSClient); } if (communicationCfg->find("LASER1") != communicationCfg->end()) { //IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER1"], m_AlarmCfgWrapper->m_Laser1ComAlarm); //m_LaserClients.push_back(client); //client->Init(); //ConfigManager::GetInstance()->AddComRefCfg(client->GetConfig(), client); } if (communicationCfg->find("LASER2") != communicationCfg->end()) { //IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER2"], m_AlarmCfgWrapper->m_Laser2ComAlarm); //m_LaserClients.push_back(client); //client->Init(); //ConfigManager::GetInstance()->AddComRefCfg(client->GetConfig(), client); } if (communicationCfg->find("LASER3") != communicationCfg->end()) { //IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER3"], m_AlarmCfgWrapper->m_Laser3ComAlarm); //m_LaserClients.push_back(client); //client->Init(); //ConfigManager::GetInstance()->AddComRefCfg(client->GetConfig(), client); } if (communicationCfg->find("LASER4") != communicationCfg->end()) { //IPGLaserClientV1* client = new IPGLaserClientV1((*communicationCfg)["LASER4"], m_AlarmCfgWrapper->m_Laser4ComAlarm); //m_LaserClients.push_back(client); //client->Init(); //ConfigManager::GetInstance()->AddComRefCfg(client->GetConfig(), client); } if (communicationCfg->find("SIMPLE_SUPPLY") != communicationCfg->end()) { if (m_MachineCfg->m_SupplyMachineVersion == MachineCfg::VERSION_1_0) { m_SimpleSupplyClient = new PowderSupplySimpleClient((*communicationCfg)["SIMPLE_SUPPLY"]); } else if (m_MachineCfg->m_SupplyMachineVersion == MachineCfg::VERSION_2_1) { m_SimpleSupplyClient = new PowderSupplySimpleClient2((*communicationCfg)["SIMPLE_SUPPLY"]); } else if (m_MachineCfg->m_SupplyMachineVersion == MachineCfg::VERSION_2_2) { m_SimpleSupplyClient = new PowderSupplySimpleClient3((*communicationCfg)["SIMPLE_SUPPLY"]); } else { m_SimpleSupplyClient = new PowderSupplySimpleClient2((*communicationCfg)["SIMPLE_SUPPLY"]); } m_SimpleSupplyClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_SimpleSupplyClient->GetConfig(), m_SimpleSupplyClient); } /*if (communicationCfg->find("WEIGHT_CAR") != communicationCfg->end()) { m_PowderCarClient = new PowderCarClient((*communicationCfg)["WEIGHT_CAR"]); m_PowderCarClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_PowderCarClient->GetConfig(), m_PowderCarClient); }*/ if (communicationCfg->find("POWER_METER") != communicationCfg->end()) { m_PowerMeterClient = new PowerMeterClient((*communicationCfg)["POWER_METER"]); m_PowerMeterClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_PowerMeterClient->GetConfig(), m_PowerMeterClient); } if (communicationCfg->find("SCANNER_POWER") != communicationCfg->end()) { m_ScannerPowerClient = new ScannerPowerClient((*communicationCfg)["SCANNER_POWER"]); //m_ScannerPowerClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_ScannerPowerClient->GetConfig(), m_ScannerPowerClient); } } void ComServer::Startup() { if (m_TempCtrlClient != nullptr) { if (m_TempCtrlClient->GetConfig()->m_Enable)m_TempCtrlClient->Startup(); } if (m_OxygenClient) { if (m_OxygenClient->GetConfig()->m_Enable)m_OxygenClient->Startup(); } if (m_LaserChillerClient) { if (m_LaserChillerClient->GetConfig()->m_Enable)m_LaserChillerClient->Startup(); } //if (m_PurifierChillerClient) //{ // if (m_PurifierChillerClient->GetConfig()->m_Enable)m_PurifierChillerClient->Startup(); //} if (m_UPSClient) { if (m_UPSClient->GetConfig()->m_Enable)m_UPSClient->Startup(); } for (size_t i = 0; i < m_LaserClients.size(); i++) { if (m_LaserClients[i]->GetConfig()->m_Enable)m_LaserClients[i]->Startup(); } if (m_SimpleSupplyClient) { if (m_SimpleSupplyClient->GetConfig()->m_Enable)m_SimpleSupplyClient->Startup(); } //if (m_PowderCarClient) { // if (m_PowderCarClient->GetConfig()->m_Enable)m_PowderCarClient->Startup(); //} if (m_ScannerPowerClient) { if (m_ScannerPowerClient->GetConfig()->m_Enable)m_ScannerPowerClient->Startup(); } if (m_PowerMeterClient) { if (m_PowerMeterClient->GetConfig()->m_Enable)m_PowerMeterClient->Startup(); } } void ComServer::SendToClients() { m_LaserChillerClient->SendToClients(); m_UPSClient->SendToClients(); m_TempCtrlClient->SendToClients(); m_OxygenClient->SendToClients(); vector m_LaserClients; PowderSupplySimpleClient* m_SimpleSupplyClient; ScannerPowerClient* m_ScannerPowerClient; m_PowerMeterClient->SendToClients(); }