2024-04-12 15:51:41 +08:00
|
|
|
|
#include "TempCtrlClient.h"
|
2024-03-19 17:45:12 +08:00
|
|
|
|
#include "Aibus.h"
|
|
|
|
|
#include <bitset>
|
|
|
|
|
#include "../SystemInfo.h"
|
|
|
|
|
|
|
|
|
|
TempCtrlClient::TempCtrlClient(CommunicationCfg* pconfig):TcpClient(pconfig)
|
|
|
|
|
{
|
2024-04-12 15:51:41 +08:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
startPtr = &m_Stat.alarm.m_startFlag + 1;
|
|
|
|
|
count = ((size_t)&m_Stat.alarm.m_endFlag - (size_t)&startPtr) / ptrSize;
|
|
|
|
|
InsertMp(startPtr, count);
|
2024-03-19 17:45:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TempCtrlClient::~TempCtrlClient()
|
|
|
|
|
{
|
|
|
|
|
Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TempCtrlClient::InitCommand()
|
|
|
|
|
{
|
|
|
|
|
Command* pCommand = new Aibus(READ_FLOAT_POINT, m_Config->m_Addr, 0x0c, 0, true);
|
|
|
|
|
pCommand->m_Fun = &TempCtrlClient::ProcTempInfo;
|
|
|
|
|
pCommand->m_Ref = this;
|
|
|
|
|
pCommand->isNeedDel = false;
|
|
|
|
|
m_CycleCommands.push_back(pCommand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TempCtrlClient::SetTargeValue(float value)
|
|
|
|
|
{
|
|
|
|
|
EnterCriticalSection(&m_RtcCS);
|
2024-04-12 15:51:41 +08:00
|
|
|
|
float targevalue = value*m_Stat.scale->GetValue();
|
2024-03-19 17:45:12 +08:00
|
|
|
|
Command* pCommand = new Aibus(SET_TARGE_VALUE, 0x1, 0x0, (short)targevalue, false);
|
|
|
|
|
pCommand->m_Fun = &TempCtrlClient::ProcSetTemp;
|
|
|
|
|
pCommand->m_Ref = this;
|
|
|
|
|
m_RTCommands.push(pCommand);
|
|
|
|
|
LeaveCriticalSection(&m_RtcCS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TempCtrlClient::ProcTempInfo(void* pobject, Command* pcommand)
|
|
|
|
|
{
|
|
|
|
|
if (pobject == NULL)return;
|
|
|
|
|
TempCtrlClient* pTc = (TempCtrlClient*)pobject;
|
|
|
|
|
unsigned char* rseq = pcommand->m_RespSeq;
|
|
|
|
|
short floatPoint = (short)(rseq[7] << 8) + rseq[6];
|
|
|
|
|
if (floatPoint >= 128)floatPoint %= 128;
|
|
|
|
|
int scale = 1;
|
|
|
|
|
for (short i = 0; i < floatPoint; ++i) {
|
|
|
|
|
scale *= 10;
|
|
|
|
|
}
|
|
|
|
|
EnterCriticalSection(&pTc->m_ValueCS);
|
2024-04-12 15:51:41 +08:00
|
|
|
|
pTc->m_Stat.scale->SetValue( scale);
|
|
|
|
|
pTc->m_Stat.measuredValue->SetValue((float)((short)(rseq[1] << 8) + rseq[0]) / scale);
|
|
|
|
|
pTc->m_Stat.settingValue->SetValue((float)((short)(rseq[3] << 8) + rseq[2]) / scale);
|
|
|
|
|
pTc->m_Stat.outputValue->SetValue(rseq[4]);
|
2024-03-19 17:45:12 +08:00
|
|
|
|
bitset<8> bitStatus(rseq[5]);
|
2024-04-12 15:51:41 +08:00
|
|
|
|
pTc->m_Stat.alarm.isOverLimit->SetValue(bitStatus[0]);
|
|
|
|
|
pTc->m_Stat.alarm.isLowerLimit->SetValue(bitStatus[1]);
|
|
|
|
|
pTc->m_Stat.alarm.isActiveAlarm->SetValue(bitStatus[2]);
|
|
|
|
|
pTc->m_Stat.alarm.isInactiveAlarm->SetValue(bitStatus[3]);
|
|
|
|
|
pTc->m_Stat.alarm.isInputLimit->SetValue(bitStatus[4]);
|
|
|
|
|
pTc->m_Stat.alarm.al1->SetValue(bitStatus[5]);
|
|
|
|
|
pTc->m_Stat.alarm.al2->SetValue(bitStatus[6]);
|
2024-03-19 17:45:12 +08:00
|
|
|
|
EnterCriticalSection(&g_SystemInfo->m_InfoCs);
|
2024-04-12 15:51:41 +08:00
|
|
|
|
g_SystemInfo->m_PlatformTemp = pTc->m_Stat.measuredValue->GetValue();
|
|
|
|
|
g_SystemInfo->m_PlatformTempSettingValue = pTc->m_Stat.settingValue->GetValue();
|
2024-03-19 17:45:12 +08:00
|
|
|
|
LeaveCriticalSection(&g_SystemInfo->m_InfoCs);
|
|
|
|
|
LeaveCriticalSection(&pTc->m_ValueCS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TempCtrlClient::ProcSetTemp(void* pobject, Command* pcommand)
|
|
|
|
|
{
|
|
|
|
|
if (pobject == NULL)return;
|
|
|
|
|
TempCtrlClient* pTc = (TempCtrlClient*)pobject;
|
|
|
|
|
unsigned char* rseq = pcommand->m_RespSeq;
|
|
|
|
|
float fvalue = 0;
|
|
|
|
|
EnterCriticalSection(&pTc->m_ValueCS);
|
2024-04-12 15:51:41 +08:00
|
|
|
|
int scale = (pTc->m_Stat.scale->GetValue() == 0 ? 1 : pTc->m_Stat.scale->GetValue());
|
2024-03-19 17:45:12 +08:00
|
|
|
|
fvalue = (float)((short)(rseq[7] << 8) + rseq[6]) / scale;
|
|
|
|
|
|
2024-04-12 15:51:41 +08:00
|
|
|
|
pTc->m_Stat.measuredValue->SetValue((float)((short)(rseq[1] << 8) + rseq[0]) / scale);
|
|
|
|
|
pTc->m_Stat.settingValue->SetValue((float)((short)(rseq[3] << 8) + rseq[2]) / scale);
|
|
|
|
|
pTc->m_Stat.outputValue->SetValue(rseq[4]);
|
2024-03-19 17:45:12 +08:00
|
|
|
|
bitset<8> bitStatus(rseq[5]);
|
2024-04-12 15:51:41 +08:00
|
|
|
|
pTc->m_Stat.alarm.isOverLimit->SetValue(bitStatus[0]);
|
|
|
|
|
pTc->m_Stat.alarm.isLowerLimit->SetValue(bitStatus[1]);
|
|
|
|
|
pTc->m_Stat.alarm.isActiveAlarm->SetValue(bitStatus[2]);
|
|
|
|
|
pTc->m_Stat.alarm.isInactiveAlarm->SetValue(bitStatus[3]);
|
|
|
|
|
pTc->m_Stat.alarm.isInputLimit->SetValue(bitStatus[4]);
|
|
|
|
|
pTc->m_Stat.alarm.al1->SetValue(bitStatus[5]);
|
|
|
|
|
pTc->m_Stat.alarm.al2->SetValue(bitStatus[6]);
|
2024-03-19 17:45:12 +08:00
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&pTc->m_ValueCS);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-12 15:51:41 +08:00
|
|
|
|
//void TempCtrlClient::GetStat(TempStat& stat)
|
|
|
|
|
//{
|
|
|
|
|
// EnterCriticalSection(&m_ValueCS);
|
|
|
|
|
// memcpy_s(&stat.alarm, sizeof(TempAlarm), &m_Stat.alarm, sizeof(TempAlarm));
|
|
|
|
|
// stat.baseStat = m_BaseStat;
|
|
|
|
|
// stat.measuredValue = m_Stat.measuredValue;
|
|
|
|
|
// stat.outputValue = m_Stat.outputValue;
|
|
|
|
|
// stat.scale = m_Stat.scale;
|
|
|
|
|
// stat.settingValue = m_Stat.settingValue;
|
|
|
|
|
// LeaveCriticalSection(&m_ValueCS);
|
|
|
|
|
//}
|