📄 ttc31x.cpp
字号:
#include "sc_cfg.h"
#include "common.h"
#include "class.h"
#include "extern.h"
CTTC31X::CTTC31X(INT8U portno):CMasterPollingProtocol(portno)
{
CurrentQueryAddr = DevStartAddr;
SetQueryGap(1000); // need wait 1s between query
}
void CTTC31X::master_receive()
{
INT8U recbuf[81];
if (get_com_rece_num(myportno) < 81) return; // too little
read_com_rece_nbytes(recbuf, 81, myportno);
if ('*' == recbuf[0]
&& recbuf[1] == CurrentQueryAddr
&& 'S' == recbuf[3]
&& 'R' == recbuf[4]
&& 10 == recbuf[79]
&& 13 == recbuf[80]) {
if (fcs(recbuf)) {
draw_rece_message(myportno, recbuf, 81, POLL_RECE_COLOR);
QueryStatus = ANSWER;
process(recbuf);
}
}
}
void CTTC31X::process(INT8U *buf)
{
int i;
INT8U tempyx;
YxDefine_t *pyx = NULL;
for (i = 0; i < yx_num; i++) {
pyx = GetYxDefine(pyx_tbl[i]);
if (pyx->devno != buf[1]) continue; // check address
switch (pyx->type) {
case 0: // fan status
if (!memcmp(&buf[33], "Fan:Off", 7)) tempyx = 0;
else if (!memcmp(&buf[33], "Fan:On", 6)) tempyx = 1;
break;
case 1: // warn status
if (!memcmp(&buf[41], "Warn:Off", 8)) tempyx = 0;
else if (!memcmp(&buf[41], "Warn:On", 7)) tempyx = 1;
break;
case 2: // trip status
if (!memcmp(&buf[50], "Trip:Off", 8)) tempyx = 0;
else if (!memcmp(&buf[50], "Trip:On", 7)) tempyx = 1;
break;
case 3: // core status
if (!memcmp(&buf[59], "Core:Off", 8)) tempyx = 0;
else if (!memcmp(&buf[59], "Core:On", 7)) tempyx = 1;
break;
case 4: // fail status
if (!memcmp(&buf[68], "Fail:Off", 8)) tempyx = 0;
else if (!memcmp(&buf[68], "Fail:On", 7)) tempyx = 1;
break;
default:
continue;
}
ProtocolProcessYX(pyx_tbl[i], tempyx);
}
int tempyc;
YcDefine_t *pyc = NULL;
for (i = 0; i < yc_num; i++) {
pyc = GetYcDefine(pyc_tbl[i]);
if (pyc->devno != buf[1]) continue; // check address
switch (pyc->type) {
case 0: // phase A temp
tempyc = atoi(&buf[7]);
break;
case 1: // phase B
tempyc = atoi(&buf[14]);
break;
case 2: // phase C
tempyc = atoi(&buf[21]);
break;
case 3: // phase D
tempyc = atoi(&buf[28]);
break;
default:
continue;
}
yc_update_db(pyc_tbl[i], tempyc);
}
}
BOOLEAN CTTC31X::fcs(INT8U *msg)
{
INT8U temp;
char hc, lc;
temp = msg[0];
for (int i = 1; i < 77; i++)
temp ^= msg[i];
hc = (temp >> 4 ) & 0xf;
lc = temp & 0xf;
if (hc > 9) hc = hc + 'A';
else hc = hc + '0';
if (lc > 9) lc = lc + 'A';
else lc = lc + '0';
if (hc == msg[77] && lc == msg[78]) return TRUE;
else return FALSE;
}
void CTTC31X::master_send()
{
INT8U askbuf[6];
if (++CurrentQueryAddr > DevEndAddr) CurrentQueryAddr = DevStartAddr;
askbuf[0] = '@';
askbuf[1] = CurrentQueryAddr;
askbuf[2] = ' ';
askbuf[3] = 'S';
askbuf[4] = ' ';
askbuf[5] = 13;
QueryStatus = QUERY;
com_transfer(myportno, 6, askbuf);
draw_send_message(myportno, askbuf, 6, POLL_SEND_COLOR);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -