diff options
author | 2017-09-28 11:09:17 +0200 | |
---|---|---|
committer | 2017-09-28 11:12:40 +0200 | |
commit | 91a8304cf1c9d7139840f95c1ad971c9603ed5bf (patch) | |
tree | 08267435b188721419ee8bea65943cc4d80305a0 /low-can-binding | |
parent | a8eaf1f71c2906140b600314dfe935fab3a06bf2 (diff) |
Use afb_genskel tools to generate api definition
Generated files hand fixed because of usage of C++
which has to use c++ binding function afb::auth to
add afb_auth struct
Change-Id: I80ee9cb751cc813754c949d8746aec197da6d52f
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding')
-rw-r--r-- | low-can-binding/CMakeLists.txt | 2 | ||||
-rw-r--r-- | low-can-binding/binding/low-can-apidef.h | 134 | ||||
-rw-r--r-- | low-can-binding/binding/low-can-cb.cpp | 24 | ||||
-rw-r--r-- | low-can-binding/binding/low-can-hat.hpp | 4 |
4 files changed, 161 insertions, 3 deletions
diff --git a/low-can-binding/CMakeLists.txt b/low-can-binding/CMakeLists.txt index 9742580..7abb3c4 100644 --- a/low-can-binding/CMakeLists.txt +++ b/low-can-binding/CMakeLists.txt @@ -22,7 +22,7 @@ PROJECT_TARGET_ADD(low-can) # Define project Targets add_library(${TARGET_NAME} MODULE - binding/${TARGET_NAME}-hat.cpp + #binding/${TARGET_NAME}-hat.cpp binding/${TARGET_NAME}-cb.cpp binding/${TARGET_NAME}-socket.cpp binding/${TARGET_NAME}-subscription.cpp diff --git a/low-can-binding/binding/low-can-apidef.h b/low-can-binding/binding/low-can-apidef.h new file mode 100644 index 0000000..6f6ec92 --- /dev/null +++ b/low-can-binding/binding/low-can-apidef.h @@ -0,0 +1,134 @@ + +static const char _afb_description_v2_low_can[] = + "{\"openapi\":\"3.0.0\",\"$schema\":\"http:iot.bzh/download/openapi/schem" + "a-3.0/default-schema.json\",\"info\":{\"description\":\"\",\"title\":\"l" + "ow-level-can-service\",\"version\":\"4.0\",\"x-binding-c-generator\":{\"" + "api\":\"low-can\",\"version\":2,\"prefix\":\"\",\"postfix\":\"\",\"start" + "\":null,\"onevent\":null,\"init\":\"initv2\",\"scope\":\"\",\"private\":" + "false}},\"servers\":[{\"url\":\"ws://{host}:{port}/api/monitor\",\"descr" + "iption\":\"Low level CAN API.\",\"variables\":{\"host\":{\"default\":\"l" + "ocalhost\"},\"port\":{\"default\":\"1234\"}},\"x-afb-events\":[{\"$ref\"" + ":\"#/components/schemas/afb-event\"}]}],\"components\":{\"schemas\":{\"a" + "fb-reply\":{\"$ref\":\"#/components/schemas/afb-reply-v2\"},\"afb-event\"" + ":{\"$ref\":\"#/components/schemas/afb-event-v2\"},\"afb-reply-v2\":{\"ti" + "tle\":\"Generic response.\",\"type\":\"object\",\"required\":[\"jtype\"," + "\"request\"],\"properties\":{\"jtype\":{\"type\":\"string\",\"const\":\"" + "afb-reply\"},\"request\":{\"type\":\"object\",\"required\":[\"status\"]," + "\"properties\":{\"status\":{\"type\":\"string\"},\"info\":{\"type\":\"st" + "ring\"},\"token\":{\"type\":\"string\"},\"uuid\":{\"type\":\"string\"},\"" + "reqid\":{\"type\":\"string\"}}},\"response\":{\"type\":\"object\"}}},\"a" + "fb-event-v2\":{\"type\":\"object\",\"required\":[\"jtype\",\"event\"],\"" + "properties\":{\"jtype\":{\"type\":\"string\",\"const\":\"afb-event\"},\"" + "event\":{\"type\":\"string\"},\"data\":{\"type\":\"object\"}}}},\"x-perm" + "issions\":{\"monitor\":{\"permission\":\"urn:AGL:permission:low-can:publ" + "ic:monitor\"},\"write\":{\"permission\":\"urn:AGL:permission:low-can:pla" + "tform:write\"}},\"responses\":{\"200\":{\"description\":\"A complex obje" + "ct array response\",\"content\":{\"application/json\":{\"schema\":{\"$re" + "f\":\"#/components/schemas/afb-reply\"}}}}}},\"paths\":{\"/subscribe\":{" + "\"description\":\"Subscribe to CAN signals events\",\"parameters\":[{\"i" + "n\":\"query\",\"name\":\"event\",\"required\":false,\"schema\":{\"type\"" + ":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components/responses" + "/200\"}}},\"/unsubscribe\":{\"description\":\"Unsubscribe previously sus" + "cribed signals.\",\"parameters\":[{\"in\":\"query\",\"name\":\"event\",\"" + "required\":false,\"schema\":{\"type\":\"string\"}}],\"responses\":{\"200" + "\":{\"$ref\":\"#/components/responses/200\"}}},\"/get\":{\"description\"" + ":\"get a current value of CAN message\",\"parameters\":[{\"in\":\"query\"" + ",\"name\":\"event\",\"required\":false,\"schema\":{\"type\":\"string\"}}" + "],\"responses\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}},\"/" + "list\":{\"description\":\"get a supported CAN message list\",\"responses" + "\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}},\"/auth\":{\"des" + "cription\":\"Authenticate session to be raise Level Of Assurance.\",\"ge" + "t\":{\"x-permissions\":{\"$ref\":\"#/components/x-permissions/write\"},\"" + "responses\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}},\"/wri" + "te\":{\"description\":\"Write a CAN messages to the CAN bus.\",\"get\":{" + "\"x-permissions\":{\"LOA\":1},\"parameters\":[{\"in\":\"query\",\"name\"" + ":\"bus_name\",\"required\":false,\"schema\":{\"type\":\"string\"}},{\"in" + "\":\"query\",\"name\":\"frame\",\"required\":false,\"schema\":{\"type\":" + "\"array\"},\"parameters\":[{\"in\":\"query\",\"name\":\"can_id\",\"requi" + "red\":false,\"schema\":{\"type\":\"string\"}},{\"in\":\"query\",\"name\"" + ":\"can_dlc\",\"required\":false,\"schema\":{\"type\":\"string\"}},{\"in\"" + ":\"query\",\"name\":\"can_data\",\"required\":false,\"schema\":{\"type\"" + ":\"string\"}}]},{\"in\":\"query\",\"name\":\"signal_name\",\"required\":" + "false,\"schema\":{\"type\":\"string\"}},{\"in\":\"query\",\"name\":\"sig" + "nal_value\",\"required\":false,\"schema\":{\"type\":\"integer\"}}],\"res" + "ponses\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}}}}" +; +#ifdef __cplusplus +#include <afb/afb-binding> +#endif +/*static const struct afb_auth _afb_auths_v2_low_can[] = { + { .type = afb_auth_Permission, .text = "urn:AGL:permission:low-can:platform:write", .next = NULL} +};*/ + +const struct afb_auth _afb_auths_v2_low_can[] = {afb::auth_permission("urn:AGL:permission:low-can:platform:write")}; + + void subscribe(struct afb_req req); + void unsubscribe(struct afb_req req); + void get(struct afb_req req); + void list(struct afb_req req); + void auth(struct afb_req req); + void write(struct afb_req req); + +static const struct afb_verb_v2 _afb_verbs_v2_low_can[] = { + { + .verb = "subscribe", + .callback = subscribe, + .auth = NULL, + .info = "Subscribe to CAN signals events", + .session = AFB_SESSION_NONE_V2 + }, + { + .verb = "unsubscribe", + .callback = unsubscribe, + .auth = NULL, + .info = "Unsubscribe previously suscribed signals.", + .session = AFB_SESSION_NONE_V2 + }, + { + .verb = "get", + .callback = get, + .auth = NULL, + .info = "get a current value of CAN message", + .session = AFB_SESSION_NONE_V2 + }, + { + .verb = "list", + .callback = list, + .auth = NULL, + .info = "get a supported CAN message list", + .session = AFB_SESSION_NONE_V2 + }, + { + .verb = "auth", + .callback = auth, + .auth = &_afb_auths_v2_low_can[0], + .info = "Authenticate session to be raise Level Of Assurance.", + .session = AFB_SESSION_NONE_V2 + }, + { + .verb = "write", + .callback = write, + .auth = NULL, + .info = "Write a CAN messages to the CAN bus.", + .session = AFB_SESSION_LOA_1_V2 + }, + { + .verb = NULL, + .callback = NULL, + .auth = NULL, + .info = NULL, + .session = 0 + } +}; + +const struct afb_binding_v2 afbBindingV2 = { + .api = "low-can", + .specification = _afb_description_v2_low_can, + .info = "", + .verbs = _afb_verbs_v2_low_can, + .preinit = NULL, + .init = initv2, + .onevent = NULL, + .noconcurrency = 0 +}; + diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp index e84a9c7..3145065 100644 --- a/low-can-binding/binding/low-can-cb.cpp +++ b/low-can-binding/binding/low-can-cb.cpp @@ -17,6 +17,7 @@ */ #include "low-can-hat.hpp" +#include "low-can-apidef.h" #include <map> #include <queue> @@ -36,7 +37,6 @@ #include "../diagnostic/diagnostic-message.hpp" #include "../utils/openxc-utils.hpp" - ///****************************************************************************** /// /// SystemD event loop Callbacks @@ -632,3 +632,25 @@ void list(struct afb_req request) else afb_req_fail(request, "error", NULL); } + +/// @brief Initialize the binding. +/// +/// @param[in] service Structure which represent the Application Framework Binder. +/// +/// @return Exit code, zero if success. +int initv2() +{ + can_bus_t& can_bus_manager = application_t::instance().get_can_bus_manager(); + + can_bus_manager.set_can_devices(); + can_bus_manager.start_threads(); + + /// Initialize Diagnostic manager that will handle obd2 requests. + /// We pass by default the first CAN bus device to its Initialization. + /// TODO: be able to choose the CAN bus device that will be use as Diagnostic bus. + if(application_t::instance().get_diagnostic_manager().initialize()) + return 0; + + AFB_ERROR("There was something wrong with CAN device Initialization."); + return 1; +} diff --git a/low-can-binding/binding/low-can-hat.hpp b/low-can-binding/binding/low-can-hat.hpp index 1f550a8..d9fb89f 100644 --- a/low-can-binding/binding/low-can-hat.hpp +++ b/low-can-binding/binding/low-can-hat.hpp @@ -32,13 +32,15 @@ extern "C" class low_can_subscription_t; +int initv2(); void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, std::map<int, std::shared_ptr<low_can_subscription_t> >& s); void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, uint32_t pid, std::map<int, std::shared_ptr<low_can_subscription_t> >& s); int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata); - +/* void auth(struct afb_req request); void subscribe(struct afb_req request); void unsubscribe(struct afb_req request); void write(struct afb_req request); void get(struct afb_req request); void list(struct afb_req request); +*/ |