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

Clean up types.h a little #12297

Merged
merged 7 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/core/enum-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

#pragma once

#include <src/basics.h>
#include <librealsense2/hpp/rs_types.hpp>


namespace librealsense {


constexpr static char const * UNKNOWN_VALUE = "UNKNOWN";


// Require the last enumerator value to be in format of RS2_#####_COUNT
#define RS2_ENUM_HELPERS( TYPE, PREFIX ) RS2_ENUM_HELPERS_CUSTOMIZED( TYPE, 0, RS2_##PREFIX##_COUNT - 1, const char * )

Expand Down
12 changes: 8 additions & 4 deletions src/ds/advanced_mode/advanced_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "json_loader.hpp"
#include "ds/d400/d400-color.h"
#include "ds/d500/d500-color.h"

#include <rsutils/string/from.h>
#include <rsutils/string/hexdump.h>

namespace librealsense
{
Expand Down Expand Up @@ -128,8 +130,10 @@ namespace librealsense
default_450_high_res(p);
break;
default:
throw invalid_value_exception( rsutils::string::from() << "apply_preset(...) failed! Given device doesn't support Default Preset (pid=0x" <<
std::hex << device_pid << ")");
throw invalid_value_exception(
rsutils::string::from()
<< "apply_preset(...) failed! Given device doesn't support Default Preset (pid=0x"
<< rsutils::string::hexdump( device_pid ) << ")" );
break;
}
case ds::RS405U_PID:
Expand All @@ -147,8 +151,8 @@ namespace librealsense
default:
throw invalid_value_exception(
rsutils::string::from()
<< "apply_preset(...) failed! Given device doesn't support Default Preset (pid=0x" << std::hex
<< device_pid << ")" );
<< "apply_preset(...) failed! Given device doesn't support Default Preset (pid=0x"
<< rsutils::string::hexdump( device_pid ) << ")" );
break;
}
break;
Expand Down
12 changes: 9 additions & 3 deletions src/ds/advanced_mode/rs_advanced_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
#include "core/advanced_mode.h"
#include "api.h"

#define STRCASE(T, X) case RS2_##T##_##X: {\
static std::string s##T##_##X##_str = make_less_screamy(#X);\
return s##T##_##X##_str.c_str(); }
#include <rsutils/string/make-less-screamy.h>



#define STRCASE( T, X ) \
case RS2_##T##_##X: { \
static std::string s##T##_##X##_str = rsutils::string::make_less_screamy( #X ); \
return s##T##_##X##_str.c_str(); \
}

namespace librealsense
{
Expand Down
3 changes: 2 additions & 1 deletion src/ds/d400/d400-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <src/fw-update/fw-update-unsigned.h>
#include <nlohmann/json.hpp>

#include <rsutils/string/hexdump.h>
#include <regex>
#include <iterator>

Expand Down Expand Up @@ -634,7 +635,7 @@ namespace librealsense
}


pid_hex_str = hexify(_pid);
pid_hex_str = rsutils::string::from() << std::uppercase << rsutils::string::hexdump( _pid );

if ((_pid == RS416_PID || _pid == RS416_RGB_PID) && _fw_version >= firmware_version("5.12.0.1"))
{
Expand Down
2 changes: 1 addition & 1 deletion src/ds/d400/d400-private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace librealsense
intrin(1, 1) * height / 2.f,
RS2_DISTORTION_INVERSE_BROWN_CONRADY // The coefficients shall be use for undistort
};
librealsense::copy(calc_intrinsic.coeffs, table->distortion, sizeof(table->distortion));
std::memcpy(calc_intrinsic.coeffs, table->distortion, sizeof(table->distortion));
//LOG_DEBUG(endl << array2str((float_4&)(calc_intrinsic.fx, calc_intrinsic.fy, calc_intrinsic.ppx, calc_intrinsic.ppy)) << endl);

static rs2_intrinsics ref{};
Expand Down
4 changes: 3 additions & 1 deletion src/ds/d500/d500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "hdr-config.h"
#include "../common/fw/firmware-version.h"
#include "fw-update/fw-update-unsigned.h"

#include <rsutils/string/hexdump.h>
#include <nlohmann/json.hpp>
#include <vector>
#include <string>
Expand Down Expand Up @@ -494,7 +496,7 @@ namespace librealsense
[]() {return std::make_shared<y16i_to_y10msby10msb>(); }
);

pid_hex_str = hexify(_pid);
pid_hex_str = rsutils::string::from() << std::uppercase << rsutils::string::hexdump( _pid );

_is_locked = _ds_device_common->is_locked(GVD, is_camera_locked_offset);

Expand Down
4 changes: 3 additions & 1 deletion src/ds/d500/d500-private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ namespace librealsense
intrinsics.ppx = rect_params[2];
intrinsics.ppy = rect_params[3];
intrinsics.model = table->rgb_coefficients_table.distortion_model;
librealsense::copy(intrinsics.coeffs, table->rgb_coefficients_table.distortion_coeffs, sizeof(intrinsics.coeffs));
std::memcpy( intrinsics.coeffs,
table->rgb_coefficients_table.distortion_coeffs,
sizeof( intrinsics.coeffs ) );

update_table_to_correct_fisheye_distortion(const_cast<ds::d500_rgb_calibration_table&>(*table), intrinsics);

Expand Down
4 changes: 2 additions & 2 deletions src/ds/ds-calib-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace librealsense
if (_valid_extrinsic)
{
// extrinsic from calibration table, by user custom calibration, The extrinsic is stored as array of floats / little-endian
librealsense::copy(&_extr, &_calib_table.module_info.dm_v2_calib_table.depth_to_imu, sizeof(rs2_extrinsics));
std::memcpy( &_extr, &_calib_table.module_info.dm_v2_calib_table.depth_to_imu, sizeof( rs2_extrinsics ) );
}
else
{
Expand Down Expand Up @@ -300,7 +300,7 @@ namespace librealsense
if (_valid_extrinsic)
{
// only in case valid extrinsic is available in calibration data by calibration script in future or user custom calibration
librealsense::copy(&_extr, &imu_calib_table.depth_to_imu, sizeof(rs2_extrinsics));
std::memcpy( &_extr, &imu_calib_table.depth_to_imu, sizeof( rs2_extrinsics ) );
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/ds/ds-private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace librealsense
intrinsics.height = height;
intrinsics.width = width;

librealsense::copy(intrinsics.coeffs, table->distortion, sizeof(table->distortion));
std::memcpy( intrinsics.coeffs, table->distortion, sizeof( table->distortion ) );

LOG_DEBUG(endl << array2str((float_4&)(intrinsics.fx, intrinsics.fy, intrinsics.ppx, intrinsics.ppy)) << endl);

Expand Down
7 changes: 6 additions & 1 deletion src/fw-update/fw-update-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "../device-info.h"
#include "ds/d400/d400-private.h"

#include <rsutils/string/hexdump.h>

#include <chrono>
#include <stdexcept>
#include <algorithm>
Expand Down Expand Up @@ -112,7 +114,10 @@ namespace librealsense

update_device::update_device( std::shared_ptr< const device_info > const & dev_info,
std::shared_ptr< platform::usb_device > const & usb_device )
: _dev_info(dev_info), _usb_device(usb_device), _physical_port( usb_device->get_info().id), _pid(hexify(usb_device->get_info().pid))
: _dev_info( dev_info )
, _usb_device( usb_device )
, _physical_port( usb_device->get_info().id )
, _pid( rsutils::string::from() << std::uppercase << rsutils::string::hexdump( usb_device->get_info().pid ) )
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
{
if (auto messenger = _usb_device->open(FW_UPDATE_INTERFACE_NUMBER))
{
Expand Down
8 changes: 6 additions & 2 deletions src/hid/hid-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <queue>
#include "hid-device.h"

#include <rsutils/string/from.h>
#include <rsutils/string/hexdump.h>


const int USB_REQUEST_COUNT = 1;

namespace librealsense
Expand All @@ -20,8 +24,8 @@ namespace librealsense
if(info.cls != RS2_USB_CLASS_HID)
continue;
platform::hid_device_info device_info;
device_info.vid = hexify(info.vid);
device_info.pid = hexify(info.pid);
device_info.vid = rsutils::string::from() << std::uppercase << rsutils::string::hexdump( info.vid );
device_info.pid = rsutils::string::from() << std::uppercase << rsutils::string::hexdump( info.pid );
device_info.unique_id = info.unique_id;
device_info.device_path = info.unique_id;//the device unique_id is the USB port

Expand Down
18 changes: 10 additions & 8 deletions src/hw-monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace librealsense

if (dataLength)
{
librealsense::copy(writePtr + cur_index, data, dataLength);
std::memcpy( writePtr + cur_index, data, dataLength );
cur_index += dataLength;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ namespace librealsense
// throw invalid_value_exception("bulk transfer failed - user buffer too small");

inSize = std::min(res.size(),inSize); // For D457 only
librealsense::copy(in, res.data(), inSize);
std::memcpy( in, res.data(), inSize );
}
}

Expand All @@ -126,10 +126,10 @@ namespace librealsense
throw invalid_value_exception("received incomplete response to usb command");

details.receivedCommandDataLength -= 4;
librealsense::copy(details.receivedOpcode.data(), outputBuffer, 4);
std::memcpy( details.receivedOpcode.data(), outputBuffer, 4 );

if (details.receivedCommandDataLength > 0)
librealsense::copy(details.receivedCommandData.data(), outputBuffer + 4, details.receivedCommandDataLength);
std::memcpy( details.receivedCommandData.data(), outputBuffer + 4, details.receivedCommandDataLength );
}

void hw_monitor::send_hw_monitor_command(hwmon_cmd_details& details) const
Expand Down Expand Up @@ -182,8 +182,10 @@ namespace librealsense
if( !newCommand.require_response )
return std::vector<uint8_t>();

librealsense::copy(newCommand.receivedOpcode, details.receivedOpcode.data(), 4);
librealsense::copy(newCommand.receivedCommandData, details.receivedCommandData.data(), details.receivedCommandDataLength);
std::memcpy( newCommand.receivedOpcode, details.receivedOpcode.data(), 4 );
std::memcpy( newCommand.receivedCommandData,
details.receivedCommandData.data(),
details.receivedCommandDataLength );
newCommand.receivedCommandDataLength = details.receivedCommandDataLength;

// endian?
Expand Down Expand Up @@ -243,15 +245,15 @@ namespace librealsense
command command(gvd_cmd);
auto data = send(command);
auto minSize = std::min(sz, data.size());
librealsense::copy(gvd, data.data(), minSize);
std::memcpy( gvd, data.data(), minSize );
}

bool hw_monitor::is_camera_locked(uint8_t gvd_cmd, uint32_t offset) const
{
std::vector<unsigned char> gvd(HW_MONITOR_BUFFER_SIZE);
get_gvd(gvd.size(), gvd.data(), gvd_cmd);
bool value;
librealsense::copy(&value, gvd.data() + offset, 1);
std::memcpy( &value, gvd.data() + offset, 1 );
return value;
}
}
4 changes: 3 additions & 1 deletion src/hw-monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "uvc-sensor.h"
#include <mutex>
#include "platform/command-transfer.h"
#include <string>


namespace librealsense
{
Expand Down Expand Up @@ -296,7 +298,7 @@ namespace librealsense
require_response(cmd.require_response),
receivedCommandDataLength(0)
{
librealsense::copy(data, cmd.data.data(), sizeOfSendCommandData);
std::memcpy( data, cmd.data.data(), sizeOfSendCommandData );
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/linux/backend-v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ namespace librealsense
{
uint32_t device_fourcc = id;
char fourcc_buff[sizeof(device_fourcc)+1];
librealsense::copy(fourcc_buff, &device_fourcc, sizeof(device_fourcc));
std::memcpy( fourcc_buff, &device_fourcc, sizeof( device_fourcc ) );
fourcc_buff[sizeof(device_fourcc)] = 0;
return fourcc_buff;
}
Expand Down
8 changes: 4 additions & 4 deletions src/mf/mf-uvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,13 @@ namespace librealsense

auto pStruct = next_struct;
cfg.step.resize(option_range_size);
librealsense::copy(cfg.step.data(), pStruct, field_width);
std::memcpy( cfg.step.data(), pStruct, field_width );
pStruct += length;
cfg.min.resize(option_range_size);
librealsense::copy(cfg.min.data(), pStruct, field_width);
std::memcpy( cfg.min.data(), pStruct, field_width );
pStruct += length;
cfg.max.resize(option_range_size);
librealsense::copy(cfg.max.data(), pStruct, field_width);
std::memcpy( cfg.max.data(), pStruct, field_width );
return;
}
case KSPROPERTY_MEMBER_VALUES:
Expand All @@ -386,7 +386,7 @@ namespace librealsense
}

cfg.def.resize(option_range_size);
librealsense::copy(cfg.def.data(), next_struct, field_width);
std::memcpy( cfg.def.data(), next_struct, field_width );
}
return;
}
Expand Down
Loading
Loading