gccDppConsole Test C++ SDK
20170920
DPP C++ Console Demonstration
|
00001 00002 #include <iostream> 00003 #include "ConsoleHelper.h" 00004 #include "stringSplit.h" 00005 #include "stringex.h" 00006 #include <string.h> 00007 00008 using namespace stringSplit; 00009 00010 CConsoleHelper::CConsoleHelper(void) 00011 { 00012 DppLibUsb.NumDevices = 0; 00013 LibUsb_isConnected = false; 00014 LibUsb_NumDevices = 0; 00015 DppStatusString = ""; 00016 } 00017 00018 CConsoleHelper::~CConsoleHelper(void) 00019 { 00020 } 00021 00022 bool CConsoleHelper::LibUsb_Connect_Default_DPP() 00023 { 00024 00025 // flag is for notifications, if already connect will return dusbStatNoAction 00026 // use bDeviceConnected to detect connection 00027 DppLibUsb.InitializeLibusb(); 00028 LibUsb_isConnected = false; 00029 LibUsb_NumDevices = 0; 00030 DppLibUsb.NumDevices = DppLibUsb.CountDP5LibusbDevices(); 00031 if (DppLibUsb.NumDevices > 1) { 00032 // choose dpp device here or default to first device 00033 } else if (DppLibUsb.NumDevices == 1) { 00034 // default to first device 00035 } else { 00036 } 00037 if (DppLibUsb.NumDevices > 0) { 00038 DppLibUsb.CurrentDevice = 1; // set to default device 00039 DppLibUsb.DppLibusbHandle = DppLibUsb.FindUSBDevice(DppLibUsb.CurrentDevice); //connect 00040 if (DppLibUsb.bDeviceConnected) { // connection detected 00041 LibUsb_isConnected = true; 00042 LibUsb_NumDevices = DppLibUsb.NumDevices; 00043 } 00044 } else { 00045 LibUsb_isConnected = false; 00046 LibUsb_NumDevices = 0; 00047 } 00048 return (LibUsb_isConnected); 00049 } 00050 00051 void CConsoleHelper::LibUsb_Close_Connection() 00052 { 00053 if (DppLibUsb.bDeviceConnected) { // clean-up: close usb connection 00054 DppLibUsb.bDeviceConnected = false; 00055 DppLibUsb.CloseUSBDevice(DppLibUsb.DppLibusbHandle); 00056 LibUsb_isConnected = false; 00057 LibUsb_NumDevices = 0; 00058 DppLibUsb.DeinitializeLibusb(); 00059 } 00060 } 00061 00062 bool CConsoleHelper::LibUsb_SendCommand(TRANSMIT_PACKET_TYPE XmtCmd) 00063 { 00064 bool bHaveBuffer; 00065 int bSentPkt; 00066 bool bMessageSent; 00067 00068 bMessageSent = false; 00069 if (DppLibUsb.bDeviceConnected) { 00070 memset(&DP5Proto.BufferOUT[0],0,sizeof(DP5Proto.BufferOUT)); 00071 bHaveBuffer = (bool) SndCmd.DP5_CMD(DP5Proto.BufferOUT, XmtCmd); 00072 if (bHaveBuffer) { 00073 bSentPkt = DppLibUsb.SendPacketUSB(DppLibUsb.DppLibusbHandle, DP5Proto.BufferOUT, DP5Proto.PacketIn); 00074 if (bSentPkt) { 00075 bMessageSent = true; 00076 } 00077 } 00078 } 00079 return (bMessageSent); 00080 } 00081 00082 // COMMAND (CONFIG_OPTIONS Needed) 00083 // Command Description 00084 // 00085 // XMTPT_SEND_CONFIG_PACKET_TO_HW (HwCfgDP5Out,SendCoarseFineGain,PC5_PRESENT,DppType) 00086 // Processes a configuration string for errors before sending 00087 // Allows only one gain setting type (coarse,fine OR total gain) 00088 // Removes commands from string that should not be sent to device type 00089 // XMTPT_SEND_CONFIG_PACKET_EX (HwCfgDP5Out) 00090 // Sends the a configuration with minimal error checking 00091 // XMTPT_FULL_READ_CONFIG_PACKET (PC5_PRESENT,DppType) 00092 // Creates and sends a full readback command 00093 void CConsoleHelper::CreateConfigOptions(CONFIG_OPTIONS *CfgOptions, string strCfg, CDP5Status DP5Stat, bool bUseCoarseFineGain) 00094 { 00095 // ==== ==== This application supports Communications for DPP Devices Below 00096 //DEVICE_ID==0; //DP5 00097 //DEVICE_ID==1; //PX5 00098 //DEVICE_ID==2; //DP5G 00099 //DEVICE_ID==3; //MCA8000D 00100 //DEVICE_ID==4; //TB5 00101 //DEVICE_ID==5; //DP5X 00102 CfgOptions->DppType = DP5Stat.m_DP5_Status.DEVICE_ID; // DPP id to test for supported options 00103 CfgOptions->HwCfgDP5Out = strCfg; //configuration, if being sent, empty otherwise 00104 CfgOptions->PC5_PRESENT = DP5Stat.m_DP5_Status.PC5_PRESENT; //PC5 present indicator (accepts pc5 cfg commands) 00105 // bUseCoarseFineGain=true; //uses GAIA,GAIF (coarse with fine gain); 00106 // bUseCoarseFineGain=false; //uses GAIN (total gain); 00107 CfgOptions->SendCoarseFineGain = bUseCoarseFineGain; //select gain configuration control commands 00108 CfgOptions->isDP5_RevDxGains = DP5Stat.m_DP5_Status.isDP5_RevDxGains; 00109 CfgOptions->DPP_ECO = DP5Stat.m_DP5_Status.DPP_ECO; 00110 } 00111 00112 // COMMAND (CONFIG_OPTIONS Needed) 00113 // Command Description 00114 // 00115 // XMTPT_SEND_CONFIG_PACKET_TO_HW (HwCfgDP5Out,SendCoarseFineGain,PC5_PRESENT,DppType) 00116 // Processes a configuration string for errors before sending 00117 // Allows only one gain setting type (coarse,fine OR total gain) 00118 // Removes commands from string that should not be sent to device type 00119 // XMTPT_SEND_CONFIG_PACKET_EX (HwCfgDP5Out) 00120 // Sends the a configuration with minimal error checking 00121 // XMTPT_FULL_READ_CONFIG_PACKET (PC5_PRESENT,DppType) 00122 // Creates and sends a full readback command 00123 bool CConsoleHelper::LibUsb_SendCommand_Config(TRANSMIT_PACKET_TYPE XmtCmd, CONFIG_OPTIONS CfgOptions) 00124 { 00125 bool bHaveBuffer; 00126 int bSentPkt; 00127 bool bMessageSent; 00128 00129 bMessageSent = false; 00130 if (DppLibUsb.bDeviceConnected) { 00131 memset(&DP5Proto.BufferOUT[0],0,sizeof(DP5Proto.BufferOUT)); 00132 bHaveBuffer = (bool) SndCmd.DP5_CMD_Config(DP5Proto.BufferOUT, XmtCmd, CfgOptions); 00133 if (bHaveBuffer) { 00134 bSentPkt = DppLibUsb.SendPacketUSB(DppLibUsb.DppLibusbHandle, DP5Proto.BufferOUT, DP5Proto.PacketIn); 00135 if (bSentPkt) { 00136 bMessageSent = true; 00137 } 00138 } 00139 } 00140 return (bMessageSent); 00141 } 00142 00143 bool CConsoleHelper::LibUsb_ReceiveData() 00144 { 00145 bool bDataReceived; 00146 00147 bDataReceived = true; 00148 if (DppLibUsb.bDeviceConnected) { 00149 bDataReceived = ReceiveData(); 00150 } 00151 return (bDataReceived); 00152 } 00153 00159 bool CConsoleHelper::ReceiveData() 00160 { 00161 bool bDataReceived; 00162 00163 bDataReceived = true; 00164 ParsePkt.DppState.ReqProcess = ParsePkt.ParsePacket(DP5Proto.PacketIn, &DP5Proto.PIN); 00165 switch (ParsePkt.DppState.ReqProcess) { 00166 case preqProcessStatus: 00167 long idxStatus; 00168 for(idxStatus=0;idxStatus<64;idxStatus++) { 00169 DP5Stat.m_DP5_Status.RAW[idxStatus] = DP5Proto.PIN.DATA[idxStatus]; 00170 } 00171 DP5Stat.Process_Status(&DP5Stat.m_DP5_Status); 00172 DppStatusString = DP5Stat.ShowStatusValueStrings(DP5Stat.m_DP5_Status); 00173 break; 00174 case preqProcessSpectrum: 00175 ProcessSpectrumEx(DP5Proto.PIN, ParsePkt.DppState); 00176 break; 00177 //case preqProcessScopeData: 00178 // ProcessScopeDataEx(DP5Proto.PIN, ParsePkt.DppState); 00179 // break; 00180 //case preqProcessTextData: 00181 // ProcessTextDataEx(DP5Proto.PIN, ParsePkt.DppState); 00182 // break; 00183 //case preqProcessDiagData: 00184 // ProcessDiagDataEx(DP5Proto.PIN, ParsePkt.DppState); 00185 // break; 00186 case preqProcessCfgRead: 00187 ProcessCfgReadEx(DP5Proto.PIN, ParsePkt.DppState); 00188 break; 00189 //case preqProcessAck: 00190 // ProcessAck(DP5Proto.PIN.PID2); 00191 // break; 00192 //case preqProcessError: 00193 // DisplayError(DP5Proto.PIN, ParsePkt.DppState); 00194 // break; 00195 default: 00196 bDataReceived = false; 00197 break; 00198 } 00199 return (bDataReceived); 00200 } 00201 00202 //processes spectrum and spectrum+status 00203 void CConsoleHelper::ProcessSpectrumEx(Packet_In PIN, DppStateType DppState) 00204 { 00205 long idxSpectrum; 00206 long idxStatus; 00207 00208 DP5Proto.SPECTRUM.CHANNELS = (short)(256 * pow(2.0,(((PIN.PID2 - 1) & 14) / 2))); 00209 00210 for(idxSpectrum=0;idxSpectrum<DP5Proto.SPECTRUM.CHANNELS;idxSpectrum++) { 00211 DP5Proto.SPECTRUM.DATA[idxSpectrum] = (long)(PIN.DATA[idxSpectrum * 3]) + (long)(PIN.DATA[idxSpectrum * 3 + 1]) * 256 + (long)(PIN.DATA[idxSpectrum * 3 + 2]) * 65536; 00212 } 00213 00214 if ((PIN.PID2 & 1) == 0) { // spectrum + status 00215 for(idxStatus=0;idxStatus<64;idxStatus++) { 00216 DP5Stat.m_DP5_Status.RAW[idxStatus] = PIN.DATA[idxStatus + DP5Proto.SPECTRUM.CHANNELS * 3]; 00217 } 00218 DP5Stat.Process_Status(&DP5Stat.m_DP5_Status); 00219 DppStatusString = DP5Stat.ShowStatusValueStrings(DP5Stat.m_DP5_Status); 00220 } 00221 } 00222 00223 void CConsoleHelper::ClearConfigReadFormatFlags() 00224 { 00225 // configuration readback format control flags 00226 // these flags control how the configuration readback is formatted and processed 00227 DisplayCfg = false; // format configuration for display 00228 DisplaySca = false; // format sca for display (sca config sent separately) 00229 CfgReadBack = false; // format configuration for general readback 00230 SaveCfg = false; // format configuration for file save 00231 PrintCfg = false; // format configuration for print 00232 HwCfgReady = false; // configuration ready flag 00233 ScaReadBack = false; // sca readback ready flag 00234 } 00235 00236 void CConsoleHelper::ProcessCfgReadEx(Packet_In PIN, DppStateType DppState) 00237 { 00238 string strRawCfgIn; 00239 string strRawCfgOut; 00240 string strCh; 00241 string strCmdData; 00242 strRawCfgIn = ""; 00243 string strCmdD; 00244 string strCfg; 00245 bool isScaCfg = false; 00246 string strDisplayCfgOut; 00247 stringex strfn; 00248 00249 strRawCfgOut = ""; 00250 // ========================================================== 00251 // ===== Create Raw Configuration Buffer From Hardware ====== 00252 for (int idxCfg=0;idxCfg<PIN.LEN;idxCfg++) { 00253 strCh = strfn.Format("%c",PIN.DATA[idxCfg]); 00254 strRawCfgIn += strCh; 00255 strRawCfgOut += strCh; 00256 if (PIN.DATA[idxCfg] == ';') { 00257 strRawCfgIn += "\r\n"; 00258 } 00259 } 00260 00261 // ========================================================== 00262 if (DisplayCfg) { 00263 DisplayCfg = false; 00264 strCfg = strRawCfgIn; 00265 strDisplayCfgOut = strRawCfgIn; 00266 if (Dp5CmdList.size() > 0) { 00267 for (unsigned int idxCmd=0;idxCmd<=Dp5CmdList.size();idxCmd++) { 00268 strCmdD = Dp5CmdList[idxCmd]; 00269 if (strCmdD.length() > 0) { 00270 strDisplayCfgOut = ReplaceCmdDesc(strCmdD,strDisplayCfgOut); 00271 } 00272 } 00273 } 00274 return; 00275 } else if (CfgReadBack) { 00276 CfgReadBack = false; 00277 HwCfgDP5 = strRawCfgIn; 00278 HwCfgReady = true; 00279 } 00280 SaveCfg = false; 00281 PrintCfg = false; 00282 DisplayCfg = false; 00283 CfgReadBack = false; 00284 00285 isScaCfg = (bool)(ScaReadBack || DisplaySca); 00286 ScaReadBack = false; 00287 DisplaySca = false; 00288 if (isScaCfg) { 00289 return; 00290 } 00291 strCmdData = GetCmdData("MCAS",strRawCfgIn); // mca mode 00292 strCmdData = GetCmdData("MCAC",strRawCfgIn); // channels 00293 if ((atoi(strCmdData.c_str()) > 0) && (atoi(strCmdData.c_str()) <= 8192)) { 00294 mcaCH = atoi(strCmdData.c_str()); 00295 } else { 00296 mcaCH = 1024; 00297 } 00298 00299 strCmdData = GetCmdData("THSL",strRawCfgIn); // LLD thresh 00300 SlowThresholdPct = atof(strCmdData.c_str()); 00301 00302 strCmdData = GetCmdData("THFA",strRawCfgIn); // fast thresh 00303 FastChThreshold = atoi(strCmdData.c_str()); 00304 00305 strCmdData = GetCmdData("TPEA",strRawCfgIn); // peak time 00306 RiseUS = atof(strCmdData.c_str()); 00307 00308 strCmdData = GetCmdData("GAIN",strRawCfgIn); // gain 00309 strGainDisplayValue = strCmdData + "x"; 00310 00311 strPresetCmd = ""; 00312 strPresetVal = ""; 00313 00314 strCmdData = GetCmdData("PREC",strRawCfgIn); //preset count 00315 PresetCount = atoi(strCmdData.c_str()); 00316 if (PresetCount > 0) { 00317 if (strPresetCmd.length() > 0) { strPresetCmd += "/"; } 00318 if (strPresetVal.length() > 0) { strPresetVal += "/"; } 00319 strPresetCmd += "Cnt"; 00320 strPresetVal += strCmdData; 00321 } 00322 00323 strCmdData = GetCmdData("PRET",strRawCfgIn); //preset actual time 00324 PresetAcq = atof(strCmdData.c_str()); 00325 if (PresetAcq > 0) { 00326 if (strPresetCmd.length() > 0) { strPresetCmd += "/"; } 00327 if (strPresetVal.length() > 0) { strPresetVal += "/"; } 00328 strPresetCmd += "Acq"; 00329 strPresetVal += strCmdData; 00330 } 00331 00332 strCmdData = GetCmdData("PRER",strRawCfgIn); // preset real time 00333 PresetRt = atof(strCmdData.c_str()); 00334 if (PresetRt > 0) { 00335 if (strPresetCmd.length() > 0) { strPresetCmd += "/"; } 00336 if (strPresetVal.length() > 0) { strPresetVal += "/"; } 00337 strPresetCmd += "Real"; 00338 strPresetVal += strCmdData; 00339 } 00340 00341 if (strPresetCmd.length() == 0) { 00342 strPresetCmd += "None"; 00343 } 00344 if (strPresetVal.length() == 0) { 00345 //strPresetVal += ""; 00346 } 00347 00348 strCmdData = GetCmdData("CLCK",strRawCfgIn); // fpga clock mode 00349 if (atoi(strCmdData.c_str()) == 80) { 00350 b80MHzMode = true; 00351 } else { 00352 b80MHzMode = false; 00353 } 00354 00355 // DP5 oscilloscope support 00356 strCmdData = GetCmdData("INOF",strRawCfgIn); // osc. Input offset 00357 strInputOffset = strCmdData; 00358 00359 strCmdData = GetCmdData("DACO",strRawCfgIn); // osc. DAC output 00360 strAnalogOut = strCmdData; 00361 00362 strCmdData = GetCmdData("DACF",strRawCfgIn); // osc. DAC offset 00363 strOutputOffset = strCmdData; 00364 00365 strCmdData = GetCmdData("AUO1",strRawCfgIn); // osc. AUX_OUT1 00366 strTriggerSource = strCmdData; 00367 00368 strCmdData = GetCmdData("SCOE",strRawCfgIn); // osc. Scope trigger edge 00369 strTriggerSlope = strCmdData; 00370 00371 strCmdData = GetCmdData("SCOT",strRawCfgIn); // osc. Scope trigger position 00372 strTriggerPosition = strCmdData; 00373 00374 strCmdData = GetCmdData("SCOG",strRawCfgIn); // osc. Scope gain 00375 strScopeGain = strCmdData; 00376 00377 strCmdData = GetCmdData("MCAS",strRawCfgIn); // Acq Mode 00378 AcqMode = 0; 00379 strMcaMode = "MCA"; 00380 if (strCmdData == "NORM") { 00381 strMcaMode = "MCA"; 00382 } else if (strCmdData == "MCS") { 00383 strMcaMode = "MCS"; 00384 AcqMode = 1; 00385 } else if (strCmdData.length() > 0) { 00386 strMcaMode = strCmdData; 00387 } 00388 UpdateScopeCfg = true; 00389 } 00390 00391 string CConsoleHelper::GetCmdData(string strCmd, string strCfgData) 00392 { 00393 int iStart,iEnd,iCmd; 00394 string strCmdData; 00395 00396 strCmdData = ""; 00397 if (strCfgData.length() < 7) { return strCmdData; } // no data 00398 if (strCmd.length() != 4) { return strCmdData; } // bad command 00399 iCmd = (int)strCfgData.find(strCmd+"=",0); 00400 if (iCmd == -1) { return strCmdData; } // cmd not found 00401 iStart = (int)strCfgData.find("=",iCmd); 00402 if (iStart == -1) { return strCmdData; } // data start not found 00403 iEnd = (int)strCfgData.find(";",iCmd); 00404 if (iEnd == -1) {return strCmdData; } // data end found 00405 if (iStart >= iEnd) { return strCmdData; } // data error 00406 strCmdData = strCfgData.substr(iStart+1,(iEnd - (iStart+1))); 00407 return strCmdData; 00408 } 00409 00410 string CConsoleHelper::ReplaceCmdDesc(string strCmd, string strCfgData) 00411 { 00412 int iStart,iCmd; //iEnd, 00413 string strNew; 00414 string strDesc; 00415 00416 strNew = ""; 00417 if (strCfgData.length() < 7) { return strCfgData; } // no data 00418 if (strCmd.length() != 4) { return strCfgData; } // bad command 00419 iCmd = (int)strCfgData.find(strCmd+"=",0); 00420 if (iCmd == -1) { return strCfgData; } // cmd not found 00421 00422 strDesc = GetCmdDesc(strCmd); 00423 if (strDesc.length() == 0) { return strCfgData; } // cmd desc not found 00424 iStart = (int)strCfgData.find("=",iCmd); 00425 if (iStart != (iCmd + 4)) { return strCfgData; } // data start not found 00426 if (iCmd <= 0) { // usually left string has iCmd-1 00427 iCmd = 1; // in this case left has 0 chars, set offset 00428 } 00429 strNew = strCfgData.substr(0,iCmd-1) + strDesc + strCfgData.substr(iStart); 00430 return strNew; 00431 } 00432 00433 string CConsoleHelper::AppendCmdDesc(string strCmd, string strCfgData) 00434 { 00435 int iStart,iEnd,iCmd; 00436 string strNew; 00437 string strDesc; 00438 00439 strNew = ""; 00440 if (strCfgData.length() < 7) { return strCfgData; } // no data 00441 if (strCmd.length() != 4) { return strCfgData; } // bad command 00442 iCmd = (int)strCfgData.find(strCmd+"=",0); 00443 if (iCmd == -1) { return strCfgData; } // cmd not found 00444 iEnd = (int)strCfgData.find(";",iCmd); 00445 if (iEnd == -1) {return strCfgData; } // data end found 00446 iStart = (int)strCfgData.find("=",iCmd); 00447 if (iStart != (iCmd + 4)) { return strCfgData; } // data start not found 00448 if (iStart >= iEnd) { return strCfgData; } // data error 00449 strDesc = GetCmdDesc(strCmd); 00450 if (strDesc.length() == 0) { return strCfgData; } // cmd desc not found 00451 strNew = strCfgData.substr(0,iEnd+1) + " " + strDesc + strCfgData.substr(iEnd+1); 00452 return strNew; 00453 } 00454 00455 string CConsoleHelper::GetCmdDesc(string strCmd) 00456 { 00457 string strCmdName = ""; 00458 if (strCmd == "RESC") { 00459 strCmdName = "Reset Configuration"; 00460 } else if (strCmd == "CLCK") { 00461 strCmdName = "20MHz/80MHz"; 00462 } else if (strCmd == "TPEA") { 00463 strCmdName = "peaking time"; 00464 } else if (strCmd == "GAIF") { 00465 strCmdName = "Fine gain"; 00466 } else if (strCmd == "GAIN") { 00467 strCmdName = "Total Gain (analog * fine)"; 00468 } else if (strCmd == "RESL") { 00469 strCmdName = "Detector Reset lockout"; 00470 } else if (strCmd == "TFLA") { 00471 strCmdName = "Flat top"; 00472 } else if (strCmd == "TPFA") { 00473 strCmdName = "Fast channel peaking time"; 00474 } else if (strCmd == "RTDE") { 00475 strCmdName = "RTD on/off"; 00476 } else if (strCmd == "MCAS") { 00477 strCmdName = "MCA Source"; 00478 } else if (strCmd == "RTDD") { 00479 strCmdName = "Custom RTD oneshot delay"; 00480 } else if (strCmd == "RTDW") { 00481 strCmdName = "Custom RTD oneshot width"; 00482 } else if (strCmd == "PURE") { 00483 strCmdName = "PUR interval on/off"; 00484 } else if (strCmd == "SOFF") { 00485 strCmdName = "Set spectrum offset"; 00486 } else if (strCmd == "INOF") { 00487 strCmdName = "Input offset"; 00488 } else if (strCmd == "ACKE") { 00489 strCmdName = "ACK / Don't ACK packets with errors"; 00490 } else if (strCmd == "AINP") { 00491 strCmdName = "Analog input pos/neg"; 00492 } else if (strCmd == "AUO1") { 00493 strCmdName = "AUX_OUT selection"; 00494 } else if (strCmd == "AUO2") { 00495 strCmdName = "AUX_OUT2 selection"; 00496 } else if (strCmd == "BLRD") { 00497 strCmdName = "BLR down correction"; 00498 } else if (strCmd == "BLRM") { 00499 strCmdName = "BLR mode"; 00500 } else if (strCmd == "BLRU") { 00501 strCmdName = "BLR up correction"; 00502 } else if (strCmd == "BOOT") { 00503 strCmdName = "Turn supplies on/off at power up"; 00504 } else if (strCmd == "CUSP") { 00505 strCmdName = "Non-trapezoidal shaping"; 00506 } else if (strCmd == "DACF") { 00507 strCmdName = "DAC offset"; 00508 } else if (strCmd == "DACO") { 00509 strCmdName = "DAC output"; 00510 } else if (strCmd == "GAIA") { 00511 strCmdName = "Analog gain index"; 00512 } else if (strCmd == "GATE") { 00513 strCmdName = "Gate control"; 00514 } else if (strCmd == "GPED") { 00515 strCmdName = "G.P. counter edge"; 00516 } else if (strCmd == "GPGA") { 00517 strCmdName = "G.P. counter uses GATE?"; 00518 } else if (strCmd == "GPIN") { 00519 strCmdName = "G.P. counter input"; 00520 } else if (strCmd == "GPMC") { 00521 strCmdName = "G.P. counter cleared with MCA counters?"; 00522 } else if (strCmd == "GPME") { 00523 strCmdName = "G.P. counter uses MCA_EN?"; 00524 } else if (strCmd == "HVSE") { 00525 strCmdName = "HV set"; 00526 } else if (strCmd == "MCAC") { 00527 strCmdName = "MCA/MCS channels"; 00528 } else if (strCmd == "MCAE") { 00529 strCmdName = "MCA/MCS enable"; 00530 } else if (strCmd == "MCSL") { 00531 strCmdName = "MCS low threshold"; 00532 } else if (strCmd == "MCSH") { 00533 strCmdName = "MCS high threshold"; 00534 } else if (strCmd == "MCST") { 00535 strCmdName = "MCS timebase"; 00536 } else if (strCmd == "PAPS") { 00537 strCmdName = "preamp 8.5/5 (N/A)"; 00538 } else if (strCmd == "PAPZ") { 00539 strCmdName = "Pole-Zero"; 00540 } else if (strCmd == "PDMD") { 00541 strCmdName = "Peak detect mode (min/max)"; 00542 } else if (strCmd == "PRCL") { 00543 strCmdName = "Preset counts low threshold"; 00544 } else if (strCmd == "PRCH") { 00545 strCmdName = "Preset counts high threshold"; 00546 } else if (strCmd == "PREC") { 00547 strCmdName = "Preset counts"; 00548 } else if (strCmd == "PRER") { 00549 strCmdName = "Preset Real Time"; 00550 } else if (strCmd == "PRET") { 00551 strCmdName = "Preset time"; 00552 } else if (strCmd == "RTDS") { 00553 strCmdName = "RTD sensitivity"; 00554 } else if (strCmd == "RTDT") { 00555 strCmdName = "RTD threshold"; 00556 } else if (strCmd == "SCAH") { 00557 strCmdName = "SCAx high threshold"; 00558 } else if (strCmd == "SCAI") { 00559 strCmdName = "SCA index"; 00560 } else if (strCmd == "SCAL") { 00561 strCmdName = "SCAx low theshold"; 00562 } else if (strCmd == "SCAO") { 00563 strCmdName = "SCAx output (SCA1-8 only)"; 00564 } else if (strCmd == "SCAW") { 00565 strCmdName = "SCA pulse width (not indexed - SCA1-8)"; 00566 } else if (strCmd == "SCOE") { 00567 strCmdName = "Scope trigger edge"; 00568 } else if (strCmd == "SCOG") { 00569 strCmdName = "Digital scope gain"; 00570 } else if (strCmd == "SCOT") { 00571 strCmdName = "Scope trigger position"; 00572 } else if (strCmd == "TECS") { 00573 strCmdName = "TEC set"; 00574 } else if (strCmd == "THFA") { 00575 strCmdName = "Fast threshold"; 00576 } else if (strCmd == "THSL") { 00577 strCmdName = "Slow threshold"; 00578 } else if (strCmd == "TLLD") { 00579 strCmdName = "LLD threshold"; 00580 } else if (strCmd == "TPMO") { 00581 strCmdName = "Test pulser on/off"; 00582 } else if (strCmd == "VOLU") { 00583 strCmdName = "Speaker On/Off"; 00584 } else if (strCmd == "CON1") { 00585 strCmdName = "Connector 1"; 00586 } else if (strCmd == "CON2") { 00587 strCmdName = "Connector 2"; 00588 } 00589 return strCmdName; 00590 } 00591 00592 //lData=spectrum data,chan=numberof channels,bLog=display as log 00593 void CConsoleHelper::ConsoleGraph(long lData[], long chan, bool bLog, std::string strStatus) 00594 { 00595 const int ScreenW = 80; 00596 const int ScreenH = 24; 00597 char plot[ScreenW][ScreenH]; 00598 char chEmpty = char(32); 00599 #ifdef _WIN32 00600 char chBlock = char(219); 00601 #else 00602 char chBlock = char(79); 00603 #endif 00604 //long xMax; 00605 long yMax; 00606 long idxX; 00607 long idxY; 00608 double xM; 00609 double yM; 00610 long i; 00611 long x; 00612 long y; 00613 double logY; 00614 long logYLong; 00615 00616 yMax = 0; 00617 for(i=0;i<chan;i++) { 00618 if (bLog) { 00619 logY = log(1.0 + lData[i]); 00620 if (yMax < (long)logY) { 00621 yMax = (long)logY; 00622 } 00623 } else { 00624 if (yMax < lData[i]) { 00625 yMax = lData[i]; 00626 } 00627 } 00628 } 00629 00630 xM = (double)ScreenW / (double)chan; 00631 if (yMax < 1) yMax = 1; 00632 yM = (double)(((double)(ScreenH)-(double)2.0) / (double)yMax); 00633 00634 for (i=0;i<chan;i++) { 00635 idxX = (long)((double)i * xM); 00636 if (idxX >= ScreenW) idxX = ScreenW-1; 00637 00638 if (bLog) { 00639 logY = log(1.0 + lData[i]); 00640 logYLong = (long)logY; 00641 idxY = (long)((double)logYLong * yM); 00642 } else { 00643 idxY = (long)((double)lData[i] * yM); 00644 } 00645 if (idxY >= ScreenH) idxY = ScreenH-2; 00646 00647 for(y=0;y<ScreenH;y++) { 00648 if (y <= idxY) { 00649 plot[idxX][y] = chBlock; 00650 } else { 00651 plot[idxX][y] = chEmpty; 00652 } 00653 } 00654 } 00655 00656 unsigned int iRow=0; 00657 unsigned int iCol=0; 00658 unsigned int iRowLen; 00659 std::string strRow; 00660 00661 if (strStatus.length() > 0) { 00662 std::vector<string> vstr = Split(strStatus,"\r\n",true,true); // create rows 00663 for(iRow=0;iRow<(size_t)vstr.size();iRow++) { // copy to plot 00664 strRow = vstr[iRow]; 00665 iRowLen = (unsigned int)strRow.length(); 00666 for(iCol=0;iCol<iRowLen;iCol++){ 00667 plot[iCol][(ScreenH-2)-iRow] = strRow.at(iCol); 00668 } 00669 } 00670 } 00671 00672 for (y=0;y<ScreenH;y++){ 00673 for (x=0;x<ScreenW;x++){ 00674 cout << plot[x][(ScreenH-1)-y]; 00675 } 00676 #ifndef _WIN32 00677 cout << endl; 00678 #endif 00679 } 00680 } 00681 00682 string CConsoleHelper::CreateMCAData(long m_larDataBuffer[], SpectrumFileType sfInfo, DP4_FORMAT_STATUS cfgStatusLst) 00683 { 00684 string strMCA; 00685 string strText; 00686 string strADC; 00687 long idxChan; 00688 string strData; 00689 stringex strfn; 00690 00691 if (cfgStatusLst.SerialNumber <= 0) 00692 { 00693 return (""); 00694 } 00695 strText = ""; 00696 strMCA = ""; 00697 switch(sfInfo.m_iNumChan){ 00698 case 16384: 00699 strADC = "6"; 00700 break; 00701 case 8192: 00702 strADC = "5"; 00703 break; 00704 case 4096: 00705 strADC = "4"; 00706 break; 00707 case 2048: 00708 strADC = "3"; 00709 break; 00710 case 1024: 00711 strADC = "2"; 00712 break; 00713 case 512: 00714 strADC = "1"; 00715 break; 00716 case 256: 00717 strADC = "0"; 00718 break; 00719 } 00720 strMCA += "<<PMCA SPECTRUM>>\r\n"; 00721 strMCA += "TAG - " + sfInfo.strTag + "\r\n"; 00722 strMCA += "DESCRIPTION - " + sfInfo.strDescription + "\r\n"; 00723 strMCA += "GAIN - " + strADC + "\r\n"; 00724 strMCA += "THRESHOLD - 0\r\n"; 00725 strMCA += "LIVE_MODE - 0\r\n"; 00726 strMCA += "PRESET_TIME - \r\n"; 00727 strText = strfn.Format("%lf", cfgStatusLst.AccumulationTime); 00728 strMCA += "LIVE_TIME - " + strText + "\r\n"; 00729 strText = strfn.Format("%lf", cfgStatusLst.RealTime); 00730 strMCA += "REAL_TIME - " + strText + "\r\n"; 00731 strMCA += "START_TIME - \r\n"; 00732 strText = strfn.Format("%i", sfInfo.SerialNumber); 00733 strMCA += "SERIAL_NUMBER - " + strText + "\r\n"; 00734 strMCA += "<<DATA>>\r\n"; 00735 for (idxChan=0;idxChan<sfInfo.m_iNumChan;idxChan++) { 00736 strData = strfn.Format("%i", m_larDataBuffer[idxChan]); 00737 strMCA += strData + "\r\n"; 00738 } 00739 strMCA += "<<END>>\r\n"; 00740 strMCA += "<<DP5 CONFIGURATION>>\r\n"; 00741 strMCA += sfInfo.strSpectrumConfig; 00742 strMCA += "<<DP5 CONFIGURATION END>>\r\n"; 00743 strMCA += "<<DPP STATUS>>\r\n"; 00744 strMCA += sfInfo.strSpectrumStatus; // this functin is included in most examples 00745 strMCA += "<<DPP STATUS END>>\r\n"; 00746 return (strMCA); 00747 } 00748 00749 void CConsoleHelper::SaveSpectrumStringToFile(string strData) 00750 { 00751 FILE *out; 00752 string strFilename; 00753 string strError; 00754 stringex strfn; 00755 00756 strFilename = "SpectrumData.mca"; 00757 00758 if ( (out = fopen(strFilename.c_str(),"wb")) == (FILE *) NULL) 00759 strError = strfn.Format("Couldn't open %s for writing.\n", strFilename.c_str()); 00760 else 00761 { 00762 fprintf(out,"%s",strData.c_str()); 00763 } 00764 fclose(out); 00765 } 00766 00767 string CConsoleHelper::CreateSpectrumConfig(string strRawCfgIn) 00768 { 00769 string strDisplayCfgOut; 00770 string strCmdD; 00771 00772 strDisplayCfgOut = strRawCfgIn; 00773 if (Dp5CmdList.size() > 0) { 00774 for (unsigned int idxCmd=0;idxCmd<Dp5CmdList.size();idxCmd++) { 00775 strCmdD = Dp5CmdList[idxCmd]; 00776 if (strCmdD.length() > 0) { 00777 strDisplayCfgOut = AppendCmdDesc(strCmdD,strDisplayCfgOut); 00778 } 00779 } 00780 } 00781 return strDisplayCfgOut; 00782 } 00783 00784 vector<string> CConsoleHelper::MakeDp5CmdList() 00785 { 00786 vector<string> strCfgArr; 00787 strCfgArr.clear(); 00788 strCfgArr.push_back("RESC"); 00789 strCfgArr.push_back("CLCK"); 00790 strCfgArr.push_back("TPEA"); 00791 strCfgArr.push_back("GAIF"); 00792 strCfgArr.push_back("GAIN"); 00793 strCfgArr.push_back("RESL"); 00794 strCfgArr.push_back("TFLA"); 00795 strCfgArr.push_back("TPFA"); 00796 strCfgArr.push_back("PURE"); 00797 strCfgArr.push_back("RTDE"); 00798 strCfgArr.push_back("MCAS"); 00799 strCfgArr.push_back("MCAC"); 00800 strCfgArr.push_back("SOFF"); 00801 strCfgArr.push_back("AINP"); 00802 strCfgArr.push_back("INOF"); 00803 strCfgArr.push_back("GAIA"); 00804 strCfgArr.push_back("CUSP"); 00805 strCfgArr.push_back("PDMD"); 00806 strCfgArr.push_back("THSL"); 00807 strCfgArr.push_back("TLLD"); 00808 strCfgArr.push_back("THFA"); 00809 strCfgArr.push_back("DACO"); 00810 strCfgArr.push_back("DACF"); 00811 strCfgArr.push_back("RTDS"); 00812 strCfgArr.push_back("RTDT"); 00813 strCfgArr.push_back("BLRM"); 00814 strCfgArr.push_back("BLRD"); 00815 strCfgArr.push_back("BLRU"); 00816 strCfgArr.push_back("GATE"); 00817 strCfgArr.push_back("AUO1"); 00818 strCfgArr.push_back("PRET"); 00819 strCfgArr.push_back("PRER"); 00820 strCfgArr.push_back("PREL"); 00821 strCfgArr.push_back("PREC"); 00822 strCfgArr.push_back("PRCL"); 00823 strCfgArr.push_back("PRCH"); 00824 strCfgArr.push_back("HVSE"); 00825 strCfgArr.push_back("TECS"); 00826 strCfgArr.push_back("PAPZ"); 00827 strCfgArr.push_back("PAPS"); 00828 strCfgArr.push_back("SCOE"); 00829 strCfgArr.push_back("SCOT"); 00830 strCfgArr.push_back("SCOG"); 00831 strCfgArr.push_back("MCSL"); 00832 strCfgArr.push_back("MCSH"); 00833 strCfgArr.push_back("MCST"); 00834 strCfgArr.push_back("AUO2"); 00835 strCfgArr.push_back("TPMO"); 00836 strCfgArr.push_back("GPED"); 00837 strCfgArr.push_back("GPIN"); 00838 strCfgArr.push_back("GPME"); 00839 strCfgArr.push_back("GPGA"); 00840 strCfgArr.push_back("GPMC"); 00841 strCfgArr.push_back("MCAE"); 00842 strCfgArr.push_back("VOLU"); 00843 strCfgArr.push_back("CON1"); 00844 strCfgArr.push_back("CON2"); 00845 strCfgArr.push_back("BOOT"); 00846 return strCfgArr; 00847 }