Barst  2.0
A server that controls lab hardware.
cpl defs.h
1 
3 #ifndef _CPL_DEFS_H_
4 #define _CPL_DEFS_H_
5 
6 #include <tchar.h>
7 #include <string>
8 #include <Windows.h> // we need to include windows to include ftd2xx.h
9 
10 #define BARST_VERSION 22000 // it's 2.20.00
11 
12 #define MIN_PIPE_BUF_SIZE 20 // smallest named pipe buffer possible
13 #define DEVICE_NAME_SIZE 8 // size of the unique internal name given for all devices/managers
14 #define MIN_BUFF_IN 256 // smallest server read (clients write) buffer for named pipe communicator
15 #define MIN_BUFF_OUT 256 // smallest server write (clients read) buffer for named pipe communicator
16 #define MIN_FTDI_LIB_VER 0x00030204 // the lowest FTDI version we accept for FTDI lib driver
17 #define MIN_RTV_LIB_VER 1080 // the lowest RTV version we accept for RTV dll lib driver
18 #define FTDI_MAX_BUFF_H (510*128) // max buffer that FTDI can r/w on high speed devices.
19 #define FTDI_MAX_BUFF_L (62*1024) // max buffer that FTDI can r/w on low speed devices.
20 #define FTDI_BAUD_2232H 200000 // clock rate is actually 1MHz = 200000*5
21 #define FTDI_BAUD_DEFAULT 62500 // clock rate is actually 1MHz = 62500*16
22 #define SERIAL_MAX_LENGTH 24 // maximum length serial comports can be (e.g. com4)
23 
24 
25 #define BAD_INPUT_PARAMS 1
26 #define NO_SYS_RESOURCE 2 // out of memory, etc.
27 #define ALREADY_OPEN 3 // tried to open device etc. that was already opened. or made request already pending
28 #define SIZE_MISSMATCH 4 // size of massage doesn't match expected size.
29 #define INVALID_CHANN 5 // channel requested is not set, out of range etc.
30 #define UNKWN_ERROR 6
31 #define DRIVER_ERROR 7
32 #define DEVICE_CLOSING 8 // device is closing so no data can be read/sent
33 #define INVALID_DEVICE 9 // the device you tried to create (e.g. ADC) isn't recognized
34 #define INACTIVE_DEVICE 10 // tried to do something with inactive device
35 #define INVALID_COMMAND 11 // didn't understand what you wanted, or command is invalid in this state/stage
36 #define UNEXPECTED_READ 12 // when the packet read doesn't match anything
37 #define NO_CHAN 13 // channel wasn't created as requested because something went wrong. Or no channel was provided
38 #define BUFF_TOO_SMALL 14 // provided buffer was too small, or wanted to write more than the buffer can take
39 #define NOT_FOUND 15 // library or object wasn't found
40 #define TIMED_OUT 16 // timed out while waiting for something
41 #define INVALID_MAN 17 // the manager (e.g. rtv, ftdi) you wanted to communicate with is not recognized
42 #define RW_FAILED 18
43 #define LIBRARY_ERROR 19
44 
47 #define FT_ERROR(x, nTemp) (((nTemp= x)!=0)?(nTemp + 100):0) // 101 + 1-19 = (101 to 200)
48 #define RTV_ERROR(x, nTemp) (((nTemp= -x)!=0)?(nTemp + 200):0) // 201 + 1-201 = (201 to 500)
49 #define MCDAQ_ERROR(x, nTemp) (((nTemp= x)!=0)?(nTemp + 500):0) // 101 + 1-19 = (501 to 1601)
50 #define WIN_ERROR(x, nTemp) (((nTemp= x)!=0)?(nTemp + 10000):0) // 10001 + ? = (10001 to ?)
51 
52 
55 #ifdef _UNICODE
56 #define tstring wstring
57 #define tostringstream wostringstream
58 #define tstringstream wstringstream
59 #else
60 #define tstring string
61 #define tostringstream ostringstream
62 #define tstringstream stringstream
63 #endif
64 
65 
67 enum EQueryType
68 {
69  /*** Everything sent to Barst starts with SBaseIn, optionally followed by other structs (each of which is prefaced
70  by SBase). Response by Barst is also SBaseIn or SBaseOut, optionally followed by other structs (each of which is prefaced
71  by SBase). The eType parameter of these structs are defined in this enum and determines the reason/type of the clients/server's
72  communication. The response eType of SBaseIn is typically the same eType as the eType sent, except in case of error it might be
73  eResponse or anything else, or if the response is a SBaseOut eType would be on of the eResponseExX.
74 
75  If data is sent to multiple layers, the lowest layer responds, and each layer needs
76  its own SBaseIn header. For instance, if you send data to the main manager which then passes it on to a manager
77  you have to provide two SBaseIn struct for each manager. The response would then come from the manager. ***/
78 
80  eNone= 0, // invalid
81  eQuery, // Requests info, response is typically eResponseEx with other stuff following
82  eSet, // Sets something, typically sends target specific info following SBaseIn
83  eDelete, // Deletes a channel or manager
84  ePassOn, // Tells upper layer to passs data on to next layer
85  eData, // SBaseIn followed by SBase and data, or just SBaseIn if that's the data
86  eTrigger, // Used to make a device do something
87  eResponse, // General response
88  eVersion, // dwInfo parameter is the version #
89  eActivate, // Tells server to activate a device
90  eInactivate, // Tells server to de-activate a device
91  /*** Cat B - SBaseOut ***/
92  eResponseEx, // szName
93  eResponseExL, // llLargeInteger
94  eResponseExD, // dDouble
95  /*** Cat C ***/
96  // ftdi struct info
97  eFTDIChan, // SBase followed by FT_DEVICE_LIST_INFO_NODE
98  eFTDIChanInit, // SBase followed by SChanInitFTDI
99  eFTDIPeriphInit, // SBase followed by SInitPeriphFT
100  eFTDIMultiWriteInit, // SBase followed by SValveInit
101  eFTDIADCInit, // SBase followed by SADCInit
102  eFTDIMultiReadInit, // SBase followed by SValveInit
103  eFTDIPinReadInit, // SBase followed by SPinInit
104  eFTDIPinWriteInit, // SBase followed by SPinInit
105  eRTVChanInit, // SBase followed by SChanInitRTV
106  eSerialChanInit, // SBase followed by SChanInitSerial
107  // possible buffer types
108  eFTDIMultiWriteData, // SBase followed by array of multi write data in the form of SValveData
109  eADCData, // SADCData struct (only from sBase ahead, sDataBase has its own eType)
110  eFTDIMultiReadData, // SBase followed by multi read pin data in form of bool array
111  eFTDIPinWDataArray, // SBase followed by pin data in form of SPinWData array
112  eFTDIPinWDataBufArray, // SBase followed by a SPinWData followed by pin data in form of unsigned char array
113  eFTDIPinRDataArray, // SBase followed by pin data read in form of unsigned char array
114  eRTVImageBuf, // SBase followed by a RTV image buffer.
115  eSerialWriteData, // SBase followed by SSerialData followed by data to be written
116  eSerialReadData,
117  eMCDAQChanInit, // SBase followed by SChanInitMCDAQ
118  eMCDAQWriteData, // SBase followed by SMCDAQWData
119  eCancelReadRequest, // SBaseIn indicating that a previous read request by the pipe should be canceld
120  eServerTime, // SBaseIn followed by SBase followed by SPerfTime
121 
122 
123  // managers - the values that eType2 can take
124  eFTDIMan= 1000,
125  eRTVMan,
126  eSerialMan,
127  eMCDAQMan,
128 };
129 
130 
131 
132 
135 // Simplest struct that can be sent on its own from/to user.
136 typedef struct SBaseIn
137 {
138  DWORD dwSize; // the size of the SBaseIn struct (16)
139  EQueryType eType; // the reason this was sent
140  // one knows which of the three types was used based on eType
141  union {
142  int nChan; // the channel number
143  EQueryType eType2; // a secondary reason for sending
144  DWORD dwInfo; // When a DWORD is required
145  };
146  int nError; // an error code.
147 } SBaseIn;
148 
149 // struct used to preface other structs.
150 typedef struct SBase
151 {
152  DWORD dwSize; // the size of SBase + the size of the struct following
153  EQueryType eType; // the struct following
154 } SBase;
155 
156 // Alternative to SBaseIn so we can send a it more info. Typically used when we send info on a channel.
157 typedef struct SBaseOut
158 {
159  // SBaseIn with sBaseIn.eType one of the eResponseExX types. sBaseIn.dwSize is 32 bytes.
160  SBaseIn sBaseIn;
161  union {
162  TCHAR szName[DEVICE_NAME_SIZE]; // eResponseEx
163  double dDouble; // eResponseExD
164  LARGE_INTEGER llLargeInteger; // eResponseExL
165  };
166  bool bActive; // if the channels this was sent for is active.
167 } SBaseOut;
168 
169 
170 
171 
172 typedef struct SPerfTime
173 {
174  double dRelativeTime;
175  double dUTCTime;
176 } SPerfTime;
177 
178 
179 
180 
181 /******************** FTDI ************************/
182 
187 typedef struct SChanInitFTDI
188 {
189  // sizes must be larger than what we'll ever write/read
190  DWORD dwBuffIn; // Size of the max buffer that client writes to server
191  DWORD dwBuffOut; // Size of the max buffer that client reads from server
192  DWORD dwBaud; // The baud rate used by the channel. We disregard the value supplied by the user.
193 } SChanInitFTDI;
194 
195 
198 typedef struct SInitPeriphFT
199 {
200  int nChan; // the channel number of this device within the FTDI channel.
201  // Holds the max buffer length that the write buffer will EVER be.
202  // The actual length of buffer written can vary depending on which devices are active
203  // but you can safley write to buffer for this length. For instance, if multi write and adc
204  // devices are active, say multi write needs only 18 bytes and adc needs 4000 bytes to be written. Then 4000
205  // bytes will be written, but the multi write device will have to initialize the full 4000 bytes, not just the 18 bytes
206  // with the default values. This is typically done when inactivating, the state in which each device starts.
207  // This size is the max of all devices, including padding if needed.
208  DWORD dwBuff;
209  // min buffer THIS device needs, actual buffer written/read might be larger (dwBuff) but not smaller
210  // while this device is active we are guaranteed to write/read dwMinSizeR/W
211  DWORD dwMinSizeR;
212  DWORD dwMinSizeW;
213  DWORD dwMaxBaud; // the baud rate this device needs. We use the min of all devices.
214  // the bit output mode (FT_xx), sync/async bit bang. If both are availible for all devices we use async.
215  // We and all the bit modes of all the devices so we find mode supported by all devices.
216  unsigned char ucBitMode;
217  unsigned char ucBitOutput; // the bits of the USB bus that are outputs for this device.
218 } SInitPeriphFT;
219 
220 
221 
228 typedef struct SValveInit
229 {
230  DWORD dwBoards; // the number of boards connected (each has 8 bits).
231  // the number of clock cycles to use for each tick (i.e. actual baud rate will be bausrate/dwClkPerData)
232  DWORD dwClkPerData;
233  unsigned char ucClk; // the bit number (0-7) that is the clock line
234  unsigned char ucData; // the bit number (0-7) that is the data line
235  unsigned char ucLatch; // the bit number (0-7) that is the latch (Sa on MC74HC165A) signal
236  // if reading device, and if true than we will continuosly read and send the data read to the
237  // client that initially triggered this device. This ensures we read as much data as possible.
238  // If it's a writing device we ignore this parameter.
239  bool bContinuous;
240 } SValveInit;
241 
242 
246 typedef struct SValveData
247 {
260  unsigned short usIndex;
261  bool bValue; // true to set bit high, false to set low.
262 } SValveData;
263 
264 
265 
270 typedef struct SPinInit
271 {
275  unsigned short usBytesUsed;
278  unsigned char ucActivePins;
281  unsigned char ucInitialVal;
286 } SPinInit;
287 
294 typedef struct SPinWData
295 {
296  // how many times this byte will be repeated in the output buffer.
297  unsigned short usRepeat;
298  // the the byte to output usRepeat times.
299  unsigned char ucValue;
300  /* Which of the output bytes to update. This lets you update only some of the output bytes
301  while not changing the others. For instance, if the pins for this device were selected as bits
302  3 and 7, i.e. ucActivePins was set to 0x88. But you only want to update bit 3 with this struct,
303  then you set ucPinSelect to 0x08 and only bit 3 will be changed. The other bit will remain as is.*/
304  unsigned char ucPinSelect;
305 } SPinWData;
306 
307 
308 
311 typedef struct SADCInit
312 {
333  unsigned char ucClk;
337  unsigned char ucLowestDataBit;
340  unsigned char ucDataBits;
345  unsigned char ucRateFilter;
347  bool bChop;
349  bool bChan1;
351  bool bChan2;
357  unsigned char ucInputRange;
359  unsigned char ucBitsPerData;
363  bool bStatusReg;
370 } SADCInit;
371 
372 
375 typedef struct SADCData
376 {
393  DWORD dwPos;
406  DWORD dwCount1;
407  DWORD dwChan2Start;
408  DWORD dwCount2;
416  DWORD dwChan1S;
417  DWORD dwChan2S;
424  float fSpaceFull;
427  float fTimeWorked;
429  float fDataRate;
435  unsigned char ucError;
437  double dStartTime;
438 } SADCData;
439 
440 
441 
442 
443 
444 
445 /************* RTV ****************/
446 
448 typedef struct SChanInitRTV
449 {
451  unsigned char ucBrightness;
453  unsigned char ucHue;
455  unsigned char ucUSat;
457  unsigned char ucVSat;
459  unsigned char ucLumaContrast;
461  unsigned char ucLumaFilt;
464  unsigned char ucColorFmt;
467  unsigned char ucVideoFmt;
474  bool bLossless;
478  unsigned char ucBpp;
480  int nWidth;
482  int nHeight;
485  DWORD dwBuffSize;
486 } SChanInitRTV;
487 
488 
489 
490 
491 
492 
493 /************* CommPort****************/
494 
496 typedef struct SChanInitSerial
497 {
498  TCHAR szPortName[SERIAL_MAX_LENGTH]; // The name of the port, e.g. COM1
499  DWORD dwMaxStrWrite; // max size of any data to be written
500  DWORD dwMaxStrRead; // max size of any data to be read
501  DWORD dwBaudRate; // baud rate with which to open the channel
502  // The number of stop bits to use. Can be one of 0, 1, or 2. 0 means 1 bit,
503  // 1, means 1.5 bits, and 2 means 2 bit.
504  unsigned char ucStopBits;
505  unsigned char ucParity;
506  // The number of bits in the bytes transmitted and received. Can be between
507  // 4 and 8, including 4 and 8.
508  unsigned char ucByteSize;
510 
512 typedef struct SSerialData
513 {
514  DWORD dwSize; // size of data to read/write
515  DWORD dwTimeout; // 0 means infinite wait
516  char cStop; // when reading, the character on which to stop
517  bool bStop; // if cStop is used, when reading
518 } SSerialData;
519 
520 
521 
522 // FT_DEVICE_LIST_INFO_NODE_OS is simmalr to FT_DEVICE_LIST_INFO_NODE,
523 // except the last item instead of being a FT_HANDLE which is a void*
524 // so size is either 4 or 8 bytes, is instead always 8 bytes. The _OS struct is
525 // always used when sending to clients to ensure x64, x86 comaptibility.
527  ULONG Flags;
528  ULONG Type;
529  ULONG ID;
530  DWORD LocId;
531  char SerialNumber[16];
532  char Description[64];
533  unsigned __int64 ftHandle;
535 
536 
537 
538 
539 
540 /************* MCDAQ device****************/
541 
542 
544 typedef struct SChanInitMCDAQ
545 {
546  unsigned char ucDirection; // 0 for reading, 1 for writing, 2 for read/write
547  unsigned short usInitialVal; // the initial value to set the port to, when writing
548  bool bContinuous; // when reading, whether it occurs continuously
550 
551 
553 typedef struct SMCDAQWData
554 {
555  unsigned short usValue; // the value to output.
556  /* Which of the output bits to update. This lets you update only some of the output bits
557  while not changing the others. For instance, if you only want to update bit 3 with this
558  struct, then you set usBitSelect to 0x0008 and only bit 3 will be changed. The other
559  bits will remain as is.*/
560  unsigned short usBitSelect;
561 } SMCDAQWData;
562 
563 
564 
565 #endif
DWORD dwCount1
Definition: cpl defs.h:406
unsigned char ucDataBits
Definition: cpl defs.h:340
unsigned char ucLowestDataBit
Definition: cpl defs.h:337
unsigned char ucBrightness
Definition: cpl defs.h:451
bool bReverseBytes
Definition: cpl defs.h:367
unsigned short usIndex
Definition: cpl defs.h:260
unsigned char ucError
Definition: cpl defs.h:435
float fSpaceFull
Definition: cpl defs.h:424
unsigned char ucBpp
Definition: cpl defs.h:478
bool bStatusReg
Definition: cpl defs.h:363
bool bChan1
Definition: cpl defs.h:349
unsigned char ucInitialVal
Definition: cpl defs.h:281
unsigned char ucVSat
Definition: cpl defs.h:457
bool bContinuous
Definition: cpl defs.h:285
DWORD dwChan1S
Definition: cpl defs.h:416
SBase sBase
Definition: cpl defs.h:390
unsigned char ucLumaFilt
Definition: cpl defs.h:461
SBaseIn sDataBase
Definition: cpl defs.h:388
float fUSBBuffToUse
Definition: cpl defs.h:326
unsigned char ucActivePins
Definition: cpl defs.h:278
bool bConfigureADC
Definition: cpl defs.h:369
unsigned char ucRateFilter
Definition: cpl defs.h:345
unsigned char ucUSat
Definition: cpl defs.h:455
bool bLossless
Definition: cpl defs.h:474
bool bChan2
Definition: cpl defs.h:351
float fTimeWorked
Definition: cpl defs.h:427
DWORD dwPos
Definition: cpl defs.h:393
bool bChop
Definition: cpl defs.h:347
unsigned char ucBitsPerData
Definition: cpl defs.h:359
DWORD dwDataPerTrans
Definition: cpl defs.h:331
DWORD dwBuffSize
Definition: cpl defs.h:485
float fDataRate
Definition: cpl defs.h:429
unsigned char ucVideoFmt
Definition: cpl defs.h:467
unsigned char ucHue
Definition: cpl defs.h:453
double dStartTime
Definition: cpl defs.h:437
unsigned char ucColorFmt
Definition: cpl defs.h:464
unsigned char ucLumaContrast
Definition: cpl defs.h:459
unsigned char ucInputRange
Definition: cpl defs.h:357
unsigned char ucClk
Definition: cpl defs.h:333
unsigned short usBytesUsed
Definition: cpl defs.h:275