Skip to content

feat: EF572 support reading units mechanism#606

Open
HaydenCummins-eaton wants to merge 6 commits into
edgexfoundry:mainfrom
HaydenCummins-eaton:EF-572-Support-ReadingUnits-Mechanism
Open

feat: EF572 support reading units mechanism#606
HaydenCummins-eaton wants to merge 6 commits into
edgexfoundry:mainfrom
HaydenCummins-eaton:EF-572-Support-ReadingUnits-Mechanism

Conversation

@HaydenCummins-eaton

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • [X ] I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • [X ] I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?)

Testing Instructions

  1. Add the ReadingUnits field to the configuration.yaml file for your example under the Writable section and set it to true.
Writable:
 LogLevel: DEBUG
 Reading:
   ReadingUnits: true
  1. Customize a device example profile as follows (device-counter for this example):
    a. Under deviceResources, add the units field to the properties, and choose a unit
"deviceResources":
  [
    {
      "name": "Counter",
      "description": "A counter generating incrementing values",
      "attributes": { "register": "count01" },
      "properties": { "valueType": "Uint32", "readWrite": "RW", "units": "Kelvin" }
    }
  ]
  1. Compile and run the example, now, within mqtt explorer or another similar tool, you should be able to see the units field populated as a property of the device.

@cloudxxx8

Copy link
Copy Markdown
Member

@HaydenCummins-eaton please squash your commit message to pass the DCO check

@cloudxxx8 cloudxxx8 requested a review from iain-anderson May 6, 2026 03:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for optionally including a device resource’s configured units value in generated EdgeX readings/events, controlled via a new dynamic configuration flag (Writable/Reading/ReadingUnits).

Changes:

  • Extend edgex_data_process_event() to accept the service context so it can read Writable/Reading/ReadingUnits and conditionally add the units field to each reading.
  • Add a default config entry for Writable/Reading/ReadingUnits (default false).
  • Update the random example configuration to enable Writable.Reading.ReadingUnits.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/c/service.c Updates event creation call to pass svc into edgex_data_process_event().
src/c/device.c Updates GET handling to pass svc into edgex_data_process_event().
src/c/autoevent.c Updates auto-event generation to pass ai->svc into edgex_data_process_event().
src/c/data.h Extends edgex_data_process_event() prototype with a devsdk_service_t *svc parameter.
src/c/data.c Reads Writable/Reading/ReadingUnits and conditionally injects units into reading maps.
src/c/config.c Adds default config key Writable/Reading/ReadingUnits set to false.
src/c/examples/random/res/configuration.yaml Enables Writable.Reading.ReadingUnits: true for the random example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/c/data.c Outdated
Comment on lines +132 to +135
//check ReadingUnits configuration
bool includeUnits = false;
includeUnits = iot_data_string_map_get_bool(svc->config.sdkconf, "Writable/Reading/ReadingUnits", false);
printf("DEBUG: CHECKING REGISTRY includeUnits = %s\n", includeUnits ? "true" : "false");
Comment thread src/c/data.c Outdated
Comment on lines +159 to +171
printf("DEBUG: includeUnits = %s\n", includeUnits ? "true" : "false");
printf("DEBUG: commandinfo->pvals[%d]->units = %s\n", i,
commandinfo->pvals[i]->units ? commandinfo->pvals[i]->units : "NULL");

if (includeUnits && commandinfo->pvals[i]->units && *commandinfo->pvals[i]->units)
{
printf("DEBUG: Adding units field: %s\n", commandinfo->pvals[i]->units);
iot_data_string_map_add (rmap, "units", iot_data_alloc_string (commandinfo->pvals[i]->units, IOT_DATA_REF));
}
else
{
printf("DEBUG: NOT adding units field\n");
}
Comment thread src/c/data.c Outdated
Comment on lines +159 to +171
printf("DEBUG: includeUnits = %s\n", includeUnits ? "true" : "false");
printf("DEBUG: commandinfo->pvals[%d]->units = %s\n", i,
commandinfo->pvals[i]->units ? commandinfo->pvals[i]->units : "NULL");

if (includeUnits && commandinfo->pvals[i]->units && *commandinfo->pvals[i]->units)
{
printf("DEBUG: Adding units field: %s\n", commandinfo->pvals[i]->units);
iot_data_string_map_add (rmap, "units", iot_data_alloc_string (commandinfo->pvals[i]->units, IOT_DATA_REF));
}
else
{
printf("DEBUG: NOT adding units field\n");
}
Comment thread src/c/data.c Outdated
bool doTransforms,
bool reducedEvents
bool reducedEvents,
devsdk_service_t *svc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either pass includeUnits as a bool (the calling function would get the value from the service_t structure, as per the AI comment on sdkconf use) or pass svc as const devsdk_service_t* and remove the doTransforms and reducedEvents parameters (the function can get them from svc itself)

Comment thread src/c/config.c Outdated
iot_data_string_map_add (result, "Device/Discovery/Enabled", iot_data_alloc_bool (true));
iot_data_string_map_add (result, "Device/Discovery/Interval", iot_data_alloc_ui32 (0));
iot_data_string_map_add (result, "Device/MaxCmdOps", iot_data_alloc_ui32 (0));
//adding reading Units here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

omit

Signed-off-by: HaydenCummins-eaton <haydenmcummins@eaton.com>
@HaydenCummins-eaton

Copy link
Copy Markdown
Contributor Author

Most recent commit removes the printf statements and unnecessary comments. It also removes the svc reference passed in in favor of the includeUnits bool. Testing tells me this functions the same. Let me know what other changes are necessary and I'll make them as requested.

@HaydenCummins-eaton

Copy link
Copy Markdown
Contributor Author

Once everything looks okay I'll squash my commit

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/c/device.c:722

  • Same concurrency concern as the other edgex_data_process_event call site: reading svc->config.sdkconf here can race with dynamic config updates that replace/free values in the map. Prefer caching Writable/Reading/ReadingUnits into an atomic field during config update/population and passing that cached value into edgex_data_process_event.
      result = edgex_data_process_event (dev, cmdinfo, results, tags, svc->config.device.datatransform, svc->reduced_events, iot_data_string_map_get_bool(svc->config.sdkconf, "Writable/Reading/ReadingUnits", false));

Comment thread src/c/autoevent.c Outdated
}
edgex_event_cooked *event =
edgex_data_process_event (dev, ai->resource, results, tags, ai->svc->config.device.datatransform, ai->svc->reduced_events);
edgex_data_process_event (dev, ai->resource, results, tags, ai->svc->config.device.datatransform, ai->svc->reduced_events, iot_data_string_map_get_bool(ai->svc->config.sdkconf, "Writable/Reading/ReadingUnits", false));
Comment thread src/c/device.c Outdated
{
devsdk_error err = EDGEX_OK;
result = edgex_data_process_event (dev, cmdinfo, results, tags, svc->config.device.datatransform, svc->reduced_events);
result = edgex_data_process_event (dev, cmdinfo, results, tags, svc->config.device.datatransform, svc->reduced_events, iot_data_string_map_get_bool(svc->config.sdkconf, "Writable/Reading/ReadingUnits", false));
Comment thread src/c/service.c Outdated
Comment on lines +1422 to +1423
edgex_event_cooked *event = edgex_data_process_event
(dev, command, values, tags, svc->config.device.datatransform, svc->reduced_events);
(dev, command, values, tags, svc->config.device.datatransform, svc->reduced_events, iot_data_string_map_get_bool(svc->config.sdkconf, "Writable/Reading/ReadingUnits", false));
Signed-off-by: HaydenCummins-eaton <haydenmcummins@eaton.com>
@HaydenCummins-eaton

Copy link
Copy Markdown
Contributor Author

Changed that to an atomic bool located in config and adjusted calls accordingly, atomic bool should be populated by edgex_device_populateCommonConfigFromMap now and each call to edgex_data_process_event should be thread safe now

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/c/config.c Outdated
iot_data_string_map_add (result, "Device/Discovery/Enabled", iot_data_alloc_bool (true));
iot_data_string_map_add (result, "Device/Discovery/Interval", iot_data_alloc_ui32 (0));
iot_data_string_map_add (result, "Device/MaxCmdOps", iot_data_alloc_ui32 (0));

Comment thread src/c/data.c
Comment on lines +152 to +156
// Add units field if ReadingUnits is enabled and the device resource has units configured
if (includeUnits && commandinfo->pvals[i]->units && *commandinfo->pvals[i]->units)
{
iot_data_string_map_add (rmap, "units", iot_data_alloc_string (commandinfo->pvals[i]->units, IOT_DATA_REF));
}
Comment thread src/c/data.c Outdated
bool useCBOR = false;
uint64_t timenow = iot_time_nsecs ();

@cloudxxx8 cloudxxx8 requested a review from iain-anderson May 20, 2026 02:36

@iain-anderson iain-anderson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In addition to the items identified by CoPilot:

  • add code to edgex_device_config_toJson so that the new configuration element is included in the results of a request for the current config
  • if the units configuration is to be dynamic, add code to edgex_device_updateConf to reset it when a new config is pushed

@cloudxxx8

Copy link
Copy Markdown
Member

@HaydenCummins-eaton We are releasing v4.0.2. Are you able to address the review comments recently?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@cloudxxx8 cloudxxx8 requested a review from iain-anderson June 30, 2026 05:38
@iain-anderson

Copy link
Copy Markdown
Member

@cloudxxx8 @HaydenCummins-eaton comments re edgex_device_config_toJson / edgex_device_updateConf not yet addressed

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.

4 participants