EventAdapterCL.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //-----------------------------------------------------------------------------
  2. // (c) 2015 by Baumer
  3. // Project: GenApi
  4. // Author: Thomas Doering
  5. // Adapted from EventAdapterU3V.h
  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 CEventAdapterCL class.
  28. */
  29. #ifndef GENAPI_EVENTADAPTERCL_H
  30. #define GENAPI_EVENTADAPTERCL_H
  31. #include <GenApi/EventAdapter.h>
  32. namespace GENAPI_NAMESPACE
  33. {
  34. /* ------------------------------------------- */
  35. // Declaration of CL / GenCP 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. //! CL/GenCP command header
  49. typedef struct PACK_STRUCT CL_COMMAND_HEADER
  50. {
  51. // prefix
  52. uint16_t Preamble;
  53. uint16_t CcdCrc16;
  54. uint16_t ScdCrc16;
  55. uint16_t ChannelId;
  56. // CCD
  57. uint16_t Flags;
  58. uint16_t CommandId;
  59. uint16_t Length;
  60. uint16_t ReqId;
  61. } CL_COMMAND_HEADER;
  62. //! CL/GenCP EVENT_CMD specific command data WITHOUT event specific data
  63. typedef struct PACK_STRUCT CL_EVENT_DATA
  64. {
  65. // SCD
  66. uint16_t ReservedOrEventSize;
  67. uint16_t EventId;
  68. uint64_t Timestamp;
  69. } CL_EVENT_DATA;
  70. //! CL/GenCP EVENT_CMD specific command data WITH event specific data
  71. typedef struct PACK_STRUCT CL_EVENT_DATA1
  72. {
  73. // SCD
  74. uint16_t ReservedOrEventSize;
  75. uint16_t EventId;
  76. uint64_t Timestamp;
  77. uint8_t Data[1];
  78. } CL_EVENT_DATA1;
  79. //! Entire event data message
  80. typedef struct PACK_STRUCT CL_EVENT_MESSAGE
  81. {
  82. CL_COMMAND_HEADER CommandHeader;
  83. union {
  84. CL_EVENT_DATA EventData;
  85. // CL_EVENT_DATA1 EventData1;
  86. };
  87. } CL_EVENT_MESSAGE;
  88. const uint16_t CL_EVENT_PREAMBLE = 0x0100;
  89. const uint16_t CL_EVENT_CMD_ID = 0x0C00;
  90. const size_t CL_COMMAND_HEADER_SIZE = sizeof (CL_COMMAND_HEADER);
  91. const size_t CL_EVENT_BASIC_SIZE = sizeof (CL_EVENT_MESSAGE);
  92. // restore the previous packing
  93. #pragma pack(pop)
  94. /* ------------------------------------------- */
  95. //! Connects a U3V Event to a node map
  96. class GENAPI_DECL CEventAdapterCL : public CEventAdapter
  97. {
  98. public:
  99. //! Constructor
  100. CEventAdapterCL(INodeMap* pNodeMap = NULL);
  101. //! Destructor
  102. virtual ~CEventAdapterCL();
  103. virtual void DeliverMessage( const uint8_t msg[], uint32_t numBytes );
  104. //! Delivers the Event + Data listed in the packet
  105. void DeliverEventData(const CL_EVENT_DATA *pEventData, uint16_t length);
  106. };
  107. }
  108. #endif // GENAPI_EVENTADAPTERCL_H