From 7b62eefaf33b9bb69eb324333232ae0919fc295f Mon Sep 17 00:00:00 2001 From: Yuta Doi Date: Fri, 18 May 2018 17:16:14 +0900 Subject: Add API which can get information about the car state getCarInfo() can get the car state informations as follows: - parking brake state : true/false - accelerator pedal position : 0-127.5 - car state : "stop"/"run" The details are described in doc/ApplicationGuide.md in project apps/agl-service-windowmanager-2017. Change-Id: I2a4a06ceeedbd2d3b1188a7fb442e1272e46897b Signed-off-by: Yuta Doi --- src/app.cpp | 37 ++++++++++++++++++++++++++++++++----- src/app.hpp | 1 + src/main.cpp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/app.cpp b/src/app.cpp index ac789ad..eaebd59 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -807,11 +807,6 @@ result App::api_get_area_info(char const *drawing_name) { return Err("Could not find layer for surface"); } - struct LayoutState &state = *o_state; - if ((state.main != *surface_id) && (state.sub != *surface_id)) { - return Err("Surface is inactive"); - } - // Set area rectangle compositor::rect area_info = this->area_info[*surface_id]; json_object *object = json_object_new_object(); @@ -823,6 +818,38 @@ result App::api_get_area_info(char const *drawing_name) { return Ok(object); } +result App::api_get_car_info(char const *label) { + HMI_DEBUG("wm", "called"); + + json_object *j_in = nullptr; + json_object *j_out = nullptr; + + if (0 == strcmp("parking_brake_status", label)) { + // Get parking brake status + json_bool val = this->crr_car_info_.parking_brake_stt; + j_in = json_object_new_boolean(val); + } + else if (0 == strcmp("accelerator.pedal.position", label)) { + // Get accelerator pedal position + double val = this->crr_car_info_.accel_pedal_pos; + j_in = json_object_new_double(val); + } + else if (0 == strcmp("car_state", label)) { + // Get car state + const char* val = this->crr_car_info_.car_stt; + j_in = json_object_new_string(val); + } + else { + return Err("Car info does not exist"); + } + + // Create output object + j_out = json_object_new_object(); + json_object_object_add(j_out, "value", j_in); + + return Ok(j_out); +} + void App::activate(int id) { auto ip = this->controller->sprops.find(id); if (ip != this->controller->sprops.end()) { diff --git a/src/app.hpp b/src/app.hpp index 13bc421..2e6ad69 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -233,6 +233,7 @@ struct App { void api_enddraw(char const *drawing_name); result api_get_display_info(); result api_get_area_info(char const *drawing_name); + result api_get_car_info(char const *label); void api_ping(); void send_event(char const *evname); void send_event(char const *evname, char const *label); diff --git a/src/main.cpp b/src/main.cpp index 1db33a4..99ad323 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -452,6 +452,40 @@ void windowmanager_getareainfo_thunk(afb_req req) noexcept { } +void windowmanager_getcarinfo_thunk(afb_req req) noexcept { + std::lock_guard guard(binding_m); + #ifdef ST + ST(); + #endif + if (g_afb_instance == nullptr) { + afb_req_fail(req, "failed", "Binding not initialized, did the compositor die?"); + return; + } + + try { + json_object *jreq = afb_req_json(req); + + json_object *j_label = nullptr; + if (! json_object_object_get_ex(jreq, "label", &j_label)) { + afb_req_fail(req, "failed", "Need char const* argument label"); + return; + } + char const* a_label = json_object_get_string(j_label); + + auto ret = g_afb_instance->app.api_get_car_info(a_label); + if (ret.is_err()) { + afb_req_fail(req, "failed", ret.unwrap_err()); + return; + } + + afb_req_success(req, ret.unwrap(), "success"); + } catch (std::exception &e) { + afb_req_fail_f(req, "failed", "Uncaught exception while calling getcarinfo: %s", e.what()); + return; + } + +} + void windowmanager_wm_subscribe(afb_req req) noexcept { std::lock_guard guard(binding_m); #ifdef ST @@ -650,6 +684,7 @@ const struct afb_verb_v2 windowmanager_verbs[] = { { "getdisplayinfo", windowmanager_getdisplayinfo_thunk, nullptr, nullptr, AFB_SESSION_NONE }, { "getareainfo", windowmanager_getareainfo_thunk, nullptr, nullptr, AFB_SESSION_NONE }, { "wm_subscribe", windowmanager_wm_subscribe, nullptr, nullptr, AFB_SESSION_NONE }, + { "getcarinfo", windowmanager_getcarinfo_thunk, nullptr, nullptr, AFB_SESSION_NONE }, { "list_drawing_names", windowmanager_list_drawing_names, nullptr, nullptr, AFB_SESSION_NONE }, { "ping", windowmanager_ping, nullptr, nullptr, AFB_SESSION_NONE }, { "debug_status", windowmanager_debug_status, nullptr, nullptr, AFB_SESSION_NONE }, -- cgit 1.2.3-korg