#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_TempHumidityUnitClient(nullptr) , m_BusChillerClient(nullptr) , m_WaterTempClient(nullptr) { m_AlarmCfgWrapper = ConfigManager::GetInstance()->GetAlarmCfg(); } ComServer::~ComServer() { if (m_WaterTempClient)m_WaterTempClient->SetRunFlag(false); 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_BusChillerClient)m_BusChillerClient->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_TempHumidityUnitClient)m_TempHumidityUnitClient->SetRunFlag(false); if (m_WaterTempClient)delete m_WaterTempClient; 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_BusChillerClient)delete m_BusChillerClient; 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]; } if (m_TempHumidityUnitClient)delete m_TempHumidityUnitClient; 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("BUS_CHILLER") != communicationCfg->end()) { m_BusChillerClient = new ChillerClient((*communicationCfg)["BUS_CHILLER"], &m_ExtCfg->m_LaserChillerType); m_BusChillerClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_BusChillerClient->GetConfig(), m_BusChillerClient); } /*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()) { CreateLaserClient("LASER1", m_AlarmCfgWrapper->m_Laser1ComAlarm); } if (communicationCfg->find("LASER2") != communicationCfg->end()) { CreateLaserClient("LASER2", m_AlarmCfgWrapper->m_Laser2ComAlarm); } if (communicationCfg->find("LASER3") != communicationCfg->end()) { CreateLaserClient("LASER3", m_AlarmCfgWrapper->m_Laser3ComAlarm); } if (communicationCfg->find("LASER4") != communicationCfg->end()) { CreateLaserClient("LASER4", m_AlarmCfgWrapper->m_Laser4ComAlarm); } if (communicationCfg->find("LASER5") != communicationCfg->end()) { CreateLaserClient("LASER5", m_AlarmCfgWrapper->m_Laser5ComAlarm); } if (communicationCfg->find("LASER6") != communicationCfg->end()) { CreateLaserClient("LASER6", m_AlarmCfgWrapper->m_Laser6ComAlarm); } if (communicationCfg->find("LASER7") != communicationCfg->end()) { CreateLaserClient("LASER7", m_AlarmCfgWrapper->m_Laser7ComAlarm); } if (communicationCfg->find("LASER8") != communicationCfg->end()) { CreateLaserClient("LASER8", m_AlarmCfgWrapper->m_Laser8ComAlarm); } if (communicationCfg->find("SIMPLE_SUPPLY") != communicationCfg->end()) { if (m_MachineCfg->m_SupplyMachineVersion->GetValue() == MachineCfg::VERSION_1_0) { m_SimpleSupplyClient = new PowderSupplySimpleClient((*communicationCfg)["SIMPLE_SUPPLY"]); } else if (m_MachineCfg->m_SupplyMachineVersion->GetValue() == MachineCfg::VERSION_2_1) { m_SimpleSupplyClient = new PowderSupplySimpleClient2((*communicationCfg)["SIMPLE_SUPPLY"]); } else if (m_MachineCfg->m_SupplyMachineVersion->GetValue() == 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); } if (communicationCfg->find("TEMP_HUMIDITY_UNIT") != communicationCfg->end()) { m_TempHumidityUnitClient = new TempHumidityUnit((*communicationCfg)["TEMP_HUMIDITY_UNIT"]); m_TempHumidityUnitClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_TempHumidityUnitClient->GetConfig(), m_TempHumidityUnitClient); } if (communicationCfg->find("PIPE_WATER_TEMP") != communicationCfg->end()) { m_WaterTempClient = new WaterTempClient((*communicationCfg)["PIPE_WATER_TEMP"]); m_WaterTempClient->Init(); ConfigManager::GetInstance()->AddComRefCfg(m_WaterTempClient->GetConfig(), m_WaterTempClient); } } 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_BusChillerClient) { if (m_BusChillerClient->GetConfig()->m_Enable)m_BusChillerClient->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(); } if (m_TempHumidityUnitClient) { if (m_TempHumidityUnitClient->GetConfig()->m_Enable)m_TempHumidityUnitClient->Startup(); } if (m_WaterTempClient) { if (m_WaterTempClient->GetConfig()->m_Enable)m_WaterTempClient->Startup(); } } void ComServer::CreateLaserClient(string strFlag, AlarmCfg* alarm) { map* communicationCfg = ConfigManager::GetInstance()->GetCommunicationCfg(); TcpClient* client = NULL; switch (m_ExtCfg->m_LaserType) { case ExtCfg::IPG: { client = new IPGLaserClient((*communicationCfg)[strFlag], alarm); }break; case ExtCfg::XC: { client = new CXLaserClient((*communicationCfg)[strFlag], alarm); }break; case ExtCfg::IPG_V1: { client = new IPGLaserClientV1((*communicationCfg)[strFlag], alarm); }break; case ExtCfg::CX_FLAT: { client = new CXFlatLaserClient((*communicationCfg)[strFlag], alarm); }break; default:client = new IPGLaserClientV1((*communicationCfg)[strFlag], alarm); } m_LaserClients.push_back(client); client->Init(); ConfigManager::GetInstance()->AddComRefCfg(client->GetConfig(), client); } void ComServer::Shutdown() { if(m_TempCtrlClient) m_TempCtrlClient->Shutdown(); if (m_OxygenClient) m_OxygenClient->Shutdown(); if (m_BusChillerClient) m_BusChillerClient->Shutdown(); if (m_UPSClient) m_UPSClient->Shutdown(); for (size_t i = 0; i < m_LaserClients.size(); i++) { if (m_LaserClients[i])m_LaserClients[i]->Shutdown(); } if(m_SimpleSupplyClient) m_SimpleSupplyClient->Shutdown(); if (m_ScannerPowerClient) m_ScannerPowerClient->Shutdown(); if (m_PowerMeterClient) m_PowerMeterClient->Shutdown(); if (m_TempHumidityUnitClient) m_TempHumidityUnitClient->Shutdown(); if (m_WaterTempClient) m_WaterTempClient->Shutdown(); if (m_PowderCarClient) m_PowderCarClient->Shutdown(); } void ComServer::SendToClients() { if(m_BusChillerClient) m_BusChillerClient->SendToClients(LASERCHILLER); if(m_UPSClient) m_UPSClient->SendToClients(UPSPARAM); if(m_TempCtrlClient) m_TempCtrlClient->SendToClients(TEMPCTRLPARAM); if(m_OxygenClient) m_OxygenClient->SendToClients(OXYGENPARAM); for (size_t i = 0; i < m_LaserClients.size(); ++i) { if(m_LaserClients[i]) m_LaserClients[i]->SendToClients(LASERPARAM,"_"+to_string(i)); } if (m_SimpleSupplyClient) { if (m_MachineCfg->m_SupplyMachineVersion->GetValue() == MachineCfg::VERSION_1_0) { m_SimpleSupplyClient->SendToClients(SIMPLESUPPLYPARAM_V10); } else if (m_MachineCfg->m_SupplyMachineVersion->GetValue() == MachineCfg::VERSION_2_1) { m_SimpleSupplyClient->SendToClients(SIMPLESUPPLYPARAM_V21); } else if (m_MachineCfg->m_SupplyMachineVersion->GetValue() == MachineCfg::VERSION_2_2) { m_SimpleSupplyClient->SendToClients(SIMPLESUPPLYPARAM_V22); } else { m_SimpleSupplyClient->SendToClients(SIMPLESUPPLYPARAM_V21); } } if(m_ScannerPowerClient) m_ScannerPowerClient->SendToClients(SCANNERPOWERPARAM); if(m_PowerMeterClient) m_PowerMeterClient->SendToClients(POWERMETERPARAM); }