/* Make the subscription or unsubscription to the event */
if (((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, s[can_subscription->get_index()]->get_event())) < 0)
{
- ERROR(binder_interface, "%s: Operation goes wrong for signal: %s", __FUNCTION__, can_subscription->get_name().c_str());
+ ERROR("Operation goes wrong for signal: %s", can_subscription->get_name().c_str());
return -1;
}
return 0;
static int create_event_handle(std::shared_ptr<low_can_subscription_t>& can_subscription, std::map<int, std::shared_ptr<low_can_subscription_t> >& s)
{
int sub_index = can_subscription->get_index();
- can_subscription->set_event(afb_daemon_make_event(binder_interface->daemon, can_subscription->get_name().c_str()));
+ can_subscription->set_event(afb_daemon_make_event(can_subscription->get_name().c_str()));
s[sub_index] = can_subscription;
if (!afb_event_is_valid(s[sub_index]->get_event()))
{
- ERROR(binder_interface, "%s: Can't create an event for %s, something goes wrong.", __FUNCTION__, can_subscription->get_name().c_str());
+ ERROR("Can't create an event for %s, something goes wrong.", can_subscription->get_name().c_str());
return -1;
}
return 0;
{
if (!afb_event_is_valid(s[sub_index]->get_event()) && !subscribe)
{
- NOTICE(binder_interface, "%s: Event isn't valid, no need to unsubscribed.", __FUNCTION__);
+ NOTICE("Event isn't valid, no need to unsubscribed.");
ret = -1;
}
ret = 0;
static int add_to_event_loop(std::shared_ptr<low_can_subscription_t>& can_subscription)
{
struct sd_event_source* event_source = nullptr;
- return ( sd_event_add_io(afb_daemon_get_event_loop(binder_interface->daemon),
+ return ( sd_event_add_io(afb_daemon_get_event_loop(),
&event_source,
can_subscription->get_socket().socket(),
EPOLLIN,
diag_m.add_recurring_request(diag_req, sig->get_name().c_str(), false, sig->get_decoder(), sig->get_callback(), event_filter.frequency);
if(can_subscription->create_rx_filter(sig) < 0)
{return -1;}
- DEBUG(binder_interface, "%s: Signal: %s subscribed", __FUNCTION__, sig->get_name().c_str());
+ DEBUG("Signal: %s subscribed", sig->get_name().c_str());
if(it == s.end() && add_to_event_loop(can_subscription) < 0)
{
diag_m.cleanup_request(
diag_m.find_recurring_request(*diag_req), true);
- WARNING(binder_interface, "%s: signal: %s isn't supported. Canceling operation.", __FUNCTION__, sig->get_name().c_str());
+ WARNING("signal: %s isn't supported. Canceling operation.", sig->get_name().c_str());
return -1;
}
}
else
{
if(sig->get_supported())
- {DEBUG(binder_interface, "%s: %s cancelled due to unsubscribe", __FUNCTION__, sig->get_name().c_str());}
+ {DEBUG("%s cancelled due to unsubscribe", sig->get_name().c_str());}
else
{
- WARNING(binder_interface, "%s: signal: %s isn't supported. Canceling operation.", __FUNCTION__, sig->get_name().c_str());
+ WARNING("signal: %s isn't supported. Canceling operation.", sig->get_name().c_str());
return -1;
}
}
{return -1;}
rets++;
- DEBUG(binder_interface, "%s: signal: %s subscribed", __FUNCTION__, sig->get_name().c_str());
+ DEBUG("signal: %s subscribed", sig->get_name().c_str());
}
return rets;
}
openxc_DynamicField search_key = build_DynamicField(tag);
sf = utils::signals_manager_t::instance().find_signals(search_key);
if (sf.can_signals.empty() && sf.diagnostic_messages.empty())
- NOTICE(binder_interface, "%s: No signal(s) found for %s.", __FUNCTION__, tag.c_str());
+ NOTICE("No signal(s) found for %s.", tag.c_str());
else
ret = subscribe_unsubscribe_signals(request, subscribe, sf, event_filter);
#include "application.hpp"
#include "../can/can-bus.hpp"
-// Interface between the daemon and the binding
-const struct afb_binding_interface *binder_interface;
-
extern "C"
{
- static const struct afb_verb_desc_v1 verbs[]=
+ static int initv2();
+
+ static const struct afb_verb_v2 verbs[]=
{
- { .name= "subscribe", .session= AFB_SESSION_NONE, .callback= subscribe, .info= "subscribe to notification of CAN bus messages." },
- { .name= "unsubscribe", .session= AFB_SESSION_NONE, .callback= unsubscribe, .info= "unsubscribe a previous subscription." }
+ { .verb= "subscribe", .callback= subscribe, .auth= NULL, .session= AFB_SESSION_NONE},
+ { .verb= "unsubscribe", .callback= unsubscribe, .auth= NULL, .session= AFB_SESSION_NONE},
+ { .verb= NULL, .callback= NULL, .auth= NULL, .session= 0}
};
- static const struct afb_binding binding_desc {
- AFB_BINDING_VERSION_1,
- {
- "Low level CAN bus service",
- "low-can",
- verbs
- }
+ const struct afb_binding_v2 afbBindingV2 {
+ .api = "low-can",
+ .specification = NULL,
+ .verbs = verbs,
+ .preinit = NULL,
+ .init = initv2,
+ .onevent = NULL,
+ .noconcurrency = 0
};
- const struct afb_binding *afbBindingV1Register (const struct afb_binding_interface *itf)
- {
- binder_interface = itf;
-
- return &binding_desc;
- }
-
/// @brief Initialize the binding.
///
/// @param[in] service Structure which represent the Application Framework Binder.
///
/// @return Exit code, zero if success.
- int afbBindingV1ServiceInit(struct afb_service service)
+ static int initv2()
{
can_bus_t& can_bus_manager = application_t::instance().get_can_bus_manager();
if(application_t::instance().get_diagnostic_manager().initialize())
return 0;
- ERROR(binder_interface, "%s: There was something wrong with CAN device Initialization.", __FUNCTION__);
+ ERROR("There was something wrong with CAN device Initialization.");
return 1;
}
};
extern "C"
{
- #define AFB_BINDING_VERSION 1
+ #define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
};
-extern "C" struct afb_binding_interface;
-
-extern const struct afb_binding_interface *binder_interface;
-
class low_can_subscription_t;
void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, std::map<int, std::shared_ptr<low_can_subscription_t> >& s);
{
std::lock_guard<std::mutex> decoded_can_message_lock(decoded_can_message_mutex_);
push_new_vehicle_message(subscription_id, vehicle_message);
- DEBUG(binder_interface, "%s: %s CAN signals processed.", __FUNCTION__, sig->get_name().c_str());
+ DEBUG("%s CAN signals processed.", sig->get_name().c_str());
}
}
}
{
std::lock_guard<std::mutex> decoded_can_message_lock(decoded_can_message_mutex_);
push_new_vehicle_message(subscription_id, vehicle_message);
- DEBUG(binder_interface, "%s: %s CAN signals processed.", __FUNCTION__, s[subscription_id]->get_name().c_str());
+ DEBUG("%s CAN signals processed.", s[subscription_id]->get_name().c_str());
}
}
}
{
can_msg = can_message_q_.front();
can_message_q_.pop();
- DEBUG(binder_interface, "%s: Here is the next can message : id %X, length %X, data %02X%02X%02X%02X%02X%02X%02X%02X", __FUNCTION__, can_msg.get_id(), can_msg.get_length(),
+ DEBUG("Here is the next can message : id %X, length %X, data %02X%02X%02X%02X%02X%02X%02X%02X", can_msg.get_id(), can_msg.get_length(),
can_msg.get_data()[0], can_msg.get_data()[1], can_msg.get_data()[2], can_msg.get_data()[3], can_msg.get_data()[4], can_msg.get_data()[5], can_msg.get_data()[6], can_msg.get_data()[7]);
return can_msg;
}
{
v_msg = vehicle_message_q_.front();
vehicle_message_q_.pop();
- DEBUG(binder_interface, "%s: next vehicle message poped", __FUNCTION__);
+ DEBUG("next vehicle message poped");
return v_msg;
}
if(can_devices_.empty())
{
- ERROR(binder_interface, "%s: No mapping found in config file: '%s'. Check it that it have a CANbus-mapping section.",
+ ERROR("No mapping found in config file: '%s'. Check it that it have a CANbus-mapping section.",
__FUNCTION__, conf_file_.filepath().c_str());
}
}
if(signal_state.size() <= 0)
{
*send = false;
- ERROR(binder_interface, "%s: No state found with index: %d", __FUNCTION__, (int)value);
+ ERROR("No state found with index: %d", (int)value);
}
return decoded_value;
}
const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send)
{
float value = decoder_t::parseSignalBitfield(signal, message);
- DEBUG(binder_interface, "%s: Decoded message from parseSignalBitfield: %f", __FUNCTION__, value);
+ DEBUG("Decoded message from parseSignalBitfield: %f", value);
// Must call the decoders every time, regardless of if we are going to
// decide to send the signal or not.
if(new_format == can_message_format_t::STANDARD || new_format == can_message_format_t::EXTENDED || new_format == can_message_format_t::INVALID)
format_ = new_format;
else
- ERROR(binder_interface, "%s: Can set format, wrong format chosen", __FUNCTION__);
+ ERROR("Can set format, wrong format chosen");
}
/// @brief Take a canfd_frame struct to initialize class members
switch(nbytes)
{
case CANFD_MTU:
- DEBUG(binder_interface, "%s: Got an CAN FD frame", __FUNCTION__);
+ DEBUG("Got an CAN FD frame");
maxdlen = CANFD_MAX_DLEN;
break;
case CAN_MTU:
- DEBUG(binder_interface, "%s: Got a legacy CAN frame", __FUNCTION__);
+ DEBUG("Got a legacy CAN frame");
maxdlen = CAN_MAX_DLEN;
break;
default:
- ERROR(binder_interface, "%s: unsupported CAN frame", __FUNCTION__);
+ ERROR("unsupported CAN frame");
break;
}
data.push_back(frame.data[i]);
};
- DEBUG(binder_interface, "%s: Found id: %X, format: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", __FUNCTION__,
+ DEBUG("Found id: %X, format: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X",
id, (uint8_t)format, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
}
if(nbytes <= CAN_MTU)
{
- DEBUG(binder_interface, "%s: Got a legacy CAN frame", __FUNCTION__);
+ DEBUG("Got a legacy CAN frame");
maxdlen = CAN_MAX_DLEN;
}
else
{
- ERROR(binder_interface, "%s: unsupported CAN frame", __FUNCTION__);
+ ERROR("unsupported CAN frame");
}
if (frame.can_id & CAN_ERR_FLAG)
data.push_back(frame.data[i]);
};
-// DEBUG(binder_interface, "%s: Found id: %X, format: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", __FUNCTION__,
+// DEBUG("Found id: %X, format: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X",
// id, (uint8_t)format, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
}
::memcpy(frame.data, get_data(), length_);
}
else
- ERROR(binder_interface, "%s: can_message_t not correctly initialized to be sent", __FUNCTION__);
+ ERROR("can_message_t not correctly initialized to be sent");
return frame;
}
::memcpy(frame.data, get_data(), length_);
}
else
- ERROR(binder_interface, "%s: can_message_t not correctly initialized to be sent", __FUNCTION__);
+ ERROR("can_message_t not correctly initialized to be sent");
return frame;
}
reset();
initialized_ = true;
- DEBUG(binder_interface, "%s: Diagnostic Manager initialized", __FUNCTION__);
+ DEBUG("Diagnostic Manager initialized");
return initialized_;
}
void diagnostic_manager_t::init_diagnostic_shims()
{
shims_ = diagnostic_init_shims(shims_logger, shims_send, NULL);
- DEBUG(binder_interface, "%s: Shims initialized", __FUNCTION__);
+ DEBUG("Shims initialized");
}
/// @brief Force cleanup all active requests.
void diagnostic_manager_t::reset()
{
- DEBUG(binder_interface, "%s: Clearing existing diagnostic requests", __FUNCTION__);
+ DEBUG("Clearing existing diagnostic requests");
cleanup_active_requests(true);
}
char buffer[256];
vsnprintf(buffer, 256, format, args);
- DEBUG(binder_interface, "%s: %s", __FUNCTION__, buffer);
+ DEBUG("%s", buffer);
va_end(args);
}
{
cancel_request(entry);
find_and_erase(entry, recurring_requests_);
- DEBUG(binder_interface, "%s: Cancelling completed, recurring request: %s", __FUNCTION__, request_string);
+ DEBUG("Cancelling completed, recurring request: %s", request_string);
}
else if (!entry->get_recurring())
{
- DEBUG(binder_interface, "%s: Cancelling completed, non-recurring request: %s", __FUNCTION__, request_string);
+ DEBUG("Cancelling completed, non-recurring request: %s", request_string);
cancel_request(entry);
find_and_erase(entry, non_recurring_requests_);
}
// Erase any existing request not already cleaned.
cleanup_request(entry, true);
- DEBUG(binder_interface, "%s: Added one-time diagnostic request on bus %s: %s", __FUNCTION__,
+ DEBUG("Added one-time diagnostic request on bus %s: %s",
bus_.c_str(), request_string);
non_recurring_requests_.push_back(entry);
}
else
{
- WARNING(binder_interface, "%s: There isn't enough request entry. Vector exhausted %d/%d", __FUNCTION__, (int)non_recurring_requests_.size(), MAX_SIMULTANEOUS_DIAG_REQUESTS);
+ WARNING("There isn't enough request entry. Vector exhausted %d/%d", (int)non_recurring_requests_.size(), MAX_SIMULTANEOUS_DIAG_REQUESTS);
non_recurring_requests_.resize(MAX_SIMULTANEOUS_DIAG_REQUESTS);
}
return entry;
bool diagnostic_manager_t::validate_optional_request_attributes(float frequencyHz)
{
if(frequencyHz > MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ) {
- DEBUG(binder_interface, "%s: Requested recurring diagnostic frequency %lf is higher than maximum of %d", __FUNCTION__,
+ DEBUG("Requested recurring diagnostic frequency %lf is higher than maximum of %d",
frequencyHz, MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ);
return false;
}
}
else
{
- WARNING(binder_interface, "%s: There isn't enough request entry. Vector exhausted %d/%d", __FUNCTION__, (int)recurring_requests_.size(), MAX_SIMULTANEOUS_DIAG_REQUESTS);
+ WARNING("There isn't enough request entry. Vector exhausted %d/%d", (int)recurring_requests_.size(), MAX_SIMULTANEOUS_DIAG_REQUESTS);
recurring_requests_.resize(MAX_SIMULTANEOUS_DIAG_REQUESTS);
}
}
else
- { DEBUG(binder_interface, "%s: Can't add request, one already exists with same key", __FUNCTION__);}
+ { DEBUG("Can't add request, one already exists with same key");}
return entry;
}
found_signals = utils::signals_manager_t::instance().find_signals(build_DynamicField(adr->get_name()));
found_signals.diagnostic_messages.front()->set_supported(false);
cleanup_request(adr, true);
- NOTICE(binder_interface, "%s: PID not supported or ill formed. Please unsubscribe from it. Error code : %d", __FUNCTION__, response.negative_response_code);
+ NOTICE("PID not supported or ill formed. Please unsubscribe from it. Error code : %d", response.negative_response_code);
message = build_VehicleMessage(build_SimpleMessage(adr->get_name(), build_DynamicField("This PID isn't supported by your vehicle.")));
}
{
if (config_content_.size() <= 0)
{
- ERROR(binder_interface, "%s: Can't load the INI config file.", __FUNCTION__);
+ ERROR("Can't load the INI config file.");
return false;
}
- DEBUG(binder_interface, "%s: Configuration file parsed", __FUNCTION__);
+ DEBUG("Configuration file parsed");
return true;
}
lookup_signals_by_id(key.numeric_value, application_t::instance().get_diagnostic_messages(), sf.diagnostic_messages);
break;
default:
- ERROR(binder_interface, "%s: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.", __FUNCTION__);
+ ERROR("wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");
break;
}
- DEBUG(binder_interface, "%s: Found %d signal(s)", __FUNCTION__, (int)(sf.can_signals.size() + sf.diagnostic_messages.size()));
+ DEBUG("Found %d signal(s)", (int)(sf.can_signals.size() + sf.diagnostic_messages.size()));
return sf;
}
}
\ No newline at end of file
// Attempts to open a socket to CAN bus
::strcpy(ifr.ifr_name, device_name.c_str());
- DEBUG(binder_interface, "%s: BCM socket ifr_name is : %s", __FUNCTION__, ifr.ifr_name);
+ DEBUG("BCM socket ifr_name is : %s", ifr.ifr_name);
if(::ioctl(socket_, SIOCGIFINDEX, &ifr) < 0)
{
- ERROR(binder_interface, "%s: ioctl failed. Error was : %s", __FUNCTION__, strerror(errno));
+ ERROR("ioctl failed. Error was : %s", strerror(errno));
close();
}
else
if(connect((struct sockaddr *)&tx_address_, sizeof(tx_address_)) < 0)
{
- ERROR(binder_interface, "%s: Connect failed. %s", __FUNCTION__, strerror(errno));
+ ERROR("Connect failed. %s", strerror(errno));
close();
}
// Needed because of using systemD event loop. See sd_event_add_io manual.
ioctl(s.socket(), SIOCGIFNAME, &ifr);
long unsigned int frame_size = nbytes-sizeof(struct bcm_msg_head);
- DEBUG(binder_interface, "Data available: %li bytes read. BCM head, opcode: %i, can_id: %i, nframes: %i", frame_size, msg.msg_head.opcode, msg.msg_head.can_id, msg.msg_head.nframes);
- DEBUG(binder_interface, "read: Found on bus %s:\n id: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", ifr.ifr_name, msg.msg_head.can_id, msg.frames.can_dlc,
+ DEBUG("Data available: %li bytes read. BCM head, opcode: %i, can_id: %i, nframes: %i", frame_size, msg.msg_head.opcode, msg.msg_head.can_id, msg.msg_head.nframes);
+ DEBUG("read: Found on bus %s:\n id: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", ifr.ifr_name, msg.msg_head.can_id, msg.frames.can_dlc,
msg.frames.data[0], msg.frames.data[1], msg.frames.data[2], msg.frames.data[3], msg.frames.data[4], msg.frames.data[5], msg.frames.data[6], msg.frames.data[7]);
struct timeval tv;
// Attempts to open a socket to CAN bus
::strcpy(ifr.ifr_name, device_name.c_str());
- DEBUG(binder_interface, "%s: ifr_name is : %s", __FUNCTION__, ifr.ifr_name);
+ DEBUG("ifr_name is : %s", ifr.ifr_name);
if(::ioctl(socket_, SIOCGIFINDEX, &ifr) < 0)
{
- ERROR(binder_interface, "%s: ioctl failed. Error was : %s", __FUNCTION__, strerror(errno));
+ ERROR("ioctl failed. Error was : %s", strerror(errno));
close();
}
else
if(bind((struct sockaddr *)&tx_address_, sizeof(tx_address_)) < 0)
{
- ERROR(binder_interface, "%s: Bind failed. %s", __FUNCTION__, strerror(errno));
+ ERROR("Bind failed. %s", strerror(errno));
close();
}
}
ifr.ifr_ifindex = addr.can_ifindex;
ioctl(s.socket(), SIOCGIFNAME, &ifr);
- DEBUG(binder_interface, "Data available: %i bytes read", (int)nbytes);
- DEBUG(binder_interface, "read: Found on bus %s:\n id: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", ifr.ifr_name, frame.can_id, frame.len,
+ DEBUG("Data available: %i bytes read", (int)nbytes);
+ DEBUG("read: Found on bus %s:\n id: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", ifr.ifr_name, frame.can_id, frame.len,
frame.data[0], frame.data[1], frame.data[2], frame.data[3], frame.data[4], frame.data[5], frame.data[6], frame.data[7]);
struct timeval tv;
socketcan_t& operator<<(socketcan_t& s, const T& obj)
{
if (::sendto(s.socket(), &obj, sizeof(obj), 0, (const struct sockaddr*)&s.get_tx_address(), sizeof(s.get_tx_address())) < 0)
- ERROR(binder_interface, "%s: Error sending : %i %s", __FUNCTION__, errno, ::strerror(errno));
+ ERROR("Error sending : %i %s", errno, ::strerror(errno));
return s;
}
}