gccDppConsole Test C++ SDK  20170920
DPP C++ Console Demonstration
DeviceIO/DP5Protocol.h
Go to the documentation of this file.
00001 
00002 #pragma once
00003 #include <math.h>
00004 
00005 enum TRANSMIT_PACKET_TYPE {
00006      //REQUEST_PACKETS_TO_DP5
00007         XMTPT_SEND_STATUS,
00008     XMTPT_SEND_SPECTRUM,
00009     XMTPT_SEND_CLEAR_SPECTRUM,
00010     XMTPT_SEND_SPECTRUM_STATUS,
00011     XMTPT_SEND_CLEAR_SPECTRUM_STATUS,
00012     XMTPT_BUFFER_SPECTRUM,
00013     XMTPT_BUFFER_CLEAR_SPECTRUM,
00014     XMTPT_SEND_BUFFER,
00015     XMTPT_SEND_DP4_STYLE_STATUS,
00016     XMTPT_SEND_PX4_CONFIG,
00017     XMTPT_SEND_SCOPE_DATA,
00018     XMTPT_SEND_512_BYTE_MISC_DATA,
00019     XMTPT_SEND_SCOPE_DATA_REARM,
00020     XMTPT_SEND_ETHERNET_SETTINGS,
00021     XMTPT_SEND_DIAGNOSTIC_DATA,
00022         XMTPT_SEND_NETFINDER_PACKET,
00023     XMTPT_SEND_HARDWARE_DESCRIPTION,
00024     XMTPT_SEND_SCA,
00025     XMTPT_LATCH_SEND_SCA,
00026     XMTPT_LATCH_CLEAR_SEND_SCA,
00027     XMTPT_SEND_ROI_OR_FIXED_BLOCK,
00028     XMTPT_PX4_STYLE_CONFIG_PACKET,
00029     XMTPT_SEND_CONFIG_PACKET_EX,
00030         XMTPT_SEND_CONFIG_PACKET_TO_HW,
00031     XMTPT_READ_CONFIG_PACKET,
00032     XMTPT_READ_CONFIG_PACKET_EX,
00033     XMTPT_FULL_READ_CONFIG_PACKET,
00034     XMTPT_SCA_READ_CONFIG_PACKET,
00035     XMTPT_ERASE_FPGA_IMAGE,
00036     XMTPT_UPLOAD_PACKET_FPGA,
00037     XMTPT_REINITIALIZE_FPGA,
00038     XMTPT_ERASE_UC_IMAGE_0,
00039     XMTPT_ERASE_UC_IMAGE_1,
00040     XMTPT_ERASE_UC_IMAGE_2,
00041     XMTPT_UPLOAD_PACKET_UC,
00042     XMTPT_SWITCH_TO_UC_IMAGE_0,
00043     XMTPT_SWITCH_TO_UC_IMAGE_1,
00044     XMTPT_SWITCH_TO_UC_IMAGE_2,
00045     XMTPT_UC_FPGA_CHECKSUMS,
00046 
00047     //VENDOR_REQUESTS_TO_DP5
00048     XMTPT_CLEAR_SPECTRUM_BUFFER_A,
00049     XMTPT_ENABLE_MCA_MCS,
00050     XMTPT_DISABLE_MCA_MCS,
00051     XMTPT_ARM_DIGITAL_OSCILLOSCOPE,
00052     XMTPT_AUTOSET_INPUT_OFFSET,
00053     XMTPT_AUTOSET_FAST_THRESHOLD,
00054     XMTPT_READ_IO3_0,
00055     XMTPT_WRITE_IO3_0,
00056     XMTPT_WRITE_512_BYTE_MISC_DATA,
00057     XMTPT_SET_DCAL,
00058     XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL_PZ,
00059     XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL_UC,
00060     XMTPT_SET_BOOT_FLAGS,
00061     XMTPT_SET_HV_DP4_EMULATION,
00062     XMTPT_SET_TEC_DP4_EMULATION,
00063     XMTPT_SET_INPUT_OFFSET_DP4_EMULATION,
00064     XMTPT_SET_ADC_CAL_GAIN_OFFSET,
00065     XMTPT_SET_SPECTRUM_OFFSET,
00066     XMTPT_REQ_SCOPE_DATA_MISC_DATA_SCA_PACKETS,
00067     XMTPT_SET_SERIAL_NUMBER,
00068     XMTPT_CLEAR_GP_COUNTER,
00069     XMTPT_SWITCH_SUPPLIES,
00070     
00071     XMTPT_SEND_TEST_PACKET,
00072         XMTPT_REQ_ACK_PACKET,
00073         XMTPT_FORCE_SCOPE_TRIGGER,
00074         XMTPT_READ_MCA8000D_OPTION_PA_CAL,
00075         XMTPT_AU34_2_RESTART
00076 };  //TRANSMIT_PACKET_TYPE
00077 
00078 //enum RECEIVE_PACKET_TYPE {
00079 //     //RESPONSE_PACKETS_FROM_DP5
00080 //    RCVPT_DP4_STYLE_STATUS,
00081 //    RCVPT_256_CHANNEL_SPECTRUM,
00082 //    RCVPT_256_CHANNEL_SPECTRUM_STATUS,
00083 //    RCVPT_512_CHANNEL_SPECTRUM,
00084 //    RCVPT_512_CHANNEL_SPECTRUM_STATUS,
00085 //    RCVPT_1024_CHANNEL_SPECTRUM,
00086 //    RCVPT_1024_CHANNEL_SPECTRUM_STATUS,
00087 //    RCVPT_2048_CHANNEL_SPECTRUM,
00088 //    RCVPT_2048_CHANNEL_SPECTRUM_STATUS,
00089 //    RCVPT_4096_CHANNEL_SPECTRUM,
00090 //    RCVPT_4096_CHANNEL_SPECTRUM_STATUS,
00091 //    RCVPT_8192_CHANNEL_SPECTRUM,
00092 //    RCVPT_8192_CHANNEL_SPECTRUM_STATUS,
00093 //    RCVPT_SCOPE_DATA,
00094 //    RCVPT_512_BYTE_MISC_DATA,
00095 //    RCVPT_IO3_0_STATE
00096 //};  //RECEIVE_PACKET_TYPE
00097 
00098 enum PID1_TYPE {
00099     PID1_REQ_STATUS = 0x01,
00100     PID1_REQ_SPECTRUM = 0x02,
00101     PID1_REQ_SCOPE_MISC = 0x03,
00102     PID1_REQ_SCA = 0x04,
00103     PID1_REQ_CONFIG = 0x20,
00104     PID1_REQ_FPGA_UC = 0x30,
00105     PID1_RCV_STATUS = 0x80,
00106     PID1_RCV_SPECTRUM = 0x81,
00107     PID1_RCV_SCOPE_MISC = 0x82,
00108     PID1_RCV_SCA = 0x83,
00109     PID1_VENDOR_REQ = 0xF0,
00110         PID1_COMM_TEST = 0xF1,
00111     PID1_ACK = 0xFF
00112 };  //PID1_TYPE
00113 
00114 enum PID2_REQ_STATUS_TYPE {
00115     PID2_SEND_DP4_STYLE_STATUS = 0x01
00116 };  //PID2_REQ_STATUS_TYPE
00117 
00118 enum PID2_REQ_SPECTRUM_TYPE {
00119     // REQUEST_PACKETS_TO_DP5
00120     PID2_SEND_SPECTRUM = 0x01,
00121     PID2_SEND_CLEAR_SPECTRUM = 0x02,
00122     PID2_SEND_SPECTRUM_STATUS = 0x03,
00123     PID2_SEND_CLEAR_SPECTRUM_STATUS = 0x04
00124     //PID2_BUFFER_SPECTRUM,
00125     //PID2_BUFFER_CLEAR_SPECTRUM,
00126     //PID2_SEND_BUFFER,
00127     //PID2_SEND_CONFIG
00128 };  //PID2_REQ_SPECTRUM_TYPE
00129 
00130 enum PID2_REQ_SCOPE_MISC_TYPE {
00131     PID2_SEND_SCOPE_DATA = 0x01,
00132     PID2_SEND_512_BYTE_MISC_DATA = 0x02,
00133     PID2_SEND_SCOPE_DATA_REARM = 0x03,
00134     PID2_SEND_ETHERNET_SETTINGS = 0x04,
00135     PID2_SEND_DIAGNOSTIC_DATA = 0x05,
00136     PID2_SEND_HARDWARE_DESCRIPTION = 0x06,
00137         PID2_SEND_NETFINDER_READBACK = 0x07,
00138         PID2_SEND_I2C_DATA = 0x08,
00139         PID2_SEND_LIST_MODE_DATA = 0x09,
00140         PID2_SEND_OPTION_PA_CALIBRATION = 0x0A
00141 };  //PID2_REQ_SCOPE_MISC_TYPE
00142 
00143 enum PID2_REQ_SCA_TYPE {
00144     PID2_SEND_SCA = 0x01,
00145     PID2_LATCH_SEND_SCA = 0x02,
00146     PID2_LATCH_CLEAR_SEND_SCA = 0x03
00147 };  //PID2_REQ_SCA_TYPE
00148 
00149 enum PID2_REQ_CONFIG_TYPE {
00150     PID2_PX4_STYLE_CONFIG_PACKET = 0x01,
00151     PID2_TEXT_CONFIG_PACKET = 0x02,
00152     PID2_CONFIG_READBACK_PACKET = 0x03
00153 };  //PID2_SEND_CONFIG_TYPE
00154 
00155 enum PID2_REQ_FPGA_UC_TYPE {
00156     PID2_ERASE_FPGA_IMAGE = 0x01,
00157     PID2_UPLOAD_PACKET_FPGA = 0x02,
00158     PID2_REINITIALIZE_FPGA = 0x03,
00159     PID2_ERASE_UC_IMAGE_0 = 0x04,
00160     PID2_ERASE_UC_IMAGE_1 = 0x05,
00161     PID2_ERASE_UC_IMAGE_2 = 0x06,
00162     PID2_UPLOAD_PACKET_UC = 0x07,
00163     PID2_SWITCH_TO_UC_IMAGE_0 = 0x08,
00164     PID2_SWITCH_TO_UC_IMAGE_1 = 0x09,
00165     PID2_SWITCH_TO_UC_IMAGE_2 = 0x0A
00166     //PID2_UC_FPGA_CHECKSUMS
00167 };  //PID2_REQ_FPGA_UC_TYPE
00168 
00169 enum PID2_VENDOR_REQ_TYPE {
00170     PID2_CLEAR_SPECTRUM_BUFFER_A = 0x01,
00171     PID2_ENABLE_MCA_MCS = 0x02,
00172     PID2_DISABLE_MCA_MCS = 0x03,
00173     PID2_ARM_DIGITAL_OSCILLOSCOPE = 0x04,
00174     PID2_AUTOSET_INPUT_OFFSET = 0x05,
00175     PID2_AUTOSET_FAST_THRESHOLD = 0x06,
00176     PID2_READ_IO3_0 = 0x07,
00177     PID2_WRITE_IO3_0 = 0x08,
00178     PID2_WRITE_512_BYTE_MISC_DATA = 0x09,
00179     PID2_SET_DCAL = 0x0A,
00180     PID2_SET_PZ_CORRECTION_UC_TEMP_CAL_PZ = 0x0B,
00181     PID2_SET_PZ_CORRECTION_UC_TEMP_CAL_UC = 0x0C,
00182     PID2_SET_BOOT_FLAGS = 0x0D,
00183     //PID2_SET_HV_DP4_EMULATION
00184     //PID2_SET_TEC_DP4_EMULATION
00185     //PID2_SET_INPUT_OFFSET_DP4_EMULATION
00186     PID2_SET_ADC_CAL_GAIN_OFFSET = 0x0E,
00187     //PID2_SET_SPECTRUM_OFFSET
00188     //PID2_REQ_SCOPE_DATA_MISC_DATA_SCA_PACKETS
00189     PID2_SET_SERIAL_NUMBER = 0x0F,
00190     PID2_CLEAR_GP_COUNTER = 0x10,
00191     PID2_SET_ETHERNET_SETTINGS = 0x11,
00192     //PID2_SWITCH_SUPPLIES
00193     PID2_ETHERNET_ALLOW_SHAREING = 0x20,
00194     PID2_ETHERNET_NO_SHARING = 0x21,
00195     PID2_ETHERNET_LOCK_IP = 0x22,
00196         PID2_GENERIC_FPGA_WRITE = 0x89
00197 };  //PID2_VENDOR_REQ_TYPE
00198 
00199 enum PID2_RCV_STATUS_TYPE {
00200     RCVPT_DP4_STYLE_STATUS = 0x01
00201 };  //PID2_RCV_STATUS_TYPE
00202     
00203 enum PID2_RCV_SPECTRUM_TYPE {
00204     RCVPT_256_CHANNEL_SPECTRUM = 0x01,
00205     RCVPT_256_CHANNEL_SPECTRUM_STATUS = 0x02,
00206     RCVPT_512_CHANNEL_SPECTRUM = 0x03,
00207     RCVPT_512_CHANNEL_SPECTRUM_STATUS = 0x04,
00208     RCVPT_1024_CHANNEL_SPECTRUM = 0x05,
00209     RCVPT_1024_CHANNEL_SPECTRUM_STATUS = 0x06,
00210     RCVPT_2048_CHANNEL_SPECTRUM = 0x07,
00211     RCVPT_2048_CHANNEL_SPECTRUM_STATUS = 0x08,
00212     RCVPT_4096_CHANNEL_SPECTRUM = 0x09,
00213     RCVPT_4096_CHANNEL_SPECTRUM_STATUS = 0x0A,
00214     RCVPT_8192_CHANNEL_SPECTRUM = 0x0B,
00215     RCVPT_8192_CHANNEL_SPECTRUM_STATUS = 0x0C
00216 };  //PID2_RCV_SPECTRUM_TYPE
00217 
00218 enum PID2_RCV_SCOPE_MISC_TYPE {
00219     RCVPT_SCOPE_DATA = 0x01,
00220     RCVPT_512_BYTE_MISC_DATA = 0x02,
00221     RCVPT_SCOPE_DATA_WITH_OVERFLOW = 0x03,
00222     RCVPT_ETHERNET_SETTINGS = 0x04,
00223     RCVPT_DIAGNOSTIC_DATA = 0x05,
00224     RCVPT_HARDWARE_DESCRIPTION = 0x06,
00225         RCVPT_CONFIG_READBACK = 0x07,
00226         RCVPT_NETFINDER_READBACK = 0x08,
00227         RCVPT_I2C_DATA = 0x09,
00228         RCVPT_LIST_MODE_DATA = 0x0A,
00229         RCVPT_LIST_MODE_DATA_FIFO_FULL = 0x0B,
00230         RCVPT_OPTION_PA_CALIBRATION = 0x0C
00231 };  //PID2_REQ_SCOPE_MISC_TYPE
00232 
00233 enum PID2_RCV_SCA_TYPE {
00234     RCVPT_SCA = 0x01
00235 };  //PID2_REQ_SCA_TYPE
00236 
00237 enum PID2_ACK_TYPE {  //PID1_ACK, PID2_ACK_TYPE)
00238     PID2_ACK_OK = 0x00,
00239     PID2_ACK_SYNC_ERROR = 0x01,
00240     PID2_ACK_PID_ERROR = 0x02,
00241     PID2_ACK_LEN_ERROR = 0x03,
00242     PID2_ACK_CHECKSUM_ERROR = 0x04,
00243     PID2_ACK_BAD_PARAM = 0x05,
00244     PID2_ACK_BAD_HEX_REC = 0x06,
00245     PID2_ACK_UNRECOG = 0x07,
00246     PID2_ACK_FPGA_ERROR = 0x08,
00247     PID2_ACK_CP2201_NOT_FOUND = 0x09,
00248     PID2_ACK_SCOPE_DATA_NOT_AVAIL = 0x0A,
00249     PID2_ACK_PC5_NOT_PRESENT = 0x0B,
00250     PID2_ACK_OK_ETHERNET_SHARE_REQ = 0x0C,
00251         PID2_ACK_ETHERNET_BUSY = 0x0D,
00252         PID2_ACK_I2C_ERROR = 0x0E,
00253         PID2_ACK_OK_FPGA_UPLOAD_ADDR = 0x0F,
00254         PID2_ACK_FEATURE_NOT_FPGA_SUPPORTED = 0x10,
00255         PID2_ACK_CAL_DATA_NOT_PRESENT = 0x11
00256 };  //PID2_ACK_TYPE
00257 
00258 //#define PID1_ACK 0xFF
00259 
00260 #define ACK 0
00261 //#define STATUS 1
00262 //#define SPECTRUM 2
00263 #define SYNC1_ 0xF5
00264 #define SYNC2_ 0xFA
00265 
00266 #define RS232 0
00267 #define USB 1
00268 #define ETHERNET 2
00269 
00270 #define ETHERNET_TIMEOUT 1000   // default timeout of 1000mS
00271 #define RS232_TIMEOUT 2500      // default timeout of 2500mS (8K spectrum ~2.2s)
00272 #define USB_TIMEOUT 500         // default timeout of 500mS
00273 
00274 #define Retries 2   // total of 3 attempts
00275 
00276 typedef struct _Packet_In {
00277     unsigned char PID1;
00278     unsigned char PID2;
00279     unsigned short LEN;  // signed, but data payload always less than 32768
00280     unsigned char STATUS;
00281     unsigned char DATA[32768];
00282     long CheckSum;
00283 } Packet_In;
00284 
00285 struct Packet_Out {
00286     unsigned char PID1;
00287     unsigned char PID2;
00288     unsigned short LEN;  // signed, but data payload always less than 32768
00289     unsigned char EXPECTEDRESPONSE;
00290     unsigned char DATA[514];
00291 };
00292 
00293 #define MAX_BUFFER_DATA         8192
00294 #define MAX_SCOPE_DATA          2048
00295 #define USB_DiagDataDelayMS 2500
00296 
00297 struct Spec {
00298         long DATA[MAX_BUFFER_DATA];   // this keeps total of static data under 64K VB limit
00299         short CHANNELS;
00300 };
00301 
00302 class CDP5Protocol
00303 {
00304 public:
00305         CDP5Protocol(void);
00306         ~CDP5Protocol(void);
00307 
00309         short InPacketType;
00310         // Incoming packet buffer. (24648==largest possible IN packet.)
00311         unsigned char PacketIn[24648]; 
00312 
00314         long RS232BytesInBuffer;
00316         long RS232_RThreshold;
00318         bool RS232HeaderReceived;
00320         short RS232PacketPtr;
00321 
00323         bool ScaleAuto;
00325         unsigned char Scope[2048];
00327         unsigned char MiscData[512];
00329         bool CommError;
00331         unsigned char BufferOUT[520];
00333         Spec SPECTRUM;
00335         Packet_In PIN;
00336 
00338         bool ACK_Received;
00340         bool Packet_Received;
00342         bool Timeout_flag;
00343 
00344         int UDP_offset;
00345         bool Netfinder_active;
00346         int Netfinder_Seq;
00347 
00349         bool USB_Default_Timeout;
00350 };
00351