📄 jzdc.cpp
字号:
#include "sc_cfg.h"
#include "common.h"
#include "class.h"
#include "extern.h"
const INT8U CJZDC::nbb_sync_code[6] = {0xeb, 0x90, 0xeb, 0x90, 0xeb, 0x90};
CJZDC::CJZDC(INT8U portno):CMasterProtocol(portno)
{
sync_flag = FALSE;
ControlFlag = FALSE;
CurrentRecvAddr = 0;
}
void CJZDC::master_receive()
{
INT8U recbuf[10];
while (get_com_rece_num(myportno) >= 6) {
if (sync_flag == TRUE) {
if (ControlFlag == TRUE) {
read_com_rece_nbytes(&recbuf[0], 6, myportno);
if (!memcmp(&recbuf[0], nbb_sync_code, 6)) { // begin sync
ControlFlag = FALSE;
draw_rece_message(myportno, recbuf, 6, SYNC_COLOR);
continue;
}
if (!packet_crc_check(&recbuf[0])) {
ControlFlag = FALSE;
sync_flag = FALSE;
continue;
} // crc check failure need sync again
draw_rece_message(myportno, &recbuf[0], 6, WHITE);
if (recbuf[1] == 0x61 || recbuf[1] == 0xc2
|| recbuf[1] == 0xb3 || recbuf[1] == 0xf4) {
Process(&recbuf[0]);
}
}
else {
read_com_rece_nbytes(recbuf, 6, myportno);
if (recbuf[0] == 0x71 && packet_crc_check(&recbuf[0])) {
ControlFlag = TRUE;
CurrentRecvAddr = recbuf[3];
draw_rece_message(myportno, recbuf, 6, SYNC_COLOR);
}
else sync_flag = FALSE;
}
}
else { // need sync
get_com_rece_nbytes(recbuf, 6, myportno);
if (!memcmp(recbuf, nbb_sync_code, 6)) { // begin sync
sync_flag = TRUE;
ControlFlag = FALSE;
read_com_rece_nbytes(recbuf, 6, myportno);
draw_rece_message(myportno, recbuf, 6, SYNC_COLOR);
}
else del_com_rece_one(myportno);
}
}
}
BOOLEAN CJZDC::packet_crc_check(INT8U *buf)
{
return (get_crc8_code(buf,5) == buf[5] ? TRUE:FALSE);
}
void CJZDC::deal()
{
master_receive();
}
void CJZDC::Process(INT8U *buf)
{
int i;
YxDefine_t *pyx = NULL;
YcDefine_t *pyc = NULL;
if (buf[0] <= 0x7f) { // yc frame
for (i = 0; i < yc_num; i++) {
pyc = GetYcDefine(pyc_tbl[i]);
if (pyc->devno == CurrentRecvAddr) {
if (pyc->order == buf[0] * 2) {
yc_update_db(pyc_tbl[i], (buf[1] + buf[2] * 256) / 5);
}
if (pyc->order == buf[0] * 2 + 1) {
yc_update_db(pyc_tbl[i], (buf[3] + buf[4] * 256) / 5);
}
}
}
}
INT8U yxorder = buf[0] - 0xf0;
INT8U innorder = 0;
INT32U tempyx = buf[1] + (buf[2] << 8) + (buf[3] << 16) + (buf[4] << 24);
INT8U value = 0;
if (buf[0] >= 0xf0) { // yx frame
for (i = 0; i < yx_num; i++) {
pyx = GetYxDefine(pyx_tbl[i]);
if (pyx->devno == CurrentRecvAddr) {
if (pyx->info >= yxorder * 32 && pyx->info < (yxorder + 1) *32) {
innorder = pyx->info % 32;
value = tempyx >> innorder;
yx_update_db(pyx_tbl[i], value);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -