gccDppConsole Test C++ SDK
20170920
DPP C++ Console Demonstration
|
00001 #include "SendCommand.h" 00002 #include "stringex.h" 00003 00004 CSendCommand::CSendCommand(void) 00005 { 00006 } 00007 00008 CSendCommand::~CSendCommand(void) 00009 { 00010 } 00011 00012 bool CSendCommand::TestPacketCkSumOK(unsigned char Data[]) 00013 { 00014 long idxBuffer; 00015 long CS; 00016 long PktLen; 00017 unsigned char CHKSUM_MSB; 00018 //unsigned char CHKSUM_LSB; 00019 00020 PktLen = (Data[4] * 256) + Data[5]; 00021 CS = Data[0] + Data[1] + Data[2] + Data[3] + Data[4] + Data[5]; 00022 if (PktLen > 0) { 00023 for (idxBuffer=0; idxBuffer<PktLen;idxBuffer++) { 00024 CS = CS + Data[idxBuffer + 6]; 00025 } 00026 } 00027 CS = (CS ^ 0xFFFF) + 1; 00028 CHKSUM_MSB = (unsigned char)((CS & 0xFF00) / 256); // calculated checksum 00029 //CHKSUM_LSB = (unsigned char)(CS & 0xFF); 00030 if ((Data[PktLen + 6] == CHKSUM_MSB) && (Data[PktLen + 7] == (CS & 0xFF))) { 00031 return true; 00032 } else { 00033 return false; 00034 } 00035 } 00036 00037 //Extend Packet_Out to include entire message 00038 //include send packet data finishing into dp5_cmd 00039 //remove control and interface objects 00040 //move send packet to separate function 00041 00042 bool CSendCommand::DP5_CMD(unsigned char Buffer[], TRANSMIT_PACKET_TYPE XmtCmd) 00043 { 00044 bool bCmdFound; 00045 string D; 00046 Packet_Out POUT; 00047 00048 bCmdFound = true; 00049 POUT.LEN = 0; 00050 string strCfg; 00051 long lLen; 00052 //long idxData; 00053 00054 switch (XmtCmd) { 00056 case XMTPT_SEND_STATUS: 00057 POUT.PID1 = PID1_REQ_STATUS; 00058 POUT.PID2 = PID2_SEND_DP4_STYLE_STATUS; // send status only 00059 break; 00060 //case XMTPT_SEND_SPECTRUM: 00061 //break; 00062 //case XMTPT_SEND_CLEAR_SPECTRUM: 00063 //break; 00064 case XMTPT_SEND_SPECTRUM_STATUS: 00065 POUT.PID1 = PID1_REQ_SPECTRUM; 00066 POUT.PID2 = PID2_SEND_SPECTRUM_STATUS; // send spectrum & status 00067 break; 00068 case XMTPT_SEND_CLEAR_SPECTRUM_STATUS: 00069 POUT.PID1 = PID1_REQ_SPECTRUM; 00070 POUT.PID2 = PID2_SEND_CLEAR_SPECTRUM_STATUS; // send & clear spectrum & status 00071 break; 00072 //case XMTPT_BUFFER_SPECTRUM: 00073 //break; 00074 //case XMTPT_BUFFER_CLEAR_SPECTRUM: 00075 //break; 00076 //case XMTPT_SEND_BUFFER: 00077 //break; 00078 //case XMTPT_SEND_DP4_STYLE_STATUS: 00079 //break; 00080 //case XMTPT_SEND_CONFIG: 00081 //break; 00082 case XMTPT_SEND_SCOPE_DATA: 00083 POUT.PID1 = PID1_REQ_SCOPE_MISC; 00084 POUT.PID2 = PID2_SEND_SCOPE_DATA; 00085 break; 00086 case XMTPT_SEND_512_BYTE_MISC_DATA: 00087 POUT.PID1 = PID1_REQ_SCOPE_MISC; 00088 POUT.PID2 = PID2_SEND_512_BYTE_MISC_DATA; // request misc data 00089 break; 00090 case XMTPT_SEND_SCOPE_DATA_REARM: 00091 POUT.PID1 = PID1_REQ_SCOPE_MISC; 00092 POUT.PID2 = PID2_SEND_SCOPE_DATA_REARM; 00093 break; 00094 //case XMTPT_SEND_ETHERNET_SETTINGS: 00095 //break; 00096 case XMTPT_SEND_DIAGNOSTIC_DATA: 00097 POUT.PID1 = PID1_REQ_SCOPE_MISC; 00098 POUT.PID2 = PID2_SEND_DIAGNOSTIC_DATA; // Request Diagnostic Packet 00099 POUT.LEN = 0; 00100 break; 00101 case XMTPT_SEND_NETFINDER_PACKET: 00102 POUT.PID1 = PID1_REQ_SCOPE_MISC; 00103 POUT.PID2 = PID2_SEND_NETFINDER_READBACK; // Request NetFinder Packet 00104 POUT.LEN = 0; 00105 break; 00106 //case XMTPT_SEND_HARDWARE_DESCRIPTION: 00107 //break; 00108 //case XMTPT_SEND_SCA: 00109 //break; 00110 //case XMTPT_LATCH_SEND_SCA: 00111 //break; 00112 //case XMTPT_LATCH_CLEAR_SEND_SCA: 00113 //break; 00114 //case XMTPT_SEND_ROI_OR_FIXED_BLOCK: 00115 //break; 00116 //case XMTPT_PX4_STYLE_CONFIG_PACKET: 00117 //break; 00118 case XMTPT_SCA_READ_CONFIG_PACKET: 00119 strCfg = ""; 00120 strCfg = "SCAW=?;"; 00121 strCfg +="SCAI=1;SCAL=?;SCAH=?;SCAO=?;"; 00122 strCfg +="SCAI=2;SCAL=?;SCAH=?;SCAO=?;"; 00123 strCfg +="SCAI=3;SCAL=?;SCAH=?;SCAO=?;"; 00124 strCfg +="SCAI=4;SCAL=?;SCAH=?;SCAO=?;"; 00125 strCfg +="SCAI=5;SCAL=?;SCAH=?;SCAO=?;"; 00126 strCfg +="SCAI=6;SCAL=?;SCAH=?;SCAO=?;"; 00127 strCfg +="SCAI=7;SCAL=?;SCAH=?;SCAO=?;"; 00128 strCfg +="SCAI=8;SCAL=?;SCAH=?;SCAO=?;"; 00129 lLen = (long)strCfg.length(); 00130 if (lLen > 0) { 00131 strCfg = AsciiCmdUtil.MakeUpper(strCfg); 00132 AsciiCmdUtil.CopyAsciiData(POUT.DATA, strCfg, lLen); 00133 } 00134 POUT.PID1 = PID1_REQ_CONFIG; 00135 POUT.PID2 = PID2_CONFIG_READBACK_PACKET; // read config packet 00136 POUT.LEN = (unsigned short)lLen; 00137 break; 00138 case XMTPT_ERASE_FPGA_IMAGE: 00139 POUT.PID1 = PID1_REQ_FPGA_UC; 00140 POUT.PID2 = PID2_ERASE_FPGA_IMAGE; 00141 POUT.LEN = 2; 00142 POUT.DATA[0] = 0x12; 00143 POUT.DATA[1] = 0x34; 00144 break; 00145 //case XMTPT_UPLOAD_PACKET_FPGA: 00146 //break; 00147 //case XMTPT_REINITIALIZE_FPGA: 00148 //break; 00149 //case XMTPT_ERASE_UC_IMAGE_0: 00150 //break; 00151 case XMTPT_ERASE_UC_IMAGE_1: 00152 POUT.PID1 = PID1_REQ_FPGA_UC; 00153 POUT.PID2 = PID2_ERASE_UC_IMAGE_1; // erase image #1 (sector 5) 00154 POUT.LEN = 2; 00155 POUT.DATA[0] = 0x12; 00156 POUT.DATA[1] = 0x34; 00157 break; 00158 //case XMTPT_ERASE_UC_IMAGE_2: 00159 //break; 00160 //case XMTPT_UPLOAD_PACKET_UC: 00161 //break; 00162 //case XMTPT_SWITCH_TO_UC_IMAGE_0: 00163 //break; 00164 case XMTPT_SWITCH_TO_UC_IMAGE_1: 00165 POUT.PID1 = PID1_REQ_FPGA_UC; 00166 POUT.PID2 = PID2_SWITCH_TO_UC_IMAGE_1; // switch to uC image #1 00167 POUT.LEN = 2; 00168 POUT.DATA[0] = 0xA5; // uC FLASH unlock keys 00169 POUT.DATA[1] = 0xF1; 00170 break; 00171 //case XMTPT_SWITCH_TO_UC_IMAGE_2: 00172 //break; 00173 //case XMTPT_UC_FPGA_CHECKSUMS: 00174 //break; 00176 //case XMTPT_CLEAR_SPECTRUM_BUFFER_A: 00177 //break; 00178 case XMTPT_ENABLE_MCA_MCS: 00179 POUT.PID1 = PID1_VENDOR_REQ; 00180 POUT.PID2 = PID2_ENABLE_MCA_MCS; 00181 POUT.LEN = 0; 00182 break; 00183 case XMTPT_DISABLE_MCA_MCS: 00184 POUT.PID1 = PID1_VENDOR_REQ; 00185 POUT.PID2 = PID2_DISABLE_MCA_MCS; 00186 POUT.LEN = 0; 00187 break; 00188 case XMTPT_ARM_DIGITAL_OSCILLOSCOPE: 00189 POUT.PID1 = PID1_VENDOR_REQ; 00190 POUT.PID2 = PID2_ARM_DIGITAL_OSCILLOSCOPE; // arm trigger 00191 break; 00192 //case XMTPT_AUTOSET_INPUT_OFFSET: 00193 //break; 00194 case XMTPT_AUTOSET_FAST_THRESHOLD: 00195 POUT.PID1 = PID1_VENDOR_REQ; 00196 POUT.PID2 = PID2_AUTOSET_FAST_THRESHOLD; 00197 POUT.LEN = 0; 00198 break; 00199 //case XMTPT_READ_IO3_0: 00200 //break; 00201 //case XMTPT_WRITE_IO3_0: 00202 //break; 00203 //case XMTPT_SET_DCAL: 00204 //break; 00205 //case XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL: 00206 //break; 00207 //case XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL: 00208 //break; 00209 //case XMTPT_SET_BOOT_FLAGS: 00210 //break; 00211 //case XMTPT_SET_HV_DP4_EMULATION: 00212 //break; 00213 //case XMTPT_SET_TEC_DP4_EMULATION: 00214 //break; 00215 //case XMTPT_SET_INPUT_OFFSET_DP4_EMULATION: 00216 //break; 00217 //case XMTPT_SET_ADC_CAL_GAIN_OFFSET: 00218 //break; 00219 //case XMTPT_SET_SPECTRUM_OFFSET: 00220 //break; 00221 //case XMTPT_REQ_SCOPE_DATA_MISC_DATA_SCA_PACKETS: 00222 //break; 00223 //case XMTPT_SET_SERIAL_NUMBER: 00224 //break; 00225 //case XMTPT_CLEAR_GP_COUNTER: 00226 //break; 00227 //case XMTPT_SWITCH_SUPPLIES: 00228 //break; 00229 //case XMTPT_SEND_TEST_PACKET: 00230 //break; 00231 case XMTPT_REQ_ACK_PACKET: 00232 POUT.PID1 = PID1_COMM_TEST; 00233 POUT.PID2 = PID2_ACK_OK; 00234 POUT.LEN = 0; 00235 break; 00236 case XMTPT_FORCE_SCOPE_TRIGGER: 00237 POUT.PID1 = PID1_VENDOR_REQ; 00238 POUT.PID2 = PID2_GENERIC_FPGA_WRITE; // generic FPGA write 00239 POUT.LEN = 2; 00240 POUT.DATA[0] = 119; // force scope trigger 00241 POUT.DATA[1] = 0; // data doesn't matter 00242 break; 00243 case XMTPT_AU34_2_RESTART: 00244 POUT.PID1 = PID1_VENDOR_REQ; 00245 POUT.PID2 = PID2_GENERIC_FPGA_WRITE; // generic FPGA write 00246 POUT.LEN = 2; 00247 POUT.DATA[0] = 0x73; // AU34_2_RESTART 00248 POUT.DATA[1] = 0; // data doesn't matter 00249 break; 00250 case XMTPT_READ_MCA8000D_OPTION_PA_CAL: 00251 POUT.PID1 = PID1_REQ_SCOPE_MISC; 00252 POUT.PID2 = PID2_SEND_OPTION_PA_CALIBRATION; 00253 POUT.LEN = 0; 00254 break; 00255 default: 00256 bCmdFound = false; 00257 break; 00258 } 00259 if (bCmdFound) { 00260 if (! POUT_Buffer(POUT, Buffer)) { 00261 bCmdFound = false; 00262 } 00263 } 00264 return bCmdFound; 00265 } 00266 00267 //DP5_CMD_Config is for: (requires pc5 and device info) 00268 // XMTPT_SEND_CONFIG_PACKET_TO_HW 00269 // XMTPT_SEND_CONFIG_PACKET_EX 00270 // XMTPT_FULL_READ_CONFIG_PACKET 00271 // XMTPT_READ_CONFIG_PACKET 00272 // XMTPT_READ_CONFIG_PACKET_EX 00273 bool CSendCommand::DP5_CMD_Config(unsigned char Buffer[], TRANSMIT_PACKET_TYPE XmtCmd, CONFIG_OPTIONS CfgOptions) 00274 { 00275 bool bCmdFound; 00276 string D; 00277 Packet_Out POUT; 00278 bCmdFound = true; 00279 POUT.LEN = 0; 00280 string strCfg; 00281 long lLen; 00282 00283 switch (XmtCmd) { 00284 case XMTPT_SEND_CONFIG_PACKET_TO_HW: 00285 // CONFIG_OPTIONS Needed: 00286 // CfgOptions.HwCfgDP5Out 00287 // CfgOptions.SendCoarseFineGain 00288 // CfgOptions.PC5_PRESENT 00289 // CfgOptions.DppType 00290 strCfg = ""; 00291 strCfg = CfgOptions.HwCfgDP5Out; 00292 00293 if (CfgOptions.SendCoarseFineGain) { 00294 strCfg = AsciiCmdUtil.RemoveCmd("GAIN",strCfg); 00295 } else { 00296 strCfg = AsciiCmdUtil.RemoveCmd("GAIA",strCfg); 00297 strCfg = AsciiCmdUtil.RemoveCmd("GAIF",strCfg); 00298 } 00299 strCfg = AsciiCmdUtil.RemoveCmdByDeviceType(strCfg, CfgOptions.PC5_PRESENT, CfgOptions.DppType, CfgOptions.isDP5_RevDxGains, CfgOptions.DPP_ECO); 00300 lLen = (long)strCfg.length(); 00301 if (lLen > 0) { 00302 strCfg = AsciiCmdUtil.MakeUpper(strCfg); 00303 AsciiCmdUtil.CopyAsciiData(POUT.DATA, strCfg, lLen); 00304 } 00305 POUT.PID1 = PID1_REQ_CONFIG; 00306 POUT.PID2 = PID2_TEXT_CONFIG_PACKET; // text config packet 00307 POUT.LEN = (unsigned short)lLen; 00308 break; 00309 case XMTPT_SEND_CONFIG_PACKET_EX: // bypass any filters 00310 // CONFIG_OPTIONS Needed: 00311 // CfgOptions.HwCfgDP5Out 00312 strCfg = ""; 00313 strCfg = CfgOptions.HwCfgDP5Out; 00314 lLen = (long)strCfg.length(); 00315 if (lLen > 0) { 00316 strCfg = AsciiCmdUtil.MakeUpper(strCfg); 00317 AsciiCmdUtil.CopyAsciiData(POUT.DATA, strCfg, lLen); 00318 } 00319 POUT.PID1 = PID1_REQ_CONFIG; 00320 POUT.PID2 = PID2_TEXT_CONFIG_PACKET; // text config packet 00321 POUT.LEN = (unsigned short)lLen; 00322 break; 00323 case XMTPT_FULL_READ_CONFIG_PACKET: 00324 // CONFIG_OPTIONS Needed: 00325 // CfgOptions.PC5_PRESENT 00326 // CfgOptions.DppType 00327 strCfg = ""; 00328 strCfg = AsciiCmdUtil.CreateFullReadBackCmd(CfgOptions.PC5_PRESENT, CfgOptions.DppType, CfgOptions.isDP5_RevDxGains, CfgOptions.DPP_ECO); 00329 lLen = (long)strCfg.length(); 00330 if (lLen > 0) { 00331 strCfg = AsciiCmdUtil.MakeUpper(strCfg); 00332 AsciiCmdUtil.CopyAsciiData(POUT.DATA, strCfg, lLen); 00333 } 00334 POUT.PID1 = PID1_REQ_CONFIG; 00335 POUT.PID2 = PID2_CONFIG_READBACK_PACKET; // read config packet 00336 POUT.LEN = (unsigned short)lLen; 00337 break; 00338 case XMTPT_READ_CONFIG_PACKET_EX: // bypass any filters 00339 strCfg = ""; 00340 strCfg = CfgOptions.HwCfgDP5Out; 00341 lLen = (long)strCfg.length(); 00342 if (lLen > 0) { 00343 strCfg = AsciiCmdUtil.MakeUpper(strCfg); 00344 AsciiCmdUtil.CopyAsciiData(POUT.DATA, strCfg, lLen); //ForceASCII_20110606 00345 } 00346 POUT.PID1 = PID1_REQ_CONFIG; 00347 POUT.PID2 = PID2_CONFIG_READBACK_PACKET; // text config packet 00348 POUT.LEN = (unsigned short)lLen; 00349 break; 00350 case XMTPT_READ_CONFIG_PACKET: 00351 strCfg = ""; 00352 strCfg += "CLCK=?;"; // FPGA clock 00353 strCfg += "TPEA=?;"; // peak time 00354 strCfg += "GAIN=?;"; // gain 00355 if (CfgOptions.DppType == dppMCA8000D) { 00356 strCfg += "GAIA=?;"; // coarse gain 00357 } 00358 strCfg += "MCAS=?;"; // mca mode 00359 strCfg += "MCAC=?;"; // channels 00360 strCfg += "INOF=?;"; // osc. Input offset 00361 strCfg += "THSL=?;"; // LLD thresh 00362 strCfg += "TFLA=?;"; // flat top width 00363 strCfg += "THFA=?;"; // fast thresh 00364 strCfg += "DACO=?;"; // osc. DAC output 00365 strCfg += "DACF=?;"; // osc. DAC offset 00366 strCfg += "AUO1=?;"; // osc. AUX_OUT1 00367 strCfg += "PRET=?;"; // preset actual time 00368 strCfg += "PRER=?;"; // preset real time 00369 strCfg += "PREC=?;"; // preset count 00370 if (CfgOptions.DppType == dppMCA8000D) { 00371 strCfg += "PREL=?;"; // preset real time 00372 } 00373 strCfg += "HVSE=?;"; // high voltage setting for manufacuting test 00374 strCfg += "SCOE=?;"; // osc. Scope trigger edge 00375 strCfg += "SCOT=?;"; // osc. Scope trigger position 00376 strCfg += "SCOG=?;"; // osc. Scope gain 00377 00378 lLen = (long)strCfg.length(); 00379 if (lLen > 0) { 00380 strCfg = AsciiCmdUtil.MakeUpper(strCfg); 00381 AsciiCmdUtil.CopyAsciiData(POUT.DATA, strCfg, lLen); 00382 } 00383 POUT.PID1 = PID1_REQ_CONFIG; 00384 POUT.PID2 = PID2_CONFIG_READBACK_PACKET; // read config packet 00385 POUT.LEN = (unsigned short)lLen; 00386 break; 00387 default: 00388 bCmdFound = false; 00389 break; 00390 } 00391 if (bCmdFound) { 00392 if (! POUT_Buffer(POUT, Buffer)) { 00393 bCmdFound = false; 00394 } 00395 } 00396 return bCmdFound; 00397 } 00398 00399 00400 //Extend Packet_Out to include entire message 00401 //include send packet data finishing into dp5_cmd 00402 //remove control and interface objects 00403 //move send packet to separate function 00404 bool CSendCommand::DP5_CMD_Data(unsigned char Buffer[], TRANSMIT_PACKET_TYPE XmtCmd, unsigned char DataOut[]) 00405 { 00406 bool bCmdFound; 00407 short idxMiscData; 00408 Packet_Out POUT; 00409 long PktLen; 00410 00411 bCmdFound = false; 00412 POUT.LEN = 0; 00413 string strCfg; 00414 long idxData; 00415 switch (XmtCmd) { //REQUEST_PACKETS_TO_DP5 00416 case XMTPT_WRITE_512_BYTE_MISC_DATA: 00417 POUT.PID1 = PID1_VENDOR_REQ; 00418 POUT.PID2 = PID2_WRITE_512_BYTE_MISC_DATA; // write misc data 00419 POUT.LEN = 512; 00420 for (idxMiscData=0;idxMiscData<=511;idxMiscData++) { // byte array padded w/NULLs 00421 POUT.DATA[idxMiscData] = DataOut[idxMiscData]; 00422 } 00423 bCmdFound = true; 00424 if (! POUT_Buffer(POUT, Buffer)) { 00425 bCmdFound = false; 00426 } 00427 break; 00428 case XMTPT_SEND_TEST_PACKET: 00429 PktLen = (DataOut[4] * 256) + DataOut[5] + 8; // get entire packet size 00430 if ((PktLen >= 8) && (PktLen <= 12)) { // test data len 0-4 bytes 00431 if (TestPacketCkSumOK(DataOut)) { // check the message for correct check sum 00432 for(idxData=0;idxData<PktLen;idxData++) { // load the data into the command buffer 00433 Buffer[idxData] = DataOut[idxData]; 00434 } 00435 bCmdFound = true; 00436 } 00437 } 00438 break; 00439 default: 00440 bCmdFound = false; 00441 break; 00442 } 00443 return bCmdFound; 00444 } 00445 00446 bool CSendCommand::POUT_Buffer(Packet_Out POUT, unsigned char Buffer[]) 00447 { 00448 long idxBuffer; 00449 long CS; 00450 00451 Buffer[0] = SYNC1_; 00452 Buffer[1] = SYNC2_; 00453 Buffer[2] = POUT.PID1; 00454 Buffer[3] = POUT.PID2; 00455 Buffer[4] = (POUT.LEN & 0xFF00) / 256; 00456 Buffer[5] = POUT.LEN & 0xFF; 00457 00458 CS = SYNC1_ + SYNC2_ + POUT.PID1 + POUT.PID2 + ((POUT.LEN & 0xFF00) / 256) + (POUT.LEN & 0xFF); 00459 00460 if (POUT.LEN > 0) { 00461 for (idxBuffer=0; idxBuffer<POUT.LEN;idxBuffer++) { 00462 Buffer[idxBuffer + 6] = POUT.DATA[idxBuffer]; 00463 CS = CS + POUT.DATA[idxBuffer]; 00464 } 00465 } 00466 CS = (CS ^ 0xFFFF) + 1; 00467 Buffer[POUT.LEN + 6] = (unsigned char)((CS & 0xFF00) / 256); 00468 Buffer[POUT.LEN + 7] = (unsigned char)(CS & 0xFF); 00469 return true; 00470 } 00471