123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- #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;
- }
|