+ else
+ {
+ afb_req_fail(request, "Invalid", "Data array must hold 1 to 8 values.");
+ return;
+ }
+
+ if(! send_frame(cfd, application_t::instance().get_can_bus_manager().get_can_device_name(bus_name)))
+ afb_req_success(request, nullptr, "Message correctly sent");
+ else
+ afb_req_fail(request, "Error", "sending the message. See the log for more details.");
+}
+
+static void write_signal(afb_req_t request, const std::string& name, json_object *json_value)
+{
+ struct canfd_frame cfd;
+ struct utils::signals_found sf;
+ signal_encoder encoder = nullptr;
+ bool send = true;
+
+ ::memset(&cfd, 0, sizeof(cfd));
+
+ openxc_DynamicField search_key = build_DynamicField(name);
+ sf = utils::signals_manager_t::instance().find_signals(search_key);
+ openxc_DynamicField dynafield_value = build_DynamicField(json_value);
+
+ if (sf.signals.empty())
+ {
+ afb_req_fail_f(request, "No signal(s) found for %s. Message not sent.", name.c_str());
+ return;
+ }
+
+ std::shared_ptr<signal_t>& sig = sf.signals[0];
+ if(! sig->get_writable())
+ {
+ afb_req_fail_f(request, "%s isn't writable. Message not sent.", sig->get_name().c_str());
+ return;
+ }
+
+ uint64_t value = (encoder = sig->get_encoder()) ?
+ encoder(*sig, dynafield_value, &send) :
+ encoder_t::encode_DynamicField(*sig, dynafield_value, &send);
+
+ cfd = encoder_t::build_frame(sig, value);
+ if(! send_frame(cfd, sig->get_message()->get_bus_device_name()) && send)
+ afb_req_success(request, nullptr, "Message correctly sent");
+ else
+ afb_req_fail(request, "Error", "Sending the message. See the log for more details.");
+}
+
+void write(afb_req_t request)
+{
+ struct json_object* args = nullptr, *json_value = nullptr;
+ const char *name = nullptr;
+
+ args = afb_req_json(request);
+
+ // Process about Raw CAN message on CAN bus directly
+ if (args != NULL && ! wrap_json_unpack(args, "{ss, so !}",
+ "bus_name", &name,
+ "frame", &json_value))
+ write_raw_frame(request, name, json_value);
+
+ // Search signal then encode value.
+ else if(args != NULL &&
+ ! wrap_json_unpack(args, "{ss, so !}",
+ "signal_name", &name,
+ "signal_value", &json_value))
+ write_signal(request, std::string(name), json_value);
+ else
+ afb_req_fail(request, "Error", "Request argument malformed");
+}
+
+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.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.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(afb_req_t request)
+{
+ int rc = 0;
+ struct json_object* args = nullptr,
+ *json_name = nullptr;
+ json_object *ans = nullptr;
+
+ args = afb_req_json(request);