pf_packet.cpp
Go to the documentation of this file.
1 //#include <algorithm>
2 
4 
5 bool PFPacket::parse_buf(uint8_t* buf, size_t buf_len, size_t& remainder, size_t& packet_size)
6 {
7  const size_t SIZE = get_size();
8  boost::shared_array<uint8_t> buffer(new uint8_t[SIZE]);
9  std::copy(buf, buf + SIZE, buffer.get());
10  ros::serialization::IStream stream(buffer.get(), SIZE);
11  uint16_t h_size;
12  uint32_t p_size;
13  uint16_t num;
14  std::tie(h_size, p_size, num) = read_header(stream);
15 
16  auto data_size = p_size - h_size;
17  if (buf_len < p_size)
18  return false;
19 
20  read_data(&buf[h_size], num);
21  remainder = buf_len - p_size;
22  packet_size = p_size;
23  return true;
24 }
25 
26 int PFPacket::find_packet_start(uint8_t* buf, size_t buf_len)
27 {
28  char p_type[2];
29  get_type(p_type);
30  for (size_t i = 0; i < buf_len - 4; i++)
31  {
32  if (((unsigned char)buf[i]) == 0x5c && ((unsigned char)buf[i + 1]) == 0xa2 &&
33  ((unsigned char)buf[i + 2]) == p_type[0] && ((unsigned char)buf[i + 3]) == p_type[1])
34  {
35  return i;
36  }
37  }
38  return -1;
39 }
virtual std::tuple< uint16_t, uint32_t, uint16_t > read_header(ros::serialization::IStream &stream)=0
bool parse_buf(uint8_t *buf, size_t buf_len, size_t &remainder, size_t &p_size)
Definition: pf_packet.cpp:5
virtual size_t get_size()=0
virtual void read_data(uint8_t *buf, size_t num)=0
int find_packet_start(uint8_t *buf, size_t buf_len)
Definition: pf_packet.cpp:26
virtual void get_type(char *p_type)=0


pf_driver
Author(s): Harsh Deshpande
autogenerated on Fri Feb 24 2023 03:59:35