Skip to content

RSDK-11439 — Avoid hardcoding fields for protos strings (things like types response.source_name and response. mime_type)#66

Merged
hexbabe merged 10 commits intoviam-modules:mainfrom
hexbabe:fix/no-hardcoded-consts
Mar 5, 2026
Merged

RSDK-11439 — Avoid hardcoding fields for protos strings (things like types response.source_name and response. mime_type)#66
hexbabe merged 10 commits intoviam-modules:mainfrom
hexbabe:fix/no-hardcoded-consts

Conversation

@hexbabe
Copy link
Collaborator

@hexbabe hexbabe commented Mar 2, 2026

RSDK-11439

Summary

RSDK-11439

Replaces hardcoded attribute key strings ("serial_number", "sensors", "width", "height", "format") with named inline const constants defined in orbbec.hpp.

Constants are shared across translation units via the existing orbbec.hpp header — no new files. Updated usages in:

  • orbbec.cpp — config parsing (Reconfigure, discovery config generation)
  • device_control.hpp — device info, camera params, module config creation
  • discovery.cpp — resource discovery attribute population

Manual Tests

Tested on linux/amd64 (Framework Laptop) using viam module reload-local:

  1. Built module locally with make build (Conan, gcc 13, x86_64)
  2. Packaged and hot-reloaded onto machine via viam module reload-local
  3. Added viam:orbbec:discovery — successfully discovered Astra2 serial AARY14100X5
  4. Added viam:orbbec:astra2 with discovered serial — get_images() returned color (1280×720 JPEG ✅) and depth (1.8MB ✅)

PR Process

Number of LGTM-ers (required): 1

Note

This is my first PR done using OpenClaw running on my Framework laptop. It handled implementation as well as manual testing via viam-cli and browser tooling by signing into and using the Viam Web App.

hexbabe added 6 commits March 1, 2026 20:14
Move inline constants from orbbec.cpp into a dedicated constants header
file (src/module/constants.hpp) under the orbbec:: namespace.

Fixes RSDK-11439
Add kAttrSerialNumber, kAttrSensors, kAttrWidth, kAttrHeight, kAttrFormat
to constants.hpp and use them throughout orbbec.cpp and discovery.cpp
instead of repeating raw string literals.
New attribute key constants (kAttrSerialNumber, kAttrSensors, kAttrWidth,
kAttrHeight, kAttrFormat) declared in the existing CONSTANTS block in
orbbec.cpp alongside the original constants. constants.hpp removed.
@hexbabe hexbabe requested review from SebastianMunozP, oliviamiller and seanavery and removed request for oliviamiller March 2, 2026 02:49
Copy link

@seanavery seanavery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR mentions discovery.cpp but only diff is in orbec.cpp.. are we missing some const replacements there?

const uint64_t maxFrameSetTimeDiffUs =
2000; // max time difference between frames in a frameset to be considered simultaneous, in microseconds (equal to 2 ms)

const std::string kAttrSerialNumber = "serial_number";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be in the header orbbec.hpp?

Copy link
Collaborator Author

@hexbabe hexbabe Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, they should so they can be shared across other TUs. Done

const std::string kAttrWidth = "width";
const std::string kAttrHeight = "height";
const std::string kAttrFormat = "format";
// CONSTANTS END
Copy link

@seanavery seanavery Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] remove comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done thanks

Copy link

@seanavery seanavery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to use the new consts in device_control.hpp?

@hexbabe hexbabe force-pushed the fix/no-hardcoded-consts branch from 44fbd36 to 14ff73e Compare March 2, 2026 22:27
Moves kAttrSerialNumber, kAttrSensors, kAttrWidth, kAttrHeight, kAttrFormat
to orbbec.hpp as inline const so they can be shared across translation units.
Updates discovery.cpp to use kAttrSerialNumber instead of hardcoded string.
@hexbabe hexbabe force-pushed the fix/no-hardcoded-consts branch from 14ff73e to 34db767 Compare March 2, 2026 22:30
@hexbabe
Copy link
Collaborator Author

hexbabe commented Mar 2, 2026

Do we also need to use the new consts in device_control.hpp?

@seanavery thanks for the thorough review. De-consted more files, and manually re-tested.

Replaces hardcoded "serial_number", "sensors", "width", "height",
"format" strings in device_control.hpp with orbbec::kAttr* constants
from orbbec.hpp.
@hexbabe hexbabe force-pushed the fix/no-hardcoded-consts branch from 290de7a to c4b0c96 Compare March 2, 2026 22:43
@hexbabe hexbabe requested a review from seanavery March 2, 2026 22:43
Copy link

@seanavery seanavery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending last two nits

depth_sensor[orbbec::kAttrHeight] = static_cast<int>(sp->template as<VideoStreamProfileT>()->getHeight());
depth_sensor[orbbec::kAttrFormat] =
ob::TypeHelper::convertOBFormatTypeToString(sp->template as<VideoStreamProfileT>()->getFormat());
sensors["depth"] = depth_sensor;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] const this?

color_sensor[orbbec::kAttrHeight] = static_cast<int>(sp->template as<VideoStreamProfileT>()->getHeight());
color_sensor[orbbec::kAttrFormat] =
ob::TypeHelper::convertOBFormatTypeToString(sp->template as<VideoStreamProfileT>()->getFormat());
sensors["color"] = color_sensor;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. moved "color" and "depth" to hpp so they can be shared too

hexbabe added 2 commits March 4, 2026 18:09
Address review feedback: use constants instead of raw string literals
for sensor names in device_control.hpp. Moved kColorSourceName and
kDepthSourceName from orbbec.cpp to orbbec.hpp so they can be shared
across translation units.
@hexbabe hexbabe merged commit 3e46afe into viam-modules:main Mar 5, 2026
5 checks passed
@hexbabe hexbabe deleted the fix/no-hardcoded-consts branch March 5, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants