gccDppConsole Test C++ SDK
20170920
DPP C++ Console Demonstration
|
00001 00002 #include "DP5Status.h" 00003 #include "stringex.h" 00004 #include "DppConst.h" 00005 #ifdef _MSC_VER 00006 #pragma warning(disable:4996) 00007 #endif 00008 00009 CDP5Status::CDP5Status(void) 00010 { 00011 } 00012 00013 CDP5Status::~CDP5Status(void) 00014 { 00015 } 00016 00017 void CDP5Status::Process_Status(DP4_FORMAT_STATUS *m_DP5_Status) 00018 { 00019 bool bDMCA_LiveTime = false; 00020 unsigned int uiFwBuild = 0; 00021 00022 m_DP5_Status->DEVICE_ID = m_DP5_Status->RAW[39]; 00023 m_DP5_Status->FastCount = DppUtil.LongWordToDouble(0, m_DP5_Status->RAW); 00024 m_DP5_Status->SlowCount = DppUtil.LongWordToDouble(4, m_DP5_Status->RAW); 00025 m_DP5_Status->GP_COUNTER = DppUtil.LongWordToDouble(8, m_DP5_Status->RAW); 00026 m_DP5_Status->AccumulationTime = (float)m_DP5_Status->RAW[12] * 0.001 + (float)(m_DP5_Status->RAW[13] + (float)m_DP5_Status->RAW[14] * 256.0 + (float)m_DP5_Status->RAW[15] * 65536.0) * 0.1; 00027 m_DP5_Status->RealTime = ((double)m_DP5_Status->RAW[20] + ((double)m_DP5_Status->RAW[21] * 256.0) + ((double)m_DP5_Status->RAW[22] * 65536.0) + ((double)m_DP5_Status->RAW[23] * 16777216.0)) * 0.001; 00028 00029 m_DP5_Status->Firmware = m_DP5_Status->RAW[24]; 00030 m_DP5_Status->FPGA = m_DP5_Status->RAW[25]; 00031 00032 if (m_DP5_Status->Firmware > 0x65) { 00033 m_DP5_Status->Build = m_DP5_Status->RAW[37] & 0xF; //Build # added in FW6.06 00034 } else { 00035 m_DP5_Status->Build = 0; 00036 } 00037 00038 //Firmware Version: 6.07 Build: 0 has LiveTime and PREL 00039 //DEVICE_ID 0=DP5,1=PX5,2=DP5G,3=MCA8000D,4=TB5 00040 if (m_DP5_Status->DEVICE_ID == dppMCA8000D) { 00041 if (m_DP5_Status->Firmware >= 0x67) { 00042 bDMCA_LiveTime = true; 00043 } 00044 } 00045 00046 if (bDMCA_LiveTime) { 00047 m_DP5_Status->LiveTime = ((double)m_DP5_Status->RAW[16] + ((double)m_DP5_Status->RAW[17] * 256.0) + ((double)m_DP5_Status->RAW[18] * 65536.0) + ((double)m_DP5_Status->RAW[19] * 16777216.0)) * 0.001; 00048 } else { 00049 m_DP5_Status->LiveTime = 0; 00050 } 00051 00052 if (m_DP5_Status->RAW[29] < 128) { 00053 m_DP5_Status->SerialNumber = (unsigned long)DppUtil.LongWordToDouble(26, m_DP5_Status->RAW); 00054 } else { 00055 m_DP5_Status->SerialNumber = -1; 00056 } 00057 00058 // m_DP5_Status->HV = (double)(m_DP5_Status->RAW[31] + (m_DP5_Status->RAW[30] & 15) * 256) * 0.5; // 0.5V/count 00059 00060 if (m_DP5_Status->RAW[30] < 128) { // not negative 00061 m_DP5_Status->HV = ((double)m_DP5_Status->RAW[31] + ((double)m_DP5_Status->RAW[30] * 256.0)) * 0.5; // 0.5V/count 00062 } else { 00063 m_DP5_Status->HV = (((double)m_DP5_Status->RAW[31] + ((double)m_DP5_Status->RAW[30] * 256)) - 65536.0) * 0.5; // 0.5V/count 00064 } 00065 00066 m_DP5_Status->DET_TEMP = (double)((m_DP5_Status->RAW[33]) + (m_DP5_Status->RAW[32] & 15) * 256) * 0.1; // - 273.16; // 0.1K/count 00067 m_DP5_Status->DP5_TEMP = m_DP5_Status->RAW[34] - ((m_DP5_Status->RAW[34] & 128) * 2); 00068 00069 m_DP5_Status->PresetRtDone = ((m_DP5_Status->RAW[35] & 128) == 128); 00070 00071 //unsigned char:35 BIT:D6 00072 // == Preset LiveTime Done for MCA8000D 00073 // == FAST Thresh locked for other dpp devices 00074 m_DP5_Status->PresetLtDone = false; 00075 m_DP5_Status->AFAST_LOCKED = false; 00076 if (bDMCA_LiveTime) { // test for MCA8000D 00077 m_DP5_Status->PresetLtDone = ((m_DP5_Status->RAW[35] & 64) == 64); 00078 } else { 00079 m_DP5_Status->AFAST_LOCKED = ((m_DP5_Status->RAW[35] & 64) == 64); 00080 } 00081 m_DP5_Status->MCA_EN = ((m_DP5_Status->RAW[35] & 32) == 32); 00082 m_DP5_Status->PRECNT_REACHED = ((m_DP5_Status->RAW[35] & 16) == 16); 00083 m_DP5_Status->SCOPE_DR = ((m_DP5_Status->RAW[35] & 4) == 4); 00084 m_DP5_Status->DP5_CONFIGURED = ((m_DP5_Status->RAW[35] & 2) == 2); 00085 00086 m_DP5_Status->AOFFSET_LOCKED = ((m_DP5_Status->RAW[36] & 128) == 0); // 0=locked, 1=searching 00087 m_DP5_Status->MCS_DONE = ((m_DP5_Status->RAW[36] & 64) == 64); 00088 00089 m_DP5_Status->b80MHzMode = ((m_DP5_Status->RAW[36] & 2) == 2); 00090 m_DP5_Status->bFPGAAutoClock = ((m_DP5_Status->RAW[36] & 1) == 1); 00091 00092 m_DP5_Status->PC5_PRESENT = ((m_DP5_Status->RAW[38] & 128) == 128); 00093 if (m_DP5_Status->PC5_PRESENT) { 00094 m_DP5_Status->PC5_HV_POL = ((m_DP5_Status->RAW[38] & 64) == 64); 00095 m_DP5_Status->PC5_8_5V = ((m_DP5_Status->RAW[38] & 32) == 32); 00096 } else { 00097 m_DP5_Status->PC5_HV_POL = false; 00098 m_DP5_Status->PC5_8_5V = false; 00099 } 00100 00101 if (m_DP5_Status->Firmware >= 0x65) { // reboot flag added FW6.05 00102 if ((m_DP5_Status->RAW[36] & 32) == 32) { 00103 m_DP5_Status->ReBootFlag = true; 00104 } else { 00105 m_DP5_Status->ReBootFlag = false; 00106 } 00107 } else { 00108 m_DP5_Status->ReBootFlag = false; 00109 } 00110 00111 m_DP5_Status->TEC_Voltage = (((double)(m_DP5_Status->RAW[40] & 15) * 256.0) + (double)(m_DP5_Status->RAW[41])) / 758.5; 00112 m_DP5_Status->DPP_ECO = m_DP5_Status->RAW[49]; 00113 m_DP5_Status->bScintHas80MHzOption = false; 00114 m_DP5_Status->DPP_options = (m_DP5_Status->RAW[42] & 15); 00115 m_DP5_Status->HPGe_HV_INH = false; 00116 m_DP5_Status->HPGe_HV_INH_POL = false; 00117 m_DP5_Status->AU34_2 = false; 00118 m_DP5_Status->isAscInstalled = false; 00119 m_DP5_Status->isDP5_RevDxGains = false; 00120 if (m_DP5_Status->DEVICE_ID == dppPX5) { 00121 if (m_DP5_Status->DPP_options == PX5_OPTION_HPGe_HVPS) { 00122 m_DP5_Status->HPGe_HV_INH = ((m_DP5_Status->RAW[42] & 32) == 32); 00123 m_DP5_Status->HPGe_HV_INH_POL = ((m_DP5_Status->RAW[42] & 16) == 16); 00124 if (m_DP5_Status->DPP_ECO == 1) { 00125 m_DP5_Status->isAscInstalled = true; 00126 m_DP5_Status->AU34_2 = ((m_DP5_Status->RAW[42] & 64) == 64); 00127 } 00128 } 00129 } else if ((m_DP5_Status->DEVICE_ID == dppDP5G) || (m_DP5_Status->DEVICE_ID == dppTB5)) { 00130 if ((m_DP5_Status->DPP_ECO == 1) || (m_DP5_Status->DPP_ECO == 2)) { 00131 // DPP_ECO == 2 80MHz option added 20150409 00132 m_DP5_Status->bScintHas80MHzOption = true; 00133 } 00134 } else if (m_DP5_Status->DEVICE_ID == dppDP5) { 00135 uiFwBuild = m_DP5_Status->Firmware; 00136 uiFwBuild = uiFwBuild << 8; 00137 uiFwBuild = uiFwBuild + m_DP5_Status->Build; 00138 // uiFwBuild - firmware with build for comparison 00139 if (uiFwBuild >= 0x686) { 00140 // 0xFF Value indicates old Analog Gain Count of 16 00141 // Values < 0xFF indicate new gain count of 24 and new board rev 00142 // "DP5 G3 Configuration P" will not be used (==0xFF) 00143 if (m_DP5_Status->DPP_ECO < 0xFF) { 00144 m_DP5_Status->isDP5_RevDxGains = true; 00145 } 00146 00147 } 00148 00149 } 00150 } 00151 00152 string CDP5Status::DP5_Dx_OptionFlags(unsigned char DP5_Dx_Options) { 00153 unsigned char D7D6; 00154 unsigned char D5D4; 00155 unsigned char D3D0; 00156 string strRev(""); 00157 stringex strfn; 00158 00159 //D7-D6: 0 = DP5 Rev D 00160 // 1 = DP5 Rev E (future) 00161 // 2 = DP5 Rev F (future) 00162 // 3 = DP5 Rev G (future) 00163 D7D6 = ((DP5_Dx_Options >> 6) & 0x03) + 'D'; 00164 //D5-D4: minor rev, 0-3 (i.e. Rev D0, D1 etc.) 00165 D5D4 = ((DP5_Dx_Options >> 4) & 0x03); 00166 //D3-D0: Configuration 0 = A, 1=B, 2=C... 15=P. 00167 D3D0 = (DP5_Dx_Options & 0x0F) + 'A'; 00168 00169 strRev = strfn.Format("DP5 Rev %c%d Configuration %c",D7D6,D5D4,D3D0); 00170 return(strRev); 00171 00172 } 00173 00174 string CDP5Status::ShowStatusValueStrings(DP4_FORMAT_STATUS m_DP5_Status) 00175 { 00176 string strConfig(""); 00177 string strTemp; 00178 string strIntPart; 00179 string strFracPart; 00180 stringex strfn; 00181 00182 strTemp = GetDeviceNameFromVal(m_DP5_Status.DEVICE_ID); 00183 strConfig = "Device Type: " + strTemp + "\r\n"; 00184 strTemp = strfn.Format("Serial Number: %lu\r\n",m_DP5_Status.SerialNumber); //SerialNumber 00185 strConfig += strTemp; 00186 strTemp = "Firmware: " + DppUtil.BYTEVersionToString(m_DP5_Status.Firmware); 00187 strConfig += strTemp; 00188 if (m_DP5_Status.Firmware > 0x65) { 00189 strTemp = strfn.Format(" Build: %d\r\n", m_DP5_Status.Build); 00190 strConfig += strTemp; 00191 } else { 00192 strConfig += "\r\n"; 00193 } 00194 strTemp = "FPGA: " + DppUtil.BYTEVersionToString(m_DP5_Status.FPGA) + "\r\n"; 00195 strConfig += strTemp; 00196 if (m_DP5_Status.DEVICE_ID != dppMCA8000D) { 00197 strTemp = strfn.Format("Fast Count: %.0f\r\n",m_DP5_Status.FastCount); //FastCount 00198 strConfig += strTemp; 00199 } 00200 strTemp = strfn.Format("Slow Count: %.0f\r\n",m_DP5_Status.SlowCount); //SlowCount 00201 strConfig += strTemp; 00202 strTemp = strfn.Format("GP Count: %.0f\r\n",m_DP5_Status.GP_COUNTER); //GP Count 00203 strConfig += strTemp; 00204 00205 if (m_DP5_Status.DEVICE_ID != dppMCA8000D) { 00206 strTemp = strfn.Format("Accumulation Time: %.0f\r\n",m_DP5_Status.AccumulationTime); //AccumulationTime 00207 strConfig += strTemp; 00208 } 00209 00210 strTemp = strfn.Format("Real Time: %.0f\r\n",m_DP5_Status.RealTime); //RealTime 00211 strConfig += strTemp; 00212 00213 if (m_DP5_Status.DEVICE_ID == dppMCA8000D) { 00214 strTemp = strfn.Format("Live Time: %.0f\r\n",m_DP5_Status.LiveTime); //RealTime 00215 strConfig += strTemp; 00216 } 00217 00218 return strConfig; 00219 } 00220 00221 string CDP5Status::PX5_OptionsString(DP4_FORMAT_STATUS m_DP5_Status) 00222 { 00223 string strOptions(""); 00224 string strValue(""); 00225 00226 if (m_DP5_Status.DEVICE_ID == dppPX5) { 00227 //m_DP5_Status.DPP_options = 1; 00228 //m_DP5_Status.HPGe_HV_INH = true; 00229 //m_DP5_Status.HPGe_HV_INH_POL = true; 00230 if (m_DP5_Status.DPP_options > 0) { 00231 //===============PX5 Options================== 00232 strOptions += "PX5 Options: "; 00233 if ((m_DP5_Status.DPP_options & 1) == 1) { 00234 strOptions += "HPGe HVPS\r\n"; 00235 } else { 00236 strOptions += "Unknown\r\n"; 00237 } 00238 //===============HPGe HVPS HV Status================== 00239 strOptions += "HPGe HV: "; 00240 if (m_DP5_Status.HPGe_HV_INH) { 00241 strOptions += "not inhibited\r\n"; 00242 } else { 00243 strOptions += "inhibited\r\n"; 00244 } 00245 //===============HPGe HVPS Inhibit Status================== 00246 strOptions += "INH Polarity: "; 00247 if (m_DP5_Status.HPGe_HV_INH_POL) { 00248 strOptions += "high\r\n"; 00249 } else { 00250 strOptions += "low\r\n"; 00251 } 00252 } else { 00253 strOptions += "PX5 Options: None\r\n"; // strOptions += "No Options Installed" 00254 } 00255 } 00256 return strOptions; 00257 } 00258 00259 string CDP5Status::GetStatusValueStrings(DP4_FORMAT_STATUS m_DP5_Status) 00260 { 00261 string strConfig(""); 00262 string strTemp; 00263 string strIntPart; 00264 string strFracPart; 00265 stringex strfn; 00266 00267 strTemp = GetDeviceNameFromVal(m_DP5_Status.DEVICE_ID); 00268 strConfig = "Device Type: " + strTemp + "\r\n"; 00269 strTemp = strfn.Format("Serial Number: %lu\r\n",m_DP5_Status.SerialNumber); //SerialNumber 00270 strConfig += strTemp; 00271 strTemp = "Firmware: " + DppUtil.BYTEVersionToString(m_DP5_Status.Firmware); 00272 strConfig += strTemp; 00273 if (m_DP5_Status.Firmware > 0x65) { 00274 strTemp = strfn.Format(" Build: %d\r\n", m_DP5_Status.Build); 00275 strConfig += strTemp; 00276 } else { 00277 strConfig += "\r\n"; 00278 } 00279 strTemp = "FPGA: " + DppUtil.BYTEVersionToString(m_DP5_Status.FPGA) + "\r\n"; 00280 strConfig += strTemp; 00281 if (m_DP5_Status.DEVICE_ID != dppMCA8000D) { 00282 strTemp = strfn.Format("Fast Count: %.0f\r\n",m_DP5_Status.FastCount); //FastCount 00283 strConfig += strTemp; 00284 } 00285 strTemp = strfn.Format("Slow Count: %.0f\r\n",m_DP5_Status.SlowCount); //SlowCount 00286 strConfig += strTemp; 00287 strTemp = strfn.Format("GP Count: %.0f\r\n",m_DP5_Status.GP_COUNTER); //GP Count 00288 strConfig += strTemp; 00289 00290 if (m_DP5_Status.DEVICE_ID != dppMCA8000D) { 00291 strTemp = strfn.Format("Accumulation Time: %.0f\r\n",m_DP5_Status.AccumulationTime); //AccumulationTime 00292 strConfig += strTemp; 00293 } 00294 00295 strTemp = strfn.Format("Real Time: %.0f\r\n",m_DP5_Status.RealTime); //RealTime 00296 strConfig += strTemp; 00297 00298 if (m_DP5_Status.DEVICE_ID == dppMCA8000D) { 00299 strTemp = strfn.Format("Live Time: %.0f\r\n",m_DP5_Status.LiveTime); //RealTime 00300 strConfig += strTemp; 00301 } 00302 00303 if ((m_DP5_Status.DEVICE_ID != dppDP5G) && (m_DP5_Status.DEVICE_ID != dppTB5) && (m_DP5_Status.DEVICE_ID != dppMCA8000D)) { 00304 strTemp = strfn.Format("Detector Temp: %.0fK\r\n",m_DP5_Status.DET_TEMP); //"##0�C") ' round to nearest degree 00305 strConfig += strTemp; 00306 strTemp = strfn.Format("Detector HV: %.0fV\r\n",m_DP5_Status.HV); 00307 strConfig += strTemp; 00308 strTemp = strfn.Format("Board Temp: %d�C\r\n",(int)m_DP5_Status.DP5_TEMP); 00309 strConfig += strTemp; 00310 } else if ((m_DP5_Status.DEVICE_ID == dppDP5G) || (m_DP5_Status.DEVICE_ID == dppTB5)) { // GAMMARAD5,TB5 00311 if (m_DP5_Status.DET_TEMP > 0) { 00312 strTemp = strfn.Format("Detector Temp: %.1fK\r\n",m_DP5_Status.DET_TEMP); 00313 strConfig += strTemp; 00314 } else { 00315 strConfig += ""; 00316 } 00317 strTemp = strfn.Format("HV Set: %.0fV\r\n",m_DP5_Status.HV); 00318 strConfig += strTemp; 00319 } else if (m_DP5_Status.DEVICE_ID == dppMCA8000D) { // Digital MCA 00320 strTemp = strfn.Format("Board Temp: %d�C\r\n",(int)m_DP5_Status.DP5_TEMP); 00321 strConfig += strTemp; 00322 } 00323 if (m_DP5_Status.DEVICE_ID == dppPX5) { 00324 strTemp = PX5_OptionsString(m_DP5_Status); 00325 strConfig += strTemp; 00326 strTemp = strfn.Format("TEC V: %.3fV\r\n",m_DP5_Status.TEC_Voltage); 00327 strConfig += strTemp; 00328 } 00329 return strConfig; 00330 } 00331 00332 void CDP5Status::Process_Diagnostics(Packet_In PIN, DiagDataType *dd, int device_type) 00333 { 00334 long idxVal; 00335 string strVal; 00336 double DP5_ADC_Gain[10]; // convert each ADC count to engineering units - values calculated in FORM.LOAD 00337 double PC5_ADC_Gain[3]; 00338 double PX5_ADC_Gain[12]; 00339 stringex strfn; 00340 00341 DP5_ADC_Gain[0] = 1.0 / 0.00286; // 2.86mV/C 00342 DP5_ADC_Gain[1] = 1.0; // Vdd mon (out-of-scale) 00343 DP5_ADC_Gain[2] = (30.1 + 20.0) / 20.0; // PWR 00344 DP5_ADC_Gain[3] = (13.0 + 20.0) / 20.0; // 3.3V 00345 DP5_ADC_Gain[4] = (4.99 + 20.0) / 20.0; // 2.5V 00346 DP5_ADC_Gain[5] = 1.0; // 1.2V 00347 DP5_ADC_Gain[6] = (35.7 + 20.0) / 20.0; // 5.5V 00348 DP5_ADC_Gain[7] = (35.7 + 75.0) / 35.7; // -5.5V (this one is tricky) 00349 DP5_ADC_Gain[8] = 1.0; // AN_IN 00350 DP5_ADC_Gain[9] = 1.0; // VREF_IN 00351 00352 PC5_ADC_Gain[0] = 500.0; // HV: 1500V/3V 00353 PC5_ADC_Gain[1] = 100.0; // TEC: 300K/3V 00354 PC5_ADC_Gain[2] = (20.0 + 10.0) / 10.0; // +8.5/5V 00355 00356 //PX5_ADC_Gain[0] = (30.1 + 20.0) / 20.0; // PWR 00357 PX5_ADC_Gain[0] = (69.8 + 20.0) / 20.0; // 9V (was originally PWR) 00358 PX5_ADC_Gain[1] = (13.0 + 20.0) / 20.0; // 3.3V 00359 PX5_ADC_Gain[2] = (4.99 + 20.0) / 20.0; // 2.5V 00360 PX5_ADC_Gain[3] = 1.0; // 1.2V 00361 PX5_ADC_Gain[4] = (30.1 + 20.0) / 20.0; // 5V 00362 PX5_ADC_Gain[5] = (10.7 + 75.0) / 10.7; // -5V (this one is tricky) 00363 PX5_ADC_Gain[6] = (64.9 + 20.0) / 20.0; // +PA 00364 PX5_ADC_Gain[7] = (10.7 + 75) / 10.7; // -PA 00365 PX5_ADC_Gain[8] = (16.0 + 20.0) / 20.0; // +TEC 00366 PX5_ADC_Gain[9] = 500.0; // HV: 1500V/3V 00367 PX5_ADC_Gain[10] = 100.0; // TEC: 300K/3V 00368 PX5_ADC_Gain[11] = 1.0 / 0.00286; // 2.86mV/C 00369 00370 dd->Firmware = PIN.DATA[0]; 00371 dd->FPGA = PIN.DATA[1]; 00372 strVal = "0x0" + FmtHex(PIN.DATA[2], 2) + FmtHex(PIN.DATA[3], 2) + FmtHex(PIN.DATA[4], 2); 00373 dd->SRAMTestData = strtol(strVal.c_str(),NULL,0); 00374 dd->SRAMTestPass = (dd->SRAMTestData == 0xFFFFFF); 00375 dd->TempOffset = PIN.DATA[180] + 256 * (PIN.DATA[180] > 127); // 8-bit signed value 00376 00377 if ((device_type == dppDP5) || (device_type == dppDP5X)) { 00378 for(idxVal=0;idxVal<10;idxVal++){ 00379 dd->ADC_V[idxVal] = (float)((((PIN.DATA[5 + idxVal * 2] & 3) * 256) + PIN.DATA[6 + idxVal * 2]) * 2.44 / 1024.0 * DP5_ADC_Gain[idxVal]); // convert counts to engineering units (C or V) 00380 } 00381 dd->ADC_V[7] = dd->ADC_V[7] + dd->ADC_V[6] * (float)(1.0 - DP5_ADC_Gain[7]); // -5.5V is a function of +5.5V 00382 dd->strTempRaw = strfn.Format("% #.0f0C", dd->ADC_V[0] - 271.3); 00383 dd->strTempCal = strfn.Format("% #.0f0C", (dd->ADC_V[0] - 280.0 + dd->TempOffset)); 00384 } else if (device_type == dppPX5) { 00385 for(idxVal=0;idxVal<11;idxVal++){ 00386 dd->ADC_V[idxVal] = (float)((((PIN.DATA[5 + idxVal * 2] & 15) * 256) + PIN.DATA[6 + idxVal * 2]) * 3.0 / 4096.0 * PX5_ADC_Gain[idxVal]); // convert counts to engineering units (C or V) 00387 } 00388 dd->ADC_V[11] = (float)((((PIN.DATA[5 + 11 * 2] & 3) * 256) + PIN.DATA[6 + 11 * 2]) * 3.0 / 1024.0 * PX5_ADC_Gain[11]); // convert counts to engineering units (C or V) 00389 dd->ADC_V[5] = (float)(dd->ADC_V[5] - (3.0 * PX5_ADC_Gain[5]) + 3.0); // -5V uses +3VR 00390 dd->ADC_V[7] = (float)(dd->ADC_V[7] - (3.0 * PX5_ADC_Gain[7]) + 3.0); // -PA uses +3VR 00391 dd->strTempRaw = strfn.Format("%#.1fC", dd->ADC_V[11] - 271.3); 00392 dd->strTempCal = strfn.Format("%#.1fC", (dd->ADC_V[11] - 280.0 + dd->TempOffset)); 00393 } 00394 00395 dd->PC5_PRESENT = false; // assume no PC5, then check to see if there are any non-zero bytes 00396 for(idxVal=25;idxVal<=38;idxVal++) { 00397 if (PIN.DATA[idxVal] > 0) { 00398 dd->PC5_PRESENT = true; 00399 break; 00400 } 00401 } 00402 00403 if (dd->PC5_PRESENT) { 00404 for(idxVal=0;idxVal<=2;idxVal++) { 00405 dd->PC5_V[idxVal] = (float)((((PIN.DATA[25 + idxVal * 2] & 15) * 256) + PIN.DATA[26 + idxVal * 2]) * 3.0 / 4096.0 * PC5_ADC_Gain[idxVal]); // convert counts to engineering units (C or V) 00406 } 00407 if (PIN.DATA[34] < 128) { 00408 dd->PC5_SN = (unsigned long)DppUtil.LongWordToDouble(31, PIN.DATA); 00409 } else { 00410 dd->PC5_SN = -1; // no PC5 S/N 00411 } 00412 if ((PIN.DATA[35] == 255) && (PIN.DATA[36] == 255)) { 00413 dd->PC5Initialized = false; 00414 dd->PC5DCAL = 0; 00415 } else { 00416 dd->PC5Initialized = true; 00417 dd->PC5DCAL = (float)(((float)(PIN.DATA[35]) * 256.0 + (float)(PIN.DATA[36])) * 3.0 / 4096.0); 00418 } 00419 dd->IsPosHV = ((PIN.DATA[37] & 128) == 128); 00420 dd->Is8_5VPreAmp = ((PIN.DATA[37] & 64) == 64); 00421 dd->Sup9VOn = ((PIN.DATA[38] & 8) == 8); 00422 dd->PreAmpON = ((PIN.DATA[38] & 4) == 4); 00423 dd->HVOn = ((PIN.DATA[38] & 2) == 2); 00424 dd->TECOn = ((PIN.DATA[38] & 1) == 1); 00425 } else { 00426 for(idxVal=0;idxVal<=2;idxVal++) { 00427 dd->PC5_V[idxVal] = 0; 00428 } 00429 dd->PC5_SN = -1; // no PC5 S/N 00430 dd->PC5Initialized = false; 00431 dd->PC5DCAL = 0; 00432 dd->IsPosHV = false; 00433 dd->Is8_5VPreAmp = false; 00434 dd->Sup9VOn = false; 00435 dd->PreAmpON = false; 00436 dd->HVOn = false; 00437 dd->TECOn = false; 00438 } 00439 for(idxVal=0;idxVal<=191;idxVal++) { 00440 dd->DiagData[idxVal] = PIN.DATA[idxVal + 39]; 00441 } 00442 //string strData; 00443 //strData = DisplayBufferArray(PIN.DATA, 256); 00444 //SaveStringDataToFile(strData); 00445 } 00446 00447 string CDP5Status::DiagnosticsToString(DiagDataType dd, int device_type) 00448 { 00449 long idxVal; 00450 string strVal; 00451 string strDiag; 00452 stringex strfn; 00453 00454 strDiag = "Firmware: " + VersionToStr(dd.Firmware) + "\r\n"; 00455 strDiag += "FPGA: " + VersionToStr(dd.FPGA) + "\r\n"; 00456 strDiag += "SRAM Test: "; 00457 if (dd.SRAMTestPass) { 00458 strDiag += "PASS\r\n"; 00459 } else { 00460 strDiag += "ERROR @ 0x" + FmtHex(dd.SRAMTestData, 6) + "\r\n"; 00461 } 00462 00463 if ((device_type == dppDP5) || (device_type == dppDP5X)) { 00464 strDiag += "DP5 Temp (raw): " + dd.strTempRaw + "\r\n"; 00465 strDiag += "DP5 Temp (cal'd): " + dd.strTempCal + "\r\n"; 00466 strDiag += "PWR: " + FmtPc5Pwr(dd.ADC_V[2]) + "\r\n"; 00467 strDiag += "3.3V: " + FmtPc5Pwr(dd.ADC_V[3]) + "\r\n"; 00468 strDiag += "2.5V: " + FmtPc5Pwr(dd.ADC_V[4]) + "\r\n"; 00469 strDiag += "1.2V: " + FmtPc5Pwr(dd.ADC_V[5]) + "\r\n"; 00470 strDiag += "+5.5V: " + FmtPc5Pwr(dd.ADC_V[6]) + "\r\n"; 00471 strDiag += "-5.5V: " + FmtPc5Pwr(dd.ADC_V[7]) + "\r\n"; 00472 strDiag += "AN_IN: " + FmtPc5Pwr(dd.ADC_V[8]) + "\r\n"; 00473 strDiag += "VREF_IN: " + FmtPc5Pwr(dd.ADC_V[9]) + "\r\n"; 00474 00475 strDiag += "\r\n"; 00476 if (dd.PC5_PRESENT) { 00477 strDiag += "PC5: Present\r\n"; 00478 strVal = strfn.Format("%dV",(int)(dd.PC5_V[0])); 00479 strDiag += "HV: " + strVal + "\r\n"; 00480 strVal = strfn.Format("%#.1fK",dd.PC5_V[1]); 00481 strDiag += "Detector Temp: " + strVal + "\r\n"; 00482 strDiag += "+8.5/5V: " + FmtPc5Pwr(dd.PC5_V[2]) + "\r\n"; 00483 if (dd.PC5_SN > -1) { 00484 strDiag += "PC5 S/N: " + FmtLng(dd.PC5_SN) + "\r\n"; 00485 } else { 00486 strDiag += "PC5 S/N: none\r\n"; 00487 } 00488 if (dd.PC5Initialized) { 00489 strDiag += "PC5 DCAL: " + FmtPc5Pwr(dd.PC5DCAL) + "\r\n"; 00490 } else { 00491 strDiag += "PC5 DCAL: Uninitialized\r\n"; 00492 } 00493 strDiag += "PC5 Flavor: "; 00494 strDiag += IsAorB(dd.IsPosHV, "+HV, ", "-HV, "); 00495 strDiag += IsAorB(dd.Is8_5VPreAmp, "8.5V preamp", "5V preamp") + "\r\n"; 00496 strDiag += "PC5 Supplies:\r\n"; 00497 strDiag += "9V: " + OnOffStr(dd.Sup9VOn) + "\r\n"; 00498 strDiag += "Preamp: " + OnOffStr(dd.PreAmpON) + "\r\n"; 00499 strDiag += "HV: " + OnOffStr(dd.HVOn) + "\r\n"; 00500 strDiag += "TEC: " + OnOffStr(dd.TECOn) + "\r\n"; 00501 } else { 00502 strDiag += "PC5: Not Present\r\n"; 00503 } 00504 } else if (device_type == dppPX5) { 00505 strDiag += "PX5 Temp (raw): " + dd.strTempRaw + "\r\n"; 00506 strDiag += "PX5 Temp (cal'd): " + dd.strTempCal + "\r\n"; 00507 //strDiag += "PWR: " + FmtPc5Pwr(dd.ADC_V[0]) + "\r\n"; 00508 strDiag += "9V: " + FmtPc5Pwr(dd.ADC_V[0]) + "\r\n"; 00509 strDiag += "3.3V: " + FmtPc5Pwr(dd.ADC_V[1]) + "\r\n"; 00510 strDiag += "2.5V: " + FmtPc5Pwr(dd.ADC_V[2]) + "\r\n"; 00511 strDiag += "1.2V: " + FmtPc5Pwr(dd.ADC_V[3]) + "\r\n"; 00512 strDiag += "+5V: " + FmtPc5Pwr(dd.ADC_V[4]) + "\r\n"; 00513 strDiag += "-5V: " + FmtPc5Pwr(dd.ADC_V[5]) + "\r\n"; 00514 strDiag += "+PA: " + FmtPc5Pwr(dd.ADC_V[6]) + "\r\n"; 00515 strDiag += "-PA: " + FmtPc5Pwr(dd.ADC_V[7]) + "\r\n"; 00516 strDiag += "TEC: " + FmtPc5Pwr(dd.ADC_V[8]) + "\r\n"; 00517 strDiag += "ABS(HV): " + FmtHvPwr(dd.ADC_V[9]) + "\r\n"; 00518 strDiag += "DET_TEMP: " + FmtPc5Temp(dd.ADC_V[10]) + "\r\n"; 00519 } 00520 00521 strDiag += "\r\nDiagnostic Data\r\n"; 00522 strDiag += "---------------\r\n"; 00523 for(idxVal=0;idxVal<=191;idxVal++) { 00524 if ((idxVal % 8) == 0) { 00525 strDiag += FmtHex(idxVal, 2) + ":"; 00526 } 00527 strDiag += FmtHex(dd.DiagData[idxVal], 2) + " "; 00528 if ((idxVal % 8) == 7) { 00529 strDiag += "\r\n"; 00530 } 00531 } 00532 return (strDiag); 00533 } 00534 00535 string CDP5Status::DiagStrPX5Option(DiagDataType dd, int device_type) 00536 { 00537 long idxVal; 00538 string strVal; 00539 string strDiag; 00540 stringex strfn; 00541 00542 strDiag = "Firmware: " + VersionToStr(dd.Firmware) + "\r\n"; 00543 strDiag += "FPGA: " + VersionToStr(dd.FPGA) + "\r\n"; 00544 strDiag += "SRAM Test: "; 00545 if (dd.SRAMTestPass) { 00546 strDiag += "PASS\r\n"; 00547 } else { 00548 strDiag += "ERROR @ 0x" + FmtHex(dd.SRAMTestData, 6) + "\r\n"; 00549 } 00550 00551 if (device_type == dppPX5) { 00552 strDiag += "PX5 Temp (raw): " + dd.strTempRaw + "\r\n"; 00553 strDiag += "PX5 Temp (cal'd): " + dd.strTempCal + "\r\n"; 00554 strDiag += "9V: " + FmtPc5Pwr(dd.ADC_V[0]) + "\r\n"; 00555 strDiag += "3.3V: " + FmtPc5Pwr(dd.ADC_V[1]) + "\r\n"; 00556 strDiag += "2.5V: " + FmtPc5Pwr(dd.ADC_V[2]) + "\r\n"; 00557 strDiag += "TDET: " + FmtPc5Pwr(dd.ADC_V[3]) + "\r\n"; 00558 strDiag += "+5V: " + FmtPc5Pwr(dd.ADC_V[4]) + "\r\n"; 00559 strDiag += "-5V: " + FmtPc5Pwr(dd.ADC_V[5]) + "\r\n"; 00560 strDiag += "+PA: " + FmtPc5Pwr(dd.ADC_V[6]) + "\r\n"; 00561 strDiag += "-PA: " + FmtPc5Pwr(dd.ADC_V[7]) + "\r\n"; 00562 strDiag += "TEC: " + FmtPc5Pwr(dd.ADC_V[8]) + "\r\n"; 00563 strDiag += "ABS(HV): " + FmtHvPwr(dd.ADC_V[9]) + "\r\n"; 00564 strDiag += "DET_TEMP: " + FmtPc5Temp(dd.ADC_V[10]) + "\r\n"; 00565 } 00566 00567 strDiag += "\r\nDiagnostic Data\r\n"; 00568 strDiag += "---------------\r\n"; 00569 for(idxVal=0;idxVal<=191;idxVal++) { 00570 if ((idxVal % 8) == 0) { 00571 strDiag += FmtHex(idxVal, 2) + ":"; 00572 } 00573 strDiag += FmtHex(dd.DiagData[idxVal], 2) + " "; 00574 if ((idxVal % 8) == 7) { 00575 strDiag += "\r\n"; 00576 } 00577 } 00578 return (strDiag); 00579 } 00580 00581 string CDP5Status::FmtHvPwr(float fVal) 00582 { 00583 string strVal; 00584 stringex strfn; 00585 strVal = strfn.Format("%#.1fV", fVal); // "#.##0V" 00586 return strVal; 00587 } 00588 00589 string CDP5Status::FmtPc5Pwr(float fVal) 00590 { 00591 string strVal; 00592 stringex strfn; 00593 strVal = strfn.Format("%#.3fV", fVal); // "#.##0V" 00594 return strVal; 00595 } 00596 00597 string CDP5Status::FmtPc5Temp(float fVal) 00598 { 00599 string strVal; 00600 stringex strfn; 00601 strVal = strfn.Format("%#.1fK", fVal); // "#.##0V" 00602 return strVal; 00603 } 00604 00605 string CDP5Status::FmtHex(long FmtHex, long HexDig) 00606 { 00607 string strHex; 00608 string strFmt; 00609 stringex strfn; 00610 strFmt = strfn.Format("%d",HexDig); // max size of 0 pad 00611 strFmt = "%0" + strFmt + "X"; // string format specifier 00612 strHex = strfn.Format(strFmt.c_str(), FmtHex); // create padded string 00613 return strHex; 00614 } 00615 00616 string CDP5Status::FmtLng(long lVal) 00617 { 00618 string strVal; 00619 stringex strfn; 00620 strVal = strfn.Format("%d", lVal); 00621 return strVal; 00622 } 00623 00624 string CDP5Status::VersionToStr(unsigned char bVersion) 00625 { 00626 string strVerMajor; 00627 string strVerMinor; 00628 string strVer; 00629 stringex strfn; 00630 strVerMajor = strfn.Format("%d",((bVersion & 0xF0) / 16)); 00631 strVerMinor = strfn.Format("%02d",(bVersion & 0x0F)); 00632 strVer = strVerMajor + "." + strVerMinor; 00633 return (strVer); 00634 } 00635 00636 string CDP5Status::OnOffStr(bool bOn) 00637 { 00638 if (bOn) { 00639 return("ON"); 00640 } else { 00641 return("OFF"); 00642 } 00643 } 00644 00645 string CDP5Status::IsAorB(bool bIsA, string strA, string strB) 00646 { 00647 if (bIsA) { 00648 return(strA); 00649 } else { 00650 return(strB); 00651 } 00652 } 00653 00654 string CDP5Status::GetDeviceNameFromVal(int DeviceTypeVal) 00655 { 00656 string strDeviceType; 00657 switch(DeviceTypeVal) { 00658 case 0: 00659 strDeviceType = "DP5"; 00660 break; 00661 case 1: 00662 strDeviceType = "PX5"; 00663 break; 00664 case 2: 00665 strDeviceType = "DP5G"; 00666 break; 00667 case 3: 00668 strDeviceType = "MCA8000D"; 00669 break; 00670 case 4: 00671 strDeviceType = "TB5"; 00672 break; 00673 case 5: 00674 strDeviceType = "DP5-X"; 00675 break; 00676 default: //if unknown set to DP5 00677 strDeviceType = "DP5"; 00678 break; 00679 } 00680 return strDeviceType; 00681 } 00682 00683 string CDP5Status::DisplayBufferArray(unsigned char buffer[], unsigned long bufSizeIn) 00684 { 00685 unsigned long i; 00686 string strVal(""); 00687 string strMsg(""); 00688 stringex strfn; 00689 for(i=0;i<bufSizeIn;i++) { 00690 strVal = strfn.Format("%.2X ",buffer[i]); 00691 strMsg += strVal; 00692 //if (((i+1) % 16) == 0 ) { 00693 // strMsg += "\r\n"; 00694 //} else 00695 if (((i+1) % 8) == 0 ) { 00696 // strMsg += " "; 00697 //strMsg += "\r\n"; 00698 strMsg += "\n"; 00699 } 00700 } 00701 //strMsg += "\n"; 00702 return strMsg; 00703 } 00704 00705 void CDP5Status::SaveStringDataToFile(string strData) 00706 { 00707 FILE *out; 00708 string strFilename; 00709 string strError; 00710 stringex strfn; 00711 00712 strFilename = "vcDP5_Data.txt"; 00713 00714 if ( (out = fopen(strFilename.c_str(),"w")) == (FILE *) NULL) 00715 strError = strfn.Format("Couldn't open %s for writing.\n", strFilename.c_str()); 00716 else 00717 { 00718 fprintf(out,"%s\n",strData.c_str()); 00719 } 00720 fclose(out); 00721 } 00722 00723 00724 00725 00726 00727 00728 00729 00730 00731 00732 00733 00734