gccDppConsole Test C++ SDK
1.0.0.0
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 // ACQ_DEVICE_TYPE 00096 // devtypeMCA8000A=0; //MCA8000A 00097 // devtypeDP4=1; //DP4 00098 // devtypePX4=2; //PX4 00099 // devtypeDP4EMUL=3; //DP5,FW5,DP4 emulation 00100 // devtypePX4EMUL=4; //DP5,FW5,Px4 emulation 00101 // ==== ==== This application DOES NOT SUPPORT Communications for DPP Devices Above 00102 // ==== ==== This application supports Communications for DPP Devices Below 00103 // devtypeDP5=5; //DP5,FW6 00104 // devtypePX5=6; //PX5 00105 // devtypeDP5G=7; //DP5G 00106 // devtypeDMCA=8; //Digital MCA 00107 // ==== ==== This application supports Communications for DPP Devices Below 00108 //DEVICE_ID==0; //DP5 00109 //DEVICE_ID==1; //PX5 00110 //DEVICE_ID==2; //DP5G 00111 //DEVICE_ID==3; //DMCA 00112 CfgOptions->DppType = DP5Stat.m_DP5_Status.DEVICE_ID + 5; //5 is added to get the Acquisition Device type 00113 CfgOptions->HwCfgDP5Out = strCfg; //configuration, if being sent, empty otherwise 00114 CfgOptions->PC5_PRESENT = DP5Stat.m_DP5_Status.PC5_PRESENT; //PC5 present indicator (accepts pc5 cfg commands) 00115 // bUseCoarseFineGain=true; //uses GAIA,GAIF (coarse with fine gain); 00116 // bUseCoarseFineGain=false; //uses GAIN (total gain); 00117 CfgOptions->SendCoarseFineGain = bUseCoarseFineGain; //select gain configuration control commands 00118 } 00119 00120 // COMMAND (CONFIG_OPTIONS Needed) 00121 // Command Description 00122 // 00123 // XMTPT_SEND_CONFIG_PACKET_TO_HW (HwCfgDP5Out,SendCoarseFineGain,PC5_PRESENT,DppType) 00124 // Processes a configuration string for errors before sending 00125 // Allows only one gain setting type (coarse,fine OR total gain) 00126 // Removes commands from string that should not be sent to device type 00127 // XMTPT_SEND_CONFIG_PACKET_EX (HwCfgDP5Out) 00128 // Sends the a configuration with minimal error checking 00129 // XMTPT_FULL_READ_CONFIG_PACKET (PC5_PRESENT,DppType) 00130 // Creates and sends a full readback command 00131 bool CConsoleHelper::LibUsb_SendCommand_Config(TRANSMIT_PACKET_TYPE XmtCmd, CONFIG_OPTIONS CfgOptions) 00132 { 00133 bool bHaveBuffer; 00134 int bSentPkt; 00135 bool bMessageSent; 00136 00137 bMessageSent = false; 00138 if (DppLibUsb.bDeviceConnected) { 00139 memset(&DP5Proto.BufferOUT[0],0,sizeof(DP5Proto.BufferOUT)); 00140 bHaveBuffer = (bool) SndCmd.DP5_CMD_Config(DP5Proto.BufferOUT, XmtCmd, CfgOptions); 00141 if (bHaveBuffer) { 00142 bSentPkt = DppLibUsb.SendPacketUSB(DppLibUsb.DppLibusbHandle, DP5Proto.BufferOUT, DP5Proto.PacketIn); 00143 if (bSentPkt) { 00144 bMessageSent = true; 00145 } 00146 } 00147 } 00148 return (bMessageSent); 00149 } 00150 00151 bool CConsoleHelper::LibUsb_ReceiveData() 00152 { 00153 bool bDataReceived; 00154 00155 bDataReceived = true; 00156 if (DppLibUsb.bDeviceConnected) { 00157 bDataReceived = ReceiveData(); 00158 } 00159 return (bDataReceived); 00160 } 00161 00167 bool CConsoleHelper::ReceiveData() 00168 { 00169 bool bDataReceived; 00170 00171 bDataReceived = true; 00172 ParsePkt.DppState.ReqProcess = ParsePkt.ParsePacket(DP5Proto.PacketIn, &DP5Proto.PIN); 00173 switch (ParsePkt.DppState.ReqProcess) { 00174 case preqProcessStatus: 00175 long idxStatus; 00176 for(idxStatus=0;idxStatus<64;idxStatus++) { 00177 DP5Stat.m_DP5_Status.RAW[idxStatus] = DP5Proto.PIN.DATA[idxStatus]; 00178 } 00179 DP5Stat.Process_Status(&DP5Stat.m_DP5_Status); 00180 DppStatusString = DP5Stat.ShowStatusValueStrings(DP5Stat.m_DP5_Status); 00181 break; 00182 case preqProcessSpectrum: 00183 ProcessSpectrumEx(DP5Proto.PIN, ParsePkt.DppState); 00184 break; 00185 //case preqProcessScopeData: 00186 // ProcessScopeDataEx(DP5Proto.PIN, ParsePkt.DppState); 00187 // break; 00188 //case preqProcessTextData: 00189 // ProcessTextDataEx(DP5Proto.PIN, ParsePkt.DppState); 00190 // break; 00191 //case preqProcessDiagData: 00192 // ProcessDiagDataEx(DP5Proto.PIN, ParsePkt.DppState); 00193 // break; 00194 case preqProcessCfgRead: 00195 ProcessCfgReadEx(DP5Proto.PIN, ParsePkt.DppState); 00196 break; 00197 //case preqProcessAck: 00198 // ProcessAck(DP5Proto.PIN.PID2); 00199 // break; 00200 //case preqProcessError: 00201 // DisplayError(DP5Proto.PIN, ParsePkt.DppState); 00202 // break; 00203 default: 00204 bDataReceived = false; 00205 break; 00206 } 00207 return (bDataReceived); 00208 } 00209 00210 //processes spectrum and spectrum+status 00211 void CConsoleHelper::ProcessSpectrumEx(Packet_In PIN, DppStateType DppState) 00212 { 00213 long idxSpectrum; 00214 long idxStatus; 00215 00216 DP5Proto.SPECTRUM.CHANNELS = (short)(256 * pow(2.0,(((PIN.PID2 - 1) & 14) / 2))); 00217 00218 for(idxSpectrum=0;idxSpectrum<DP5Proto.SPECTRUM.CHANNELS;idxSpectrum++) { 00219 DP5Proto.SPECTRUM.DATA[idxSpectrum] = (long)(PIN.DATA[idxSpectrum * 3]) + (long)(PIN.DATA[idxSpectrum * 3 + 1]) * 256 + (long)(PIN.DATA[idxSpectrum * 3 + 2]) * 65536; 00220 } 00221 00222 if ((PIN.PID2 & 1) == 0) { // spectrum + status 00223 for(idxStatus=0;idxStatus<64;idxStatus++) { 00224 DP5Stat.m_DP5_Status.RAW[idxStatus] = PIN.DATA[idxStatus + DP5Proto.SPECTRUM.CHANNELS * 3]; 00225 } 00226 DP5Stat.Process_Status(&DP5Stat.m_DP5_Status); 00227 DppStatusString = DP5Stat.ShowStatusValueStrings(DP5Stat.m_DP5_Status); 00228 } 00229 } 00230 00231 void CConsoleHelper::ClearConfigReadFormatFlags() 00232 { 00233 // configuration readback format control flags 00234 // these flags control how the configuration readback is formatted and processed 00235 DisplayCfg = false; // format configuration for display 00236 DisplaySca = false; // format sca for display (sca config sent separately) 00237 CfgReadBack = false; // format configuration for general readback 00238 SaveCfg = false; // format configuration for file save 00239 PrintCfg = false; // format configuration for print 00240 HwCfgReady = false; // configuration ready flag 00241 ScaReadBack = false; // sca readback ready flag 00242 } 00243 00244 void CConsoleHelper::ProcessCfgReadEx(Packet_In PIN, DppStateType DppState) 00245 { 00246 string strRawCfgIn; 00247 string strRawCfgOut; 00248 string strCh; 00249 string strCmdData; 00250 strRawCfgIn = ""; 00251 string strCmdD; 00252 string strCfg; 00253 bool isScaCfg = false; 00254 string strDisplayCfgOut; 00255 stringex strfn; 00256 00257 strRawCfgOut = ""; 00258 // ========================================================== 00259 // ===== Create Raw Configuration Buffer From Hardware ====== 00260 for (int idxCfg=0;idxCfg<PIN.LEN;idxCfg++) { 00261 strCh = strfn.Format("%c",PIN.DATA[idxCfg]); 00262 strRawCfgIn += strCh; 00263 strRawCfgOut += strCh; 00264 if (PIN.DATA[idxCfg] == ';') { 00265 strRawCfgIn += "\r\n"; 00266 } 00267 } 00268 00269 // ========================================================== 00270 if (DisplayCfg) { 00271 DisplayCfg = false; 00272 strCfg = strRawCfgIn; 00273 strDisplayCfgOut = strRawCfgIn; 00274 if (Dp5CmdList.size() > 0) { 00275 for (unsigned int idxCmd=0;idxCmd<=Dp5CmdList.size();idxCmd++) { 00276 strCmdD = Dp5CmdList[idxCmd]; 00277 if (strCmdD.length() > 0) { 00278 strDisplayCfgOut = ReplaceCmdDesc(strCmdD,strDisplayCfgOut); 00279 } 00280 } 00281 } 00282 return; 00283 } else if (CfgReadBack) { 00284 CfgReadBack = false; 00285 HwCfgDP5 = strRawCfgIn; 00286 HwCfgReady = true; 00287 } 00288 SaveCfg = false; 00289 PrintCfg = false; 00290 DisplayCfg = false; 00291 CfgReadBack = false; 00292 00293 isScaCfg = (bool)(ScaReadBack || DisplaySca); 00294 ScaReadBack = false; 00295 DisplaySca = false; 00296 if (isScaCfg) { 00297 return; 00298 } 00299 strCmdData = GetCmdData("MCAS",strRawCfgIn); // mca mode 00300 strCmdData = GetCmdData("MCAC",strRawCfgIn); // channels 00301 if ((atoi(strCmdData.c_str()) > 0) && (atoi(strCmdData.c_str()) <= 8192)) { 00302 mcaCH = atoi(strCmdData.c_str()); 00303 } else { 00304 mcaCH = 1024; 00305 } 00306 00307 strCmdData = GetCmdData("THSL",strRawCfgIn); // LLD thresh 00308 SlowThresholdPct = atof(strCmdData.c_str()); 00309 00310 strCmdData = GetCmdData("THFA",strRawCfgIn); // fast thresh 00311 FastChThreshold = atoi(strCmdData.c_str()); 00312 00313 strCmdData = GetCmdData("TPEA",strRawCfgIn); // peak time 00314 RiseUS = atof(strCmdData.c_str()); 00315 00316 strCmdData = GetCmdData("GAIN",strRawCfgIn); // gain 00317 strGainDisplayValue = strCmdData + "x"; 00318 00319 strPresetCmd = ""; 00320 strPresetVal = ""; 00321 00322 strCmdData = GetCmdData("PREC",strRawCfgIn); //preset count 00323 PresetCount = atoi(strCmdData.c_str()); 00324 if (PresetCount > 0) { 00325 if (strPresetCmd.length() > 0) { strPresetCmd += "/"; } 00326 if (strPresetVal.length() > 0) { strPresetVal += "/"; } 00327 strPresetCmd += "Cnt"; 00328 strPresetVal += strCmdData; 00329 } 00330 00331 strCmdData = GetCmdData("PRET",strRawCfgIn); //preset actual time 00332 PresetAcq = atof(strCmdData.c_str()); 00333 if (PresetAcq > 0) { 00334 if (strPresetCmd.length() > 0) { strPresetCmd += "/"; } 00335 if (strPresetVal.length() > 0) { strPresetVal += "/"; } 00336 strPresetCmd += "Acq"; 00337 strPresetVal += strCmdData; 00338 } 00339 00340 strCmdData = GetCmdData("PRER",strRawCfgIn); // preset real time 00341 PresetRt = atof(strCmdData.c_str()); 00342 if (PresetRt > 0) { 00343 if (strPresetCmd.length() > 0) { strPresetCmd += "/"; } 00344 if (strPresetVal.length() > 0) { strPresetVal += "/"; } 00345 strPresetCmd += "Real"; 00346 strPresetVal += strCmdData; 00347 } 00348 00349 if (strPresetCmd.length() == 0) { 00350 strPresetCmd += "None"; 00351 } 00352 if (strPresetVal.length() == 0) { 00353 //strPresetVal += ""; 00354 } 00355 00356 strCmdData = GetCmdData("CLCK",strRawCfgIn); // fpga clock mode 00357 if (atoi(strCmdData.c_str()) == 80) { 00358 b80MHzMode = true; 00359 } else { 00360 b80MHzMode = false; 00361 } 00362 00363 // DP5 oscilloscope support 00364 strCmdData = GetCmdData("INOF",strRawCfgIn); // osc. Input offset 00365 strInputOffset = strCmdData; 00366 00367 strCmdData = GetCmdData("DACO",strRawCfgIn); // osc. DAC output 00368 strAnalogOut = strCmdData; 00369 00370 strCmdData = GetCmdData("DACF",strRawCfgIn); // osc. DAC offset 00371 strOutputOffset = strCmdData; 00372 00373 strCmdData = GetCmdData("AUO1",strRawCfgIn); // osc. AUX_OUT1 00374 strTriggerSource = strCmdData; 00375 00376 strCmdData = GetCmdData("SCOE",strRawCfgIn); // osc. Scope trigger edge 00377 strTriggerSlope = strCmdData; 00378 00379 strCmdData = GetCmdData("SCOT",strRawCfgIn); // osc. Scope trigger position 00380 strTriggerPosition = strCmdData; 00381 00382 strCmdData = GetCmdData("SCOG",strRawCfgIn); // osc. Scope gain 00383 strScopeGain = strCmdData; 00384 00385 strCmdData = GetCmdData("MCAS",strRawCfgIn); // Acq Mode 00386 AcqMode = 0; 00387 strMcaMode = "MCA"; 00388 if (strCmdData == "NORM") { 00389 strMcaMode = "MCA"; 00390 } else if (strCmdData == "MCS") { 00391 strMcaMode = "MCS"; 00392 AcqMode = 1; 00393 } else if (strCmdData.length() > 0) { 00394 strMcaMode = strCmdData; 00395 } 00396 UpdateScopeCfg = true; 00397 } 00398 00399 string CConsoleHelper::GetCmdData(string strCmd, string strCfgData) 00400 { 00401 int iStart,iEnd,iCmd; 00402 string strCmdData; 00403 00404 strCmdData = ""; 00405 if (strCfgData.length() < 7) { return strCmdData; } // no data 00406 if (strCmd.length() != 4) { return strCmdData; } // bad command 00407 iCmd = (int)strCfgData.find(strCmd,0); 00408 if (iCmd == -1) { return strCmdData; } // cmd not found 00409 iStart = (int)strCfgData.find("=",iCmd); 00410 if (iStart == -1) { return strCmdData; } // data start not found 00411 iEnd = (int)strCfgData.find(";",iCmd); 00412 if (iEnd == -1) {return strCmdData; } // data end found 00413 if (iStart >= iEnd) { return strCmdData; } // data error 00414 strCmdData = strCfgData.substr(iStart+1,(iEnd - (iStart+1))); 00415 return strCmdData; 00416 } 00417 00418 string CConsoleHelper::ReplaceCmdDesc(string strCmd, string strCfgData) 00419 { 00420 int iStart,iCmd; //iEnd, 00421 string strNew; 00422 string strDesc; 00423 00424 strNew = ""; 00425 if (strCfgData.length() < 7) { return strCfgData; } // no data 00426 if (strCmd.length() != 4) { return strCfgData; } // bad command 00427 iCmd = (int)strCfgData.find(strCmd,0); 00428 if (iCmd == -1) { return strCfgData; } // cmd not found 00429 00430 strDesc = GetCmdDesc(strCmd); 00431 if (strDesc.length() == 0) { return strCfgData; } // cmd desc not found 00432 iStart = (int)strCfgData.find("=",iCmd); 00433 if (iStart != (iCmd + 4)) { return strCfgData; } // data start not found 00434 if (iCmd <= 0) { // usually left string has iCmd-1 00435 iCmd = 1; // in this case left has 0 chars, set offset 00436 } 00437 strNew = strCfgData.substr(0,iCmd-1) + strDesc + strCfgData.substr(iStart); 00438 return strNew; 00439 } 00440 00441 string CConsoleHelper::GetCmdDesc(string strCmd) 00442 { 00443 string strCmdName = ""; 00444 if (strCmd == "RESC") { 00445 strCmdName = "Reset Configuration"; 00446 } else if (strCmd == "CLCK") { 00447 strCmdName = "20MHz/80MHz"; 00448 } else if (strCmd == "TPEA") { 00449 strCmdName = "peaking time"; 00450 } else if (strCmd == "GAIF") { 00451 strCmdName = "Fine gain"; 00452 } else if (strCmd == "GAIN") { 00453 strCmdName = "Total Gain (analog * fine)"; 00454 } else if (strCmd == "RESL") { 00455 strCmdName = "Detector Reset lockout"; 00456 } else if (strCmd == "TFLA") { 00457 strCmdName = "Flat top"; 00458 } else if (strCmd == "TPFA") { 00459 strCmdName = "Fast channel peaking time"; 00460 } else if (strCmd == "RTDE") { 00461 strCmdName = "RTD on/off"; 00462 } else if (strCmd == "MCAS") { 00463 strCmdName = "MCA Source"; 00464 } else if (strCmd == "RTDD") { 00465 strCmdName = "Custom RTD oneshot delay"; 00466 } else if (strCmd == "RTDW") { 00467 strCmdName = "Custom RTD oneshot width"; 00468 } else if (strCmd == "PURE") { 00469 strCmdName = "PUR interval on/off"; 00470 } else if (strCmd == "SOFF") { 00471 strCmdName = "Set spectrum offset"; 00472 } else if (strCmd == "INOF") { 00473 strCmdName = "Input offset"; 00474 } else if (strCmd == "ACKE") { 00475 strCmdName = "ACK / Don't ACK packets with errors"; 00476 } else if (strCmd == "AINP") { 00477 strCmdName = "Analog input pos/neg"; 00478 } else if (strCmd == "AUO1") { 00479 strCmdName = "AUX_OUT selection"; 00480 } else if (strCmd == "AUO2") { 00481 strCmdName = "AUX_OUT2 selection"; 00482 } else if (strCmd == "BLRD") { 00483 strCmdName = "BLR down correction"; 00484 } else if (strCmd == "BLRM") { 00485 strCmdName = "BLR mode"; 00486 } else if (strCmd == "BLRU") { 00487 strCmdName = "BLR up correction"; 00488 } else if (strCmd == "BOOT") { 00489 strCmdName = "Turn supplies on/off at power up"; 00490 } else if (strCmd == "CUSP") { 00491 strCmdName = "Non-trapezoidal shaping"; 00492 } else if (strCmd == "DACF") { 00493 strCmdName = "DAC offset"; 00494 } else if (strCmd == "DACO") { 00495 strCmdName = "DAC output"; 00496 } else if (strCmd == "GAIA") { 00497 strCmdName = "Analog gain index"; 00498 } else if (strCmd == "GATE") { 00499 strCmdName = "Gate control"; 00500 } else if (strCmd == "GPED") { 00501 strCmdName = "G.P. counter edge"; 00502 } else if (strCmd == "GPGA") { 00503 strCmdName = "G.P. counter uses GATE?"; 00504 } else if (strCmd == "GPIN") { 00505 strCmdName = "G.P. counter input"; 00506 } else if (strCmd == "GPMC") { 00507 strCmdName = "G.P. counter cleared with MCA counters?"; 00508 } else if (strCmd == "GPME") { 00509 strCmdName = "G.P. counter uses MCA_EN?"; 00510 } else if (strCmd == "HVSE") { 00511 strCmdName = "HV set"; 00512 } else if (strCmd == "MCAC") { 00513 strCmdName = "MCA/MCS channels"; 00514 } else if (strCmd == "MCAE") { 00515 strCmdName = "MCA/MCS enable"; 00516 } else if (strCmd == "MCSL") { 00517 strCmdName = "MCS low threshold"; 00518 } else if (strCmd == "MCSH") { 00519 strCmdName = "MCS high threshold"; 00520 } else if (strCmd == "MCST") { 00521 strCmdName = "MCS timebase"; 00522 } else if (strCmd == "PAPS") { 00523 strCmdName = "preamp 8.5/5 (N/A)"; 00524 } else if (strCmd == "PAPZ") { 00525 strCmdName = "Pole-Zero"; 00526 } else if (strCmd == "PDMD") { 00527 strCmdName = "Peak detect mode (min/max)"; 00528 } else if (strCmd == "PRCL") { 00529 strCmdName = "Preset counts low threshold"; 00530 } else if (strCmd == "PRCH") { 00531 strCmdName = "Preset counts high threshold"; 00532 } else if (strCmd == "PREC") { 00533 strCmdName = "Preset counts"; 00534 } else if (strCmd == "PRER") { 00535 strCmdName = "Preset Real Time"; 00536 } else if (strCmd == "PRET") { 00537 strCmdName = "Preset time"; 00538 } else if (strCmd == "RTDS") { 00539 strCmdName = "RTD sensitivity"; 00540 } else if (strCmd == "RTDT") { 00541 strCmdName = "RTD threshold"; 00542 } else if (strCmd == "SCAH") { 00543 strCmdName = "SCAx high threshold"; 00544 } else if (strCmd == "SCAI") { 00545 strCmdName = "SCA index"; 00546 } else if (strCmd == "SCAL") { 00547 strCmdName = "SCAx low theshold"; 00548 } else if (strCmd == "SCAO") { 00549 strCmdName = "SCAx output (SCA1-8 only)"; 00550 } else if (strCmd == "SCAW") { 00551 strCmdName = "SCA pulse width (not indexed - SCA1-8)"; 00552 } else if (strCmd == "SCOE") { 00553 strCmdName = "Scope trigger edge"; 00554 } else if (strCmd == "SCOG") { 00555 strCmdName = "Digital scope gain"; 00556 } else if (strCmd == "SCOT") { 00557 strCmdName = "Scope trigger position"; 00558 } else if (strCmd == "TECS") { 00559 strCmdName = "TEC set"; 00560 } else if (strCmd == "THFA") { 00561 strCmdName = "Fast threshold"; 00562 } else if (strCmd == "THSL") { 00563 strCmdName = "Slow threshold"; 00564 } else if (strCmd == "TLLD") { 00565 strCmdName = "LLD threshold"; 00566 } else if (strCmd == "TPMO") { 00567 strCmdName = "Test pulser on/off"; 00568 } else if (strCmd == "VOLU") { 00569 strCmdName = "Speaker On/Off"; 00570 } else if (strCmd == "CON1") { 00571 strCmdName = "Connector 1"; 00572 } else if (strCmd == "CON2") { 00573 strCmdName = "Connector 2"; 00574 } 00575 return strCmdName; 00576 } 00577 00578 //lData=spectrum data,chan=numberof channels,bLog=display as log 00579 void CConsoleHelper::ConsoleGraph(long lData[], long chan, bool bLog, std::string strStatus) 00580 { 00581 const int ScreenW = 80; 00582 const int ScreenH = 24; 00583 char plot[ScreenW][ScreenH]; 00584 char chEmpty = char(32); 00585 #ifdef _WIN32 00586 char chBlock = char(219); 00587 #else 00588 char chBlock = char(79); 00589 #endif 00590 //long xMax; 00591 long yMax; 00592 long idxX; 00593 long idxY; 00594 double xM; 00595 double yM; 00596 long i; 00597 long x; 00598 long y; 00599 double logY; 00600 long logYLong; 00601 00602 yMax = 0; 00603 for(i=0;i<chan;i++) { 00604 if (bLog) { 00605 logY = log(1.0 + lData[i]); 00606 if (yMax < (long)logY) { 00607 yMax = (long)logY; 00608 } 00609 } else { 00610 if (yMax < lData[i]) { 00611 yMax = lData[i]; 00612 } 00613 } 00614 } 00615 00616 xM = (double)ScreenW / (double)chan; 00617 if (yMax < 1) yMax = 1; 00618 yM = (double)(((double)(ScreenH)-(double)2.0) / (double)yMax); 00619 00620 for (i=0;i<chan;i++) { 00621 idxX = (long)((double)i * xM); 00622 if (idxX >= ScreenW) idxX = ScreenW-1; 00623 00624 if (bLog) { 00625 logY = log(1.0 + lData[i]); 00626 logYLong = (long)logY; 00627 idxY = (long)((double)logYLong * yM); 00628 } else { 00629 idxY = (long)((double)lData[i] * yM); 00630 } 00631 if (idxY >= ScreenH) idxY = ScreenH-2; 00632 00633 for(y=0;y<ScreenH;y++) { 00634 if (y <= idxY) { 00635 plot[idxX][y] = chBlock; 00636 } else { 00637 plot[idxX][y] = chEmpty; 00638 } 00639 } 00640 } 00641 00642 unsigned int iRow=0; 00643 unsigned int iCol=0; 00644 unsigned int iRowLen; 00645 std::string strRow; 00646 00647 if (strStatus.length() > 0) { 00648 std::vector<string> vstr = Split(strStatus,"\r\n",true,true); // create rows 00649 for(iRow=0;iRow<(size_t)vstr.size();iRow++) { // copy to plot 00650 strRow = vstr[iRow]; 00651 iRowLen = (unsigned int)strRow.length(); 00652 for(iCol=0;iCol<iRowLen;iCol++){ 00653 plot[iCol][(ScreenH-2)-iRow] = strRow.at(iCol); 00654 } 00655 } 00656 } 00657 00658 for (y=0;y<ScreenH;y++){ 00659 for (x=0;x<ScreenW;x++){ 00660 cout << plot[x][(ScreenH-1)-y]; 00661 } 00662 #ifndef _WIN32 00663 cout << endl; 00664 #endif 00665 } 00666 } 00667