gccDppConsole Test C++ SDK  20170920
DPP C++ Console Demonstration
DeviceIO/ParsePacket.cpp
Go to the documentation of this file.
00001 #include "ParsePacket.h"
00002 
00003 CParsePacket::CParsePacket(void)
00004 {
00005 }
00006 
00007 CParsePacket::~CParsePacket(void)
00008 {
00009 }
00010 
00011 void CParsePacket::ParsePacketStatus(unsigned char P[], Packet_In *PIN)
00012 {
00013     short X;
00014     long CSum;
00015 
00016     CSum = 0;
00017     if (P[0] == SYNC1_) {
00018         if (P[1] == SYNC2_) {
00019             if (P[4] < 128) {  // LEN MSB < 128, i.e. LEN < 32768
00020                 PIN->LEN = (P[4] * 256) + P[5];
00021                 PIN->PID1 = P[2];
00022                 PIN->PID2 = P[3];
00023                                 for (X=0;X <=(PIN->LEN+5);X++) {        // add up all the bytes except checksum
00024                     CSum = CSum + P[X];
00025                 }
00026                 CSum = CSum + 256 * (long)(P[PIN->LEN + 6]) + (long)(P[PIN->LEN + 7]);
00027                 PIN->CheckSum = CSum;
00028                 if ((CSum & 0xFFFF) == 0) {
00029                     PIN->STATUS = 0;      // packet is OK
00030                     if (PIN->LEN > 0) {
00031                                                 for (X=6;X <=(PIN->LEN+5);X++) {        
00032                             PIN->DATA[X - 6] = P[X];
00033                                                 }
00034                     }
00035                 } else {
00036                     PIN->STATUS = PID2_ACK_CHECKSUM_ERROR;    // checksum error
00037                 }
00038             } else {
00039                 PIN->STATUS = PID2_ACK_LEN_ERROR;        // length error
00040             }
00041         } else {
00042             PIN->STATUS = PID2_ACK_SYNC_ERROR;            // sync error
00043         }
00044     } else {
00045         PIN->STATUS = PID2_ACK_SYNC_ERROR ;               // sync error
00046     }
00047 }
00048 
00049 string CParsePacket::PID2_TextToString(string strPacketSource, unsigned char PID2)
00050 {
00051         string strPID2;
00052         strPID2 = "";
00053         switch (PID2) {
00054                 case PID2_ACK_OK:    // ACK OK
00055             //PID2_TextToString = strPacketSource + ": OK\t";
00056             //strPID2 = "ACK_OK";
00057                         strPID2 = "";
00058             //ACK_Received = True
00059                         break;
00060         case PID2_ACK_SYNC_ERROR:
00061             strPID2 = strPacketSource + ": Sync Error\t";
00062                         break;
00063         case PID2_ACK_PID_ERROR:
00064             strPID2 = strPacketSource + ": PID Error\t";
00065                         break;
00066         case PID2_ACK_LEN_ERROR:
00067             strPID2 = strPacketSource + ": Length Error\t";
00068                         break;
00069         case PID2_ACK_CHECKSUM_ERROR:
00070             strPID2 = strPacketSource + ": Checksum Error\t";
00071                         break;
00072         case PID2_ACK_BAD_PARAM:        // now msg includes bad parameter
00073                         // put the error extractor in a new function
00074                 //[] If PIN.LEN > 0 Then ' BAD CMD (PID2=7), BAD PARAM (PID2=5), NO PC5 (PID2=11) errors return offending command string
00075       //        [] T$ = ""
00076       //        [] For X = 0 To PIN.LEN - 1
00077       //                [] T$ = T$ + Chr(PIN.DATA(X))
00078       //        [] Next X
00079       //        [] End If
00080             strPID2 = strPacketSource + ": Bad Parameter\t";
00081                         break;
00082         case PID2_ACK_BAD_HEX_REC:
00083             strPID2 = strPacketSource + ": Bad HEX Record\t";
00084                         break;
00085         case PID2_ACK_FPGA_ERROR:
00086             strPID2 = strPacketSource + ": FPGA not initialized\t";
00087                         break;
00088         case PID2_ACK_CP2201_NOT_FOUND:
00089             strPID2 = strPacketSource + ": CP2201 not found\t";
00090                         break;
00091         case PID2_ACK_SCOPE_DATA_NOT_AVAIL:
00092             strPID2 = strPacketSource + ": No scope data\t";
00093                         break;
00094         case PID2_ACK_PC5_NOT_PRESENT:
00095             strPID2 = strPacketSource + ": PC5 not present\t";
00096                         break;
00097         case PID2_ACK_OK_ETHERNET_SHARE_REQ:
00098             strPID2 = strPacketSource + ": Ethernet sharing request\t";
00099                         break;
00100         case PID2_ACK_ETHERNET_BUSY:
00101             strPID2 = strPacketSource + ": Ethernet sharing request\t";
00102                         break;
00103                 //[] Case :TextLog "ACK: PC5 NOT DETECTED '" + T$ + "'" + vbCrLf
00104         case PID2_ACK_CAL_DATA_NOT_PRESENT:
00105             strPID2 = strPacketSource + ": Calibration data not present\t";
00106                         break;
00107         case PID2_ACK_UNRECOG:
00108             strPID2 = strPacketSource + ": Unrecognized Command\t";
00109                         break;
00110                 default:
00111                         strPID2 = strPacketSource + ": Unrecognized Error\t";
00112                         break;
00113         }
00114         return strPID2;
00115 }
00116 
00117 long CParsePacket::ParsePacket(unsigned char P[], Packet_In *PIN)
00118 {
00119         long ParsePkt;
00120     ParsePkt = preqProcessNone;
00121     ParsePacketStatus (P, PIN);
00122     if (PIN->STATUS == PID2_ACK_OK) { // no errors
00123         if ((PIN->PID1 == PID1_RCV_STATUS) && (PIN->PID2 == PID2_SEND_DP4_STYLE_STATUS)) { // DP4-style status
00124             ParsePkt = preqProcessStatus;
00125         } else if ((PIN->PID1 == PID1_RCV_SPECTRUM) && ((PIN->PID2 >= RCVPT_256_CHANNEL_SPECTRUM) && (PIN->PID2 <= RCVPT_8192_CHANNEL_SPECTRUM_STATUS))) { // spectrum / spectrum+status
00126             ParsePkt = preqProcessSpectrum;
00127         //} else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == PID2_SEND_SCOPE_DATA)) { //scope data packet
00128         //    ParsePkt = preqProcessScopeData;
00129         //} else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == PID2_SEND_512_BYTE_MISC_DATA)) { //text data packet
00130         //    ParsePkt = preqProcessTextData;
00131         } else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == RCVPT_SCOPE_DATA)) { //scope data packet
00132             //ScopeOverFlow = false;
00133             ParsePkt = preqProcessScopeData;
00134         } else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == RCVPT_512_BYTE_MISC_DATA)) { //text data packet
00135             ParsePkt = preqProcessTextData;
00136         } else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == RCVPT_SCOPE_DATA_WITH_OVERFLOW)) { //scope data with overflow packet
00137             //ScopeOverFlow = true;
00138             //ParsePkt = preqProcessScopeData;
00139             ParsePkt = preqProcessScopeDataOverFlow;
00140         } else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == RCVPT_ETHERNET_SETTINGS)) { //ethernet settings packet
00141             //ParsePkt = preqProcessInetSettings;
00142         } else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == RCVPT_DIAGNOSTIC_DATA)) { //diagnostic data  packet
00143             ParsePkt = preqProcessDiagData;
00144         //} else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == RCVPT_HARDWARE_DESCRIPTION)) { //hardware description packet
00145             //ParsePkt = preqProcessHwDesc;
00146         } else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == RCVPT_CONFIG_READBACK)) {
00147             ParsePkt = preqProcessCfgRead;
00148         //} else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == RCVPT_NETFINDER_READBACK)) {
00149             //ParsePkt = preqProcessNetFindRead;
00150         } else if ((PIN->PID1 == PID1_RCV_SCOPE_MISC) && (PIN->PID2 == RCVPT_OPTION_PA_CALIBRATION)) {
00151             ParsePkt = preqProcessPaCal;
00152         } else if (PIN->PID1 == PID1_ACK) {
00153             ParsePkt = preqProcessAck;
00154         } else {
00155             PIN->STATUS = PID2_ACK_PID_ERROR;  // unknown PID
00156             ParsePkt = preqProcessError;
00157         }
00158     } else {
00159         ParsePkt = preqProcessError;
00160     }
00161 
00162     //PIN->PID1 = 0;    // overwrite the PIDs so packet can't be erroneously processed again
00163     //PIN->PID2 = 0;
00164 
00165         return ParsePkt;
00166 }
00167 
00168 //ElseIf PIN.PID2 = 7 Then ' Config readback response packet
00169 //    txtConfig.Text = ""
00170 //    For X = 0 To PIN.LEN - 1
00171 //        txtConfig.Text = txtConfig.Text + Chr(PIN.DATA(X))
00172 //        If Chr(PIN.DATA(X)) = ";" Then
00173 //            txtConfig.Text = txtConfig.Text + vbCrLf
00174 //        End If
00175 //    Next X
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183