EventAdapterGEV.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //-----------------------------------------------------------------------------
  2. // (c) 2006 by Basler Vision Technologies
  3. // Section: Vision Components
  4. // Project: GenApi
  5. // Author: Fritz Dierks
  6. // $Header$
  7. //
  8. // License: This file is published under the license of the EMVA GenICam Standard Group.
  9. // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
  10. // If for some reason you are missing this file please contact the EMVA or visit the website
  11. // (http://www.genicam.org) for a full copy.
  12. //
  13. // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
  14. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
  17. // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  20. // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. // POSSIBILITY OF SUCH DAMAGE.
  24. //-----------------------------------------------------------------------------
  25. /**
  26. \file
  27. \brief Declaration of the CEventAdapterGEV class.
  28. */
  29. #ifndef GENAPI_EVENTADAPTERGEV_H
  30. #define GENAPI_EVENTADAPTERGEV_H
  31. #include <GenApi/EventAdapter.h>
  32. namespace GENAPI_NAMESPACE
  33. {
  34. /* ------------------------------------------- */
  35. // Declaration of GigE Vision Event message structures
  36. // some useful macros
  37. #if defined( _MSC_VER )
  38. #define PACK_STRUCT
  39. #elif defined (__GNUC__)
  40. // While gcc-4 understands #pragma pack,
  41. // gcc-3 does not
  42. #define PACK_STRUCT __attribute__((packed))
  43. #else
  44. # error Unknown platform
  45. #endif
  46. // make sure everything is properly packed
  47. #pragma pack(push, 1)
  48. //! header of a GVCP request packet
  49. typedef struct PACK_STRUCT GVCP_REQUEST_HEADER
  50. {
  51. uint8_t Magic;
  52. uint8_t Flags;
  53. uint16_t Command;
  54. uint16_t Length;
  55. uint16_t ReqId;
  56. } GVCP_REQUEST_HEADER;
  57. //! layout of a GVCP event item (common to all types)
  58. typedef struct PACK_STRUCT GVCP_EVENT_ITEM_BASIC
  59. {
  60. uint16_t ReservedOrEventSize;
  61. uint16_t EventId;
  62. } GVCP_EVENT_ITEM_BASIC;
  63. //! layout of a GVCP event item (Extended ID flag not set)
  64. typedef struct PACK_STRUCT GVCP_EVENT_ITEM
  65. {
  66. uint16_t ReservedOrEventSize;
  67. uint16_t EventId;
  68. uint16_t StreamChannelId;
  69. uint16_t BlockId;
  70. uint32_t TimestampHigh;
  71. uint32_t TimestampLow;
  72. } GVCP_EVENT_ITEM;
  73. //! Layout of a GVCP event request packet (Extended ID flag not set)
  74. typedef struct PACK_STRUCT GVCP_EVENT_REQUEST
  75. {
  76. GVCP_REQUEST_HEADER Header;
  77. GVCP_EVENT_ITEM Items[ 1 ];
  78. } GVCP_EVENT_REQUEST;
  79. //! Layout of a GVCP event data request packet (Extended ID flag not set)
  80. typedef struct PACK_STRUCT GVCP_EVENTDATA_REQUEST
  81. {
  82. GVCP_REQUEST_HEADER Header;
  83. GVCP_EVENT_ITEM Event;
  84. uint32_t Data[ 1 ];
  85. } GVCP_EVENTDATA_REQUEST;
  86. //! layout of a GVCP event item (Extended ID flag set)
  87. typedef struct PACK_STRUCT GVCP_EVENT_ITEM_EXTENDED_ID
  88. {
  89. uint16_t ReservedOrEventSize;
  90. uint16_t EventId;
  91. uint16_t StreamChannelId;
  92. uint16_t BlockId;
  93. uint32_t BlockId64High;
  94. uint32_t BlockId64Low;
  95. uint32_t TimestampHigh;
  96. uint32_t TimestampLow;
  97. } GVCP_EVENT_ITEM_EXTENDED_ID;
  98. //! Layout of a GVCP event request packet (Extended ID flag set)
  99. typedef struct PACK_STRUCT GVCP_EVENT_REQUEST_EXTENDED_ID
  100. {
  101. GVCP_REQUEST_HEADER Header;
  102. GVCP_EVENT_ITEM_EXTENDED_ID Items[ 1 ];
  103. } GVCP_EVENT_REQUEST_EXTENDED_ID;
  104. //! Layout of a GVCP event data request packet (Extended ID flag set)
  105. typedef struct PACK_STRUCT GVCP_EVENTDATA_REQUEST_EXTENDED_ID
  106. {
  107. GVCP_REQUEST_HEADER Header;
  108. GVCP_EVENT_ITEM_EXTENDED_ID Event;
  109. uint32_t Data[ 1 ];
  110. } GVCP_EVENTDATA_REQUEST_EXTENDED_ID;
  111. const uint8_t COMMAND_MAGIC = 0x42;
  112. typedef enum GVCP_MESSAGE_TAGS
  113. {
  114. TAG_EVENT_CMD = 0xc0,
  115. TAG_EVENTDATA_CMD = 0xc2
  116. } GVCP_MESSAGE_TAGS;
  117. // restore the previous packing
  118. #pragma pack(pop)
  119. /* ------------------------------------------- */
  120. //! Connects a GigE Event to a node map
  121. class GENAPI_DECL CEventAdapterGEV : public CEventAdapter
  122. {
  123. public:
  124. //! Constructor
  125. CEventAdapterGEV(INodeMap* pNodeMap = NULL);
  126. //! Destructor
  127. virtual ~CEventAdapterGEV();
  128. virtual void DeliverMessage( const uint8_t msg[], uint32_t numBytes );
  129. //! Delivers the Events listed in the Event packet (Extended ID flag not set)
  130. void DeliverEventMessage(const GVCP_EVENT_REQUEST *pEvent);
  131. //! Delivers the Event + Data listed in the EventData packet (Extended ID flag not set)
  132. void DeliverEventMessage(const GVCP_EVENTDATA_REQUEST *pEventData);
  133. //! Delivers the Events listed in the Event packet (Extended ID flag set)
  134. void DeliverEventMessage(const GVCP_EVENT_REQUEST_EXTENDED_ID *pEvent);
  135. //! Delivers the Event + Data listed in the EventData packet (Extended ID flag set)
  136. void DeliverEventMessage(const GVCP_EVENTDATA_REQUEST_EXTENDED_ID *pEventData);
  137. private:
  138. void DeliverEventItem(const GVCP_EVENT_ITEM_BASIC *pItem, unsigned int length);
  139. /*
  140. The code for handling event messages and attaching event items to the EventPort
  141. is the same for events with and without extended ID.
  142. Only the datatype differs, so we keep the implementation in these templates
  143. */
  144. template<typename EVT_REQ_TYPE> void DeliverEventMessageImpl(const EVT_REQ_TYPE *pEvent);
  145. template<typename EVT_REQ_TYPE> void DeliverEventDataMessageImpl(const EVT_REQ_TYPE *pEvent);
  146. void AttachItemToPorts(const uint8_t *pItem, uint16_t event_id, unsigned int length);
  147. };
  148. }
  149. #endif // GENAPI_EVENTADAPTERGEV_H