X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=low-can-binding%2Fbinding%2Flow-can-cb.cpp;h=1b7ce1075b5636bdc1812c036feacf32b75973bd;hb=05d31a77fb2742d4aedd26a13454b21b5df83b20;hp=5916e3921cb2819300bce780435807612a323326;hpb=d31f5d10465003e720c9d0f54e4f935f96d81151;p=apps%2Fagl-service-can-low-level.git diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp index 5916e392..1b7ce107 100644 --- a/low-can-binding/binding/low-can-cb.cpp +++ b/low-can-binding/binding/low-can-cb.cpp @@ -451,7 +451,7 @@ static int write_signal(const std::string& name, uint64_t value) if(sig->get_writable()) { cf = encoder_t::build_frame(sig, value); - const std::string bus_name = sig->get_message()->get_bus_name(); + const std::string bus_name = sig->get_message()->get_bus_device_name(); rc = send_frame(bus_name, cf); } else @@ -484,7 +484,7 @@ void write(struct afb_req request) (json_object_object_get_ex(json_value, "can_dlc", &json_can_dlc) && (json_object_is_type(json_can_dlc, json_type_double) || json_object_is_type(json_can_dlc, json_type_int))) && (json_object_object_get_ex(json_value, "can_data", &json_can_data) && json_object_is_type(json_can_data, json_type_array) )) { - write_raw_frame(json_object_get_string(json_name), + rc = write_raw_frame(json_object_get_string(json_name), json_object_get_int(json_can_id), (uint8_t)json_object_get_int(json_can_dlc), json_can_data); @@ -500,7 +500,7 @@ void write(struct afb_req request) (json_object_object_get_ex(args, "signal_name", &json_name) && json_object_is_type(json_name, json_type_string)) && (json_object_object_get_ex(args, "signal_value", &json_value) && (json_object_is_type(json_value, json_type_double) || json_object_is_type(json_value, json_type_int)))) { - write_signal(json_object_get_string(json_name), + rc = write_signal(json_object_get_string(json_name), (uint64_t)json_object_get_double(json_value)); } else @@ -514,3 +514,113 @@ void write(struct afb_req request) else afb_req_fail(request, "error", NULL); } + +static struct json_object *get_signals_value(const std::string& name) +{ + struct utils::signals_found sf; + struct json_object *ans = nullptr; + + openxc_DynamicField search_key = build_DynamicField(name); + sf = utils::signals_manager_t::instance().find_signals(search_key); + + if (sf.can_signals.empty()) + { + AFB_WARNING("No signal(s) found for %s.", name.c_str()); + return NULL; + } + ans = json_object_new_array(); + for(const auto& sig: sf.can_signals) + { + struct json_object *jobj = json_object_new_object(); + json_object_object_add(jobj, "event", json_object_new_string(sig->get_name().c_str())); + json_object_object_add(jobj, "value", json_object_new_double(sig->get_last_value())); + json_object_array_add(ans, jobj); + } + + return ans; +} +void get(struct afb_req request) +{ + int rc = 0; + struct json_object* args = nullptr, + *json_name = nullptr; + json_object *ans = nullptr; + + args = afb_req_json(request); + + // Process about Raw CAN message on CAN bus directly + if (args != nullptr && + (json_object_object_get_ex(args, "event", &json_name) && json_object_is_type(json_name, json_type_string) )) + { + ans = get_signals_value(json_object_get_string(json_name)); + if (!ans) + rc = -1; + } + else + { + AFB_ERROR("Request argument malformed. Please use the following syntax:"); + rc = -1; + } + + if (rc >= 0) + afb_req_success(request, ans, NULL); + else + afb_req_fail(request, "error", NULL); +} + + +static struct json_object *list_can_message(const std::string& name) +{ + struct utils::signals_found sf; + struct json_object *ans = nullptr; + + openxc_DynamicField search_key = build_DynamicField(name); + sf = utils::signals_manager_t::instance().find_signals(search_key); + + if (sf.can_signals.empty() && sf.diagnostic_messages.empty()) + { + AFB_WARNING("No signal(s) found for %s.", name.c_str()); + return NULL; + } + ans = json_object_new_array(); + for(const auto& sig: sf.can_signals) + { + json_object_array_add(ans, + json_object_new_string(sig->get_name().c_str())); + } + for(const auto& sig: sf.diagnostic_messages) + { + json_object_array_add(ans, + json_object_new_string(sig->get_name().c_str())); + } + + return ans; +} + +void list(struct afb_req request) +{ + int rc = 0; + json_object *ans = nullptr; + struct json_object* args = nullptr, + *json_name = nullptr; + args = afb_req_json(request); + const char *name; + if ((args != nullptr) && + (json_object_object_get_ex(args, "event", &json_name) && json_object_is_type(json_name, json_type_string))) + { + name = json_object_get_string(json_name); + } + else + { + name = "*"; + } + + ans = list_can_message(name); + if (!ans) + rc = -1; + + if (rc >= 0) + afb_req_success(request, ans, NULL); + else + afb_req_fail(request, "error", NULL); +}