📄 mod1.cpp
字号:
{
INT16U temp;
askbuf[0] = station_add;
askbuf[1] = SET_COIL;
askbuf[2] = 0x00;
if (port_yk_info.yk_cmd == YKCTRIP) {
askbuf[3] = 0x0d;
}
else if (port_yk_info.yk_cmd == YKCCLOSE) {
askbuf[3] = 0x0c;
}
else {
askbuf[3] = 0;
}
askbuf[4] = 0xff;
askbuf[5] = 0x00;
temp = crc16(askbuf, 6);
askbuf[6] = (temp >> 8) & 0xff;
askbuf[7] = temp & 0xff;
currentCMD = READ_AI;
rece_end = 2;
com_transfer(myportno, 8, askbuf);
draw_send_message(myportno, askbuf, 8, POLL_SEND_COLOR);
}
void CMod1::send_yk_esc()
{
INT16U temp;
askbuf[0] = station_add;
askbuf[1] = SET_COIL;
askbuf[2] = 0x00;
askbuf[3] = 0x0e;
askbuf[4] = 0xff;
askbuf[5] = 0x00;
temp = crc16(askbuf, 6);
askbuf[6] = (temp >> 8) & 0xff;
askbuf[7] = temp & 0xff;
currentCMD = SET_COIL;
rece_end = 2;
com_transfer(myportno, 8, askbuf);
draw_send_message(myportno, askbuf, 8, POLL_SEND_COLOR);
}
void CMod1::send_ds()
{
askbuf[0] = 0x00;
draw_send_message(myportno, askbuf, 1, POLL_SEND_COLOR);
}
void CMod1::send_soe_length()
{
INT16U temp;
askbuf[0] = station_add;
askbuf[1] = 0x14;
askbuf[2] = 0x07;
askbuf[3] = 0x06;
askbuf[4] = 0x00;
askbuf[5] = 0x02;
askbuf[6] = 0x00;
askbuf[7] = 0x00;
askbuf[8] = 0x00;
askbuf[9] = 0x01;
temp = crc16(askbuf, 10);
askbuf[10] = (temp >> 8) & 0xff;
askbuf[11] = temp & 0xff;
currentCMD = 0x14;
rece_end = 2;
com_transfer(myportno, 12, askbuf);
draw_send_message(myportno, askbuf, 12, POLL_SEND_COLOR);
}
void CMod1::processSOE_LENGTH(INT8U *buf)
{
soelength = ((buf[5] << 8)&0xff00) + buf[6];
if(soelength >=30)
soelength = 30;
}
void CMod1::send_soe_clear()
{
INT16U temp;
askbuf[0] = station_add;
askbuf[1] = 0x15;
askbuf[2] = 0x09;
askbuf[3] = 0x06;
askbuf[4] = 0x00;
askbuf[5] = 0x02;
askbuf[6] = 0x00;
askbuf[7] = 0x02;
askbuf[8] = 0x00;
askbuf[9] = 0x01;
askbuf[10] = 0xff;
askbuf[11] = 0x00;
temp = crc16(askbuf, 12);
askbuf[12] = (temp >> 8) & 0xff;
askbuf[13] = temp & 0xff;
currentCMD = 0x15;
rece_end = 2;
com_transfer(myportno, 14, askbuf);
draw_send_message(myportno, askbuf, 14, POLL_SEND_COLOR);
}
void CMod1::send_soe()//qurey_soe!
{
INT16U temp;
soelength = 7*(soelength); //?
askbuf[0] = station_add;
askbuf[1] = 0x14;
askbuf[2] = 0x07;
askbuf[3] = 0x06;
askbuf[4] = 0x00;
askbuf[5] = 0x02;
askbuf[6] = 0x00;
askbuf[7] = 0x03;
askbuf[8] = INT8U((soelength >> 8)&0x00ff);
askbuf[9] = INT8U(soelength & 0x00ff);
temp = crc16(askbuf, 10);
askbuf[10] = (temp >> 8) & 0xff;
askbuf[11] = temp & 0xff;
currentCMD = 0x14;
rece_end = 2;
com_transfer(myportno, 12, askbuf);
draw_send_message(myportno, askbuf, 12, POLL_SEND_COLOR);
}
void CMod1::processSOE(INT8U *buf)
{
send_soe_clear();
int i, j;
soe_record_t temp_soe;
sclock sclk;
INT16U temp;
INT16U no = soelength;
for (i = 0; i < no; i++) {
for (j = 0; j < _TotalYx; j++) {
if ((myportno == (yx_define[j].portno - 1)) && (buf[5] == yx_define[j].devno)
&& (yx_define[j].channel == buf[i * 7 + 5])&&(yx_define[j].type == buf[i*7+7])) {
temp_soe.status_switch_no = j & 0xfff;
if (buf[i * 7 + 5] == 0x06)
temp_soe.status_switch_no |= 0x8000;
else if(
(buf[i * 7 + 5] == 0x07)||
( ((buf[i * 7 + 4] == 11) || (buf[i * 7 + 4] == 11) ||(buf[i * 7 + 4] == 11))&&
(buf[i * 7 + 5] == 0x05) )
)
temp_soe.status_switch_no &= 0x7fff;
else return;
GetClock(&sclk);
temp = ((buf[i * 7 + 14] << 8) & 0xff00) + buf[i * 7 + 13];
/* temp_soe.time.date = (((sclk.year % 100) << 9) & 0xfe00) +
((sclk.month << 5) & 0x01e0) + (sclk.day & 0x001f);
temp_soe.time.time = ((sclk.weekday << 12) & 0xf000) +
((buf[i * 7 + 10] << 7) & 0x0f80) + (buf[i * 7 + 11] & 0x007f);
temp_soe.time.msec = ((buf[i * 7 + 12] << 10) & 0xfc00) +
(temp & 0x03ff);*/
temp_soe.day = sclk.day;
temp_soe.hour = buf[i * 7 + 10];
temp_soe.minute = buf[i * 7 + 11];
temp_soe.second = temp / 1000;
temp_soe.msecond = temp % 1000;
insert_soe(&temp_soe);
}
}
}
}
void CMod1::master_send()
{
int i;
if (!is_port_yk_doing(myportno)) yk_flag = FALSE;
if (yk_flag) return;
if (port_yk_info.Y_PRESET) {
if (port_yk_info.yk_des == myportno) {
port_yk_info.Y_PRESET = FALSE;
yk_flag = TRUE;
send_yk_preset();
send_add = port_yk_info.dev_no;
rece_end = 2;
return;
}
}
if (port_yk_info.Y_EXEC) {
if (port_yk_info.yk_des == myportno) {
port_yk_info.Y_EXEC = FALSE;
yk_flag = FALSE;
send_yk_exec();
send_add = port_yk_info.dev_no;
rece_end = 2;
return;
}
}
if (port_yk_info.Y_ESC) {
if (port_yk_info.yk_des == myportno) {
port_yk_info.Y_ESC = FALSE;
yk_flag = FALSE;//bu zai zuo
send_yk_esc();
send_add = port_yk_info.dev_no;
rece_end = 2;
return;
}
}
if (send_cycle >= 4000) {
send_cycle = 1;
}
if ((send_cycle % 100 == 0)&(send_cycle > 8)) {
send_ds();//guangbo
send_cycle++;
rece_end = 0;
return;
}
switch (send_state[station_add]) {
case 0: case 4:
send_yx();
++send_state[station_add];
send_add = station_add;
rece_end = 2;
change_addr();
break;
case 1: case 6:
send_yc();
++send_state[station_add];
send_add = station_add;
rece_end = 2;
change_addr();
break;
case 2: case 5: case 7:
send_leds();
++send_state[station_add];
send_add = station_add;
rece_end = 2;
change_addr();
break;
case 3:
send_ymyc();
++send_state[station_add] ;
send_add = station_add;
rece_end = 2;
change_addr();
break;
case 8:
send_soe_length();
++send_state[station_add] ;
send_add = station_add;
rece_end = 2;
break;
case 9:
send_soe();
++send_state[station_add] ;
send_add = station_add;
rece_end = 2;
break;
case 10:
// send_ds();
send_state[station_add]=0;
send_add = station_add;
rece_end = 2;
change_addr();
break;
}
}
void CMod1::process(INT8U *buf)
{
switch (buf[1]) {
case 0x02:
processREAD_DI(buf);
break;
case 0x03:
//processREADWORD(buf);
break;
case 0x04:
processREAD_AI(buf);
break;
case 0x05:
processSET_COIL(buf);
break;
case 0x14:
if (buf[2] == 0x04)
{
processSOE_LENGTH(buf);
}
else processSOE(buf);
break;
case 0x15:
break;
}
}
void CMod1::master_receive()
{
INT16U rece_len;
rece_len = get_com_rece_num(myportno);
if (rece_len < 3) return;
get_com_rece_nbytes(recbuf, 3, myportno);
INT16U framelen = recbuf[2] + 5;
if (recbuf[0] == send_add && recbuf[1] == currentCMD) {
if (rece_len >= framelen) {
read_com_rece_nbytes(recbuf, framelen, myportno);
INT16U temp = crc16(recbuf, framelen - 2);
INT16U temp1 = ((recbuf[framelen - 2] << 8) | recbuf[framelen - 1]);
if (temp == temp1) {
draw_rece_message(myportno, recbuf, framelen, POLL_RECE_COLOR);
rece_end = 1;
process(recbuf);
}
}
}
else del_com_rece_one(myportno);
}
void CMod1::deal()
{
master_receive();
if (!port_free(myportno)) return;
if (port_timeout[myportno] >=9) {
if (rece_end == 1) {
fail_count[send_add] = 0;
LINK_flag[send_add] = 1;
}
else if (rece_end == 2) {
if (fail_count[send_add] > 3)
LINK_flag[send_add] = 0;
else fail_count[send_add]++;
clear_com_rece_buf(myportno);
}
master_send();
port_timeout[myportno] = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -