aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuta Doi <yuta-d@witz-inc.co.jp>2018-05-18 17:16:14 +0900
committerYuta Doi <yuta-d@witz-inc.co.jp>2018-05-18 17:16:14 +0900
commit7b62eefaf33b9bb69eb324333232ae0919fc295f (patch)
tree3cbaf1c253f3744607ab2c0685f58ae3a78e3e40
parent9f61fdc39edd93c7da5b77b4bc92963e4df31b82 (diff)
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 <yuta-d@witz-inc.co.jp>
-rw-r--r--doc/ApplicationGuide.md29
-rw-r--r--src/app.cpp37
-rw-r--r--src/app.hpp1
-rw-r--r--src/main.cpp35
4 files changed, 97 insertions, 5 deletions
diff --git a/doc/ApplicationGuide.md b/doc/ApplicationGuide.md
index 2240bb1..9c19b69 100644
--- a/doc/ApplicationGuide.md
+++ b/doc/ApplicationGuide.md
@@ -479,8 +479,10 @@ This is the public interface of the class `LibWindowmanager`.
int endDraw(json_object *object);
int getDisplayInfo(json_object *object);
int getAreaInfo(json_object *in_obj, json_object *out_obj);
+ int getCarInfo(json_object *in_obj, json_object *out_obj);
int getAreaInfo(const char *label, json_object *out_obj);
+ int getCarInfo(const char *label, json_object *out_obj);
void set_event_handler(enum EventType et, handler_fun f);
@@ -600,6 +602,33 @@ The same information can given by SyncDraw event.
This function is same with `getAreaInfo(json_object *in_obj, json_object *out_obj)`,
but only has difference of 1st argument.
+### getCarInfo(json_object *in_obj, json_object *out_obj)
+
+**args1: `{ 'kKeyLabel': 'label name' }`**
+**args2: `{ }`**
+This function gets the information of car by the application as follows:
+- parking brake state
+- accelerator pedal position
+- car state
+
+It outputs the car information for json_object in the 2nd argument as follows:
+
+| in_obj | out_obj |
+|:------------------------------------------|:------------------------------------|
+| { "label": "parking_brake_status" } | {"value": json_bool (true/false)} |
+| { "label": "accelerator.pedal.position" } | {"value": double (0 - 127.5)} |
+| { "label": "car_state" } | {"value": const char* (stop/run)} |
+
+It should be called after calling activateSurface().
+It should not be called in the event handler because it occurs hang-up.
+
+### getCarInfo(const char *label, json_object *out_obj)
+
+**args1: String of label name**
+**args2: `{ }`**
+This function is same with `getCarInfo(json_object *in_obj, json_object *out_obj)`,
+but only has difference of 1st argument.
+
### set\_event\_handler(enum EventType et, handler_fun f)
This method needs to be used to register event handlers for the WM
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<json_object *> App::api_get_area_info(char const *drawing_name) {
return Err<json_object *>("Could not find layer for surface");
}
- struct LayoutState &state = *o_state;
- if ((state.main != *surface_id) && (state.sub != *surface_id)) {
- return Err<json_object *>("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<json_object *> App::api_get_area_info(char const *drawing_name) {
return Ok<json_object *>(object);
}
+result<json_object *> 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<json_object *>("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<json_object *>(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<json_object *> api_get_display_info();
result<json_object *> api_get_area_info(char const *drawing_name);
+ result<json_object *> 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<std::mutex> 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<std::mutex> 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 },