pybackend_extras.cpp
Go to the documentation of this file.
1 #include "pybackend_extras.h"
2 #include <cinttypes>
3 
4 using namespace librealsense;
5 
6 #define STB_IMAGE_WRITE_IMPLEMENTATION
7 #include "../../third-party/stb_image_write.h"
8 
9 // 123e4567-e89b-12d3-a456-426655440000
10 namespace pybackend2 {
11 
13  {
15  sscanf(str.c_str(), "%8" SCNx32"-%4" SCNx16"-%4" SCNx16"-%2" SCNx8"%2" SCNx8"-%2"
16  SCNx8"%2" SCNx8"%2" SCNx8"%2" SCNx8"%2" SCNx8"%2" SCNx8,
17  &g.data1, &g.data2, &g.data3, g.data4, g.data4+1, g.data4+2,
18  g.data4+3, g.data4+4, g.data4+5, g.data4+6, g.data4+7);
19 
20  return g;
21  }
22 
23  std::vector<uint8_t> encode_command(command opcode,
24  uint32_t p1 = 0,
25  uint32_t p2 = 0,
26  uint32_t p3 = 0,
27  uint32_t p4 = 0,
28  std::vector<uint8_t> data = std::vector<uint8_t>())
29  {
30  std::vector<uint8_t> raw_data;
31  auto cmd_op_code = static_cast<uint32_t>(opcode);
32 
33  const uint16_t pre_header_data = 0xcdab;
34  raw_data.resize(HW_MONITOR_BUFFER_SIZE);
35  auto write_ptr = raw_data.data();
36  size_t header_size = 4;
37 
38  size_t cur_index = 2;
39  *reinterpret_cast<uint16_t *>(write_ptr + cur_index) = pre_header_data;
40  cur_index += sizeof(uint16_t);
41  *reinterpret_cast<unsigned int *>(write_ptr + cur_index) = cmd_op_code;
42  cur_index += sizeof(unsigned int);
43 
44  // Parameters
45  *reinterpret_cast<unsigned*>(write_ptr + cur_index) = p1;
46  cur_index += sizeof(unsigned);
47  *reinterpret_cast<unsigned*>(write_ptr + cur_index) = p2;
48  cur_index += sizeof(unsigned);
49  *reinterpret_cast<unsigned*>(write_ptr + cur_index) = p3;
50  cur_index += sizeof(unsigned);
51  *reinterpret_cast<unsigned*>(write_ptr + cur_index) = p4;
52  cur_index += sizeof(unsigned);
53 
54  // Data
55  std::copy(data.begin(), data.end(), reinterpret_cast<uint8_t*>(write_ptr + cur_index));
56  cur_index += data.size();
57 
58  *reinterpret_cast<uint16_t*>(raw_data.data()) = static_cast<uint16_t>(cur_index - header_size);// Length doesn't include hdr.
59  raw_data.resize(cur_index);
60  return raw_data;
61  }
62 
63 }
GLboolean GLboolean g
platform::guid stoguid(std::string str)
std::vector< uint8_t > encode_command(command opcode, uint32_t p1=0, uint32_t p2=0, uint32_t p3=0, uint32_t p4=0, std::vector< uint8_t > data=std::vector< uint8_t >())
unsigned short uint16_t
Definition: stdint.h:79
GLsizei const GLchar *const * string
unsigned char uint8_t
Definition: stdint.h:78
unsigned int uint32_t
Definition: stdint.h:80
const uint16_t HW_MONITOR_BUFFER_SIZE
Definition: hw-monitor.h:41
Definition: parser.hpp:150
void copy(void *dst, void const *src, size_t size)
Definition: types.cpp:836


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39