gccDppConsole Test C++ SDK  1.0.0.0
DPP C++ Console Demonstration
DeviceIO/SendCommand.cpp
Go to the documentation of this file.
00001 #include "SendCommand.h"
00002 #include "stringex.h"
00003 
00004 CSendCommand::CSendCommand(void)
00005 {
00006 }
00007 
00008 CSendCommand::~CSendCommand(void)
00009 {
00010 }
00011 
00012 string CSendCommand::MakeUpper(string StdString)
00013 {
00014   const int length = (int)StdString.length();
00015   for(int i=0; i<length ; ++i)
00016   {
00017     StdString[i] = std::toupper(StdString[i]);
00018   }
00019   return StdString;
00020 }
00021 
00022 bool CSendCommand::TestPacketCkSumOK(unsigned char Data[])
00023 {
00024     long idxBuffer;
00025     long CS;
00026         long PktLen;
00027         unsigned char CHKSUM_MSB;
00028         unsigned char CHKSUM_LSB;
00029     
00030         PktLen = (Data[4] * 256) + Data[5];
00031     CS = Data[0] + Data[1] + Data[2] + Data[3] + Data[4] + Data[5];
00032         if (PktLen > 0) {
00033                 for (idxBuffer=0; idxBuffer<PktLen;idxBuffer++) {
00034             CS = CS + Data[idxBuffer + 6];
00035                 }
00036     }
00037     CS = (CS ^ 0xFFFF) + 1;
00038     CHKSUM_MSB = (unsigned char)((CS & 0xFF00) / 256);  // calculated checksum
00039     CHKSUM_LSB = (unsigned char)(CS & 0xFF);
00040         if ((Data[PktLen + 6] == CHKSUM_MSB) && (Data[PktLen + 7] == (CS & 0xFF))) {
00041                 return true;
00042         } else {
00043                 return false;
00044         }
00045 }
00046 
00047 string CSendCommand::RemoveCmd(string strCmd, string strCfgData)
00048 {
00049         int iStart,iEnd,iCmd;
00050         string strNew;
00051 
00052         strNew = "";
00053         if (strCfgData.length() < 7) { return strCfgData; }     // no data
00054         if (strCmd.length() != 4) {     return strCfgData; }            // bad command
00055         iCmd = (int)strCfgData.find(strCmd,0);
00056         if (iCmd == -1) { return strCfgData; }                                          // cmd not found        
00057         iStart = iCmd;
00058         iEnd = (int)strCfgData.find(";",iCmd);
00059         if (iEnd == -1) { return strCfgData; }                                          // end not found
00060         if (iEnd <= iStart) { return strCfgData; }                                      // unknown error
00061         strNew = strCfgData.substr(0,iStart) + strCfgData.substr(iEnd+1);
00062         return strNew;
00063 }
00064 
00066 string CSendCommand::RemoveCmdByDeviceType(string strCfgDataIn, bool PC5_PRESENT, int DppType)
00067 {
00068         string strCfgData;
00069     bool isHVSE;
00070     bool isPAPS;
00071     bool isTECS;
00072     bool isVOLU;
00073         bool isCON1;
00074         bool isCON2;
00075     bool isINOF;
00076     bool isBOOT;
00077         bool isGATE;
00078         bool isPAPZ;
00079         bool isSCTC;
00080 
00081         strCfgData = strCfgDataIn;
00082         if (DppType == devtypeMCA8000D) {
00083                 strCfgData = Remove_MCA8000D_Cmds(strCfgData,DppType);
00084                 return strCfgData;
00085         }
00086     isHVSE = (((DppType !=  devtypePX5) && PC5_PRESENT) || DppType == devtypePX5);
00087     isPAPS = (DppType != devtypeDP5G) && (DppType != devtypeTB5);
00088     isTECS = (((DppType == devtypeDP5) && PC5_PRESENT) || (DppType != devtypeDP5G) || (DppType != devtypeTB5));
00089     isVOLU = (DppType == devtypePX5);
00090     isCON1 = (DppType != devtypeDP5);
00091     isCON2 = (DppType != devtypeDP5);
00092     isINOF = (DppType != devtypeDP5G) && (DppType != devtypeTB5);
00093         isSCTC = (DppType == devtypeDP5G) || (DppType == devtypeTB5);
00094     isBOOT = (DppType == devtypeDP5);
00095         isGATE = (DppType == devtypeDP5);
00096         isPAPZ = (DppType == devtypePX5);
00097         if (!isHVSE) { strCfgData = RemoveCmd("HVSE", strCfgData); }  //High Voltage Bias
00098         if (!isPAPS) { strCfgData = RemoveCmd("PAPS", strCfgData); }  //Preamp Voltage
00099         if (!isTECS) { strCfgData = RemoveCmd("TECS", strCfgData); }  //Cooler Temperature
00100         if (!isVOLU) { strCfgData = RemoveCmd("VOLU", strCfgData); }  //px5 speaker
00101         if (!isCON1) { strCfgData = RemoveCmd("CON1", strCfgData); }  //connector 1
00102         if (!isCON2) { strCfgData = RemoveCmd("CON2", strCfgData); }  //connector 2
00103         if (!isINOF) { strCfgData = RemoveCmd("INOF", strCfgData); }  //input offset
00104         if (!isBOOT) { strCfgData = RemoveCmd("BOOT", strCfgData); }  //PC5 On At StartUp
00105         if (!isGATE) { strCfgData = RemoveCmd("GATE", strCfgData); }  //Gate input
00106         if (!isPAPZ) { strCfgData = RemoveCmd("PAPZ", strCfgData); }  //Pole-Zero
00107         if (!isSCTC) { strCfgData = RemoveCmd("RCTC", strCfgData); }  //Scintillator Time Constant
00108         return strCfgData;
00109 }
00110 
00112 string CSendCommand::Remove_MCA8000D_Cmds(string strCfgDataIn, int DppType)
00113 {
00114         string strCfgData;
00115         
00116         strCfgData = strCfgDataIn;
00117         if (DppType == devtypeMCA8000D) {
00118                 strCfgData = RemoveCmd("CLCK", strCfgData);
00119                 strCfgData = RemoveCmd("TPEA", strCfgData);
00120                 strCfgData = RemoveCmd("GAIF", strCfgData);
00121                 strCfgData = RemoveCmd("GAIN", strCfgData);
00122                 strCfgData = RemoveCmd("RESL", strCfgData);
00123                 strCfgData = RemoveCmd("TFLA", strCfgData);
00124                 strCfgData = RemoveCmd("TPFA", strCfgData);
00125                 //strCfgData = RemoveCmd("PURE", strCfgData);
00126                 strCfgData = RemoveCmd("RTDE", strCfgData);
00127                 strCfgData = RemoveCmd("AINP", strCfgData);
00128                 strCfgData = RemoveCmd("INOF", strCfgData);
00129                 strCfgData = RemoveCmd("CUSP", strCfgData);
00130                 strCfgData = RemoveCmd("THFA", strCfgData);
00131                 strCfgData = RemoveCmd("DACO", strCfgData);
00132                 strCfgData = RemoveCmd("DACF", strCfgData);
00133                 strCfgData = RemoveCmd("RTDS", strCfgData);
00134                 strCfgData = RemoveCmd("RTDT", strCfgData);
00135                 strCfgData = RemoveCmd("BLRM", strCfgData);
00136                 strCfgData = RemoveCmd("BLRD", strCfgData);
00137                 strCfgData = RemoveCmd("BLRU", strCfgData);
00138                 strCfgData = RemoveCmd("PRET", strCfgData);
00139                 strCfgData = RemoveCmd("HVSE", strCfgData);
00140                 strCfgData = RemoveCmd("TECS", strCfgData);
00141                 strCfgData = RemoveCmd("PAPZ", strCfgData);
00142                 strCfgData = RemoveCmd("PAPS", strCfgData);
00143                 strCfgData = RemoveCmd("TPMO", strCfgData);
00144                 strCfgData = RemoveCmd("SCAH", strCfgData);
00145                 strCfgData = RemoveCmd("SCAI", strCfgData);
00146                 strCfgData = RemoveCmd("SCAL", strCfgData);
00147                 strCfgData = RemoveCmd("SCAO", strCfgData);
00148                 strCfgData = RemoveCmd("SCAW", strCfgData);
00149                 strCfgData = RemoveCmd("BOOT", strCfgData);
00150 
00151                 // added to list late, recheck at later date 20120817
00152                 strCfgData = RemoveCmd("CON1", strCfgData);
00153                 strCfgData = RemoveCmd("CON2", strCfgData);
00154 
00155                 // no implemented as of 20120817, will be implemented at some time
00156                 strCfgData = RemoveCmd("VOLU", strCfgData);      
00157         }
00158         return strCfgData;
00159 }
00160 
00161 //Extend Packet_Out to include entire message
00162 //include send packet data finishing into dp5_cmd
00163 //remove control and interface objects
00164 //move send packet to separate function
00165 
00166 bool CSendCommand::DP5_CMD(unsigned char Buffer[], TRANSMIT_PACKET_TYPE XmtCmd)
00167 {
00168     bool bCmdFound;
00169     string D;
00170     Packet_Out POUT; 
00171     
00172     bCmdFound = true;
00173     POUT.LEN = 0;
00174         string strCfg;
00175         long lLen;
00176         //long idxData;
00177 
00178         switch (XmtCmd) {
00180                 case XMTPT_SEND_STATUS:
00181             POUT.PID1 = PID1_REQ_STATUS;
00182             POUT.PID2 = PID2_SEND_DP4_STYLE_STATUS;   // send status only
00183                         break;
00184         //case XMTPT_SEND_SPECTRUM:
00185                         //break;
00186         //case XMTPT_SEND_CLEAR_SPECTRUM:
00187                         //break;
00188         case XMTPT_SEND_SPECTRUM_STATUS:
00189             POUT.PID1 = PID1_REQ_SPECTRUM;
00190             POUT.PID2 = PID2_SEND_SPECTRUM_STATUS;   // send spectrum & status
00191                         break;
00192         case XMTPT_SEND_CLEAR_SPECTRUM_STATUS:
00193             POUT.PID1 = PID1_REQ_SPECTRUM;
00194             POUT.PID2 = PID2_SEND_CLEAR_SPECTRUM_STATUS;   // send & clear spectrum & status
00195                         break;
00196         //case XMTPT_BUFFER_SPECTRUM:
00197                         //break;
00198         //case XMTPT_BUFFER_CLEAR_SPECTRUM:
00199                         //break;
00200         //case XMTPT_SEND_BUFFER:
00201                         //break;
00202         //case XMTPT_SEND_DP4_STYLE_STATUS:
00203                         //break;
00204         //case XMTPT_SEND_CONFIG:
00205                         //break;
00206         case XMTPT_SEND_SCOPE_DATA:
00207             POUT.PID1 = PID1_REQ_SCOPE_MISC;
00208             POUT.PID2 = PID2_SEND_SCOPE_DATA;
00209                         break;
00210         case XMTPT_SEND_512_BYTE_MISC_DATA:
00211             POUT.PID1 = PID1_REQ_SCOPE_MISC;
00212             POUT.PID2 = PID2_SEND_512_BYTE_MISC_DATA; // request misc data
00213                         break;
00214         case XMTPT_SEND_SCOPE_DATA_REARM:
00215             POUT.PID1 = PID1_REQ_SCOPE_MISC;
00216             POUT.PID2 = PID2_SEND_SCOPE_DATA_REARM;
00217                         break;
00218         //case XMTPT_SEND_ETHERNET_SETTINGS:
00219                         //break;
00220         case XMTPT_SEND_DIAGNOSTIC_DATA:
00221             POUT.PID1 = PID1_REQ_SCOPE_MISC;
00222             POUT.PID2 = PID2_SEND_DIAGNOSTIC_DATA;   // Request Diagnostic Packet
00223             POUT.LEN = 0;
00224                         break;
00225         case XMTPT_SEND_NETFINDER_PACKET:
00226             POUT.PID1 = PID1_REQ_SCOPE_MISC;
00227             POUT.PID2 = PID2_SEND_NETFINDER_READBACK;   // Request NetFinder Packet
00228             POUT.LEN = 0;
00229                         break;
00230         //case XMTPT_SEND_HARDWARE_DESCRIPTION:
00231                         //break;
00232         //case XMTPT_SEND_SCA:
00233                         //break;
00234         //case XMTPT_LATCH_SEND_SCA:
00235                         //break;
00236         //case XMTPT_LATCH_CLEAR_SEND_SCA:
00237                         //break;
00238         //case XMTPT_SEND_ROI_OR_FIXED_BLOCK:
00239                         //break;
00240    //     case XMTPT_PX4_STYLE_CONFIG_PACKET:
00241                         //break;
00242                 case XMTPT_READ_CONFIG_PACKET:
00243                         strCfg = "";
00244                         strCfg += "CLCK=?;"; // FPGA clock
00245                         strCfg += "TPEA=?;"; // peak time
00246                         strCfg += "GAIN=?;"; // gain
00247                         strCfg += "MCAS=?;"; // mca mode
00248                         strCfg += "MCAC=?;"; // channels
00249                         strCfg += "INOF=?;"; // osc. Input offset
00250                         strCfg += "THSL=?;"; // LLD thresh
00251                         strCfg += "THFA=?;"; // fast thresh
00252                         strCfg += "DACO=?;"; // osc. DAC output
00253                         strCfg += "DACF=?;"; // osc. DAC offset
00254                         strCfg += "AUO1=?;"; // osc. AUX_OUT1
00255                         strCfg += "PRET=?;"; // preset actual time
00256                         strCfg += "PRER=?;"; // preset real time
00257                         strCfg += "PREC=?;"; // preset count 
00258                         strCfg += "SCOE=?;"; // osc. Scope trigger edge
00259                         strCfg += "SCOT=?;"; // osc. Scope trigger position
00260                         strCfg += "SCOG=?;"; // osc. Scope gain
00261 
00262                         lLen = (long)strCfg.length();
00263                         if (lLen > 0) {
00264                                 strCfg = MakeUpper(strCfg);
00265                                 CopyAsciiData(POUT.DATA, strCfg, lLen);
00266                         }
00267             POUT.PID1 = PID1_REQ_CONFIG;
00268             POUT.PID2 = PID2_CONFIG_READBACK_PACKET;   // read config packet
00269             POUT.LEN = (unsigned short)lLen;
00270                         break;
00271                 case XMTPT_SCA_READ_CONFIG_PACKET:
00272                         strCfg = "";
00273                         strCfg = "SCAW=?;";
00274                         strCfg +="SCAI=1;SCAL=?;SCAH=?;SCAO=?;";
00275                         strCfg +="SCAI=2;SCAL=?;SCAH=?;SCAO=?;";
00276                         strCfg +="SCAI=3;SCAL=?;SCAH=?;SCAO=?;";
00277                         strCfg +="SCAI=4;SCAL=?;SCAH=?;SCAO=?;";
00278                         strCfg +="SCAI=5;SCAL=?;SCAH=?;SCAO=?;";
00279                         strCfg +="SCAI=6;SCAL=?;SCAH=?;SCAO=?;";
00280                         strCfg +="SCAI=7;SCAL=?;SCAH=?;SCAO=?;";
00281                         strCfg +="SCAI=8;SCAL=?;SCAH=?;SCAO=?;";
00282                         lLen = (long)strCfg.length();
00283                         if (lLen > 0) {
00284                                 strCfg = MakeUpper(strCfg);
00285                                 CopyAsciiData(POUT.DATA, strCfg, lLen);
00286                         }
00287             POUT.PID1 = PID1_REQ_CONFIG;
00288             POUT.PID2 = PID2_CONFIG_READBACK_PACKET;   // read config packet
00289             POUT.LEN = (unsigned short)lLen;
00290                         break;
00291                  case XMTPT_ERASE_FPGA_IMAGE:
00292             POUT.PID1 = PID1_REQ_FPGA_UC;
00293             POUT.PID2 = PID2_ERASE_FPGA_IMAGE;
00294             POUT.LEN = 2;
00295             POUT.DATA[0] = 0x12;
00296             POUT.DATA[1] = 0x34;
00297                         break;
00298         //case XMTPT_UPLOAD_PACKET_FPGA:
00299                         //break;
00300         //case XMTPT_REINITIALIZE_FPGA:
00301                         //break;
00302         //case XMTPT_ERASE_UC_IMAGE_0:
00303                         //break;
00304         case XMTPT_ERASE_UC_IMAGE_1:
00305             POUT.PID1 = PID1_REQ_FPGA_UC;
00306             POUT.PID2 = PID2_ERASE_UC_IMAGE_1;   // erase image #1 (sector 5)
00307             POUT.LEN = 2;
00308             POUT.DATA[0] = 0x12;
00309             POUT.DATA[1] = 0x34;
00310                         break;
00311         //case XMTPT_ERASE_UC_IMAGE_2:
00312                         //break;
00313         //case XMTPT_UPLOAD_PACKET_UC:
00314                         //break;
00315         //case XMTPT_SWITCH_TO_UC_IMAGE_0:
00316                         //break;
00317         case XMTPT_SWITCH_TO_UC_IMAGE_1:
00318             POUT.PID1 = PID1_REQ_FPGA_UC;
00319             POUT.PID2 = PID2_SWITCH_TO_UC_IMAGE_1;   // switch to uC image #1
00320             POUT.LEN = 2;
00321             POUT.DATA[0] = 0xA5; // uC FLASH unlock keys
00322             POUT.DATA[1] = 0xF1;
00323                         break;
00324         //case XMTPT_SWITCH_TO_UC_IMAGE_2:
00325                         //break;
00326         //case XMTPT_UC_FPGA_CHECKSUMS:
00327                         //break;
00329         //case XMTPT_CLEAR_SPECTRUM_BUFFER_A:
00330                         //break;
00331         case XMTPT_ENABLE_MCA_MCS:
00332             POUT.PID1 = PID1_VENDOR_REQ;
00333             POUT.PID2 = PID2_ENABLE_MCA_MCS; 
00334             POUT.LEN = 0;
00335                         break;
00336         case XMTPT_DISABLE_MCA_MCS:
00337             POUT.PID1 = PID1_VENDOR_REQ;
00338             POUT.PID2 = PID2_DISABLE_MCA_MCS; 
00339             POUT.LEN = 0;
00340                         break;
00341         case XMTPT_ARM_DIGITAL_OSCILLOSCOPE:
00342             POUT.PID1 = PID1_VENDOR_REQ;
00343             POUT.PID2 = PID2_ARM_DIGITAL_OSCILLOSCOPE;   // arm trigger
00344                         break;
00345         //case XMTPT_AUTOSET_INPUT_OFFSET:
00346                         //break;
00347         case XMTPT_AUTOSET_FAST_THRESHOLD:
00348             POUT.PID1 = PID1_VENDOR_REQ;
00349             POUT.PID2 = PID2_AUTOSET_FAST_THRESHOLD; 
00350             POUT.LEN = 0;
00351                         break;
00352         //case XMTPT_READ_IO3_0:
00353                         //break;
00354         //case XMTPT_WRITE_IO3_0:
00355                         //break;
00356         //case XMTPT_SET_DCAL:
00357                         //break;
00358         //case XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL:
00359                         //break;
00360         //case XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL:
00361                         //break;
00362         //case XMTPT_SET_BOOT_FLAGS:
00363                         //break;
00364         //case XMTPT_SET_HV_DP4_EMULATION:
00365                         //break;
00366         //case XMTPT_SET_TEC_DP4_EMULATION:
00367                         //break;
00368         //case XMTPT_SET_INPUT_OFFSET_DP4_EMULATION:
00369                         //break;
00370         //case XMTPT_SET_ADC_CAL_GAIN_OFFSET:
00371                         //break;
00372         //case XMTPT_SET_SPECTRUM_OFFSET:
00373                         //break;
00374         //case XMTPT_REQ_SCOPE_DATA_MISC_DATA_SCA_PACKETS:
00375                         //break;
00376         //case XMTPT_SET_SERIAL_NUMBER:
00377                         //break;
00378         //case XMTPT_CLEAR_GP_COUNTER:
00379                         //break;
00380         //case XMTPT_SWITCH_SUPPLIES:
00381                         //break;
00382         //case XMTPT_SEND_TEST_PACKET:
00383                         //break;
00384         case XMTPT_REQ_ACK_PACKET:
00385             POUT.PID1 = PID1_COMM_TEST;
00386             POUT.PID2 = PID2_ACK_OK; 
00387             POUT.LEN = 0;
00388                         break;
00389                 case XMTPT_FORCE_SCOPE_TRIGGER:
00390             POUT.PID1 = PID1_VENDOR_REQ;
00391             POUT.PID2 = PID2_GENERIC_FPGA_WRITE;        // generic FPGA write
00392             POUT.LEN = 2;
00393             POUT.DATA[0] = 119;                                         // force scope trigger
00394             POUT.DATA[1] = 0;                                           // data doesn't matter
00395                         break;
00396                 case XMTPT_AU34_2_RESTART:
00397             POUT.PID1 = PID1_VENDOR_REQ;
00398             POUT.PID2 = PID2_GENERIC_FPGA_WRITE;        // generic FPGA write
00399             POUT.LEN = 2;
00400             POUT.DATA[0] = 0x73;                                        // AU34_2_RESTART
00401             POUT.DATA[1] = 0;                                           // data doesn't matter
00402                         break;
00403         case XMTPT_READ_MCA8000D_OPTION_PA_CAL:
00404             POUT.PID1 = PID1_REQ_SCOPE_MISC;
00405             POUT.PID2 = PID2_SEND_OPTION_PA_CALIBRATION; 
00406             POUT.LEN = 0;
00407                         break;
00408                 default:
00409             bCmdFound = false;
00410                         break;
00411         }
00412         if (bCmdFound) {
00413         if (! POUT_Buffer(POUT, Buffer)) {
00414             bCmdFound = false;
00415         }
00416     }
00417         return bCmdFound;
00418 }
00419 
00420 //DP5_CMD_Config is for: (requires pc5 and device info)
00421 //              XMTPT_SEND_CONFIG_PACKET_TO_HW
00422 //              XMTPT_SEND_CONFIG_PACKET_EX
00423 //              XMTPT_FULL_READ_CONFIG_PACKET
00424 bool CSendCommand::DP5_CMD_Config(unsigned char Buffer[], TRANSMIT_PACKET_TYPE XmtCmd, CONFIG_OPTIONS CfgOptions)
00425 {
00426     bool bCmdFound;
00427     string D;
00428     Packet_Out POUT; 
00429     bCmdFound = true;
00430     POUT.LEN = 0;
00431         string strCfg;
00432         long lLen;
00433 
00434         switch (XmtCmd) {
00435         case XMTPT_SEND_CONFIG_PACKET_TO_HW:
00436                         // CONFIG_OPTIONS Needed:
00437                         //              CfgOptions.HwCfgDP5Out
00438                         //              CfgOptions.SendCoarseFineGain
00439                         //              CfgOptions.PC5_PRESENT
00440                         //              CfgOptions.DppType
00441                         strCfg = "";
00442                         strCfg = CfgOptions.HwCfgDP5Out;
00443 
00444                         if (CfgOptions.SendCoarseFineGain) {
00445                                 strCfg = RemoveCmd("GAIN",strCfg);
00446                         } else {
00447                                 strCfg = RemoveCmd("GAIA",strCfg);
00448                                 strCfg = RemoveCmd("GAIF",strCfg);
00449                         }
00450                         strCfg = RemoveCmdByDeviceType(strCfg, CfgOptions.PC5_PRESENT, CfgOptions.DppType);
00451                         lLen = (long)strCfg.length();
00452                         if (lLen > 0) {
00453                                 strCfg = MakeUpper(strCfg);
00454                                 CopyAsciiData(POUT.DATA, strCfg, lLen);
00455                         }
00456             POUT.PID1 = PID1_REQ_CONFIG;
00457             POUT.PID2 = PID2_TEXT_CONFIG_PACKET;   // text config packet
00458             POUT.LEN = (unsigned short)lLen;
00459                         break;
00460         case XMTPT_SEND_CONFIG_PACKET_EX:                       // bypass any filters
00461                         // CONFIG_OPTIONS Needed:
00462                         //              CfgOptions.HwCfgDP5Out
00463                         strCfg = "";
00464                         strCfg = CfgOptions.HwCfgDP5Out;
00465                         lLen = (long)strCfg.length();
00466                         if (lLen > 0) {
00467                                 strCfg = MakeUpper(strCfg);
00468                                 CopyAsciiData(POUT.DATA, strCfg, lLen);
00469                         }
00470             POUT.PID1 = PID1_REQ_CONFIG;
00471             POUT.PID2 = PID2_TEXT_CONFIG_PACKET;   // text config packet
00472             POUT.LEN = (unsigned short)lLen;
00473                         break;
00474          case XMTPT_FULL_READ_CONFIG_PACKET:
00475                         // CONFIG_OPTIONS Needed:
00476                         //              CfgOptions.PC5_PRESENT
00477                         //              CfgOptions.DppType
00478                         strCfg = "";
00479                         strCfg = CreateFullReadBackCmd(CfgOptions.PC5_PRESENT, CfgOptions.DppType);
00480                         lLen = (long)strCfg.length();
00481                         if (lLen > 0) {
00482                                 strCfg = MakeUpper(strCfg);
00483                                 CopyAsciiData(POUT.DATA, strCfg, lLen);
00484                         }
00485             POUT.PID1 = PID1_REQ_CONFIG;
00486             POUT.PID2 = PID2_CONFIG_READBACK_PACKET;   // read config packet
00487             POUT.LEN = (unsigned short)lLen;
00488                         break;
00489                 default:
00490             bCmdFound = false;
00491                         break;
00492         }
00493         if (bCmdFound) {
00494         if (! POUT_Buffer(POUT, Buffer)) {
00495             bCmdFound = false;
00496         }
00497     }
00498         return bCmdFound;
00499 }
00500 
00501 string CSendCommand::CreateResTestReadBackCmd(bool bSendCoarseFineGain, int DppType)
00502 {
00503         string strCfg("");
00504     bool isINOF;
00505 
00506     isINOF = (DppType != devtypeDP5G) && (DppType != devtypeTB5);
00507         strCfg = "";
00508         strCfg += "CLCK=?;";
00509         strCfg += "TPEA=?;";
00510         if (bSendCoarseFineGain) { strCfg += "GAIF=?;"; }
00511         if (!bSendCoarseFineGain) { strCfg += "GAIN=?;"; }
00512         strCfg += "RESL=?;";
00513         strCfg += "TFLA=?;";
00514         strCfg += "TPFA=?;";
00515         strCfg += "PURE=?;";
00516         strCfg += "RTDE=?;";
00517         strCfg += "MCAS=?;";
00518         strCfg += "MCAC=?;";
00519         strCfg += "SOFF=?;";
00520         strCfg += "AINP=?;";
00521         if (isINOF) { strCfg += "INOF=?;"; }
00522         if (bSendCoarseFineGain) { strCfg += "GAIA=?;"; }
00523         return strCfg;
00524 }
00525 
00526 string CSendCommand::CreateFullReadBackCmd(bool PC5_PRESENT, int DppType)
00527 {
00528         string strCfg("");
00529     bool isHVSE;
00530     bool isPAPS;
00531     bool isTECS;
00532     bool isVOLU;
00533         bool isCON1;
00534         bool isCON2;
00535     bool isINOF;
00536     bool isBOOT;
00537         bool isGATE;
00538     bool isPAPZ;
00539         bool isSCTC;
00540 
00541         if (DppType == devtypeMCA8000D) {
00542                 strCfg = CreateFullReadBackCmdMCA8000D(DppType);
00543                 return strCfg;
00544         }
00545     isHVSE = (((DppType != devtypePX5) && PC5_PRESENT) || DppType == devtypePX5);
00546     isPAPS = (DppType != devtypeDP5G) && (DppType != devtypeTB5);
00547     isTECS = (((DppType == devtypeDP5) && PC5_PRESENT) || ((DppType != devtypeDP5G) && (DppType != devtypeTB5)));
00548     isVOLU = (DppType == devtypePX5);
00549     isCON1 = (DppType != devtypeDP5);
00550     isCON2 = (DppType != devtypeDP5);
00551     isINOF = (DppType != devtypeDP5G) && (DppType != devtypeTB5);
00552     isSCTC = (DppType == devtypeDP5G) || (DppType == devtypeTB5);
00553     isBOOT = (DppType == devtypeDP5);
00554         isGATE = (DppType == devtypeDP5);
00555         isPAPZ = (DppType == devtypePX5);
00556 
00557         strCfg = "";
00558         strCfg += "RESC=?;";
00559         strCfg += "CLCK=?;";
00560         strCfg += "TPEA=?;";
00561         strCfg += "GAIF=?;";
00562         strCfg += "GAIN=?;";
00563         strCfg += "RESL=?;";
00564         strCfg += "TFLA=?;";
00565         strCfg += "TPFA=?;";
00566         strCfg += "PURE=?;";
00567         if (isSCTC) { strCfg += "SCTC=?;"; }
00568         strCfg += "RTDE=?;";
00569         strCfg += "MCAS=?;";
00570         strCfg += "MCAC=?;";
00571         strCfg += "SOFF=?;";
00572         strCfg += "AINP=?;";
00573         if (isINOF) { strCfg += "INOF=?;"; }
00574         strCfg += "GAIA=?;";
00575         strCfg += "CUSP=?;";
00576         strCfg += "PDMD=?;";
00577         strCfg += "THSL=?;";
00578         strCfg += "TLLD=?;";
00579         strCfg += "THFA=?;";
00580         strCfg += "DACO=?;";
00581         strCfg += "DACF=?;";
00582         strCfg += "RTDS=?;";
00583         strCfg += "RTDT=?;";
00584         strCfg += "BLRM=?;";
00585         strCfg += "BLRD=?;";
00586         strCfg += "BLRU=?;";
00587         if (isGATE) { strCfg += "GATE=?;"; }
00588         strCfg += "AUO1=?;";
00589         strCfg += "PRET=?;";
00590         strCfg += "PRER=?;";
00591         strCfg += "PREC=?;";
00592         strCfg += "PRCL=?;";
00593         strCfg += "PRCH=?;";
00594         if (isHVSE) { strCfg += "HVSE=?;"; }
00595         if (isTECS) { strCfg += "TECS=?;"; }
00596         if (isPAPZ) { strCfg += "PAPZ=?;"; }
00597         if (isPAPS) { strCfg += "PAPS=?;"; }
00598         strCfg += "SCOE=?;";
00599         strCfg += "SCOT=?;";
00600         strCfg += "SCOG=?;";
00601         strCfg += "MCSL=?;";
00602         strCfg += "MCSH=?;";
00603         strCfg += "MCST=?;";
00604         strCfg += "AUO2=?;";
00605         strCfg += "TPMO=?;";
00606         strCfg += "GPED=?;";
00607         strCfg += "GPIN=?;";
00608         strCfg += "GPME=?;";
00609         strCfg += "GPGA=?;";
00610         strCfg += "GPMC=?;";
00611         strCfg += "MCAE=?;";
00612         if (isVOLU) { strCfg += "VOLU=?;"; }
00613         if (isCON1) { strCfg += "CON1=?;"; }
00614         if (isCON2) { strCfg += "CON2=?;"; }
00615         if (isBOOT) { strCfg += "BOOT=?;"; }
00616         return strCfg;
00617 }
00618 
00619 string CSendCommand::CreateFullReadBackCmdMCA8000D(int DppType)
00620 {
00621         string strCfg("");
00622 
00623         if (DppType == devtypeMCA8000D) {
00624                 strCfg += "RESC=?;";
00625                 strCfg += "PURE=?;";
00626                 strCfg += "MCAS=?;";
00627                 strCfg += "MCAC=?;";
00628                 strCfg += "SOFF=?;";
00629                 strCfg += "GAIA=?;";
00630                 strCfg += "PDMD=?;";
00631                 strCfg += "THSL=?;";
00632                 strCfg += "TLLD=?;";
00633                 strCfg += "GATE=?;";
00634                 strCfg += "AUO1=?;";
00635                 //strCfg += "PRET=?;";
00636                 strCfg += "PRER=?;";
00637                 strCfg += "PREL=?;";
00638                 strCfg += "PREC=?;";
00639                 strCfg += "PRCL=?;";
00640                 strCfg += "PRCH=?;";
00641                 strCfg += "SCOE=?;";
00642                 strCfg += "SCOT=?;";
00643                 strCfg += "SCOG=?;";
00644                 strCfg += "MCSL=?;";
00645                 strCfg += "MCSH=?;";
00646                 strCfg += "MCST=?;";
00647                 strCfg += "AUO2=?;";
00648                 strCfg += "GPED=?;";
00649                 strCfg += "GPIN=?;";
00650                 strCfg += "GPME=?;";
00651                 strCfg += "GPGA=?;";
00652                 strCfg += "GPMC=?;";
00653                 strCfg += "MCAE=?;";
00654                 //strCfg += "VOLU=?;";
00655                 //strCfg += "CON1=?;";
00656                 //strCfg += "CON2=?;";
00657                 strCfg += "PDMD=?;";
00658         }
00659         return strCfg;
00660 }
00661 
00662 //Extend Packet_Out to include entire message
00663 //include send packet data finishing into dp5_cmd
00664 //remove control and interface objects
00665 //move send packet to separate function
00666 bool CSendCommand::DP5_CMD_Data(unsigned char Buffer[], TRANSMIT_PACKET_TYPE XmtCmd, unsigned char DataOut[])
00667 {
00668     bool bCmdFound;
00669     short idxMiscData;
00670     Packet_Out POUT; 
00671     long PktLen;
00672     
00673     bCmdFound = false;
00674     POUT.LEN = 0;
00675         string strCfg;
00676         long idxData;
00677         switch (XmtCmd) {       //REQUEST_PACKETS_TO_DP5
00678         case XMTPT_WRITE_512_BYTE_MISC_DATA:
00679             POUT.PID1 = PID1_VENDOR_REQ;
00680             POUT.PID2 = PID2_WRITE_512_BYTE_MISC_DATA;                          // write misc data
00681             POUT.LEN = 512;
00682                         for (idxMiscData=0;idxMiscData<=511;idxMiscData++) {    // byte array padded w/NULLs
00683                 POUT.DATA[idxMiscData] = DataOut[idxMiscData];
00684                         }
00685                         bCmdFound = true;
00686                         if (! POUT_Buffer(POUT, Buffer)) {
00687                                 bCmdFound = false;
00688                         }
00689                         break;
00690          case XMTPT_SEND_TEST_PACKET:
00691                         PktLen = (DataOut[4] * 256) + DataOut[5] + 8;           // get entire packet size
00692                         if ((PktLen >= 8) && (PktLen <= 12)) {                          // test data len 0-4 bytes
00693                                 if (TestPacketCkSumOK(DataOut)) {                               // check the message for correct check sum
00694                                         for(idxData=0;idxData<PktLen;idxData++) {       // load the data into the command buffer
00695                                                 Buffer[idxData] = DataOut[idxData];
00696                                         }
00697                                         bCmdFound = true;
00698                                 }
00699                         }
00700                         break;
00701                 default:
00702             bCmdFound = false;
00703                         break;
00704         }
00705         return bCmdFound;
00706 }
00707 
00708 bool CSendCommand::POUT_Buffer(Packet_Out POUT, unsigned char Buffer[])
00709 {
00710     long idxBuffer;
00711     long CS;
00712     
00713     Buffer[0] = SYNC1_;
00714     Buffer[1] = SYNC2_;
00715     Buffer[2] = POUT.PID1;
00716     Buffer[3] = POUT.PID2;
00717     Buffer[4] = (POUT.LEN & 0xFF00) / 256;
00718     Buffer[5] = POUT.LEN & 0xFF;
00719 
00720     CS = SYNC1_ + SYNC2_ + POUT.PID1 + POUT.PID2 + ((POUT.LEN & 0xFF00) / 256) + (POUT.LEN & 0xFF);
00721 
00722         if (POUT.LEN > 0) {
00723                 for (idxBuffer=0; idxBuffer<POUT.LEN;idxBuffer++) {
00724             Buffer[idxBuffer + 6] = POUT.DATA[idxBuffer];
00725             CS = CS + POUT.DATA[idxBuffer];
00726                 }
00727     }
00728     CS = (CS ^ 0xFFFF) + 1;
00729     Buffer[POUT.LEN + 6] = (unsigned char)((CS & 0xFF00) / 256);
00730     Buffer[POUT.LEN + 7] = (unsigned char)(CS & 0xFF);
00731     return true;
00732 }
00733 
00734 string CSendCommand::RemWhitespace(string strLine)
00735 {
00736         unsigned int idxCh;
00737         string strCh;
00738         string strNoWSp;
00739         
00740         strNoWSp = "";
00741         if (strLine.find_first_of(Whitespace, 0) == std::string::npos) {                // string has no whitespace
00742                 return strLine;
00743         } else {                        // remove whitespace
00744                 for (idxCh=0;idxCh<strLine.length();idxCh++) {
00745                         strCh = strLine.substr(idxCh,1);
00746                         if (strCh.find_first_of(Whitespace, 0) == std::string::npos) {          // char is not whitespace
00747                                 strNoWSp += strCh;
00748                         }
00749                 }
00750                 return strNoWSp;
00751         }
00752 }
00753 
00754 string CSendCommand::GetDP5CfgStr(string strFilename)
00755 {
00756         FILE *txtFile;
00757         char chLine[LINE_MAX];
00758         string strCfg;
00759         string strLine;
00760         long bytesCfg;
00761         long bytesLine;
00762         long bytesTotal;
00763         long lPos;
00764         char ch;
00765         stringex strfn;
00766 
00767         if (( txtFile = fopen(strFilename.c_str(), "r")) == NULL) {  // Can't open input file
00768                 return "";
00769         }
00770         strCfg = "";
00771         while((fgets(chLine, LINE_MAX, txtFile)) != NULL) {
00772                 strLine = strfn.Format("%s",chLine);
00773                 bytesCfg = (long)strCfg.length();
00774                 bytesLine = (long)strLine.length();
00775                 bytesTotal = bytesCfg + bytesLine;
00776                 if (bytesTotal >= DP5_MAX_CFG_SIZE) {                   // if over command size quit
00777                         break; 
00778                 } else {
00779                         strLine = MakeUpper(strLine);                   // make all uppercase
00780                         lPos = (long)strLine.find(';');                                 // find the delimiter (-1=not found,0=commented line)
00781                         if (lPos > 0) {                                                         // if has delimiter that is not first char
00782                                 strLine = strLine.substr(0,lPos + 1);                   // remove string right of delimiter
00783                                 ch = strLine.at(0);                                     
00784                                 if ((ch >= 'A') && (ch <= 'Z')) {               // if is valid value
00785                                         strLine = RemWhitespace(strLine);       // remove whitespace in command sequence
00786                                         if (strLine.length() > 1) {             // check if command w/delimiter left
00787                                                 strCfg += strLine;                      // add to command string
00788                                         }
00789                                 }
00790                         }
00791                 }
00792         }
00793         fclose(txtFile);                                                        
00794         if (!(strCfg.length() > 0)) {
00795                 return "";
00796         } else {
00797                 return strCfg;
00798         }
00799 }
00800 
00801 bool CSendCommand::CopyAsciiData(unsigned char Data[], string strCfg, long lLen)
00802 {
00803         long idxData;
00804         const char *c_str1 = strCfg.c_str();
00805 
00806         if (lLen > 0) {
00807                 for(idxData=0;idxData<lLen;idxData++) {
00808                         Data[idxData] = c_str1[idxData];
00809                 }
00810                 return true;
00811         } else {
00812                 return false;
00813         }
00814         return false;
00815 }
00816