From dabf1defd12b34322b0f0d40682c282524228306 Mon Sep 17 00:00:00 2001 From: Iain Anderson Date: Wed, 28 Oct 2020 15:58:40 +0000 Subject: [PATCH] build: device-grove updates for CSDK v1.3 (#50) Signed-off-by: Iain Anderson --- Makefile | 2 +- README.md | 14 -------------- scripts/build_deps.sh | 8 +++++--- src/c/main.c | 19 +++++++++++++++++-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 064d10d..a50ff72 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ clean: rm -f $(MICROSERVICES) ./VERSION: - @git describe --abbrev=0 > ./VERSION + @git describe --abbrev=0 | sed 's/^v//' > ./VERSION version: ./VERSION echo ${VERSION} diff --git a/README.md b/README.md index 4d0af1c..981ba69 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,3 @@ By default, the configuration and profile file used by the service are available 2. --device=/dev/ < i2c-device > to map host device to the container. For Raspberry PI, it is i2c-1. **Note:** On Raspberry PI, make sure that i2c_arm=on is set. This enables i2c-1 device, required for communication between Grove PI & Raspberry PI boards. - - - - - - - - - - - - - - diff --git a/scripts/build_deps.sh b/scripts/build_deps.sh index 3a89502..af5b43e 100755 --- a/scripts/build_deps.sh +++ b/scripts/build_deps.sh @@ -3,6 +3,8 @@ set -e -x BUILD_CSDK=$1 +CSDK_VER=1.3.0-dev.10 + # Dependencies if [ ! -d deps ] then @@ -34,9 +36,9 @@ then make make install - wget https://github.com/edgexfoundry/device-sdk-c/archive/v1.2.2.zip - unzip v1.2.2.zip - cd device-sdk-c-1.2.2 + wget https://github.com/edgexfoundry/device-sdk-c/archive/v${CSDK_VER}.zip + unzip v${CSDK_VER}.zip + cd device-sdk-c-${CSDK_VER} ./scripts/build.sh cp -rf include/* /usr/include/ cp build/release/c/libcsdk.so /usr/lib/ diff --git a/src/c/main.c b/src/c/main.c index dcc0252..91e01b1 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -307,7 +307,7 @@ static bool grove_init (void *impl, struct iot_logger_t *lc, const iot_data_t *c mraa_add_subplatform (MRAA_GROVEPI, "0"); - BME680_Temp_Offset = (config) ? strtof (iot_data_string_map_get_string (config, "BME680_Temp_Offset"), NULL) : 0.0; + BME680_Temp_Offset = iot_data_f32 (iot_data_string_map_get (config, "BME680_Temp_Offset")); /* read the attributes from the device profile to initialize the driver */ profiles = edgex_profiles (impln->svc); @@ -360,6 +360,12 @@ static bool grove_init (void *impl, struct iot_logger_t *lc, const iot_data_t *c return (status == MRAA_SUCCESS); } +static void grove_reconfigure (void *impl, const iot_data_t *config) +{ + grove_pidriver_t *driver = (grove_pidriver_t *) impl; + iot_log_error (driver->lc, "Grove [Driver] configuration cannot be updated while running. Please restart the service."); +} + static bool grove_gethandler ( void *impl, @@ -735,6 +741,7 @@ static void grove_stop (void *impl, bool force) int main (int argc, char *argv[]) { + iot_data_t *defaults = NULL; grove_pidriver_t *implObject = malloc (sizeof (grove_pidriver_t)); memset (implObject, 0, sizeof (grove_pidriver_t)); sem_init (&grove_sem, 0, 0); @@ -746,6 +753,7 @@ int main (int argc, char *argv[]) devsdk_callbacks myImpls = { grove_init, + grove_reconfigure, NULL, grove_gethandler, grove_puthandler, @@ -775,8 +783,14 @@ int main (int argc, char *argv[]) } implObject->svc = grove_service; + + /* Setup default configuration */ + + defaults = iot_data_alloc_map (IOT_DATA_STRING); + iot_data_string_map_add (defaults, "BME680_Temp_Offset", iot_data_alloc_f32 (0.0)); + /* Start the device service*/ - devsdk_service_start (grove_service, &err); + devsdk_service_start (grove_service, defaults, &err); GROVE_ERR_CHECK (err); printf ("\nRunning - press ctrl-c to exit\n"); @@ -791,6 +805,7 @@ int main (int argc, char *argv[]) sem_destroy (&grove_sem); devsdk_service_free (grove_service); + iot_data_free (defaults); free (implObject); return 0;