SdkApp.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef SDKAPP_H_E1FE741F
  2. #define SDKAPP_H_E1FE741F
  3. #include "cbsdk.h"
  4. #include <mutex>
  5. #include <thread>
  6. #define NSP_REC_BUF_SIZE (4096 * 2048) // Receiving system buffer size (multiple of 4096)
  7. /// Wrapper class for SDK Qt application
  8. class SdkApp //: public InstNetwork, public InstNetwork::Listener
  9. {
  10. public:
  11. SdkApp();
  12. ~SdkApp();
  13. public:
  14. void ProcessIncomingPacket(const cbPKT_GENERIC * const pPkt); // Process incoming packets
  15. cbRESULT GetLastCbErr() {return m_lastCbErr;}
  16. void Open(uint32_t id, int nInPort = cbNET_UDP_PORT_BCAST, int nOutPort = cbNET_UDP_PORT_CNT,
  17. LPCSTR szInIP = cbNET_UDP_ADDR_INST, LPCSTR szOutIP = cbNET_UDP_ADDR_CNT, int nRecBufSize = NSP_REC_BUF_SIZE);
  18. void Close(); // stop timer and close the message loop
  19. private:
  20. void LateBindCallback(cbSdkCallbackType callbacktype);
  21. public:
  22. cbSdkResult SdkOpen(uint32_t nInstance, cbSdkConnectionType conType, cbSdkConnection con);
  23. cbSdkResult SdkClose();
  24. cbSdkResult SdkGetTime(uint32_t * cbtime);
  25. cbSdkResult SdkRegisterCallback(cbSdkCallbackType callbacktype, cbSdkCallback pCallbackFn, void * pCallbackData);
  26. cbSdkResult SdkUnRegisterCallback(cbSdkCallbackType callbacktype);
  27. private:
  28. bool m_bDone;// flag to finish networking thread
  29. uint32_t m_instInfo; // Last instrument state
  30. uint32_t m_nInstance; // library instance
  31. // packet producer thread
  32. std::thread m_thread;
  33. void threadFun();
  34. void startThread();
  35. // void OnInstNetworkEvent(NetEventType type, unsigned int code); // Event from the instrument network
  36. bool m_bInitialized; // If initialized
  37. cbRESULT m_lastCbErr; // Last error
  38. // Lock for accessing the callbacks
  39. std::mutex m_lockCallback;
  40. // Actual registered callbacks
  41. cbSdkCallback m_pCallback[CBSDKCALLBACK_COUNT];
  42. void * m_pCallbackParams[CBSDKCALLBACK_COUNT];
  43. // Late bound versions are internal
  44. cbSdkCallback m_pLateCallback[CBSDKCALLBACK_COUNT];
  45. void * m_pLateCallbackParams[CBSDKCALLBACK_COUNT];
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Declarations for tracking the beginning and end of trials
  48. // For synchronization of threads
  49. bool m_bPacketsEvent;
  50. bool m_bPacketsCmt;
  51. bool m_bPacketsTrack;
  52. uint32_t m_uCbsdkTime; // Holds the 32-bit Cerebus timestamp of the last packet received
  53. };
  54. #endif /* end of include guard: SDKAPP_H_E1FE741F */