gps_protocol.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_GPS_PROTOCOL_H_
  25. #define LIVOX_GPS_PROTOCOL_H_
  26. #include <stdint.h>
  27. #include "protocol.h"
  28. namespace livox_ros {
  29. #pragma pack(1)
  30. typedef struct {
  31. uint8_t sof;
  32. uint8_t cmd_str[1];
  33. } GpsPreamble;
  34. typedef struct {
  35. uint8_t sof;
  36. uint8_t data[1];
  37. } GpsPacket;
  38. #pragma pack()
  39. uint8_t AscciiToHex(const uint8_t *TwoChar);
  40. class GpsProtocol : public Protocol {
  41. public:
  42. GpsProtocol();
  43. ~GpsProtocol() = default;
  44. int32_t ParsePacket(const uint8_t *i_buf, uint32_t i_len,
  45. CommPacket *o_packet) override;
  46. int32_t Pack(uint8_t *o_buf, uint32_t o_buf_size, uint32_t *o_len,
  47. const CommPacket &i_packet) override;
  48. uint32_t GetPreambleLen() override;
  49. uint32_t GetPacketWrapperLen() override;
  50. uint32_t FindPacketLen(const uint8_t *buf, uint32_t buf_length) override;
  51. uint32_t GetPacketLen(const uint8_t *buf) override;
  52. int32_t CheckPreamble(const uint8_t *buf) override;
  53. int32_t CheckPacket(const uint8_t *buf) override;
  54. private:
  55. uint32_t found_length_;
  56. uint8_t CalcGpsPacketChecksum(const uint8_t *buf, uint32_t length);
  57. };
  58. } // namespace livox_ros
  59. #endif // LIVOX_GPS_PROTOCOL_H_