📄 disa3.cpp
字号:
#include "sc_cfg.h"
#include "common.h"
#include "class.h"
#include "extern.h"
CDISA3::CDISA3(INT8U portno):CNbb(portno)
{
FrameInsertNum = 9;
len_a = GetProtocolSet(myportno, 0);
if (len_a < FrameInsertNum) len_a = FrameInsertNum;
len_b = GetProtocolSet(myportno, 1);
len_c = GetProtocolSet(myportno, 2);
len_d1 = GetProtocolSet(myportno, 3);
len_d2 = GetProtocolSet(myportno, 4);
len_e = GetProtocolSet(myportno, 5) / 6 * 6;
if (len_e <= 0) len_e = 6;
YxHead = 0x00;
YcHead = 0x00;
YmHead = 0x00;
}
BOOLEAN CDISA3::BWPacketSend(INT8U FrameType, INT8U length)
{
INT8U buf[60];
yxbw_record_t temp_yx_bw;
get_yx_bw(myportno, &temp_yx_bw);
memcpy(&buf[0], nbb_sync_code, 6);
buf[6] = 0x71;
buf[7] = 0xf5;
buf[8] = 0x01;
buf[9] = source_add;
buf[10] = dest_add;
buf[11] = get_crc8_code(&buf[6], 5);
buf[12] = YxHead + temp_yx_bw.func_code;
buf[13] = temp_yx_bw.yx_code[0] & 0xff;
buf[14] = (temp_yx_bw.yx_code[0] >> 8) & 0xff;
buf[15] = temp_yx_bw.yx_code[1] & 0xff;
buf[16] = (temp_yx_bw.yx_code[1] >> 8) & 0xff;
buf[17] = get_crc8_code(&buf[12], 5);
memcpy(&buf[18], &buf[0], 18);
memcpy(&buf[36], &buf[0], 18);
for (int i = 0; i < 3; i++) {
draw_send_message(myportno, &buf[i * 18], 6, SYNC_COLOR);
draw_send_message(myportno, &buf[i * 18 + 6], 6, SYNC_COLOR);
draw_send_message(myportno, &buf[i * 18 + 12], 6, YX_COLOR);
}
com_transfer(myportno, 54, &buf[0]);
if (FrameType != FRAME_E) packet_count += FrameInsertNum;
return (isFrameOver(packet_count, length));
}
BOOLEAN CDISA3::YkRetPacketSend(INT8U FrameType, INT8U length, BOOLEAN preset_noerr)
{
INT8U buf[60];
memcpy(&buf[0], nbb_sync_code, 6);
buf[6] = 0x71;
buf[7] = 0xb3;
buf[8] = 0x01;
buf[9] = source_add;
buf[10] = dest_add;
buf[11] = get_crc8_code(&buf[6], 5);
buf[12] = 0xe1;
if (preset_noerr) {
buf[13] = buf[15] = get_ykret_code(myportno);
buf[14] = buf[16] = ykreg.ykobj;
}
else {
buf[13] = buf[15] = yk_preset_err.ykcmd;
buf[14] = buf[16] = yk_preset_err.ykobj;
}
buf[17] = get_crc8_code(&buf[12], 5);
memcpy(&buf[18], &buf[0], 18);
memcpy(&buf[36], &buf[0], 18);
for (int i = 0; i < 3; i++) {
draw_send_message(myportno, &buf[i * 18], 6, SYNC_COLOR);
draw_send_message(myportno, &buf[i * 18 + 6], 6, SYNC_COLOR);
draw_send_message(myportno, &buf[i * 18 + 12], 6, YK_COLOR);
}
com_transfer(myportno, 54, &buf[0]);
if (FrameType != FRAME_E) packet_count += FrameInsertNum;
return (isFrameOver(packet_count, length));
}
BOOLEAN CDISA3::FrameYCAssemble(INT8U *buf, INT8U length, INT8U FrameType)
{
INT16U value = 0;
INT16U dot = packet_count * 2;
if (FrameType == FRAME_A)
buf[0] = YcHead + packet_count;
if (FrameType == FRAME_B) {
if (GetTotalYcNum() <= 512)
buf[0] = YcHead + len_a + packet_count;
else
buf[0] = YcHead + packet_count;
}
if (FrameType == FRAME_C) {
if (GetTotalYcNum() <= 512)
buf[0] = YcHead + len_a + len_b + packet_count;
else
buf[0] = YcHead + packet_count;
}
value = get_yc_dot(dot);
buf[1] = value & 0xff;
buf[2] = (value >> 8) & 0xff;
value = get_yc_dot(dot + 1);
buf[3] = value & 0xff;
buf[4] = (value >> 8) & 0xff;
buf[5] = get_crc8_code(&buf[0], 5);
return (isFrameOver(++packet_count, length));
}
void CDISA3::master_send()
{
INT8U buf[20];
BOOLEAN bFrameOver;
if (!port_free(myportno)) return;
if (isFrameHead) {
frame_type = get_frame_type(frame_count);
frame_length = get_frame_length(frame_type);
if (frame_length == 0) {
if (++frame_count > 71) frame_count = 0;
return;
}
memcpy(buf, nbb_sync_code, 6);
buf[6] = 0x71;
buf[7] = frame_type;
buf[8] = frame_length;
buf[9] = source_add;
buf[10] = dest_add;
buf[11] = get_crc8_code(&buf[6], 5);
isFrameHead = FALSE;
draw_send_message(myportno, buf, 6, SYNC_COLOR);
draw_send_message(myportno, buf + 6, 6, SYNC_COLOR);
com_transfer(myportno, 12, buf);
}
else {
bFrameOver = PacketSend(frame_type, frame_length);
if (bFrameOver) {
frame_count++;
packet_count = 0;
if (frame_count > 71) frame_count = 0;
isFrameHead = TRUE;
}
}
}
BOOLEAN CDISA3::PacketSend(INT8U type, INT8U length)
{
BOOLEAN bFrameOver = FALSE;
if (length - packet_count >= FrameInsertNum) {
if (is_yx_bw(myportno)) {
return (BWPacketSend(type, length));
}
// when you doing yk, you find yk is doing
// so you must return failure check
if (!yk_preset_err.noerr) {
bFrameOver = YkRetPacketSend(type, length, yk_preset_err.noerr);
reset_yk(myportno);
yk_preset_err.noerr = TRUE;
return bFrameOver;
}
if (is_yk_return(myportno)) {
bFrameOver = YkRetPacketSend(type, length, yk_preset_err.noerr);
if (ykreg.ykcheckresult == YKRERROR) reset_yk(myportno);
ykreg.retflag = FALSE;
return bFrameOver;
}
}
if (type == FRAME_A || type == FRAME_B || type == FRAME_C)
bFrameOver = FrameYCPacketSend(type, length);
if (type == FRAME_D1)
bFrameOver = FrameD1PacketSend(length);
if (type == FRAME_D2)
bFrameOver = FrameD2PacketSend(length);
if (type == FRAME_E)
bFrameOver = FrameEPacketSend(length);
return (bFrameOver);
}
BOOLEAN CDISA3::FrameYCPacketSend(INT8U FrameType,INT8U length)
{
BOOLEAN bFrameOver = FALSE;
INT8U buf[12];
INT8U len = 6;
bFrameOver = FrameYCAssemble(&buf[0], length, FrameType);
draw_send_message(myportno, &buf[0], 6, YC_COLOR);
if (!bFrameOver) {
bFrameOver = FrameYCAssemble(&buf[6], length, FrameType);
len = 12;
draw_send_message(myportno, &buf[6], 6, YC_COLOR);
}
com_transfer(myportno, len, &buf[0]);
return bFrameOver;
}
void CDISA3::deal()
{
master_receive();
master_send();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -