Update parse packets

This commit is contained in:
John Zhao 2018-04-13 10:20:02 +08:00
parent 086be12c95
commit 36581e6c66
3 changed files with 20 additions and 31 deletions

View File

@ -320,7 +320,7 @@ std::int32_t Channels::XuCamCtrlGet(Option option) const {
data[0] = id & 0xFF;
if (XuCamCtrlQuery(uvc::XU_QUERY_GET, 3, data)) {
return (data[1] << 8) + (data[2]);
return (data[1] << 8) | (data[2]);
} else {
LOG(WARNING) << "XuCamCtrlGet value of " << option << " failed";
return -1;
@ -430,17 +430,17 @@ Channels::control_info_t Channels::XuControlInfo(Option option) const {
data[0] = id & 0xFF;
if (XuCamCtrlQuery(uvc::XU_QUERY_MIN, 3, data)) {
info.min = (data[1] << 8) + (data[2]);
info.min = (data[1] << 8) | (data[2]);
} else {
LOG(WARNING) << "Get XuControlInfo.min of " << option << " failed";
}
if (XuCamCtrlQuery(uvc::XU_QUERY_MAX, 3, data)) {
info.max = (data[1] << 8) + (data[2]);
info.max = (data[1] << 8) | (data[2]);
} else {
LOG(WARNING) << "Get XuControlInfo.max of " << option << " failed";
}
if (XuCamCtrlQuery(uvc::XU_QUERY_DEF, 3, data)) {
info.def = (data[1] << 8) + (data[2]);
info.def = (data[1] << 8) | (data[2]);
} else {
LOG(WARNING) << "Get XuControlInfo.def of " << option << " failed";
}

View File

@ -23,23 +23,12 @@ bool unpack_stereo_img_data(
request.width * request.height * bytes_per_pixel(request.format);
auto data_end = data_new + data_n;
// LOG(INFO) << "ImagePacket (raw): header=0x" << std::hex <<
// static_cast<int>(*(data_end - 1))
// << ", size=0x" << std::hex << static_cast<int>(*(data_end - 2))
// << ", frame_id="<< std::dec << ((*(data_end - 3) << 8) + *(data_end - 4))
// << ", timestamp="<< std::dec << ((*(data_end - 5) << 24) + (*(data_end -
// 6) << 16) + (*(data_end - 7) << 8) + *(data_end - 8))
// << ", exposure_time="<< std::dec << ((*(data_end - 9) << 8) + *(data_end
// - 10))
// << ", checksum=0x" << std::hex << static_cast<int>(*(data_end - 11));
std::size_t packet_n = sizeof(ImagePacket);
// LOG(INFO) << "ImagePacket Size: " << packet_n;
std::vector<std::uint8_t> packet(packet_n);
std::reverse_copy(data_end - packet_n, data_end, packet.begin());
ImagePacket img_packet(packet.data());
// LOG(INFO) << "ImagePacket (new): header=0x" << std::hex <<
// LOG(INFO) << "ImagePacket: header=0x" << std::hex <<
// static_cast<int>(img_packet.header)
// << ", size=0x" << std::hex << static_cast<int>(img_packet.size)
// << ", frame_id="<< std::dec << img_packet.frame_id

View File

@ -147,10 +147,10 @@ struct ImagePacket {
void from_data(std::uint8_t *data) {
header = *data;
size = *(data + 1);
frame_id = (*(data + 2) << 8) + *(data + 3);
timestamp = (*(data + 4) << 24) + (*(data + 5) << 16) + (*(data + 6) << 8) +
frame_id = (*(data + 2) << 8) | *(data + 3);
timestamp = (*(data + 4) << 24) | (*(data + 5) << 16) | (*(data + 6) << 8) |
*(data + 7);
exposure_time = (*(data + 8) << 8) + *(data + 9);
exposure_time = (*(data + 8) << 8) | *(data + 9);
checksum = *(data + 10);
}
};
@ -198,15 +198,15 @@ struct ImuSegment {
}
void from_data(std::uint8_t *data) {
offset = (*(data) << 8) + *(data + 1);
frame_id = (*(data + 2) << 8) + *(data + 3);
accel[0] = (*(data + 4) << 8) + *(data + 5);
accel[1] = (*(data + 6) << 8) + *(data + 7);
accel[2] = (*(data + 8) << 8) + *(data + 9);
temperature = (*(data + 10) << 8) + *(data + 11);
gyro[0] = (*(data + 12) << 8) + *(data + 13);
gyro[1] = (*(data + 14) << 8) + *(data + 15);
gyro[2] = (*(data + 16) << 8) + *(data + 17);
offset = (*(data) << 8) | *(data + 1);
frame_id = (*(data + 2) << 8) | *(data + 3);
accel[0] = (*(data + 4) << 8) | *(data + 5);
accel[1] = (*(data + 6) << 8) | *(data + 7);
accel[2] = (*(data + 8) << 8) | *(data + 9);
temperature = (*(data + 10) << 8) | *(data + 11);
gyro[0] = (*(data + 12) << 8) | *(data + 13);
gyro[1] = (*(data + 14) << 8) | *(data + 15);
gyro[2] = (*(data + 16) << 8) | *(data + 17);
}
};
#pragma pack(pop)
@ -228,9 +228,9 @@ struct ImuPacket {
}
void from_data(std::uint8_t *data) {
serial_number = (*(data) << 24) + (*(data + 1) << 16) + (*(data + 2) << 8) +
serial_number = (*(data) << 24) | (*(data + 1) << 16) | (*(data + 2) << 8) |
*(data + 3);
timestamp = (*(data + 4) << 24) + (*(data + 5) << 16) + (*(data + 6) << 8) +
timestamp = (*(data + 4) << 24) | (*(data + 5) << 16) | (*(data + 6) << 8) |
*(data + 7);
count = *(data + 8);
@ -262,7 +262,7 @@ struct ImuResPacket {
void from_data(std::uint8_t *data) {
header = *data;
state = *(data + 1);
size = (*(data + 2) << 8) + *(data + 3);
size = (*(data + 2) << 8) | *(data + 3);
std::size_t seg_n = sizeof(ImuSegment); // 18
for (std::size_t i = 4; i < size;) {