diff --git a/PrintS/Communication/BaseClient.cpp b/PrintS/Communication/BaseClient.cpp index fb9484b..8e4fe65 100644 --- a/PrintS/Communication/BaseClient.cpp +++ b/PrintS/Communication/BaseClient.cpp @@ -128,7 +128,7 @@ void BaseClient::UpdateCycleCommands() void BaseClient::InsertMp(void* startPtr, size_t count) { size_t ptrSize = sizeof(nullptr); //指针大小 - for (int i = 0; i < count; ++i) { + for (size_t i = 0; i < count; ++i) { BaseData* bd = *((BaseData**)((char*)startPtr + ptrSize * i)); if (m_baseMp.find(bd->GetCode()) != m_baseMp.end()) { printf("%s is repeated...\n", bd->GetCode().data()); diff --git a/PrintS/Communication/BaseData.h b/PrintS/Communication/BaseData.h index d3abd93..ce90d3b 100644 --- a/PrintS/Communication/BaseData.h +++ b/PrintS/Communication/BaseData.h @@ -12,6 +12,7 @@ public: virtual void SetValue(unsigned short us) {} virtual void SetValue(short s) {} virtual void SetValue(bool b) {} + virtual void SetValue(const string& str) {} //virtual void GetValue(DATATYPE& dataType, float& f) {} //virtual void GetValue(DATATYPE& dataType, int& i) {} @@ -162,4 +163,19 @@ public: virtual std::string GetValueStr() { return to_string(m_value); } private: UCHAR m_value; +}; + +class StrData : public BaseData { +public: + StrData(const std::string& code, const std::string& context) + : BaseData(code, context), m_value("") { + } + ~StrData() {} + + void SetValue(const std::string& str) { m_value = str; } + DATATYPE GetDataType() { return iSTRING; } + //std::string GetValue() { return m_value; } + virtual std::string GetValueStr() { return m_value; } +private: + string m_value; }; \ No newline at end of file diff --git a/PrintS/Communication/ComServer.cpp b/PrintS/Communication/ComServer.cpp index 9b74671..7150f1a 100644 --- a/PrintS/Communication/ComServer.cpp +++ b/PrintS/Communication/ComServer.cpp @@ -195,3 +195,16 @@ void ComServer::Startup() 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(); +} \ No newline at end of file diff --git a/PrintS/Communication/ComServer.h b/PrintS/Communication/ComServer.h index abc8b94..de7b7b6 100644 --- a/PrintS/Communication/ComServer.h +++ b/PrintS/Communication/ComServer.h @@ -23,7 +23,8 @@ public: void Init(); void Startup(); - + void SendToClients(); + public: TempCtrlClient* m_TempCtrlClient; OxygenClient* m_OxygenClient; diff --git a/PrintS/Communication/OxygenClient.cpp b/PrintS/Communication/OxygenClient.cpp index 5896ab9..b515c08 100644 --- a/PrintS/Communication/OxygenClient.cpp +++ b/PrintS/Communication/OxygenClient.cpp @@ -1,4 +1,4 @@ -#include "OxygenClient.h" +#include "OxygenClient.h" #include "Modbus.h" #include #include "../SystemInfo.h" @@ -8,6 +8,11 @@ OxygenClient::OxygenClient(CommunicationCfg* pconfig) :TcpClient(pconfig) { m_Freq = 100; m_ExtCfg = ConfigManager::GetInstance()->GetExtCfg(); + + //size_t ptrSize = sizeof(nullptr); //指针大小 + //void* startPtr = &m_DoluyoChillerStat.m_startFlag + 1; + //size_t count = ((size_t)&m_DoluyoChillerStat.m_endFlag - (size_t)&startPtr) / ptrSize; + //InsertMp(startPtr, count); } OxygenClient::~OxygenClient() @@ -16,6 +21,22 @@ OxygenClient::~OxygenClient() //OutputDebugString("oxygen close\n"); } + +void OxygenClient::AddToBaseMp(int i, Oxygenstat* stat) { + size_t ptrSize = sizeof(nullptr); //指针大小 + void* startPtr = &stat->m_startFlag + 1; + size_t count = ((size_t)&stat->m_endFlag - (size_t)&startPtr) / ptrSize; + for (size_t i = 0; i < count; ++i) { + BaseData* bd = *((BaseData**)((char*)startPtr + ptrSize * i)); + string code = bd->GetCode() + "_" + to_string(i); //区分key,添加上"_i" + if (m_baseMp.find(code) != m_baseMp.end()) { + printf("%s is repeated...\n", code.c_str()); + } + else { m_baseMp.insert(make_pair(code, bd)); } + } + +} + void OxygenClient::InitCommand() { map tref; @@ -25,6 +46,7 @@ void OxygenClient::InitCommand() tref[4] = m_ExtCfg->m_CleanBoxOxygenSensorType; for (int i = 1; i <= 4;i++) { Oxygenstat* stat = new Oxygenstat(); + AddToBaseMp(i, stat); //添加到map m_Oxygens[i] = stat; switch (tref[i]) { case ExtCfg::MOT500_LOW: { @@ -98,11 +120,11 @@ void OxygenClient::ProcPointInfo(void* pobject, Command* pcommand) Oxygenstat* stat = pOD->m_Oxygens[addr]; EnterCriticalSection(&pOD->m_ValueCS); - stat->scale = scale; + stat->scale->SetValue(scale); switch (unit) { - case 0:stat->valueUnit = "PPM"; break; - case 1:stat->valueUnit = "VOL"; break; - case 2:stat->valueUnit = "LEL"; break; + case 0:stat->valueUnit ->SetValue("PPM"); break; + case 1:stat->valueUnit->SetValue("VOL"); break; + case 2:stat->valueUnit->SetValue("LEL"); break; } LeaveCriticalSection(&pOD->m_ValueCS); } @@ -118,7 +140,7 @@ void OxygenClient::PorcConcentrationValue(void* pobject, Command* pcommand) Oxygenstat* stat = pOD->m_Oxygens[addr]; if (stat->scale == 0)return; EnterCriticalSection(&pOD->m_ValueCS); - stat->concentrationValue = (float)concentrationValue / stat->scale; + stat->concentrationValue->SetValue((float)concentrationValue / stat->scale->GetValue()); LeaveCriticalSection(&pOD->m_ValueCS); } @@ -133,8 +155,8 @@ void OxygenClient::ProcTempInfo(void* pobject, Command* pcommand) if (pOD->m_Oxygens.find(addr) == pOD->m_Oxygens.end())return; Oxygenstat* stat = pOD->m_Oxygens[addr]; EnterCriticalSection(&pOD->m_ValueCS); - stat->tempValue = (float)tempValue / 10.0f; - stat->humidityValue = (float)humidityValue / 100.0f; + stat->tempValue->SetValue((float)tempValue / 10.0f); + stat->humidityValue->SetValue((float)humidityValue / 100.0f); LeaveCriticalSection(&pOD->m_ValueCS); } @@ -252,7 +274,7 @@ void OxygenClient::PorcOxygenValue(void* pobject, Command* pcommand) if (pOD->m_Oxygens.find(addr) == pOD->m_Oxygens.end())return; int value = ((rseq[3] & 0xff) << 24) + ((rseq[4] & 0xff) << 16) + ((rseq[5] & 0xff) << 8) + (rseq[6] & 0xff); EnterCriticalSection(&pOD->m_ValueCS); - pOD->m_Oxygens[addr]->concentrationValue= (float)value / 100.0f; + pOD->m_Oxygens[addr]->concentrationValue->SetValue((float)value / 100.0f); LeaveCriticalSection(&pOD->m_ValueCS); } @@ -277,17 +299,17 @@ void OxygenClient::ProcNewVersion(void* pobject, Command* pcommand) } Oxygenstat* stat = pOD->m_Oxygens[addr]; EnterCriticalSection(&pOD->m_ValueCS); - stat->scale = scale; + stat->scale->SetValue(scale); switch (unit) { - case 0:stat->valueUnit = "PPM"; break; - case 1:stat->valueUnit = "VOL"; break; - case 2:stat->valueUnit = "LEL"; break; + case 0:stat->valueUnit->SetValue("PPM"); break; + case 1:stat->valueUnit->SetValue("VOL"); break; + case 2:stat->valueUnit->SetValue("LEL"); break; } - if(stat->scale!=0)stat->concentrationValue = (float)concentrationValue / stat->scale; - else stat->concentrationValue = (float)concentrationValue; - stat->concentrationAgValue = concentrationAgValue; - stat->tempValue = (float)tempValue / 10.0f; - stat->humidityValue = (float)humidityValue / 1000.0f; + if(stat->scale!=0)stat->concentrationValue->SetValue((float)concentrationValue / stat->scale->GetValue()); + else stat->concentrationValue->SetValue((float)concentrationValue); + stat->concentrationAgValue->SetValue(concentrationAgValue); + stat->tempValue->SetValue((float)tempValue / 10.0f); + stat->humidityValue->SetValue((float)humidityValue / 1000.0f); LeaveCriticalSection(&pOD->m_ValueCS); } \ No newline at end of file diff --git a/PrintS/Communication/OxygenClient.h b/PrintS/Communication/OxygenClient.h index 690ed90..0ca8d63 100644 --- a/PrintS/Communication/OxygenClient.h +++ b/PrintS/Communication/OxygenClient.h @@ -1,28 +1,41 @@ -#pragma once +#pragma once #include "BaseClient.h" //#include "../config/ConfigManager.h" #include #include "../config/bean/ExtCfg.h" + +#pragma pack(1) class Oxygenstat { public: - explicit Oxygenstat() { - concentrationValue = 0.0f; - valueUnit = ""; - scale = 1; - tempValue = 0.0f; - humidityValue = 0.0f; - concentrationAgValue = 0.0f; + explicit Oxygenstat() + : concentrationValue(new FloatData("concentrationValue",u8"浓度值")) + , valueUnit(new StrData("valueUnit",u8"浓度单位")) + , scale(new IntData("scale",u8"数值放大倍数")) + , tempValue(new FloatData("tempValue",u8"温度值")) + , humidityValue(new FloatData("humidityValue",u8"湿度值")) + , concentrationAgValue(new FloatData("concentrationAgValue",u8"模拟量")) + { + //concentrationValue = 0.0f; + //valueUnit = ""; + //scale = 1; + //tempValue = 0.0f; + //humidityValue = 0.0f; + //concentrationAgValue = 0.0f; } public: BaseStat baseStat; - float concentrationValue; //Ũֵ - string valueUnit; //Ũȵλ - int scale; //ֵŴ - float tempValue; //¶ֵ - float humidityValue; //ʪֵ - float concentrationAgValue; //ģ + + char m_startFlag; + FloatData* concentrationValue; //浓度值 + StrData* valueUnit; //浓度单位 + IntData* scale; //数值放大倍数 + FloatData* tempValue; //温度值 + FloatData* humidityValue; //湿度值 + FloatData* concentrationAgValue; //模拟量 + char m_endFlag; }; +#pragma pack() class OxygenClient :public TcpClient { @@ -40,7 +53,7 @@ protected: virtual void ReadTimeoutProc(Command* pcommand); virtual void ReadSuccessProc(int rlength, unsigned char* buffer, Command* pcommand); - + void AddToBaseMp(int i, Oxygenstat* stat); private: void static PorcOxygenValue(void* pobject, Command* pcommand); void static ProcPointInfo(void* pobject, Command* pcommand); diff --git a/PrintS/Communication/PowerMeterClient.cpp b/PrintS/Communication/PowerMeterClient.cpp index c50c7db..cffecc3 100644 --- a/PrintS/Communication/PowerMeterClient.cpp +++ b/PrintS/Communication/PowerMeterClient.cpp @@ -73,8 +73,8 @@ void PowerMeterClient::ProcUnitValue(void* pobject, Command* pcommand) unsigned char* rseq = pcommand->m_RespSeq; EnterCriticalSection(&pmc->m_ValueCS); - pmc->m_State.irAt =(float) ((rseq[3] & 0xff) << 8) + (rseq[4] & 0xff); - pmc->m_State.urAt = (((rseq[5] & 0xff) << 8) + (rseq[6] & 0xff))*0.1f; + pmc->m_State.irAt ->SetValue((float) ((rseq[3] & 0xff) << 8) + (rseq[4] & 0xff)); + pmc->m_State.urAt->SetValue((((rseq[5] & 0xff) << 8) + (rseq[6] & 0xff)) * 0.1f); LeaveCriticalSection(&pmc->m_ValueCS); } @@ -89,9 +89,10 @@ void PowerMeterClient::PorcPowerValue(void* pobject, Command* pcommand) q1Eq.Desc(&rseq[43]); EnterCriticalSection(&pmc->m_ValueCS); - pmc->m_State.impEp = impEp.fValue*pmc->m_State.urAt*pmc->m_State.irAt; - pmc->m_State.expEp = expEp.fValue*pmc->m_State.urAt*pmc->m_State.irAt; - pmc->m_State.q1Eq = q1Eq.fValue*pmc->m_State.urAt*pmc->m_State.irAt; + float urat = pmc->m_State.urAt->GetValue(), irat = pmc->m_State.irAt->GetValue(); + pmc->m_State.impEp->SetValue(impEp.fValue * urat * irat); + pmc->m_State.expEp->SetValue(expEp.fValue * urat * irat); + pmc->m_State.q1Eq->SetValue(q1Eq.fValue * urat * irat); LeaveCriticalSection(&pmc->m_ValueCS); } @@ -105,10 +106,12 @@ void PowerMeterClient::PorcPowerValue2(void* pobject, Command* pcommand) q3Eq.Desc(&rseq[23]); q4Eq.Desc(&rseq[43]); + EnterCriticalSection(&pmc->m_ValueCS); - pmc->m_State.q2Eq = q2Eq.fValue*pmc->m_State.urAt*pmc->m_State.irAt; - pmc->m_State.q3Eq = q3Eq.fValue*pmc->m_State.urAt*pmc->m_State.irAt; - pmc->m_State.q4Eq = q4Eq.fValue*pmc->m_State.urAt*pmc->m_State.irAt; + float urat = pmc->m_State.urAt->GetValue(), irat = pmc->m_State.irAt->GetValue(); + pmc->m_State.q2Eq->SetValue(q2Eq.fValue * urat * irat); + pmc->m_State.q3Eq->SetValue(q3Eq.fValue * urat * irat); + pmc->m_State.q4Eq->SetValue(q4Eq.fValue * urat * irat); LeaveCriticalSection(&pmc->m_ValueCS); } @@ -146,29 +149,30 @@ void PowerMeterClient::PorcVoltageValue(void* pobject, Command* pcommand) qb.Desc(&rseq[flag += 4]); qc.Desc(&rseq[flag += 4]); - - float t_uab = uab.fValue*pmc->m_State.urAt*0.1f; - float t_ubc = ubc.fValue*pmc->m_State.urAt*0.1f; - float t_uca = uca.fValue*pmc->m_State.urAt*0.1f; + EnterCriticalSection(&pmc->m_ValueCS); //wxxtest + float urat = pmc->m_State.urAt->GetValue(); + float irat = pmc->m_State.irAt->GetValue(); + float t_uab = uab.fValue * urat * 0.1f; + float t_ubc = ubc.fValue * urat * 0.1f; + float t_uca = uca.fValue * urat * 0.1f; - EnterCriticalSection(&pmc->m_ValueCS); - pmc->m_State.uab = t_uab; - pmc->m_State.ubc = t_ubc; - pmc->m_State.uca = t_uca; - pmc->m_State.ua = ua.fValue*pmc->m_State.urAt*0.1f; - pmc->m_State.ub = ub.fValue*pmc->m_State.urAt*0.1f; - pmc->m_State.uc = uc.fValue*pmc->m_State.urAt*0.1f; - pmc->m_State.ia = ia.fValue*pmc->m_State.irAt*0.001f; - pmc->m_State.ib = ib.fValue*pmc->m_State.irAt*0.001f; - pmc->m_State.ic = ic.fValue*pmc->m_State.irAt*0.001f; - pmc->m_State.pt = pt.fValue*pmc->m_State.urAt*pmc->m_State.irAt*0.1f; - pmc->m_State.pa = pa.fValue*pmc->m_State.urAt*pmc->m_State.irAt*0.1f; - pmc->m_State.pb = pb.fValue*pmc->m_State.urAt*pmc->m_State.irAt*0.1f; - pmc->m_State.pc = pc.fValue*pmc->m_State.urAt*pmc->m_State.irAt*0.1f; - pmc->m_State.qt = qt.fValue*pmc->m_State.urAt*pmc->m_State.irAt*0.1f; - pmc->m_State.qa = qa.fValue*pmc->m_State.urAt*pmc->m_State.irAt*0.1f; - pmc->m_State.qb = qb.fValue*pmc->m_State.urAt*pmc->m_State.irAt*0.1f; - pmc->m_State.qc = qc.fValue*pmc->m_State.urAt*pmc->m_State.irAt*0.1f; + pmc->m_State.uab->SetValue(t_uab); + pmc->m_State.ubc->SetValue(t_ubc); + pmc->m_State.uca->SetValue(t_uca); + pmc->m_State.ua->SetValue(ua.fValue * urat * 0.1f); + pmc->m_State.ub->SetValue(ub.fValue * urat * 0.1f); + pmc->m_State.uc->SetValue(uc.fValue * urat * 0.1f); + pmc->m_State.ia->SetValue(ia.fValue * irat * 0.001f); + pmc->m_State.ib->SetValue(ib.fValue * irat * 0.001f); + pmc->m_State.ic->SetValue(ic.fValue * irat * 0.001f); + pmc->m_State.pt->SetValue(pt.fValue * urat * irat * 0.1f); + pmc->m_State.pa->SetValue(pa.fValue * urat * irat * 0.1f); + pmc->m_State.pb->SetValue(pb.fValue * urat * irat * 0.1f); + pmc->m_State.pc->SetValue(pc.fValue * urat * irat * 0.1f); + pmc->m_State.qt->SetValue(qt.fValue * urat * irat * 0.1f); + pmc->m_State.qa->SetValue(qa.fValue * urat * irat * 0.1f); + pmc->m_State.qb->SetValue(qb.fValue * urat * irat * 0.1f); + pmc->m_State.qc->SetValue(qc.fValue * urat * irat * 0.1f); LeaveCriticalSection(&pmc->m_ValueCS); float umin = 380.0*(1.0f - pmc->m_RunCfg->m_VoltageAlarmOffset/100.0f); @@ -204,11 +208,11 @@ void PowerMeterClient::PorcVoltageValue2(void* pobject, Command* pcommand) freq.Desc(&rseq[55]); EnterCriticalSection(&pmc->m_ValueCS); - pmc->m_State.pft = pft.fValue*0.001f; - pmc->m_State.pfa = pfa.fValue*0.001f; - pmc->m_State.pfb = pfb.fValue*0.001f; - pmc->m_State.pfc = pfc.fValue*0.001f; - pmc->m_State.freq = freq.fValue*0.01f; + pmc->m_State.pft->SetValue(pft.fValue * 0.001f); + pmc->m_State.pfa->SetValue(pfa.fValue * 0.001f); + pmc->m_State.pfb->SetValue(pfb.fValue * 0.001f); + pmc->m_State.pfc->SetValue(pfc.fValue * 0.001f); + pmc->m_State.freq->SetValue(freq.fValue * 0.01f); LeaveCriticalSection(&pmc->m_ValueCS); } diff --git a/PrintS/Communication/PowerMeterClient.h b/PrintS/Communication/PowerMeterClient.h index 9eed762..f87e7d8 100644 --- a/PrintS/Communication/PowerMeterClient.h +++ b/PrintS/Communication/PowerMeterClient.h @@ -7,73 +7,107 @@ class PowerStat { public: - PowerStat() { - uab = 0.0f ; - ubc = 0.0f ; - uca = 0.0f ; - ua = 0.0f ; - ub = 0.0f ; - uc = 0.0f ; - ia = 0.0f ; - ib = 0.0f ; - ic = 0.0f ; - pt = 0.0f ; - pa = 0.0f ; - pb = 0.0f ; - pc = 0.0f ; - qt = 0.0f ; - qa = 0.0f ; - qb = 0.0f ; - qc = 0.0f ; - pft = 0.0f ; - pfa = 0.0f ; - pfb = 0.0f ; - pfc = 0.0f ; - freq = 0.0f ; - impEp=0.0f; - expEp = 0.0f; - q1Eq = 0.0f; - q2Eq = 0.0f; - q3Eq = 0.0f; - q4Eq = 0.0f; + PowerStat() + : uab(new FloatData("uab", u8"uab")) + , ubc(new FloatData("ubc", u8"ubc")) + , uca(new FloatData("uca", u8"uca")) + , ua(new FloatData("ua", u8"ua")) + , ub(new FloatData("ub", u8"ub")) + , uc(new FloatData("uc", u8"uc")) + , ia(new FloatData("ia", u8"ia")) + , ib(new FloatData("ib", u8"ib")) + , ic(new FloatData("ic", u8"ic")) + , pt(new FloatData("pt", u8"pt")) + , pa(new FloatData("pa", u8"pa")) + , pc(new FloatData("pc", u8"pc")) + , qt(new FloatData("qt", u8"qt")) + , qa(new FloatData("qa", u8"qa")) + , qb(new FloatData("qb", u8"qb")) + , qc(new FloatData("qc", u8"qc")) + , pft(new FloatData("pft", u8"pft")) + , pfa(new FloatData("pfa", u8"pfa")) + , pfb(new FloatData("pfb", u8"pfb")) + , pfc(new FloatData("pfc", u8"pfc")) + , freq(new FloatData("freq", u8"freq")) + , impEp(new FloatData("impEp", u8"impEp")) + , expEp(new FloatData("expEp", u8"expEp")) + , q1Eq(new FloatData("q1Eq", u8"q1Eq")) + , q2Eq(new FloatData("q2Eq", u8"q2Eq")) + , q3Eq(new FloatData("q3Eq", u8"q3Eq")) + , q4Eq(new FloatData("q4Eq", u8"q4Eq")) + , irAt(new FloatData("irAt", u8"irAt")) + , urAt(new FloatData("urAt", u8"urAt")) + + { + //uab = 0.0f ; + //ubc = 0.0f ; + //uca = 0.0f ; + //ua = 0.0f ; + //ub = 0.0f ; + //uc = 0.0f ; + //ia = 0.0f ; + //ib = 0.0f ; + //ic = 0.0f ; + //pt = 0.0f ; + //pa = 0.0f ; + //pb = 0.0f ; + //pc = 0.0f ; + //qt = 0.0f ; + //qa = 0.0f ; + //qb = 0.0f ; + //qc = 0.0f ; + //pft = 0.0f ; + //pfa = 0.0f ; + //pfb = 0.0f ; + //pfc = 0.0f ; + //freq = 0.0f ; + //impEp=0.0f; + //expEp = 0.0f; + //q1Eq = 0.0f; + //q2Eq = 0.0f; + //q3Eq = 0.0f; + //q4Eq = 0.0f; - irAt = 0.0f; - urAt = 0.0f; + //irAt = 0.0f; + //urAt = 0.0f; } public: //BaseStat baseStat; - float uab; - float ubc; - float uca; - float ua; - float ub; - float uc; - float ia; - float ib; - float ic; - float pt; - float pa; - float pb; - float pc; - float qt; - float qa; - float qb; - float qc; - float pft; - float pfa; - float pfb; - float pfc; - float freq; + char m_startFlag; - float impEp; - float expEp; - float q1Eq; - float q2Eq; - float q3Eq; - float q4Eq; + FloatData* uab; + FloatData* ubc; + FloatData* uca; + FloatData* ua; + FloatData* ub; + FloatData* uc; + FloatData* ia; + FloatData* ib; + FloatData* ic; + FloatData* pt; + FloatData* pa; + FloatData* pb; + FloatData* pc; + FloatData* qt; + FloatData* qa; + FloatData* qb; + FloatData* qc; + FloatData* pft; + FloatData* pfa; + FloatData* pfb; + FloatData* pfc; + FloatData* freq; + FloatData* impEp; + FloatData* expEp; + FloatData* q1Eq; + FloatData* q2Eq; + FloatData* q3Eq; + FloatData* q4Eq; + FloatData* irAt; + FloatData* urAt; + + char m_endFlag; - float irAt; - float urAt; }; class PowerMeterClient:public TcpClient