#include "UPSClient.h" #include "../utils/StringHelper.h" //#include "UpsComand.h" UPSClient::UPSClient(void* pconfig) :TcpClient(pconfig) { m_Freq = 500; size_t ptrSize = sizeof(nullptr); //指针大小 void* startPtr = &m_Stat.m_startFlag + 1; size_t count = ((size_t)&m_Stat.m_endFlag - (size_t)startPtr) / ptrSize; InsertMp(startPtr, count); } UPSClient::~UPSClient() { Shutdown(); //OutputDebugString("ups close\n"); } //void UPSClient::InitCommand() { // Command* pCommand = new UpsComand("Q1\r"); // pCommand->m_Fun = &UPSClient::ProcInfo; // pCommand->m_Ref = this; // pCommand->isNeedDel = false; // m_CycleCommands.push_back(pCommand); //} //void UPSClient::ShutDownUps(float minute) //{ // if (minute < 0.2f || minute>10)return; // char buffer[10]; // if (minute < 1.0f) // { // int tempv = (int)(minute * 10 + 0.5); // sprintf_s(buffer, sizeof(buffer), "S.%d\r", tempv); // } // else sprintf_s(buffer, sizeof(buffer), "S%f\r", minute); // EnterCriticalSection(&m_RtcCS); // Command* pCommand = new UpsComand(string(buffer)); // pCommand->m_Fun = &UPSClient::ProcShutDown; // pCommand->m_Ref = this; // pCommand->isNeedRead = false; // m_RTCommands.push(pCommand); // LeaveCriticalSection(&m_RtcCS); //} // //void UPSClient::ProcInfo(void* pobject, Command* pcommand) //{ // if (pobject == NULL)return; // UPSClient* pUw = (UPSClient*)pobject; // unsigned char* rseq = pcommand->m_RespSeq; // unsigned int dlength = pcommand->m_RespLen; // // float inputVol = (float)((rseq[1] - '0') * 1000 + (rseq[2] - '0') * 100 + (rseq[3] - '0') * 10 + (rseq[5] - '0')) / 10.0f; // float lastVol = (float)((rseq[7] - '0') * 1000 + (rseq[8] - '0') * 100 + (rseq[9] - '0') * 10 + (rseq[11] - '0')) / 10.0f; // float outputVol = (float)((rseq[13] - '0') * 1000 + (rseq[14] - '0') * 100 + (rseq[15] - '0') * 10 + (rseq[17] - '0')) / 10.0f; // int outputLoad = (rseq[19] - '0') * 100 + (rseq[20] - '0') * 10 + (rseq[21] - '0'); // float outputF = (float)((rseq[23] - '0') * 100 + (rseq[24] - '0') * 10 + (rseq[26] - '0')) / 10.0f; // float unitVol = (float)((rseq[28] - '0') * 100 + (rseq[30] - '0') * 10 + (rseq[31] - '0')) / 100.0f; // float tempValue = (float)((rseq[33] - '0') * 100 + (rseq[34] - '0') * 10 + (rseq[36] - '0')) / 10.0f; // // EnterCriticalSection(&pUw->m_ValueCS); // pUw->m_Stat.inputVol->SetValue(inputVol); // pUw->m_Stat.lastVol->SetValue(lastVol); // pUw->m_Stat.outputVol->SetValue(outputVol); // pUw->m_Stat.outputLoad->SetValue(outputLoad); // pUw->m_Stat.outputF->SetValue(outputF); // pUw->m_Stat.unitVol->SetValue(unitVol); // pUw->m_Stat.tempValue->SetValue(tempValue); // // pUw->m_Stat.isVolError->SetValue((rseq[38] == '1' ? true : false)); // pUw->m_Stat.isBatteryVolLow->SetValue((rseq[39] == '1' ? true : false)); // pUw->m_Stat.isBypassMode->SetValue((rseq[40] == '1' ? true : false)); // pUw->m_Stat.isUpsError->SetValue((rseq[41] == '1' ? true : false)); // pUw->m_Stat.upsType->SetValue((rseq[42] == '1' ? true : false)); // pUw->m_Stat.isTesting->SetValue((rseq[43] == '1' ? true : false)); // pUw->m_Stat.isShutdown->SetValue((rseq[44] == '1' ? true : false)); // // LeaveCriticalSection(&pUw->m_ValueCS); //} // //void UPSClient::ProcShutDown(void* pobject, Command* pcommand) //{ // //} void UPSClient::GetStat(Upsstat& stat) { EnterCriticalSection(&m_ValueCS); stat.baseStat = m_BaseStat; stat.inputVol = m_Stat.inputVol->GetValue(); stat.isBatteryVolLow = m_Stat.isBatteryVolLow->GetValue(); stat.isBypassMode = m_Stat.isBypassMode->GetValue(); stat.isShutdown = m_Stat.isShutdown->GetValue(); stat.isTesting = m_Stat.isTesting->GetValue(); stat.isUpsError = m_Stat.isUpsError->GetValue(); stat.isVolError = m_Stat.isVolError->GetValue(); stat.lastVol = m_Stat.lastVol->GetValue(); stat.outputF = m_Stat.outputF->GetValue(); stat.outputLoad = m_Stat.outputLoad->GetValue(); stat.outputVol = m_Stat.outputVol->GetValue(); stat.tempValue = m_Stat.tempValue->GetValue(); stat.unitVol = m_Stat.unitVol->GetValue(); stat.upsType = m_Stat.upsType->GetValue(); LeaveCriticalSection(&m_ValueCS); }