#include "stdafx.h" #include "DIOSBoardProtocolParser.h" #include "IOInterfaceMapper.h" #include "PacketDefine.h" #include "ICollimatorHandler.h" #include "DeviceDataDef.h" using namespace DIOS::Dev::Detail::MachineryECOM; PacketClass DIOSBoardProtocolParser::IdentifyPacketClass(SCFPacket *packet) { if (packet) { CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet)); if ( (pReceiveHead->FrameSize == 6 || pReceiveHead->FrameSize == 7 || pReceiveHead->FrameSize == 9 || pReceiveHead->FrameSize == 10 || pReceiveHead->FrameSize == 11) && pReceiveHead->FrameCmd == 0xFE ) { return PC_NOTIFY; } } return PC_NAN; } PacketNotifyType DIOSBoardProtocolParser::IdentifyPacketNotifyType(SCFPacket *packet) { PacketNotifyType pnt = PNT_NAN; if (packet) { CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet)); if (pReceiveHead->FuncId == IOInterfaceMapper::ID_HAND_SWITCH_GEAR_FIRST) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_HANDSWITCH_FIRST_PRESSED; } else { pnt = PNT_HANDSWITCH_FIRST_RELEASE; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_HAND_SWITCH_GEAR_SECOND) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_HANDSWITCH_SECOND_PRESSED; } else { pnt = PNT_HANDSWITCH_SECOND_RELEASE; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_SYSTEM_RESET) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_SYSTEM_RESET_START; } else { pnt = PNT_SYSTEM_RESET_STOP; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_SYSTEM_RESET_SWING) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_SYSTEM_RESET_SWING_START; } else { pnt = PNT_SYSTEM_RESET_SWING_STOP; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_SYSTEM_RESET_CIRCULAR) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_SYSTEM_RESET_CIRCULAR_START; } else { pnt = PNT_SYSTEM_RESET_CIRCULAR_STOP; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_PULSE) { pnt = PNT_PWM_OFFSET; } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_XRAYON_NOTIFY) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_XRAY_ON; } else { pnt = PNT_XRAY_OFF; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_LOW_LIMIT) { if (pReceiveHead->Data1 == 0x01) { if (pReceiveHead->Data2 == 0x1) { pnt = PNT_TUBE_ANGLE_LOW_LIMIT; } else { pnt = PNT_TUBE_ANGLE_LEAVE_LOW_LIMIT; } } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_HIGH_LIMIT) { if (pReceiveHead->Data1 == 0x01) { if (pReceiveHead->Data2 == 0x1) { pnt = PNT_TUBE_ANGLE_HIGH_LIMIT; } else { pnt = PNT_TUBE_ANGLE_LEAVE_HIGH_LIMIT; } } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_ENCODER) { if (pReceiveHead->Data1 == 0x01) { pnt = PNT_TUBE_ANGLE_ENCODER; } else if (pReceiveHead->Data1 == 0x02 && pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_ANGLE_ENCODER_Z_CLEAR; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_AD) { pnt = PNT_TUBE_HEIGHT_AD; } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_ENCODER) { if (pReceiveHead->Data1 == 0x01) { pnt = PNT_TUBE_HEIGHT_ENCODER; } else if (pReceiveHead->Data1 == 0x02 && pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HEIGHT_ENCODER_Z_CLEAR; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_HIGH_LIMIT) { if (pReceiveHead->Data1 == 0x01) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HEIGHT_HIGH_LIMIT; } else { pnt = PNT_TUBE_HEIGHT_LEAVE_HIGH_LIMIT; } } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_LOW_LIMIT) { if (pReceiveHead->Data1 == 0x01) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HEIGHT_LOW_LIMIT; } else { pnt = PNT_TUBE_HEIGHT_LEAVE_LOW_LIMIT; } } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_CAN) { pnt = PNT_CAN; } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_CONTROLLER_DIRECTION_1) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HEIGHT_CONTROLLER_DIRECTION_1_START; } else { pnt = PNT_TUBE_HEIGHT_CONTROLLER_DIRECTION_1_STOP; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HEIGHT_CONTROLLER_DIRECTION_2) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HEIGHT_CONTROLLER_DIRECTION_2_START; } else { pnt = PNT_TUBE_HEIGHT_CONTROLLER_DIRECTION_2_STOP; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_CONTROLLER_DIRECTION_1) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_ANGLE_CONTROLLER_DIRECTION_1_START; } else { pnt = PNT_TUBE_ANGLE_CONTROLLER_DIRECTION_1_STOP; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_ANGLE_CONTROLLER_DIRECTION_2) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_ANGLE_CONTROLLER_DIRECTION_2_START; } else { pnt = PNT_TUBE_ANGLE_CONTROLLER_DIRECTION_2_STOP; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_CARM_SCANNING_SWITCH) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_CARM_SCANNING_SWITCH_SWING; } else { pnt = PNT_CARM_SCANNING_SWITCH_CIRCULAR; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_1) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_1_START; } else { pnt = PNT_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_1_STOP; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_2) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_2_START; } else { pnt = PNT_TUBE_HORIZONTAL_CONTROLLER_DIRECTION_2_STOP; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_ENCODER) { if (pReceiveHead->Data1 == 0x01) { pnt = PNT_TUBE_HORIZONTAL_ENCODER; } else if (pReceiveHead->Data1 == 0x02 && pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HORIZONTAL_ENCODER_Z_CLEAR; } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_LEFT_LIMIT) { if (pReceiveHead->Data1 == 0x01) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HORIZONTAL_LEFT_LIMIT; } else { pnt = PNT_TUBE_HORIZONTAL_LEAVE_LEFT_LIMIT; } } } else if (pReceiveHead->FuncId == IOInterfaceMapper::ID_TUBE_HORIZONTAL_RIGHT_LIMIT) { if (pReceiveHead->Data1 == 0x01) { if (pReceiveHead->Data2 == 0x01) { pnt = PNT_TUBE_HORIZONTAL_RIGHT_LIMIT; } else { pnt = PNT_TUBE_HORIZONTAL_LEAVE_RIGHT_LIMIT; } } } } return pnt; } bool DIOSBoardProtocolParser::ParsePWMOffsetPacket(SCFPacket *packet, PWMOffsetPacket *outpacket) { SHORTDATA data; SHORTDATA Timedata; CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet)); data.Low = pReceiveHead->Data1; data.High = pReceiveHead->Data2; Timedata.Low = pReceiveHead->Data3; Timedata.High = pReceiveHead->Data4; outpacket->pwmoffset = data.ShortPart; outpacket->timeoffset = Timedata.ShortPart; return true; } bool DIOSBoardProtocolParser::ParseTubeHeightADPacket(SCFPacket *packet, TubeLineADPacket *outpacket) { SHORTDATA data; SHORTDATA Timedata; CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet)); data.Low = pReceiveHead->Data1; data.High = pReceiveHead->Data2; Timedata.Low = pReceiveHead->Data3; Timedata.High = pReceiveHead->Data4; outpacket->posoffset = data.ShortPart; outpacket->timeoffset = data.ShortPart; return true; } bool DIOSBoardProtocolParser::ParseEncoderPacket(SCFPacket *packet, EncoderPacket *outpacket) { Integer data; CTRLPACKETHEAD *pReceiveHead = (CTRLPACKETHEAD *)((char *)(*packet)); if (pReceiveHead->Data1 != 0x01) { return false; } data.integer_byte.integer_lowbyte_0 = pReceiveHead->Data2; data.integer_byte.integer_lowbyte_1 = pReceiveHead->Data3; data.integer_byte.integer_highbyte_0 = pReceiveHead->Data4; data.integer_byte.integer_highbyte_1 = pReceiveHead->Data5; outpacket->encoder = data.integer_int; return true; } typedef struct _CtrlPacketCan { unsigned char szTitle[2]; unsigned char FrameSize; unsigned char FrameId; unsigned char FrameCmd; unsigned char FuncId; unsigned char Data1; unsigned char stdid; unsigned char dlc; unsigned char data[8]; }CTRLPACKETCAN; bool DIOSBoardProtocolParser::ParseCanPacket(SCFPacket *packet, CanDeviceData *outpacket) { CTRLPACKETCAN *pReceiveHead = (CTRLPACKETCAN *)((char *)(*packet)); if (pReceiveHead->Data1 != 0x01) { return false; } outpacket->stdid = pReceiveHead->stdid; outpacket->dlc = pReceiveHead->dlc; memcpy_s(outpacket->data, sizeof(outpacket->data), pReceiveHead->data, sizeof(pReceiveHead->data)); return true; }