dsi_framer.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. #if !defined(DSI_FRAMER_HPP)
  9. #define DSI_FRAMER_HPP
  10. #include "types.h"
  11. #include "dsi_serial.hpp"
  12. //////////////////////////////////////////////////////////////////////////////////
  13. // Public Definitions
  14. //////////////////////////////////////////////////////////////////////////////////
  15. #define DSI_FRAMER_TIMEDOUT (MAX_USHORT-1)
  16. #define DSI_FRAMER_ERROR MAX_USHORT
  17. //////////////////////////////////////////////////////////////////////////////////
  18. // Public Class Prototypes
  19. //////////////////////////////////////////////////////////////////////////////////
  20. class DSIFramer : public DSISerialCallback
  21. {
  22. protected:
  23. DSISerial *pclSerial; // Local pointer to a DSISerial object.
  24. public:
  25. // Constuctor and Destructor
  26. DSIFramer();
  27. DSIFramer(DSISerial *pclSerial_);
  28. /////////////////////////////////////////////////////////////////
  29. // Paramaters:
  30. // *pclSerial_: A pointer to a DSISerial object.
  31. /////////////////////////////////////////////////////////////////
  32. virtual ~DSIFramer();
  33. virtual BOOL WriteMessage(void *pvData_, USHORT usSize_) = 0;
  34. /////////////////////////////////////////////////////////////////
  35. // Writes bytes to the device.
  36. // Parameters:
  37. // *pvData_: A pointer to message data, including ID,
  38. // to be queued for sending over the serial
  39. // port.
  40. // usSize_: The message size. Each implementation
  41. // must define the meaning of this size.
  42. // Returns TRUE if successful. Otherwise, it returns FALSE.
  43. /////////////////////////////////////////////////////////////////
  44. virtual USHORT WaitForMessage(ULONG ulMilliseconds_) = 0;
  45. /////////////////////////////////////////////////////////////////
  46. // Waits for a message to be received by the receive handler.
  47. // Parameters:
  48. // ulMilliseconds_: Set this value to the minimum time to
  49. // wait before returning.
  50. // If the value is 0, the function will
  51. // return immediately.
  52. // If the value is MAX_ULONG, the function
  53. // will not time out.
  54. // Returns the size of the next message. If the return value is
  55. // DSI_FRAMER_TIMEDOUT (0xFFFE), then there is no message.
  56. // If there is an error in the message handling or there is a serial
  57. // error, then the return value is DSI_FRAMER_ERROR (0xFFFF)
  58. /////////////////////////////////////////////////////////////////
  59. virtual USHORT GetMessage(void *pvData_, USHORT usSize_ = 0) = 0;
  60. /////////////////////////////////////////////////////////////////
  61. // Gets the next message.
  62. // Parameters:
  63. // *pvData_: This is a pointer to a local buffer
  64. // to which this method will copy the
  65. // message. The buffer must be large
  66. // enough to hold the message. In many
  67. // cases, the size will be known by
  68. // virtue of the messaging scheme used.
  69. // Otherwise, the size returned by
  70. // WaitForMessage() may be used.
  71. // If the function returns DSI_FRAMER_ERROR
  72. // (0xFFFF), then *pvData_ will contain a
  73. // byte-length number indicating what error
  74. // occurred. This number is implementation-
  75. // dependent.
  76. // usSize_: This is the maximum length this method
  77. // will copy to the buffer. Each
  78. // implementation must define the meaning of
  79. // this size. If set to 0, the method will
  80. // copy the entire message.
  81. // *Note that the message will be
  82. // dequeued even if the length is limited
  83. // by this parameter. Therefore, if
  84. // GetMessage() is called and usSize_
  85. // is non-zero, and usSize_ is < the
  86. // message size, the remaining message
  87. // bytes will not be recoverable.
  88. // Returns the number of bytes copied to the buffer. If the
  89. // return value is DSI_FRAMER_TIMEDOUT (0xFFFE), then there is no
  90. // message. If there is an error in the message handling or there
  91. // is a serial error, then the return value is DSI_FRAMER_ERROR (0xFFFF).
  92. /////////////////////////////////////////////////////////////////
  93. };
  94. #endif // !defined(DSI_FRAMER_HPP)