#if !defined(CHIMAERA_H) #define CHIMAERA_H #include "utils.h" struct deviceHeader_t { unsigned char cmd; unsigned char dummy; unsigned short length; static const unsigned char Data = 0x1; static const unsigned char DataAcknowledge = 0x2; // Deprecated static const unsigned char Status = 0x3; static const unsigned char StatusRequest = 0x4; static const unsigned char FlushRequest = 0x5; // Deprecated static const unsigned char PacketRequest = 0x6; static const unsigned char GenerateLHCbEvent = 0x7; static const unsigned char PIOWriteRequest = 0x8; static const unsigned char PIOReadRequest = 0x9; static const unsigned char GenerateALICEEvent = 0xa; static const unsigned char ResetRequest = 0xb; static const unsigned char ConfigurationData = 0xc; static const unsigned char Int0Enable = 0xd; static const unsigned char Int0Disable = 0xe; static const unsigned char Int0 = 0xf; static const unsigned char GenerateClockBurst = 0x10; static const unsigned char ReadAddress = 0x11; static const unsigned char Idle = 0xa5; static const unsigned char Idle2 = 0x25; }; struct statusData_t { unsigned char PIO[3]; // Port IO unsigned char seq; // Sequence counter unsigned char parityErrorCount[4]; unsigned eventCount; unsigned bufferCount :24; unsigned char rxinhibit :4; unsigned char rxerr :4; unsigned extra; unsigned short ADC[2]; }; struct devicePacket_t { unsigned char cmd; unsigned char dummy; unsigned short length; union { unsigned char uc[64]; unsigned short config[2]; unsigned data[16]; statusData_t status; }; }; typedef void * CBUSBID; const SI_STATUS SI_WRITE_UNDERRUN = 0xa; // C-callable interface int CBUSBOpen( CBUSBID *, char *, unsigned ); int CBUSBClose( CBUSBID ); void CBUSBShowErrorTrace( CBUSBID ); int CBUSBDispatch( CBUSBID, devicePacket_t &, unsigned ); int CBUSBReceive( CBUSBID, devicePacket_t &, unsigned ); int CBUSBDispatchPIOWriteRequest( HANDLE, unsigned ); int CBUSBDispatchClockBurstRequest( CBUSBID, unsigned, unsigned ); int CBUSBDispatchConfiguration( CBUSBID, unsigned, unsigned ); void CBUSBShowLastStatus( CBUSBID, devicePacket_t & ); void CBUSBShowLastData( CBUSBID, devicePacket_t & ); unsigned CBUSBFlushBuffer( CBUSBID, unsigned, bool ); class cbusb { protected: HANDLE deviceHandle; tracestream errors; tracestream trace; public: cbusb( const char *, unsigned ); ~cbusb(); operator void*(){ return errors.tellp() > 0 ? 0 : this; } bool operator !(){ return errors.tellp() <= 0 ? false : true; } void showErrorTrace(); void showInfoTrace(); // Low level message read/write functions void dispatch( devicePacket_t &, unsigned ); void receive( devicePacket_t &, unsigned ); // Higher level/compound messages void dispatchPIOWriteRequest( unsigned ); void dispatchClockBurstRequest( unsigned, unsigned ); unsigned flushBuffer( unsigned, bool ); // Utility functions void showLastStatus( devicePacket_t & ); void showLastData( devicePacket_t & ); }; #endif