Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add debug_protocol::build_command() #10261

Merged
merged 24 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
89db482
- add build_raw_data to the debug_protocol API
SamerKhshiboun Feb 21, 2022
1c582c9
Merge branch 'development' of https://github.com/IntelRealSense/libre…
SamerKhshiboun Feb 23, 2022
9b211cd
Merge branch 'development' of https://github.com/IntelRealSense/libre…
SamerKhshiboun Feb 23, 2022
d9da3dd
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 23, 2022
582c874
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 23, 2022
b15b03b
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 23, 2022
9b5b703
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 23, 2022
fe32be5
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 23, 2022
774cfeb
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 23, 2022
305c607
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 25, 2022
f6b1fb7
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 25, 2022
c7e5f3e
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 28, 2022
cddca53
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Feb 28, 2022
0f36689
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
31e3dd1
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
bcc99ad
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
944ae44
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
480c848
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
5eaf899
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
d98038f
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
4e7050a
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
8086827
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
612a605
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
8c76d84
Merge branch 'buildRawData' of https://github.com/SamerKhshiboun/libr…
SamerKhshiboun Mar 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/librealsense2/h/rs_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ int rs2_supports_device_info(const rs2_device* device, rs2_camera_info info, rs2
*/
void rs2_hardware_reset(const rs2_device * device, rs2_error ** error);

/**
* Build raw data command from opcode, parameters and data.
* The result can be used as raw_data_to_send parameter in send_and_receive_raw_data
* \param[in] device RealSense device to send data to
* \param[in] opcode Commad opcode
* \param[in] param1 First input parameter
* \param[in] param2 Second parameter
* \param[in] param3 Third parameter
* \param[in] param4 Fourth parameter
* \param[in] data Input Data (up to 1024 bytes)
* \param[in] size_of_data Size of input data in bytes
* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored
* \return rs2_raw_data_buffer which includes raw command
*/
const rs2_raw_data_buffer* rs2_build_raw_data(rs2_device* device, unsigned opcode, unsigned param1, unsigned param2,
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
unsigned param3, unsigned param4, void* data, unsigned size_of_data, rs2_error** error);

/**
* Send raw data to device
* \param[in] device RealSense device to send data to
Expand Down
25 changes: 25 additions & 0 deletions include/librealsense2/hpp/rs_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,31 @@ namespace rs2
error::handle(e);
}

std::vector<uint8_t> build_raw_data(const uint32_t opcode = 0,
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
const uint32_t param1 = 0,
const uint32_t param2 = 0,
const uint32_t param3 = 0,
const uint32_t param4 = 0,
const std::vector<uint8_t>& data = std::vector<uint8_t>()) const
{
std::vector<uint8_t> results;

rs2_error* e = nullptr;
auto buffer = rs2_build_raw_data(_dev.get(), opcode, param1, param2, param3, param4,
(void*)data.data(), (uint32_t)data.size(), &e);
std::shared_ptr<const rs2_raw_data_buffer> list(buffer, rs2_delete_raw_data);
error::handle(e);

auto size = rs2_get_raw_data_size(list.get(), &e);
error::handle(e);

auto start = rs2_get_raw_data(list.get(), &e);

results.insert(results.begin(), start, start + size);

return results;
}

std::vector<uint8_t> send_and_receive_raw_data(const std::vector<uint8_t>& input) const
{
std::vector<uint8_t> results;
Expand Down
7 changes: 7 additions & 0 deletions src/core/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace librealsense
{
public:
virtual std::vector<uint8_t> send_receive_raw_data(const std::vector<uint8_t>& input) = 0;
virtual std::vector<uint8_t> build_raw_data(const uint32_t opcode,
const uint32_t param1 = 0,
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
const uint32_t param2 = 0,
const uint32_t param3 = 0,
const uint32_t param4 = 0,
const std::vector<uint8_t>& data = std::vector<uint8_t>()) = 0;

};

MAP_EXTENSION(RS2_EXTENSION_DEBUG, librealsense::debug_interface);
Expand Down
10 changes: 10 additions & 0 deletions src/ds5/ds5-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ namespace librealsense
{
return _hw_monitor->send(input);
}

std::vector<uint8_t> ds5_device::build_raw_data(const uint32_t opcode,
const uint32_t param1,
const uint32_t param2,
const uint32_t param3,
const uint32_t param4,
const std::vector<uint8_t>& data)
{
return _hw_monitor->build_raw_data(opcode, param1, param2, param3, param4, data);
}

void ds5_device::hardware_reset()
{
Expand Down
7 changes: 7 additions & 0 deletions src/ds5/ds5-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ namespace librealsense

std::vector<uint8_t> send_receive_raw_data(const std::vector<uint8_t>& input) override;

std::vector<uint8_t> build_raw_data(const uint32_t opcode,
const uint32_t param1 = 0,
const uint32_t param2 = 0,
const uint32_t param3 = 0,
const uint32_t param4 = 0,
const std::vector<uint8_t>& data = std::vector<uint8_t>()) override;

void hardware_reset() override;

void create_snapshot(std::shared_ptr<debug_interface>& snapshot) const override;
Expand Down
11 changes: 11 additions & 0 deletions src/hw-monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ namespace librealsense
newCommand.receivedCommandData + newCommand.receivedCommandDataLength);
}

std::vector<uint8_t> hw_monitor::build_raw_data(const uint32_t opcode, const uint32_t param1, const uint32_t param2,
const uint32_t param3, const uint32_t param4, const std::vector<uint8_t>& data) const
{
int length;
std::vector<uint8_t> result;
result.resize(IVCAM_MONITOR_MAX_BUFFER_SIZE);
fill_usb_buffer(opcode, param1, param2, param3, param4, data.data(), (uint32_t)data.size(), result.data(), length);
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
result.resize(length);
return result;
}

std::string hwmon_error_string( command const & cmd, hwmon_response e )
{
auto str = hwmon_error2str( e );
Expand Down
3 changes: 3 additions & 0 deletions src/hw-monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ namespace librealsense

std::vector< uint8_t > send( std::vector< uint8_t > const & data ) const;
std::vector<uint8_t> send( command cmd, hwmon_response * = nullptr, bool locked_transfer = false ) const;
std::vector<uint8_t> build_raw_data(const uint32_t opcode, const uint32_t param1 = 0, const uint32_t param2 = 0,
const uint32_t param3 = 0, const uint32_t param4 = 0, const std::vector<uint8_t>& data = std::vector<uint8_t>()) const;

void get_gvd(size_t sz, unsigned char* gvd, uint8_t gvd_cmd) const;
static std::string get_firmware_version_string(const std::vector<uint8_t>& buff, size_t index, size_t length = 4);
static std::string get_module_serial_string(const std::vector<uint8_t>& buff, size_t index, size_t length = 6);
Expand Down
11 changes: 11 additions & 0 deletions src/ivcam/sr300.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ namespace librealsense
return _hw_monitor->send(input);
}


std::vector<uint8_t> build_raw_data(const uint32_t opcode,
const uint32_t param1 = 0,
const uint32_t param2 = 0,
const uint32_t param3 = 0,
const uint32_t param4 = 0,
const std::vector<uint8_t>& data = std::vector<uint8_t>())
{
return _hw_monitor->build_raw_data(opcode, param1, param2, param3, param4, data);
}

void hardware_reset() override
{
force_hardware_reset();
Expand Down
9 changes: 9 additions & 0 deletions src/l500/l500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,15 @@ namespace librealsense
return _hw_monitor->send(input);
}

std::vector<uint8_t> l500_device::build_raw_data(const uint32_t opcode,
const uint32_t param1,
const uint32_t param2,
const uint32_t param3,
const uint32_t param4,
const std::vector<uint8_t>& data)
{
return _hw_monitor->build_raw_data(opcode, param1, param2, param3, param4, data);
}

ivcam2::extended_temperatures l500_device::get_temperatures() const
{
Expand Down
6 changes: 6 additions & 0 deletions src/l500/l500-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ namespace librealsense
}

std::vector< uint8_t > send_receive_raw_data(const std::vector< uint8_t > & input) override;
std::vector<uint8_t> build_raw_data(const uint32_t opcode,
const uint32_t param1 = 0,
const uint32_t param2 = 0,
const uint32_t param3 = 0,
const uint32_t param4 = 0,
const std::vector<uint8_t>& data = std::vector<uint8_t>());

void hardware_reset() override
{
Expand Down
1 change: 1 addition & 0 deletions src/realsense.def
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ EXPORTS
rs2_set_region_of_interest
rs2_get_region_of_interest

rs2_build_raw_data
rs2_send_and_receive_raw_data
rs2_get_raw_data_size
rs2_delete_raw_data
Expand Down
17 changes: 16 additions & 1 deletion src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,21 @@ rs2_stream_profile* rs2_clone_video_stream_profile(const rs2_stream_profile* mod
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, mode, stream, index, format, width, height, intr)

const rs2_raw_data_buffer* rs2_build_raw_data(rs2_device* device, unsigned opcode, unsigned param1, unsigned param2,
unsigned param3, unsigned param4, void* data, unsigned size_of_data, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(device);

auto debug_interface = VALIDATE_INTERFACE(device->device, librealsense::debug_interface);

auto raw_data_buffer = static_cast<uint8_t*>(data);
std::vector<uint8_t> buffer_to_send(raw_data_buffer, raw_data_buffer + size_of_data);
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
auto ret_data = debug_interface->build_raw_data(opcode, param1, param2, param3, param4, buffer_to_send);
return new rs2_raw_data_buffer{ ret_data };

}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)

const rs2_raw_data_buffer* rs2_send_and_receive_raw_data(rs2_device* device, void* raw_data_to_send, unsigned size_of_raw_data_to_send, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(device);
Expand Down Expand Up @@ -1778,7 +1793,7 @@ void rs2_synthetic_frame_ready(rs2_source* source, rs2_frame* frame, rs2_error**
HANDLE_EXCEPTIONS_AND_RETURN(, source, frame)

rs2_pipeline* rs2_create_pipeline(rs2_context* ctx, rs2_error ** error) BEGIN_API_CALL
{
{
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
VALIDATE_NOT_NULL(ctx);

auto pipe = std::make_shared<pipeline::pipeline>(ctx->ctx);
Expand Down
53 changes: 53 additions & 0 deletions unit-tests/debug_protocol/test-build-raw-data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pyrealsense2 as rs
from rspy import devices, log, test, file, repo


def convert_bytes_to_decimal(command):
command_input = [] # array of uint_8t

# Parsing the command to array of unsigned integers(size should be < 8bits)
# threw out spaces
command = command.lower()
command = command.split()

for byte in command:
command_input.append(int('0x' + byte, 0))

return command_input


def send_hardware_monitor_command(device, command):
raw_result = rs.debug_protocol(device).send_and_receive_raw_data(command)
return raw_result[4:]


test.start("Init")
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved

try:
ctx = rs.context()
dev = ctx.query_devices()[0]

print("======================= old scenario ==========================\n")
gvd_command = "14 00 ab cd 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
converted_cmd = convert_bytes_to_decimal(gvd_command)
old_result = send_hardware_monitor_command(dev, converted_cmd)
print("old_result", old_result)

print("\n")

print("======================= NEW USAGE ==========================")
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
gvd_opcode = 0x10
new_command = rs.debug_protocol(dev).build_raw_data(gvd_opcode)
new_result = send_hardware_monitor_command(dev, new_command)
print("new_result", new_result)

print("\n")

equal = test.check_equal_lists(old_result, new_result)
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
if not equal:
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
log.w("expected results are not equal.")
except:
test.unexpected_exception()

test.finish()
test.print_results_and_exit()
8 changes: 1 addition & 7 deletions unit-tests/live/hw-errors/l500/l500-error-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,11 @@ std::map< uint8_t, std::pair< std::string, rs2_log_severity > > build_log_errors

void trigger_error_or_exit( const rs2::device & dev, uint8_t num )
{
std::vector< uint8_t > raw_data( 24, 0 );
raw_data[0] = 0x14;
raw_data[2] = 0xab;
raw_data[3] = 0xcd;
raw_data[4] = l500_trigger_error_opcode;
raw_data[12] = num;

if( auto debug = dev.as< debug_protocol >() )
{
try
{
auto raw_data = debug.build_raw_data(l500_trigger_error_opcode, 0, num);
debug.send_and_receive_raw_data( raw_data );
}
catch(std::exception const& e)
Expand Down
5 changes: 3 additions & 2 deletions unit-tests/live/options/test-drops-on-set.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import platform
import pyrealsense2 as rs
from rspy import test
from rspy import log
from rspy import test, log
import time

dev = test.find_first_device_or_exit()
Expand All @@ -29,6 +28,7 @@ def get_allowed_drops():
# Our KPI is to prevent sequential frame drops, therefore single frame drop is allowed.
return 1


def set_new_value(sensor, option, value):
global after_set_option
after_set_option = True
Expand Down Expand Up @@ -101,6 +101,7 @@ def check_color_frame_drops(frame):
if product_line == "D400":
options_to_ignore = [rs.option.visual_preset, rs.option.inter_cam_sync_mode]


def test_option_changes(sensor):
global options_to_ignore
options = sensor.get_supported_options()
Expand Down
Loading