Giter Club home page Giter Club logo

device-sdk-c's Introduction

EdgeX Device C SDK

Build Status GitHub Latest Dev Tag) GitHub Latest Stable Tag) GitHub License GitHub Pull Requests GitHub Contributors GitHub Committers GitHub Commit Activity

About

The C SDK provides a framework for building EdgeX device services in C.

Prerequisites

  • A Linux build host
  • A version of GCC supporting C11.
  • CMake version 3 or greater and make.
  • Development libraries and headers for:
    • curl (version 7.56 or later)
    • microhttpd (version 0.9)
    • libyaml (version 0.1.6 or later)
    • libcbor (version 0.5)
    • paho (version 1.3.x)
    • libuuid (from util-linux v2.x)
    • hiredis (version 0.14)
    • IOTech's C utilities package (version 1.5)

On Debian 11 "Bullseye" the requred system libraries can be installed by

apt-get install libcurl4-openssl-dev libmicrohttpd-dev libyaml-dev libcbor-dev libpaho-mqtt-dev libhiredis-dev

To install the C utilities see README.IOT.md

Building

At the toplevel C SDK directory, run

make

This retrieves dependencies and uses CMake to build the SDK. Subsequent rebuilds may be performed by moving to the build/release or build/debug directories and running make.

A .tar.gz file containing the SDK headers and library is created in the build/{debug, release} directories. When building on some distributions a .deb or .rpm file is also created, as appropriate.

Creating a Device Service

The main include file devsdk/devsdk.h contains the functions provided by the SDK and defines the callbacks which a device service implementor needs to create. Documentation is provided within that file in doxygen format. An outline device service and various examples are provided in src/c/examples to illustrate usage.

Building with docker

To build the SDK in a docker image, run the following command:

make docker

This will generate the sdk files in a results directory at the root of this project.

Alternatively, you can build a docker image which can be used to build device services in, with the following command:

docker build -t edgex-csdk-base:2.1.0 -f scripts/Dockerfile.alpine-base .

You can then write a Dockerfile for your service that begins FROM edgex-csdk-base:2.1.0

Versioning

Please refer to the EdgeX Foundry versioning policy for information on how EdgeX services are released and how EdgeX services are compatible with one another. Specifically, device services (and the associated SDK), application services (and the associated app functions SDK), and client tools (like the EdgeX CLI and UI) can have independent minor releases, but these services must be compatible with the latest major release of EdgeX.

Long Term Support

Please refer to the EdgeX Foundry LTS policy for information on support of EdgeX releases. The EdgeX community does not offer support on any non-LTS release outside of the latest release.

device-sdk-c's People

Contributors

bill-mahoney avatar bnevis-i avatar cloudxxx8 avatar drensber avatar eaton-coreymutter avatar ernestojeda avatar felixting avatar iain-anderson avatar jamesiotech avatar jamesrgregg avatar jpwhitemn avatar jpwku avatar lenny-goodell avatar lukekerr avatar mightynerderic avatar nil4git avatar sgiot avatar soda480 avatar steveoss avatar tomflem avatar ych988 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

device-sdk-c's Issues

Add support for ProvisionWatchers

ProvisionWatchers specify a (potentially wildcarded) mapping between device identifiers and device profile names. This can be used during discovery to automatically determine the correct profile to use for a newly discovered device.
This could be presented to the implementor as a utility function which would return a profile name given a device identity, or by allowing the add-device function to be called without specifying a profile name.

High resolution timestamps

See also edgexfoundry/edgex-go#1404

When setting the "origin" timestamp on an event, this should be expressed in nanoseconds. They should also be strictly increasing including in the scenario where we aren't getting real ns resolution.
(ie if new timestamp <= old timestamp, use (old ts + 1) instead. Safe to assume we aren't going to exceed 1 call per nanosecond over any length of time)

Config documentation

We should have something describing what each of the various available configuration options do. And for the current release note which are NYI.
Also remove any that are not used and not going to be used, eg Service/HealthCheck.

Get endpoint information from registry

Add an interface to the registry for retrieval of service endpoints. Implement for Consul. Use this in the SDK instead of getting them from configuration, if the registry is enabled.

Support for System Management

Provide the /config and /metrics REST endpoints as used by sys-mgmt-agent.
For glibc targets, provide heap metrics using hooks for malloc etc.

Dynamic configuration

Add a callback to the registry interface so that the service may be notified that configuration has changed.
Implement this for consul using blocking queries.
Make the SDK configuration dynamic where practical.

Small fixes Jan 2019

  • Make type names lowercase in example and documentation, eg. float32 not Float32
  • API methods should set *err to EDGEX_OK in all nonerror cases.
  • Log when GET handler fails.
  • Log CSDK version on startup.

Consistency: configuration for use of support-logging service

CSDK has the Logging/RemoteURL config setting for both enabling use of the logging service and specifying its location. This is different to other EdgeX services which have Logging/EnableRemote as a boolean switch, and derive the location from [Clients] config or the Registry. The CSDK needs to be aligned on this.

Review sizes of configured integer values

Each integral configuration value is currently typed as int64_t, and clearly this is not always appropriate. Most if not all should be unsigned, and port numbers in particular are 16-bit. This propagates through to some function parameters, eg the port number in edgex_consul_client_register_service().

Implement callback endpoint (initial)

core-metadata calls on this endpoint to notify the DS of added / deleted / updated devices.
JSON fields are id (the id of the device concerned) and type (in this issue we only address the "DEVICE" type).
Note that the only device updates in scope for Delhi are changes to the administrative state.

Log startup time and port

Other EdgeX services log:

Service started in: ...
Listening on port: ...

edgex_device_service_start() should do the same.

Consul integration

If the registry/consul is enabled on service startup, try to read initial configuration settings from consul.

In order for this feature to work, the settings for the device service need to be injected into consul via core-config-seed, or some other out-of-band mechanism.

Simplify get/set API as per Go SDK #213

IE, edgex_device_commandrequest becomes
{
const char *deviceResourceName;
const edgex_nvpairs *attributes;
const edgex_propertytype type;
}

In addition the device name is to be passed to the get/set functions, as we do in Go.

Add devices add/remove command support

See also edgexfoundry/device-sdk-go#19
Issue a command with arguments after a device is added or before it is removed.
Commands and arguments defined in the Device configuration as
AddDeviceCmd / AddDeviceArgs and RemoveDeviceCmd / RemoveDeviceArgs
(Arguments in JSON just as they are in a REST request).

Device[Profile] management API

Add the following functions for management of devices and device profiles:

edgex_device_devices()
edgex_device_remove_device()
edgex_device_remove_device_byname()
edgex_device_update_device()

edgex_device_add_profile()
edgex_device_profiles()
edgex_device_remove_profile()
edgex_device_remove_profile_byname()
edgex_device_update_profile()

Update the edgex_device_add_device() function to return the id of the newly created device.

Split out provisioning requests from configuration file

Remove support for [[DeviceList]] [[Schedules]] [[ScheduleEvents]] and [[Watchers]] from the configuration file.
Rename the profilesDir configuration element as provisioningDir
Read files in {provisioningDir}/profiles, {provisioningDir}/devices, {provisioningDir}/schedules etc and populate metadata from them.

Populate Reading.origin

If the driver does not fill in the origin field for a reading, the SDK should. Readings can take the same timestamp as their Event.

Implement Assertions on Readings

Assertions are an attribute in a device resource's value PropertyValue which specify a string value which the result is compared against. If the comparison fails, then the result is set to a string of the form “Assertion failed for device resource: , with value: ”, this also has a side-effect of setting the device operatingstate to DISABLED. In the case of the single device /command endpoint, a 500 status code is also returned. If the all form of the /command endpoint is used an assertion failure will return a 200 status, and it's the responsibilty of the client to check each reading for assertion failures.

As assertions are operations on results after they've been transformed into the string to be passed in the Reading, assertions cannot as currently defined, be applied to binary readings which result in an array of bytes vs. a string result in the Reading.

Handle recursive resources within a device profile (command chaining)

Instead of containing a reference to a device resource (the device resource's name is in the "object" field), a resourceoperation may refer to other (profile) resources. In this case the "resource" field will be set to the name of the profile resource.

See the sample profile DENT.Mod.PS6037.profile.yaml in device-modbus for an example.

Update internal scheduler to handle ScheduleEvent schema changes

As part of the Edinburgh release, there are planned changed to the ScheduleEvent object.

A new owner field is being added which is used to determine what service actually processes the ScheduleEvents as read from Core Metadata.

The existing service field is going to re-named to target, as this more accurately describes the purpose of the field.

The device SDK will now need to query the ScheduleEvents with owner matching its service name if and only if the device service has been configured for internal scheduling. I'm not sure if internal scheduling is controlled via a configuration option. I suppose it also could just be handled by whether or not there are ScheduleEvents with owner=.

Write an abstraction for the Registry functionality

Consul support then becomes an implementation of this. The command line option enabling the registry can also specify which implementation to use and its location. eg in a URL: --registry=consul://localhost:8500

Three small issues

Passing the configuration to the device profile init method as const is not helpful
Reporting of schedule interval in the debug configuration dump is broken
Dependency on libm needs to be specified

Verify device profiles on receipt

When obtaining a device profile from core-metadata we should check at least the following:

  • Values given for transform parameters should be able to be parsed, and should be of appropriate type (eg a "scale" of "0.1" is okay for floating point readings but not integers).
  • Value type names should be recognized.

Errors should cause the current operation to fail.

Process device profile elements once.

Change the device profile structs so that elements are stored as int, float, enum etc instead of string, where that is useful for us. For example value types and transform parameters.
Rework the JSON reader/writer accordingly.

readings returned in wrong format

More recent revisions of the device service specification call for GET commands on the device endpoint to return EdgeX Events rather than a name-value pair for the reading. The SDK needs to be updated in this regard.

Implement transforms on readings

The following transforms to be applied in order if specified for numeric readings:
base – a base value which is raised to the power of the reading value
scale – a multiplicative factor applied to the reading
offset – an additive factor applied to the reading

device endpoint: commands for deviceResources

The current handler for the device endpoint only allows for commands that match resources (the grouping construct in the device profile). A command should also be able to refer directly to a single deviceResource.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.