-
Notifications
You must be signed in to change notification settings - Fork 0
/
pybackend_extras.cpp
63 lines (51 loc) · 2.17 KB
/
pybackend_extras.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "pybackend_extras.h"
#include <cinttypes>
using namespace librealsense;
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "../../third-party/stb_image_write.h"
// 123e4567-e89b-12d3-a456-426655440000
namespace pybackend2 {
platform::guid stoguid(std::string str)
{
platform::guid g;
sscanf(str.c_str(), "%8" SCNx32"-%4" SCNx16"-%4" SCNx16"-%2" SCNx8"%2" SCNx8"-%2"
SCNx8"%2" SCNx8"%2" SCNx8"%2" SCNx8"%2" SCNx8"%2" SCNx8,
&g.data1, &g.data2, &g.data3, g.data4, g.data4+1, g.data4+2,
g.data4+3, g.data4+4, g.data4+5, g.data4+6, g.data4+7);
return g;
}
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>())
{
std::vector<uint8_t> raw_data;
auto cmd_op_code = static_cast<uint32_t>(opcode);
const uint16_t pre_header_data = 0xcdab;
raw_data.resize(HW_MONITOR_BUFFER_SIZE);
auto write_ptr = raw_data.data();
size_t header_size = 4;
size_t cur_index = 2;
*reinterpret_cast<uint16_t *>(write_ptr + cur_index) = pre_header_data;
cur_index += sizeof(uint16_t);
*reinterpret_cast<unsigned int *>(write_ptr + cur_index) = cmd_op_code;
cur_index += sizeof(unsigned int);
// Parameters
*reinterpret_cast<unsigned*>(write_ptr + cur_index) = p1;
cur_index += sizeof(unsigned);
*reinterpret_cast<unsigned*>(write_ptr + cur_index) = p2;
cur_index += sizeof(unsigned);
*reinterpret_cast<unsigned*>(write_ptr + cur_index) = p3;
cur_index += sizeof(unsigned);
*reinterpret_cast<unsigned*>(write_ptr + cur_index) = p4;
cur_index += sizeof(unsigned);
// Data
std::copy(data.begin(), data.end(), reinterpret_cast<uint8_t*>(write_ptr + cur_index));
cur_index += data.size();
*reinterpret_cast<uint16_t*>(raw_data.data()) = static_cast<uint16_t>(cur_index - header_size);// Length doesn't include hdr.
raw_data.resize(cur_index);
return raw_data;
}
}