12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #ifndef SDKAPP_H_E1FE741F
- #define SDKAPP_H_E1FE741F
- #include "cbsdk.h"
- #include <mutex>
- #include <thread>
- #define NSP_REC_BUF_SIZE (4096 * 2048) // Receiving system buffer size (multiple of 4096)
- /// Wrapper class for SDK Qt application
- class SdkApp //: public InstNetwork, public InstNetwork::Listener
- {
- public:
- SdkApp();
- ~SdkApp();
- public:
- void ProcessIncomingPacket(const cbPKT_GENERIC * const pPkt); // Process incoming packets
- cbRESULT GetLastCbErr() {return m_lastCbErr;}
- void Open(uint32_t id, int nInPort = cbNET_UDP_PORT_BCAST, int nOutPort = cbNET_UDP_PORT_CNT,
- LPCSTR szInIP = cbNET_UDP_ADDR_INST, LPCSTR szOutIP = cbNET_UDP_ADDR_CNT, int nRecBufSize = NSP_REC_BUF_SIZE);
- void Close(); // stop timer and close the message loop
-
- private:
- void LateBindCallback(cbSdkCallbackType callbacktype);
- public:
- cbSdkResult SdkOpen(uint32_t nInstance, cbSdkConnectionType conType, cbSdkConnection con);
- cbSdkResult SdkClose();
- cbSdkResult SdkGetTime(uint32_t * cbtime);
- cbSdkResult SdkRegisterCallback(cbSdkCallbackType callbacktype, cbSdkCallback pCallbackFn, void * pCallbackData);
- cbSdkResult SdkUnRegisterCallback(cbSdkCallbackType callbacktype);
- private:
- bool m_bDone;// flag to finish networking thread
-
- uint32_t m_instInfo; // Last instrument state
- uint32_t m_nInstance; // library instance
- // packet producer thread
- std::thread m_thread;
- void threadFun();
- void startThread();
- // void OnInstNetworkEvent(NetEventType type, unsigned int code); // Event from the instrument network
- bool m_bInitialized; // If initialized
- cbRESULT m_lastCbErr; // Last error
- // Lock for accessing the callbacks
- std::mutex m_lockCallback;
- // Actual registered callbacks
- cbSdkCallback m_pCallback[CBSDKCALLBACK_COUNT];
- void * m_pCallbackParams[CBSDKCALLBACK_COUNT];
- // Late bound versions are internal
- cbSdkCallback m_pLateCallback[CBSDKCALLBACK_COUNT];
- void * m_pLateCallbackParams[CBSDKCALLBACK_COUNT];
- /////////////////////////////////////////////////////////////////////////////
- // Declarations for tracking the beginning and end of trials
- // For synchronization of threads
- bool m_bPacketsEvent;
- bool m_bPacketsCmt;
- bool m_bPacketsTrack;
- uint32_t m_uCbsdkTime; // Holds the 32-bit Cerebus timestamp of the last packet received
- };
- #endif /* end of include guard: SDKAPP_H_E1FE741F */
|