Skip to content
Open
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 include/devsdk/devsdk-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef struct devsdk_protocols devsdk_protocols;
typedef void* devsdk_address_t;

typedef void* devsdk_resource_attr_t;
typedef void* devsdk_resource_tag_t;

typedef struct devsdk_device_t
{
Expand All @@ -45,6 +46,7 @@ typedef struct devsdk_resource_t
{
char *name;
devsdk_resource_attr_t attrs;
iot_data_t *tags;
iot_typecode_t type;
} devsdk_resource_t;

Expand Down Expand Up @@ -91,6 +93,8 @@ typedef struct devsdk_device_resources
char *resname;
/** Attributes of the device resource */
iot_data_t *attributes;
/** Tags of the device resource */
iot_data_t *tags;
/** Type of the data that may be read or written */
iot_typecode_t type;
/** Whether the resource may be read */
Expand Down
9 changes: 6 additions & 3 deletions include/devsdk/devsdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ typedef void (*devsdk_free_resource_attr) (void *impl, devsdk_resource_attr_t re
* @param nreadings The number of readings requested.
* @param requests An array specifying the readings that have been requested.
* @param readings An array in which to return the requested readings.
* @param options Options which were set for this request.
* @param tags An optional map for tags associated with the event. May be NULL.
* @param options Options which were set for this request. May be NULL
* @param exception Set this to an IOT_DATA_STRING to give more information if the operation fails.
* @return true if the operation was successful, false otherwise.
*/
Expand All @@ -141,6 +142,7 @@ typedef bool (*devsdk_handle_get)
uint32_t nreadings,
const devsdk_commandrequest *requests,
devsdk_commandresult *readings,
iot_data_t **tags,
const iot_data_t *options,
iot_data_t **exception
);
Expand Down Expand Up @@ -337,10 +339,11 @@ void devsdk_service_start (devsdk_service_t *svc, iot_data_t *driverdfls, devsdk
* @param svc The device service.
* @param device_name The name of the device that the readings have come from.
* @param resource_name Name of the resource or command which defines the Event.
* @param values An array of readings. These will be combined into an Event and submitted to core-data.
* @param values An array of readings. These will be combined into an Event and submitted to core-data. The caller is owner of the memory.
* @param tags Tags associated with the values. Tags is an optional field of the Event. May be NULL. The callee is owner of the memory.
*/

void devsdk_post_readings (devsdk_service_t *svc, const char *device_name, const char *resource_name, devsdk_commandresult *values);
void devsdk_post_readings (devsdk_service_t *svc, const char *device_name, const char *resource_name, devsdk_commandresult *values, iot_data_t *tags);

void devsdk_add_discovered_devices (devsdk_service_t *svc, uint32_t ndevices, devsdk_discovered_device *devices);

Expand Down
4 changes: 3 additions & 1 deletion include/edgex/edgex.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ typedef struct edgex_deviceresource
{
char *description;
char *name;
char *tag;
edgex_propertyvalue *properties;
iot_data_t *attributes;
iot_data_t *tags;
devsdk_resource_attr_t parsed_attrs;
struct edgex_deviceresource *next;
} edgex_deviceresource;
Expand All @@ -77,6 +77,7 @@ typedef struct edgex_devicecommand
edgex_resourceoperation *resourceOperations;
bool readable;
bool writable;
iot_data_t *tags;
struct edgex_devicecommand *next;
} edgex_devicecommand;

Expand Down Expand Up @@ -126,6 +127,7 @@ typedef struct edgex_device
uint64_t created;
char *description;
devsdk_strings *labels;
iot_data_t *tags;
char *name;
char *parent;
edgex_device_operatingstate operatingState;
Expand Down
5 changes: 3 additions & 2 deletions src/c/autoevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ static void *ae_runner (void *p)
edgex_device_alloc_crlid (NULL);
iot_log_info (ai->svc->logger, "AutoEvent: %s/%s", ai->device, ai->resource->name);
devsdk_commandresult *results = calloc (ai->resource->nreqs, sizeof (devsdk_commandresult));
iot_data_t *tags = NULL;
iot_data_t *exc = NULL;
if (dev->devimpl->address == NULL)
{
dev->devimpl->address = ai->svc->userfns.create_addr (ai->svc->userdata, dev->protocols, &exc);
}
if (dev->devimpl->address)
{
if (ai->svc->userfns.gethandler (ai->svc->userdata, dev->devimpl, ai->resource->nreqs, ai->resource->reqs, results, NULL, &exc))
if (ai->svc->userfns.gethandler (ai->svc->userdata, dev->devimpl, ai->resource->nreqs, ai->resource->reqs, results, &tags, NULL, &exc))
{
devsdk_commandresult *resdup = NULL;
if (!(ai->onChange && ai->last && devsdk_commandresult_equal (results, ai->last, ai->resource->nreqs)))
Expand All @@ -74,7 +75,7 @@ static void *ae_runner (void *p)
resdup = devsdk_commandresult_dup (results, ai->resource->nreqs);
}
edgex_event_cooked *event =
edgex_data_process_event (dev->name, ai->resource, results, ai->svc->config.device.datatransform);
edgex_data_process_event (dev, ai->resource, results, tags, ai->svc->config.device.datatransform);
if (event)
{
if (ai->svc->config.device.maxeventsize && edgex_event_cooked_size (event) > ai->svc->config.device.maxeventsize * 1024)
Expand Down
1 change: 1 addition & 0 deletions src/c/cmdinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct edgex_cmdinfo
devsdk_commandrequest *reqs;
edgex_propertyvalue **pvals;
iot_data_t **maps;
iot_data_t *tags;
char **dfls;
struct edgex_cmdinfo *next;
} edgex_cmdinfo;
Expand Down
29 changes: 23 additions & 6 deletions src/c/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ or
deviceName: String (name of the Device)
profileName: String (name of the Profile)
sourceName: String (name of the deviceResource or deviceCommand)
tags: Array of Strings (may be added to at any stage)
tags: Map of Strings (may be added to at any stage)
readings: Array of Readings
*/

edgex_event_cooked *edgex_data_process_event
(
const char *device_name,
const edgex_device *device,
const edgex_cmdinfo *commandinfo,
devsdk_commandresult *values,
iot_data_t *tags,
bool doTransforms
)
{
Expand Down Expand Up @@ -120,10 +121,10 @@ edgex_event_cooked *edgex_data_process_event
result = malloc (sizeof (edgex_event_cooked));
result->nrdgs = commandinfo->nreqs;

result->path = malloc (strlen (commandinfo->profile->name) + strlen (device_name) + strlen (commandinfo->name) + 3);
result->path = malloc (strlen (commandinfo->profile->name) + strlen (device->name) + strlen (commandinfo->name) + 3);
strcpy (result->path, commandinfo->profile->name);
strcat (result->path, "/");
strcat (result->path, device_name);
strcat (result->path, device->name);
strcat (result->path, "/");
strcat (result->path, commandinfo->name);

Expand All @@ -138,7 +139,7 @@ edgex_event_cooked *edgex_data_process_event
iot_data_string_map_add (rmap, "apiVersion", iot_data_alloc_string (EDGEX_API_VERSION, IOT_DATA_REF));
iot_data_string_map_add (rmap, "id", iot_data_alloc_string (id, IOT_DATA_TAKE));
iot_data_string_map_add (rmap, "profileName", iot_data_alloc_string (commandinfo->profile->name, IOT_DATA_REF));
iot_data_string_map_add (rmap, "deviceName", iot_data_alloc_string (device_name, IOT_DATA_REF));
iot_data_string_map_add (rmap, "deviceName", iot_data_alloc_string (device->name, IOT_DATA_REF));
iot_data_string_map_add (rmap, "resourceName", iot_data_alloc_string (commandinfo->reqs[i].resource->name, IOT_DATA_REF));
iot_data_string_map_add (rmap, "valueType", iot_data_alloc_string (edgex_typecode_tostring (tc), IOT_DATA_REF));
iot_data_string_map_add (rmap, "origin", iot_data_alloc_ui64 (values[i].origin ? values[i].origin : timenow));
Expand All @@ -160,17 +161,33 @@ edgex_event_cooked *edgex_data_process_event
default:
iot_data_string_map_add (rmap, "value", iot_data_alloc_string (iot_data_to_json (values[i].value), IOT_DATA_TAKE));
}

if (commandinfo->reqs[i].resource->tags)
{
iot_data_string_map_add (rmap, "tags", iot_data_copy(commandinfo->reqs[i].resource->tags));
}

iot_data_vector_add (rvec, i, rmap);
}

iot_data_t *event_tags = iot_data_alloc_map (IOT_DATA_STRING);
iot_data_map_merge(event_tags, tags);
iot_data_map_merge(event_tags,commandinfo->tags);
iot_data_map_merge(event_tags,device->tags);

iot_data_t *evmap = iot_data_alloc_map (IOT_DATA_STRING);
iot_data_string_map_add (evmap, "apiVersion", iot_data_alloc_string (EDGEX_API_VERSION, IOT_DATA_REF));
iot_data_string_map_add (evmap, "id", iot_data_alloc_string (eventId, IOT_DATA_TAKE));
iot_data_string_map_add (evmap, "deviceName", iot_data_alloc_string (device_name, IOT_DATA_REF));
iot_data_string_map_add (evmap, "deviceName", iot_data_alloc_string (device->name, IOT_DATA_REF));
iot_data_string_map_add (evmap, "profileName", iot_data_alloc_string (commandinfo->profile->name, IOT_DATA_REF));
iot_data_string_map_add (evmap, "sourceName", iot_data_alloc_string (commandinfo->name, IOT_DATA_REF));
iot_data_string_map_add (evmap, "origin", iot_data_alloc_ui64 (timenow));
iot_data_string_map_add (evmap, "readings", rvec);

if (iot_data_map_size(event_tags)) {
iot_data_string_map_add (evmap, "tags", event_tags);
}

iot_data_t *reqmap = iot_data_alloc_map (IOT_DATA_STRING);
iot_data_string_map_add (reqmap, "apiVersion", iot_data_alloc_string (EDGEX_API_VERSION, IOT_DATA_REF));
iot_data_string_map_add (reqmap, "event", evmap);
Expand Down
3 changes: 2 additions & 1 deletion src/c/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ void edgex_event_cooked_free (edgex_event_cooked *e);

edgex_event_cooked *edgex_data_process_event
(
const char *device_name,
const edgex_device *device,
const edgex_cmdinfo *commandinfo,
devsdk_commandresult *values,
iot_data_t *tags,
bool doTransforms
);

Expand Down
20 changes: 16 additions & 4 deletions src/c/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ static edgex_cmdinfo *infoForRes (devsdk_service_t *svc, edgex_deviceprofile *pr
result->profile = prof;
result->isget = forGet;
result->nreqs = n;
result->tags = NULL;
if (cmd->tags) {
result->tags = iot_data_add_ref(cmd->tags);
}
result->reqs = calloc (n, sizeof (devsdk_commandrequest));
result->pvals = calloc (n, sizeof (edgex_propertyvalue *));
result->maps = calloc (n, sizeof (iot_data_t *));
Expand All @@ -147,6 +151,7 @@ static edgex_cmdinfo *infoForRes (devsdk_service_t *svc, edgex_deviceprofile *pr
findDevResource (prof->device_resources, ro->deviceResource);
result->reqs[n].resource->name = devres->name;
result->reqs[n].resource->attrs = devres->parsed_attrs;
result->reqs[n].resource->tags = devres->tags;
result->reqs[n].resource->type = devres->properties->type;
if (devres->properties->mask.enabled)
{
Expand Down Expand Up @@ -196,6 +201,11 @@ static edgex_cmdinfo *infoForDevRes (devsdk_service_t *svc, edgex_deviceprofile
result->reqs[0].resource = malloc (sizeof (devsdk_resource_t));
result->reqs[0].resource->name = devres->name;
result->reqs[0].resource->attrs = devres->parsed_attrs;
result->tags = NULL;
result->reqs[0].resource->tags = NULL;
if (devres->tags) {
result->reqs[0].resource->tags = devres->tags;
}
result->reqs[0].resource->type = devres->properties->type;
if (devres->properties->mask.enabled)
{
Expand Down Expand Up @@ -397,17 +407,18 @@ static edgex_event_cooked *edgex_device_runget2
edgex_event_cooked *result = NULL;
iot_data_t *e = NULL;
devsdk_commandresult *results = calloc (cmdinfo->nreqs, sizeof (devsdk_commandresult));
iot_data_t *tags = NULL;

if (dev->devimpl->address == NULL)
{
dev->devimpl->address = svc->userfns.create_addr (svc->userdata, dev->protocols, &e);
}
if (dev->devimpl->address)
{
if (svc->userfns.gethandler (svc->userdata, dev->devimpl, cmdinfo->nreqs, cmdinfo->reqs, results, params, &e))
if (svc->userfns.gethandler (svc->userdata, dev->devimpl, cmdinfo->nreqs, cmdinfo->reqs, results, &tags, params, &e))
{
devsdk_error err = EDGEX_OK;
result = edgex_data_process_event (dev->name, cmdinfo, results, svc->config.device.datatransform);
result = edgex_data_process_event (dev, cmdinfo, results, tags, svc->config.device.datatransform);

if (result)
{
Expand Down Expand Up @@ -696,17 +707,18 @@ static edgex_event_cooked *edgex_device_runget3 (devsdk_service_t *svc, edgex_de
edgex_event_cooked *result = NULL;
iot_data_t *e = NULL;
devsdk_commandresult *results = calloc (cmdinfo->nreqs, sizeof (devsdk_commandresult));
iot_data_t *tags = NULL;

if (dev->devimpl->address == NULL)
{
dev->devimpl->address = svc->userfns.create_addr (svc->userdata, dev->protocols, &e);
}
if (dev->devimpl->address)
{
if (svc->userfns.gethandler (svc->userdata, dev->devimpl, cmdinfo->nreqs, cmdinfo->reqs, results, params, &e))
if (svc->userfns.gethandler (svc->userdata, dev->devimpl, cmdinfo->nreqs, cmdinfo->reqs, results, &tags, params, &e))
{
devsdk_error err = EDGEX_OK;
result = edgex_data_process_event (dev->name, cmdinfo, results, svc->config.device.datatransform);
result = edgex_data_process_event (dev, cmdinfo, results, tags, svc->config.device.datatransform);
if (result)
{
if (svc->config.device.updatelastconnected)
Expand Down
1 change: 1 addition & 0 deletions src/c/devman.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void devsdk_free_resources (devsdk_device_resources *r)
{
free (r->resname);
iot_data_free (r->attributes);
iot_data_free (r->tags);
devsdk_device_resources *nextr = r->next;
free (r);
r = nextr;
Expand Down
4 changes: 3 additions & 1 deletion src/c/dto-read.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ edgex_device *edgex_device_read (const iot_data_t *obj)
result->devimpl = calloc (1, sizeof (devsdk_device_t));
result->devimpl->name = result->name;
result->labels = edgex_labels_read(obj);
result->tags = iot_data_add_ref (iot_data_string_map_get (obj, "tags"));

return result;
}
Expand Down Expand Up @@ -230,9 +231,9 @@ static edgex_deviceresource *deviceresource_read (const iot_data_t *obj)
edgex_deviceresource *result = malloc (sizeof (edgex_deviceresource));
result->name = get_string (obj, "name");
result->description = get_string (obj, "description");
result->tag = get_string (obj, "tag");
result->properties = propertyvalue_read (iot_data_string_map_get (obj, "properties"));
result->attributes = iot_data_add_ref (iot_data_string_map_get (obj, "attributes"));
result->tags = iot_data_add_ref (iot_data_string_map_get (obj, "tags"));
result->parsed_attrs = NULL;
result->next = NULL;
return result;
Expand All @@ -255,6 +256,7 @@ static edgex_devicecommand *devicecommand_read (const iot_data_t *obj)
edgex_resourceoperation **last_ptr = &result->resourceOperations;

result->name = get_string (obj, "name");
result->tags = iot_data_add_ref (iot_data_string_map_get (obj, "tags"));
edgex_get_readwrite (obj, &result->readable, &result->writable);
ops = iot_data_string_map_get (obj, "resourceOperations");
iot_data_vector_iter (ops, &iter);
Expand Down
Loading