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 4 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
6 changes: 3 additions & 3 deletions include/librealsense2/h/rs_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ 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.
* Build debug_protocl raw data command from opcode, parameters and data.
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
* 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
Expand All @@ -94,8 +94,8 @@ void rs2_hardware_reset(const rs2_device * device, rs2_error ** error);
* \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,
unsigned param3, unsigned param4, void* data, unsigned size_of_data, rs2_error** error);
const rs2_raw_data_buffer* rs2_build_debug_protocol_command(rs2_device* device, unsigned int opcode, unsigned int param1, unsigned int param2,
unsigned int param3, unsigned int param4, void* data, unsigned size_of_data, rs2_error** error);

/**
* Send raw data to device
Expand Down
6 changes: 4 additions & 2 deletions include/librealsense2/hpp/rs_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ namespace rs2
error::handle(e);
}

std::vector<uint8_t> build_raw_data(const uint32_t opcode,
std::vector<uint8_t> build_command(const uint32_t opcode,
const uint32_t param1 = 0,
const uint32_t param2 = 0,
const uint32_t param3 = 0,
Expand All @@ -840,7 +840,7 @@ namespace rs2
std::vector<uint8_t> results;

rs2_error* e = nullptr;
auto buffer = rs2_build_raw_data(_dev.get(), opcode, param1, param2, param3, param4,
auto buffer = rs2_build_debug_protocol_command(_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);
Expand All @@ -849,6 +849,7 @@ namespace rs2
error::handle(e);

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

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

Expand All @@ -869,6 +870,7 @@ namespace rs2
error::handle(e);

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

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

Expand Down
5 changes: 3 additions & 2 deletions src/core/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +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,
virtual std::vector<uint8_t> build_command(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;
const uint8_t* data = nullptr,
int dataLength = 0) = 0;
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved

};

Expand Down
7 changes: 4 additions & 3 deletions src/ds5/ds5-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ namespace librealsense
return _hw_monitor->send(input);
}

std::vector<uint8_t> ds5_device::build_raw_data(const uint32_t opcode,
std::vector<uint8_t> ds5_device::build_command(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 uint8_t* data,
int dataLength)
{
return _hw_monitor->build_raw_data(opcode, param1, param2, param3, param4, data);
return _hw_monitor->build_command(opcode, param1, param2, param3, param4, data, dataLength);
}

void ds5_device::hardware_reset()
Expand Down
5 changes: 3 additions & 2 deletions src/ds5/ds5-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +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,
std::vector<uint8_t> build_command(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;
const uint8_t* data = nullptr,
int dataLength = 0) override;

void hardware_reset() override;

Expand Down
6 changes: 3 additions & 3 deletions src/hw-monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ 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
std::vector<uint8_t> hw_monitor::build_command(const uint32_t opcode, const uint32_t param1, const uint32_t param2,
const uint32_t param3, const uint32_t param4, const uint8_t* data, int dataLength) 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);
fill_usb_buffer(opcode, param1, param2, param3, param4, data, dataLength, result.data(), length);
result.resize(length);
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/hw-monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ 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;
std::vector<uint8_t> build_command(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 uint8_t* data = nullptr, int dataLength = 0) 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);
Expand Down
7 changes: 4 additions & 3 deletions src/ivcam/sr300.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,15 @@ namespace librealsense
}


std::vector<uint8_t> build_raw_data(const uint32_t opcode,
std::vector<uint8_t> build_command(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 uint8_t* data = nullptr,
int dataLength = 0)
{
return _hw_monitor->build_raw_data(opcode, param1, param2, param3, param4, data);
return _hw_monitor->build_command(opcode, param1, param2, param3, param4, data, dataLength);
}

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

std::vector<uint8_t> l500_device::build_raw_data(const uint32_t opcode,
std::vector<uint8_t> l500_device::build_command(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 uint8_t* data,
int dataLength)
{
return _hw_monitor->build_raw_data(opcode, param1, param2, param3, param4, data);
return _hw_monitor->build_command(opcode, param1, param2, param3, param4, data, dataLength);
}

ivcam2::extended_temperatures l500_device::get_temperatures() const
Expand Down
5 changes: 3 additions & 2 deletions src/l500/l500-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,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,
std::vector<uint8_t> build_command(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 uint8_t* data = nullptr,
int dataLength = 0) override;

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

rs2_build_raw_data
rs2_build_debug_protocol_command
rs2_send_and_receive_raw_data
rs2_get_raw_data_size
rs2_delete_raw_data
Expand Down
14 changes: 6 additions & 8 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,15 @@ 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
const rs2_raw_data_buffer* rs2_build_debug_protocol_command(rs2_device* device, unsigned int opcode, unsigned int param1, unsigned int param2,
unsigned int param3, unsigned int 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);
auto ret_data = debug_interface->build_raw_data(opcode, param1, param2, param3, param4, buffer_to_send);
return new rs2_raw_data_buffer{ ret_data };
auto ret_data = debug_interface->build_command(opcode, param1, param2, param3, param4, static_cast<uint8_t*>(data), size_of_data);

return new rs2_raw_data_buffer{ std::move(ret_data) };

}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)
Expand All @@ -581,7 +579,7 @@ const rs2_raw_data_buffer* rs2_send_and_receive_raw_data(rs2_device* device, voi
auto raw_data_buffer = static_cast<uint8_t*>(raw_data_to_send);
std::vector<uint8_t> buffer_to_send(raw_data_buffer, raw_data_buffer + size_of_raw_data_to_send);
auto ret_data = debug_interface->send_receive_raw_data(buffer_to_send);
return new rs2_raw_data_buffer{ ret_data };
return new rs2_raw_data_buffer{ std::move(ret_data) };
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)

Expand Down
66 changes: 66 additions & 0 deletions unit-tests/debug_protocol/test-build-raw-data-command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import pyrealsense2 as rs
from rspy import devices, log, test, file, repo


#############################################################################################
# Help Functions
#############################################################################################

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:]


#############################################################################################
# Tests
#############################################################################################

test.start("Init")
try:
ctx = rs.context()
dev = ctx.query_devices()[0]
except:
test.unexpected_exception()
test.finish()

#############################################################################################

test.start("Old Scenario Test")
try:
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"
raw_command = convert_bytes_to_decimal(gvd_command)
old_scenario_result = send_hardware_monitor_command(dev, raw_command)
except:
test.unexpected_exception()
test.finish()

#############################################################################################

test.start("New Scenario Test")
try:
gvd_opcode = 0x10
raw_command = rs.debug_protocol(dev).build_command(gvd_opcode)
new_scenario_result = send_hardware_monitor_command(dev, raw_command)
test.check_equal_lists(new_scenario_result, old_scenario_result)
except:
test.unexpected_exception()
test.finish()


#############################################################################################

test.print_results_and_exit()
53 changes: 0 additions & 53 deletions unit-tests/debug_protocol/test-build-raw-data.py

This file was deleted.

2 changes: 1 addition & 1 deletion unit-tests/live/hw-errors/l500/l500-error-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void trigger_error_or_exit( const rs2::device & dev, uint8_t num )
{
try
{
auto raw_data = debug.build_raw_data(l500_trigger_error_opcode, 0, num);
auto raw_data = debug.build_command(l500_trigger_error_opcode, 0, num);
debug.send_and_receive_raw_data( raw_data );
}
catch(std::exception const& e)
Expand Down
6 changes: 3 additions & 3 deletions unit-tests/test-fw-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_update_counter(device):
else:
log.f( "Incompatible product line:", product_line )

raw_cmd = rs.debug_protocol(device).build_raw_data(opcode, start_index, size)
raw_cmd = rs.debug_protocol(device).build_command(opcode, start_index, size)
counter = send_hardware_monitor_command(device, raw_cmd)
return counter[0]

Expand All @@ -64,10 +64,10 @@ def reset_update_counter( device ):
opcode = 0x09
start_index = 0x30
size = 0x01
raw_cmd = rs.debug_protocol(device).build_raw_data(opcode, start_index, size)
raw_cmd = rs.debug_protocol(device).build_command(opcode, start_index, size)
elif product_line == "D400":
opcode = 0x86
raw_cmd = rs.debug_protocol(device).build_raw_data(opcode)
raw_cmd = rs.debug_protocol(device).build_command(opcode)
else:
log.f( "Incompatible product line:", product_line )

Expand Down
2 changes: 1 addition & 1 deletion unit-tests/unit-tests-live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ void trigger_error(const rs2::device& dev, int num)
int opcode = 0x4d;
if (auto debug = dev.as<debug_protocol>())
{
auto raw_data = debug.build_raw_data(opcode, num);
auto raw_data = debug.build_command(opcode, num);
debug.send_and_receive_raw_data(raw_data);
}
}
Expand Down
2 changes: 1 addition & 1 deletion wrappers/csharp/Intel.RealSense/Devices/DebugDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public byte[] BuildRawData(UInt32 opcode, UInt32 param1 = 0, UInt32 param2 = 0,
dataLength = (uint)data.Length;
}

IntPtr rawDataBuffer = NativeMethods.rs2_build_raw_data(Handle, opcode, param1, param2, param3,
IntPtr rawDataBuffer = NativeMethods.rs2_build_debug_protocol_command(Handle, opcode, param1, param2, param3,
param4, nativeBytes, dataLength, out error);

IntPtr start = NativeMethods.rs2_get_raw_data(rawDataBuffer, out error);
SamerKhshiboun marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading