-
Notifications
You must be signed in to change notification settings - Fork 5k
Remove memcpy in HWM & command_transfer #12622
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,24 +143,23 @@ namespace librealsense | |
| } | ||
|
|
||
| std::vector< uint8_t > | ||
| hw_monitor::send( command cmd, hwmon_response * p_response, bool locked_transfer ) const | ||
| hw_monitor::send( command const & cmd, hwmon_response * p_response, bool locked_transfer ) const | ||
| { | ||
| hwmon_cmd newCommand(cmd); | ||
| auto opCodeXmit = static_cast<uint32_t>(newCommand.cmd); | ||
| uint32_t const opCodeXmit = cmd.cmd; | ||
|
|
||
| hwmon_cmd_details details; | ||
| details.require_response = newCommand.require_response; | ||
| details.timeOut = newCommand.timeOut; | ||
|
|
||
| fill_usb_buffer(opCodeXmit, | ||
| newCommand.param1, | ||
| newCommand.param2, | ||
| newCommand.param3, | ||
| newCommand.param4, | ||
| newCommand.data, | ||
| newCommand.sizeOfSendCommandData, | ||
| details.sendCommandData.data(), | ||
| details.sizeOfSendCommandData); | ||
| details.require_response = cmd.require_response; | ||
| details.timeOut = cmd.timeout_ms; | ||
|
|
||
| fill_usb_buffer( opCodeXmit, | ||
| cmd.param1, | ||
| cmd.param2, | ||
| cmd.param3, | ||
| cmd.param4, | ||
| cmd.data.data(), // memcpy | ||
| std::min( (uint16_t)cmd.data.size(), HW_MONITOR_BUFFER_SIZE ), | ||
| details.sendCommandData.data(), | ||
| details.sizeOfSendCommandData ); | ||
|
|
||
| if (locked_transfer) | ||
| { | ||
|
|
@@ -172,33 +171,27 @@ namespace librealsense | |
| // Error/exit conditions | ||
| if (p_response) | ||
| *p_response = hwm_Success; | ||
| if( !newCommand.require_response ) | ||
| return std::vector<uint8_t>(); | ||
|
|
||
| std::memcpy( newCommand.receivedOpcode, details.receivedOpcode.data(), 4 ); | ||
| std::memcpy( newCommand.receivedCommandData, | ||
| details.receivedCommandData.data(), | ||
| details.receivedCommandDataLength ); | ||
| newCommand.receivedCommandDataLength = details.receivedCommandDataLength; | ||
| if( ! cmd.require_response ) | ||
| return {}; | ||
|
|
||
| // endian? | ||
| auto opCodeAsUint32 = pack(details.receivedOpcode[3], details.receivedOpcode[2], | ||
| details.receivedOpcode[1], details.receivedOpcode[0]); | ||
| if (opCodeAsUint32 != opCodeXmit) | ||
| { | ||
| auto err_type = static_cast<hwmon_response>(opCodeAsUint32); | ||
| std::string err = hwmon_error_string(cmd, err_type); | ||
| LOG_DEBUG(err); | ||
| if (p_response) | ||
| //LOG_DEBUG(err); // too intrusive; may be an expected error | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You removed the line that initialize
Better to keep as comment or remove both, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I'll remove |
||
| if( p_response ) | ||
| { | ||
| *p_response = err_type; | ||
| return std::vector<uint8_t>(); | ||
| return {}; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to understand, why is this better than before? what happens behind the scene?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're exactly the same, except the latter will still work if we change the return type of the function. |
||
| } | ||
| std::string err = hwmon_error_string( cmd, err_type ); | ||
| throw invalid_value_exception(err); | ||
| } | ||
|
|
||
| return std::vector<uint8_t>(newCommand.receivedCommandData, | ||
| newCommand.receivedCommandData + newCommand.receivedCommandDataLength); | ||
| auto const pb = details.receivedCommandData.data(); | ||
| return std::vector<uint8_t>( pb, pb + details.receivedCommandDataLength ); | ||
| } | ||
|
|
||
| /*static*/ std::vector<uint8_t> hw_monitor::build_command(uint32_t opcode, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.