Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

InstNetwork.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* =STS=> InstNetwork.h[2733].aa08 open SMID:8 */
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // (c) Copyright 2010 - 2011 Blackrock Microsystems
  5. //
  6. // $Workfile: InstNetwork.h $
  7. // $Archive: /common/InstNetwork.h $
  8. // $Revision: 1 $
  9. // $Date: 3/15/10 12:21a $
  10. // $Author: Ehsan $
  11. //
  12. // $NoKeywords: $
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. //
  16. // PURPOSE:
  17. //
  18. // Common xPlatform instrument network
  19. //
  20. #ifndef INSTNETWORK_H_INCLUDED
  21. #define INSTNETWORK_H_INCLUDED
  22. #include "debugmacs.h"
  23. #include "cbhwlib.h"
  24. #include "Instrument.h"
  25. #include "cki_common.h"
  26. #include <QThread>
  27. #include <QTimer>
  28. #include <QMetaType>
  29. #include <QVector>
  30. #include <QString>
  31. enum NetCommandType
  32. {
  33. NET_COMMAND_NONE = 0, // invalid command
  34. NET_COMMAND_OPEN, // open network
  35. NET_COMMAND_CLOSE, // close network
  36. NET_COMMAND_STANDBY, // instrument standby
  37. NET_COMMAND_SHUTDOWN, // instrument shutdown
  38. };
  39. // Events by network
  40. enum NetEventType
  41. {
  42. NET_EVENT_NONE = 0, // Invalid event
  43. NET_EVENT_INIT, // Instrument initialization started
  44. NET_EVENT_LISTENERERR, // Listener is not set
  45. NET_EVENT_CBERR, // cbRESULT error happened
  46. NET_EVENT_NETOPENERR, // Error opening the instrument network
  47. NET_EVENT_NETCLIENT, // Client network connection
  48. NET_EVENT_NETSTANDALONE, // Stand-alone network connection
  49. NET_EVENT_INSTINFO, // Instrument information (sent when network is established)
  50. NET_EVENT_INSTCONNECTING, // Instrument connecting
  51. NET_EVENT_INSTHARDRESET, // Instrument reset hardware
  52. NET_EVENT_INSTCONFIG, // Instrument retrieving configuration
  53. NET_EVENT_INSTRUN, // Instrument reset software to run
  54. NET_EVENT_PCTONSPLOST, // Connection lost
  55. NET_EVENT_LINKFAILURE, // Link failure
  56. NET_EVENT_CRITICAL, // Critical data catchup
  57. NET_EVENT_CLOSE, // Instrument closed
  58. NET_EVENT_RESET, // Instrument got reset
  59. NET_EVENT_LOCKEDRESET, // Locked reset (for recording)
  60. };
  61. // Author & Date: Ehsan Azar 15 March 2010
  62. // Purpose: Instrument networking thread
  63. class InstNetwork: public QThread
  64. {
  65. Q_OBJECT
  66. public:
  67. // Instrument network listener
  68. class Listener
  69. {
  70. public:
  71. // Callback function to process packets, must be implemented in target class
  72. virtual void ProcessIncomingPacket(const cbPKT_GENERIC * const pPkt) = 0;
  73. };
  74. public:
  75. InstNetwork(STARTUP_OPTIONS startupOption = OPT_NONE);
  76. void Open(Listener * listener); // Open the network
  77. void ShutDown(); // Instrument shutdown
  78. void StandBy(); // Instrument standby
  79. bool IsStandAlone() {return m_bStandAlone;} // If running in stand-alone
  80. uint32_t getPacketCounter() {return m_nRecentPacketCount;}
  81. uint32_t getDataCounter() {return m_dataCounter;}
  82. protected:
  83. enum { INST_TICK_COUNT = 10 };
  84. void run();
  85. void ProcessIncomingPacket(const cbPKT_GENERIC * const pPkt); // Process incoming packets in stand-alone mode
  86. void timerEvent(QTimerEvent *event); // the QT timer event for stand-alone networking
  87. void OnWaitEvent(); // Non-stand-alone networking
  88. inline void CheckForLinkFailure(uint32_t nTicks, uint32_t nCurrentPacketCount); // Check link failure
  89. private:
  90. void UpdateSortModel(const cbPKT_SS_MODELSET & rUnitModel);
  91. void UpdateBasisModel(const cbPKT_FS_BASIS & rBasisModel);
  92. private:
  93. cbLevelOfConcern m_enLOC; // level of concern
  94. STARTUP_OPTIONS m_nStartupOptionsFlags;
  95. QVector<Listener *> m_listener; // instrument network listeners
  96. uint32_t m_timerTicks; // network timer ticks
  97. int m_timerId; // Stand-alone timer ID
  98. bool m_bDone;// flag to finish networking thread
  99. uint32_t m_nRecentPacketCount; // number of real packets
  100. uint32_t m_dataCounter; // data counter
  101. uint32_t m_nLastNumberOfPacketsReceived;
  102. uint32_t m_runlevel; // Last runlevel
  103. protected:
  104. static const uint32_t MAX_NUM_OF_PACKETS_TO_PROCESS_PER_PASS;
  105. bool m_bStandAlone; // If it is stand-alone
  106. Instrument m_icInstrument; // The instrument
  107. uint32_t m_instInfo; // Last instrument state
  108. uint32_t m_nInstance; // library instance
  109. uint32_t m_nIdx; // library instance index
  110. int m_nInPort; // Client port number
  111. int m_nOutPort; // Instrument port number
  112. bool m_bBroadcast;
  113. bool m_bDontRoute;
  114. bool m_bNonBlocking;
  115. int m_nRecBufSize;
  116. QString m_strInIP; // Client IPv4 address
  117. QString m_strOutIP; // Instrument IPv4 address
  118. public Q_SLOTS:
  119. void Close(); // stop timer and close the message loop
  120. private Q_SLOTS:
  121. void OnNetCommand(NetCommandType cmd, unsigned int code = 0);
  122. // Heper slots to specialize this class for networking
  123. private Q_SLOTS:
  124. virtual void OnInstNetworkEvent(NetEventType, unsigned int) {;}
  125. virtual void OnExec() {;}
  126. Q_SIGNALS:
  127. void InstNetworkEvent(NetEventType type, unsigned int code = 0);
  128. };
  129. #endif // include guard