#pragma once #include #include "defines.hpp" class CloudPointPacket { public: /** * @brief 获取当前信息的数据内容 **/ virtual unsigned char *data() const { return m_data_; } /** * @brief 获取当前信息的数据长度 **/ virtual int size() const { return m_length_; } virtual bool packet(void *data, int size) = 0; protected: CloudPointPacket() {}; ~CloudPointPacket() = default; bool packInfo(ZX::LidarMessageType type, int point_number, unsigned char distance_accuracy) { if (m_length_ < ZX::PACKET_HEAD_SIZE + ZX::PACKET_END_SIZE) { return false; } static int times = 0; m_data_[0] = '$'; m_data_[1] = '&'; m_data_[2] = type >> 8; m_data_[3] = type; m_data_[4] = point_number >> 24; m_data_[5] = point_number >> 16; m_data_[6] = point_number >> 8; m_data_[7] = point_number; m_data_[8] = distance_accuracy; m_data_[9] = times >> 16; m_data_[10] = times >> 8; m_data_[11] = times; m_data_[m_length_ - 2] = '&'; m_data_[m_length_ - 1] = '$'; times++; if (times > 0X00FFFFFF) { times = 0; } return true; } protected: unsigned char *m_data_ = nullptr; int m_length_ = 0; };