feat: EF572 support reading units mechanism#606
Conversation
Signed-off-by: HaydenCummins-eaton <haydenmcummins@eaton.com>
|
@HaydenCummins-eaton please squash your commit message to pass the DCO check |
There was a problem hiding this comment.
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 readWritable/Reading/ReadingUnitsand conditionally add theunitsfield to each reading. - Add a default config entry for
Writable/Reading/ReadingUnits(defaultfalse). - 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.
| //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"); |
| 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"); | ||
| } |
| 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"); | ||
| } |
| bool doTransforms, | ||
| bool reducedEvents | ||
| bool reducedEvents, | ||
| devsdk_service_t *svc |
There was a problem hiding this comment.
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)
| 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 |
Signed-off-by: HaydenCummins-eaton <haydenmcummins@eaton.com>
|
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. |
|
Once everything looks okay I'll squash my commit |
There was a problem hiding this comment.
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_eventcall site: readingsvc->config.sdkconfhere can race with dynamic config updates that replace/free values in the map. Prefer cachingWritable/Reading/ReadingUnitsinto an atomic field during config update/population and passing that cached value intoedgex_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));
| } | ||
| 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)); |
| { | ||
| 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)); |
| 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>
|
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 |
| 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)); | ||
|
|
| // 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)); | ||
| } |
| bool useCBOR = false; | ||
| uint64_t timenow = iot_time_nsecs (); | ||
|
|
||
iain-anderson
left a comment
There was a problem hiding this comment.
In addition to the items identified by CoPilot:
- add code to
edgex_device_config_toJsonso 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_updateConfto reset it when a new config is pushed
|
@HaydenCummins-eaton We are releasing v4.0.2. Are you able to address the review comments recently? |
|
@cloudxxx8 @HaydenCummins-eaton comments re |
PR Checklist
Please check if your PR fulfills the following requirements:
BREAKING CHANGE:describing the break)Testing Instructions
a. Under deviceResources, add the units field to the properties, and choose a unit