sdk_protocol.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // The MIT License (MIT)
  3. //
  4. // Copyright (c) 2019 Livox. All rights reserved.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. // SOFTWARE.
  23. //
  24. #ifndef LIVOX_SDK_PROTOCOL_H_
  25. #define LIVOX_SDK_PROTOCOL_H_
  26. #include <stdint.h>
  27. #include "FastCRC/FastCRC.h"
  28. #include "protocol.h"
  29. namespace livox_ros {
  30. typedef enum { kSdkVerNone, kSdkVer0, kSdkVer1 } SdkVersion;
  31. #pragma pack(1)
  32. typedef struct {
  33. uint8_t sof;
  34. uint8_t version;
  35. uint16_t length;
  36. uint8_t packet_type;
  37. uint16_t seq_num;
  38. uint16_t preamble_crc;
  39. } SdkPreamble;
  40. typedef struct {
  41. uint8_t sof;
  42. uint8_t version;
  43. uint16_t length;
  44. uint8_t packet_type;
  45. uint16_t seq_num;
  46. uint16_t preamble_crc;
  47. uint8_t cmd_set;
  48. uint8_t cmd_id;
  49. uint8_t data[1];
  50. } SdkPacket;
  51. #pragma pack()
  52. class SdkProtocol : public Protocol {
  53. public:
  54. SdkProtocol(uint16_t seed16, uint32_t seed32);
  55. ~SdkProtocol() = default;
  56. int32_t ParsePacket(const uint8_t *i_buf, uint32_t i_len,
  57. CommPacket *o_packet) override;
  58. int32_t Pack(uint8_t *o_buf, uint32_t o_buf_size, uint32_t *o_len,
  59. const CommPacket &i_packet) override;
  60. uint32_t GetPreambleLen() override;
  61. uint32_t GetPacketWrapperLen() override;
  62. uint32_t GetPacketLen(const uint8_t *buf) override;
  63. int32_t CheckPreamble(const uint8_t *buf) override;
  64. int32_t CheckPacket(const uint8_t *buf) override;
  65. private:
  66. FastCRC16 crc16_;
  67. FastCRC32 crc32_;
  68. };
  69. } // namespace livox_ros
  70. #endif // LIVOX_SDK_PROTOCOL_H_