-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Extended HWM commands refactor #12682
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,45 +2,29 @@ | |
// Copyright(c) 2023 Intel Corporation. All Rights Reserved. | ||
|
||
#include "hw_monitor_extended_buffers.h" | ||
#include "ds/d500/d500-private.h" | ||
#include <ds/ds-private.h> | ||
|
||
|
||
namespace librealsense | ||
{ | ||
int hw_monitor_extended_buffers::get_msg_length(command cmd) const | ||
{ | ||
int msg_length = HW_MONITOR_BUFFER_SIZE; | ||
if (cmd.cmd == ds::fw_cmd::GET_HKR_CONFIG_TABLE || cmd.cmd == ds::fw_cmd::SET_HKR_CONFIG_TABLE) | ||
{ | ||
auto calib_table_id = static_cast<ds::d500_calibration_table_id>(cmd.param2); | ||
auto it = ds::d500_calibration_tables_size.find(calib_table_id); | ||
if (it == ds::d500_calibration_tables_size.end()) | ||
throw std::runtime_error(rsutils::string::from() << " hwm command with wrong param2"); | ||
|
||
msg_length = it->second; | ||
} | ||
return msg_length; | ||
} | ||
|
||
int hw_monitor_extended_buffers::get_number_of_chunks(int msg_length) const | ||
int hw_monitor_extended_buffers::get_number_of_chunks(size_t msg_length) const | ||
{ | ||
return static_cast<int>(std::ceil(msg_length / 1024.0f)); | ||
return static_cast<int>(std::ceil(msg_length / (float)HW_MONITOR_BUFFER_SIZE)); | ||
} | ||
|
||
hw_monitor_extended_buffers::hwm_buffer_type hw_monitor_extended_buffers::get_buffer_type(command cmd) const | ||
{ | ||
if (cmd.cmd == ds::fw_cmd::GET_HKR_CONFIG_TABLE || cmd.cmd == ds::fw_cmd::SET_HKR_CONFIG_TABLE) | ||
bool provide_whole_table = (cmd.param4 == 0); | ||
switch( cmd.cmd) | ||
{ | ||
auto calibration_table_size = get_msg_length(cmd); | ||
|
||
bool provide_whole_table = (cmd.param4 == 0); | ||
if (calibration_table_size <= HW_MONITOR_COMMAND_SIZE || !provide_whole_table) | ||
return hwm_buffer_type::standard; | ||
if (cmd.cmd == ds::fw_cmd::GET_HKR_CONFIG_TABLE) | ||
return hwm_buffer_type::big_buffer_to_receive; | ||
return hwm_buffer_type::big_buffer_to_send; | ||
case ds::fw_cmd::GET_HKR_CONFIG_TABLE: | ||
return provide_whole_table ? hwm_buffer_type::extended_receive : hwm_buffer_type::standard; | ||
case ds::fw_cmd::SET_HKR_CONFIG_TABLE: | ||
return provide_whole_table ? hwm_buffer_type::extended_send : hwm_buffer_type::standard; | ||
default: | ||
return hwm_buffer_type::standard; | ||
} | ||
return hwm_buffer_type::standard; | ||
} | ||
|
||
// 3 cases are foreseen in this method: | ||
|
@@ -50,43 +34,62 @@ namespace librealsense | |
std::vector<uint8_t> hw_monitor_extended_buffers::send(command const & cmd, hwmon_response* p_response, bool locked_transfer) const | ||
{ | ||
hwm_buffer_type buffer_type = get_buffer_type(cmd); | ||
if (buffer_type == hwm_buffer_type::standard) | ||
switch( buffer_type) | ||
{ | ||
case hwm_buffer_type::standard: | ||
return hw_monitor::send(cmd, p_response, locked_transfer); | ||
|
||
if (buffer_type == hwm_buffer_type::big_buffer_to_receive) | ||
return send_big_buffer_to_receive(cmd, p_response, locked_transfer); | ||
|
||
// hwm_buffer_type::big_buffer_to_send is the last remaining option | ||
send_big_buffer_to_send(cmd, p_response, locked_transfer); | ||
case hwm_buffer_type::extended_receive: | ||
return extended_receive(cmd, p_response, locked_transfer); | ||
case hwm_buffer_type::extended_send: | ||
extended_send(cmd, p_response, locked_transfer); | ||
default: | ||
return std::vector<uint8_t>(); | ||
} | ||
return std::vector<uint8_t>(); | ||
} | ||
|
||
std::vector<uint8_t> hw_monitor_extended_buffers::send_big_buffer_to_receive(command cmd, hwmon_response* p_response, bool locked_transfer) const | ||
std::vector<uint8_t> hw_monitor_extended_buffers::extended_receive(command cmd, hwmon_response* p_response, bool locked_transfer) const | ||
{ | ||
int recv_msg_length = get_msg_length(cmd); | ||
uint16_t overall_chunks = get_number_of_chunks(recv_msg_length); | ||
|
||
std::vector< uint8_t > recv_msg; | ||
for (int i = 0; i < overall_chunks; ++i) | ||
|
||
// send first command with 0/0 on param4, as we don't know the table size | ||
// actual size will be returned as part for the response header and will be used | ||
// to calculate the extended loop range | ||
auto ans = hw_monitor::send(cmd, p_response, locked_transfer); | ||
recv_msg.insert(recv_msg.end(), ans.begin(), ans.end()); | ||
|
||
if (recv_msg.size() < sizeof(ds::table_header)) | ||
throw std::runtime_error(rsutils::string::from() << "Table data has invalid size = " << recv_msg.size()); | ||
|
||
|
||
ds::table_header* th = reinterpret_cast<ds::table_header*>( ans.data() ); | ||
size_t recv_msg_length = sizeof(ds::table_header) + th->table_size; | ||
|
||
if (recv_msg_length > HW_MONITOR_BUFFER_SIZE) | ||
{ | ||
// chunk number is in param4 | ||
cmd.param4 = compute_chunks_param(overall_chunks, i); | ||
|
||
auto ans = hw_monitor::send(cmd, p_response, locked_transfer); | ||
recv_msg.insert(recv_msg.end(), ans.begin(), ans.end()); | ||
// currently we assume HKR send only the table size when sending 0/0 chanks command above. | ||
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. typo - chunks 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. typo - sends |
||
// in the future the FW should send chunk 1 in 0/0 command and than we can use it here. | ||
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. typo - then |
||
// meaning remove the 'clear' and start the loop from 1 | ||
|
||
recv_msg.clear(); | ||
uint16_t overall_chunks = get_number_of_chunks( recv_msg_length ); | ||
for( int i = 0; i < overall_chunks; ++i ) | ||
{ | ||
// chunk number is in param4 | ||
cmd.param4 = compute_chunks_param( overall_chunks, i ); | ||
|
||
auto ans = hw_monitor::send( cmd, p_response, locked_transfer ); | ||
recv_msg.insert( recv_msg.end(), ans.begin(), ans.end() ); | ||
} | ||
} | ||
return recv_msg; | ||
} | ||
|
||
void hw_monitor_extended_buffers::send_big_buffer_to_send(command cmd, hwmon_response* p_response, bool locked_transfer) const | ||
void hw_monitor_extended_buffers::extended_send(command cmd, hwmon_response* p_response, bool locked_transfer) const | ||
{ | ||
int send_msg_length = get_msg_length(cmd); | ||
uint16_t overall_chunks = get_number_of_chunks(send_msg_length); | ||
|
||
// copying the data, so that this param can be overrien for the sending via hwm | ||
// copying the data, so that this param can be reused for the sending via HWM | ||
auto table_data = cmd.data; | ||
if (table_data.size() != send_msg_length) | ||
throw std::runtime_error(rsutils::string::from() << "Table data has size = " << table_data.size() << ", it should be: " << send_msg_length); | ||
uint16_t overall_chunks = get_number_of_chunks(table_data.size()); | ||
|
||
std::vector<uint8_t> answer; | ||
for (int i = 0; i < overall_chunks; ++i) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I understand correctly, this is an API change:
instead of getting the first chunk, we get the message, in which only the header is needed, and then, we get the chunks in other messages.
Please confirm this change has been implemented also in HKR side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discusses,
Current FW : we get the last chunk size of the first messages which is wrong, but since we get a valid header we extract the size from there and restart the querying process.
FW should supply a fix where 0/0 we send the first chunk with full size, then we can optimize and take this chunk and continue the loop from index 1.
This will be done on another PR once we have their fix.