From f1fa5579cae3272ba99962e1a18190ed3b597737 Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Thu, 20 Jun 2019 15:36:04 +0900 Subject: add als2019 --- README.md | 1 + binding/afm-gps-binding.c | 112 +++++++++++++++++++++++++++++++++------ conf.d/autobuild/agl/autobuild | 67 +++++++++++++++++++++++ conf.d/autobuild/linux/autobuild | 67 +++++++++++++++++++++++ conf.d/wgt/config.xml.in | 6 ++- 5 files changed, 236 insertions(+), 17 deletions(-) create mode 100644 conf.d/autobuild/agl/autobuild create mode 100644 conf.d/autobuild/linux/autobuild diff --git a/README.md b/README.md index f979cbe..2bd008f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ GPS service reports current WGS84 coordinates from GNSS devices via the gpsd app | subscribe | subscribe to gps/gnss events | *Request:* {"value": "location"} | | unsubscribe | unsubscribe to gps/gnss events | *Request:* {"value": "location"} | | location | get current gps/gnss coordinates | See **location Event JSON Response** section | +| setlocation | Longitude and Latitude data of GPS | See **location Event JSON Response** section | | record | start/stop recording gps data | See **Recording/Replaying Feature** section | ## Events diff --git a/binding/afm-gps-binding.c b/binding/afm-gps-binding.c index 873c264..c7b3d2f 100644 --- a/binding/afm-gps-binding.c +++ b/binding/afm-gps-binding.c @@ -265,18 +265,13 @@ static void add_record(json_object *jresp) static void *data_poll(void *ptr) { - int tries = 0; - /* * keep reading till an error condition happens */ - while (tries < 60) { + while (gps_waiting(&data, MSECS_TO_USECS(2000)) && !errno) + { json_object *jresp = NULL; - if (gps_waiting(&data, MSECS_TO_USECS(2000)) < 0) { - tries++; - continue; - } pthread_mutex_lock(&mutex); if (gps_read(&data) == -1) { AFB_ERROR("Cannot read from GPS daemon.\n"); @@ -372,28 +367,114 @@ static int replay_init() return timer_settime(timer_id, 0, &ts, NULL); } +/** + * @brief setlocation request callback + * @param[in] request Request from server + */ +void set_gps(afb_req_t request) +{ + const char* latitude = afb_req_value(request, "Latitude"); + const char* longitude = afb_req_value(request, "Longitude"); + + AFB_REQ_NOTICE(request, "latitude = %s,longitude = %s", latitude,longitude); + + afb_req_success(request, NULL, NULL); + + struct json_object* obj = json_object_new_object(); + + json_object_object_add(obj, "latitude", json_object_new_string(latitude)); + json_object_object_add(obj, "longitude", json_object_new_string(longitude)); + + const char* response_json_str = json_object_to_json_string(obj); + AFB_REQ_NOTICE(request, "response_json_str = %s", response_json_str); + + afb_event_push(location_event, obj); + +} +/** + * @brief carlaclient binding event function + * @param[in] api the api serving the request + * @param[in] event event name + * @param[in] object event json object + */ +static void onevent(afb_api_t api, const char *event, struct json_object *object) +{ + AFB_API_NOTICE(api, "on_event %s , object %s", event, json_object_get_string(object)); + + struct json_object *lati = NULL; + struct json_object *longi = NULL; + + if ((json_object_object_get_ex(object, "latitude", &lati)) && + (json_object_object_get_ex(object, "longitude", &longi))) + { + const char* latitude = json_object_get_string(lati); + const char* longitude = json_object_get_string(longi); + struct json_object* obj = json_object_new_object(); + + json_object_object_add(obj, "latitude", json_object_new_string(latitude)); + json_object_object_add(obj, "longitude", json_object_new_string(longitude)); + + afb_event_push(location_event, obj); + } +} +/** + * @brief the callback function + * @param[in] closure the user defined closure pointer 'closure' + * @param[in] a JSON object returned (can be NULL) + * @param[in] a string not NULL in case of error but NULL on success + * @param[in] a string handling some info (can be NULL) + * @param[in] api the api + */ +static void api_callback(void *closure, struct json_object *object, const char *error, const char *info, afb_api_t api) +{ + AFB_API_NOTICE(api, "asynchronous call, error=%s, info=%s, object=%s.", error, info, json_object_get_string(object)); +} + +/** + * @brief call api + * @param[in] api the api serving the request + * @param[in] service the api name of service + * @param[in] verb the verb of service + * @param[in] args parameter + */ +static void api_call(afb_api_t api, const char *service, const char *verb, struct json_object *args) +{ + AFB_API_NOTICE(api, "service=%s verb=%s, args=%s.", service, verb, json_object_get_string(args)); + afb_api_call(api, service, verb, args, api_callback, 0); +} +/** + * @brief call carlaclient subscribe function + * @param[in] api the api serving the request + */ +static void SubscribeCarlaclient(afb_api_t api) +{ + struct json_object* obj = json_object_new_object(); + json_object_object_add(obj, "event", json_object_new_string("positionUpdated")); + api_call(api, "carlaclient", "subscribe" ,obj); +} /* * Test to see if in demo mode first, then enable if not enable gpsd */ static int init(afb_api_t api) { - int ret; - location_event = afb_daemon_make_event("location"); - - ret = replay_init(); + // int ret; + location_event = afb_daemon_make_event("setlocation"); - if (!ret) - recording.replaying = 1; - else - gps_init(); + // ret = replay_init(); + // if (!ret) + // recording.replaying = 1; + // else + // gps_init(); + SubscribeCarlaclient(api); return 0; } static const struct afb_verb_v3 binding_verbs[] = { { .verb = "location", .callback = get_data, .info = "Get GNSS data" }, + { .verb = "setlocation", .callback = set_gps, .info = "Longitude and Latitude data of GPS" }, { .verb = "record", .callback = record, .info = "Record GPS data" }, { .verb = "subscribe", .callback = subscribe, .info = "Subscribe to GNSS events" }, { .verb = "unsubscribe", .callback = unsubscribe, .info = "Unsubscribe to GNSS events" }, @@ -408,4 +489,5 @@ const struct afb_binding_v3 afbBindingV3 = { .specification = "GNSS/GPS API", .verbs = binding_verbs, .init = init, + .onevent = onevent }; diff --git a/conf.d/autobuild/agl/autobuild b/conf.d/autobuild/agl/autobuild new file mode 100644 index 0000000..83097ab --- /dev/null +++ b/conf.d/autobuild/agl/autobuild @@ -0,0 +1,67 @@ +#!/usr/bin/make -f +# Copyright (C) 2015, 2016 "IoT.bzh" +# Author "Romain Forlot" +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +THISFILE := $(lastword $(MAKEFILE_LIST)) +BUILD_DIR := $(abspath $(dir $(THISFILE)/../../../../..)/build) +DEST := ${BUILD_DIR}/target + +.PHONY: all clean distclean configure build package help update + +all: help + +help: + @echo "List of targets available:" + @echo "" + @echo "- all" + @echo "- clean" + @echo "- distclean" + @echo "- configure" + @echo "- build: compilation, link and prepare files for package into a widget" + @echo "- package: output a widget file '*.wgt'" + @echo "- install: install in your ${CMAKE_INSTALL_DIR} directory" + @echo "" + @echo "Usage: ./conf.d/autobuild/agl/autobuild package DEST=${HOME}/opt" + @echo "Don't use your build dir as DEST as wgt file is generated at this location" + +update: configure + @cmake --build ${BUILD_DIR} --target autobuild + +clean: + @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} clean) || echo Nothing to clean + +distclean: + @rm -rf ${BUILD_DIR} + +configure: ${BUILD_DIR}/Makefile + +build: configure + @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all + +package: build + @mkdir -p ${BUILD_DIR}/$@/bin + @mkdir -p ${BUILD_DIR}/$@/etc + @mkdir -p ${BUILD_DIR}/$@/lib + @mkdir -p ${BUILD_DIR}/$@/htdocs + @mkdir -p ${BUILD_DIR}/$@/var + @cmake --build ${BUILD_DIR} --target widget + @mkdir -p ${DEST} && cp ${BUILD_DIR}/*wgt ${DEST} + +install: build + @cmake --build ${BUILD_DIR} --target install + +${BUILD_DIR}/Makefile: + @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} + @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..) diff --git a/conf.d/autobuild/linux/autobuild b/conf.d/autobuild/linux/autobuild new file mode 100644 index 0000000..83097ab --- /dev/null +++ b/conf.d/autobuild/linux/autobuild @@ -0,0 +1,67 @@ +#!/usr/bin/make -f +# Copyright (C) 2015, 2016 "IoT.bzh" +# Author "Romain Forlot" +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +THISFILE := $(lastword $(MAKEFILE_LIST)) +BUILD_DIR := $(abspath $(dir $(THISFILE)/../../../../..)/build) +DEST := ${BUILD_DIR}/target + +.PHONY: all clean distclean configure build package help update + +all: help + +help: + @echo "List of targets available:" + @echo "" + @echo "- all" + @echo "- clean" + @echo "- distclean" + @echo "- configure" + @echo "- build: compilation, link and prepare files for package into a widget" + @echo "- package: output a widget file '*.wgt'" + @echo "- install: install in your ${CMAKE_INSTALL_DIR} directory" + @echo "" + @echo "Usage: ./conf.d/autobuild/agl/autobuild package DEST=${HOME}/opt" + @echo "Don't use your build dir as DEST as wgt file is generated at this location" + +update: configure + @cmake --build ${BUILD_DIR} --target autobuild + +clean: + @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} clean) || echo Nothing to clean + +distclean: + @rm -rf ${BUILD_DIR} + +configure: ${BUILD_DIR}/Makefile + +build: configure + @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all + +package: build + @mkdir -p ${BUILD_DIR}/$@/bin + @mkdir -p ${BUILD_DIR}/$@/etc + @mkdir -p ${BUILD_DIR}/$@/lib + @mkdir -p ${BUILD_DIR}/$@/htdocs + @mkdir -p ${BUILD_DIR}/$@/var + @cmake --build ${BUILD_DIR} --target widget + @mkdir -p ${DEST} && cp ${BUILD_DIR}/*wgt ${DEST} + +install: build + @cmake --build ${BUILD_DIR} --target install + +${BUILD_DIR}/Makefile: + @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} + @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..) diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in index 95f3cf0..3cc53de 100644 --- a/conf.d/wgt/config.xml.in +++ b/conf.d/wgt/config.xml.in @@ -15,8 +15,10 @@ - + + + - + -- cgit 1.2.3-korg