void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, uint32_t pid, std::map<int, std::shared_ptr<low_can_subscription_t> >& s)
{
+ bool is_permanent_recurring_request = false;
+
if( ! can_subscription->get_diagnostic_message().empty() && can_subscription->get_diagnostic_message(pid) != nullptr)
{
DiagnosticRequest diag_req = can_subscription->get_diagnostic_message(pid)->build_diagnostic_request();
active_diagnostic_request_t* adr = application_t::instance().get_diagnostic_manager().find_recurring_request(diag_req);
if( adr != nullptr)
- application_t::instance().get_diagnostic_manager().cleanup_request(adr, true);
+ {
+ is_permanent_recurring_request = adr->get_permanent();
+
+ if(! is_permanent_recurring_request)
+ application_t::instance().get_diagnostic_manager().cleanup_request(adr, true);
+ }
}
- on_no_clients(can_subscription, s);
+ if(! is_permanent_recurring_request)
+ on_no_clients(can_subscription, s);
}
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::map<int, std::shared_ptr<low_can_subscription_t> >& s,
bool subscribe)
{
- /* 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)
+ /* Make the subscription or unsubscription to the event (if request contents are not null) */
+ if(request.itf && request.closure &&
+ ((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, s[can_subscription->get_index()]->get_event())) < 0)
{
AFB_ERROR("Operation goes wrong for signal: %s", can_subscription->get_name().c_str());
return -1;
bool subscribe,
std::vector<std::shared_ptr<diagnostic_message_t> > diagnostic_messages,
struct event_filter_t& event_filter,
- std::map<int, std::shared_ptr<low_can_subscription_t> >& s)
+ std::map<int, std::shared_ptr<low_can_subscription_t> >& s,
+ bool perm_rec_diag_req)
{
int rets = 0;
application_t& app = application_t::instance();
// If the requested diagnostic message isn't supported by the car then unsubcribe it
// no matter what we want, worse case will be a fail unsubscription but at least we don't
// poll a PID for nothing.
- //TODO: Adding callback requesting ignition status: diag_req, sig.c_str(), false, diagnostic_message_t::decode_obd2_response, diagnostic_message_t::check_ignition_status, frequency);
if(sig->get_supported() && subscribe)
{
- diag_m.add_recurring_request(diag_req, sig->get_name().c_str(), false, sig->get_decoder(), sig->get_callback(), event_filter.frequency);
+ diag_m.add_recurring_request(diag_req, sig->get_name().c_str(), false, sig->get_decoder(), sig->get_callback(), event_filter.frequency, perm_rec_diag_req);
if(can_subscription->create_rx_filter(sig) < 0)
{return -1;}
AFB_DEBUG("Signal: %s subscribed", sig->get_name().c_str());
std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex());
std::map<int, std::shared_ptr<low_can_subscription_t> >& s = sm.get_subscribed_signals();
- rets += subscribe_unsubscribe_diagnostic_messages(request, subscribe, signals.diagnostic_messages, event_filter, s);
+ rets += subscribe_unsubscribe_diagnostic_messages(request, subscribe, signals.diagnostic_messages, event_filter, s, false);
rets += subscribe_unsubscribe_can_signals(request, subscribe, signals.can_signals, event_filter, s);
return rets;
decoder_ = adr.decoder_;
callback_ = adr.callback_;
recurring_ = adr.recurring_;
+ permanent_ = adr.permanent_;
wait_for_multiple_responses_ = adr.wait_for_multiple_responses_;
frequency_clock_ = adr.frequency_clock_;
timeout_clock_ = adr.timeout_clock_;
decoder_{nullptr},
callback_{nullptr},
recurring_{false},
+ permanent_{false},
wait_for_multiple_responses_{false},
frequency_clock_{frequency_clock_t()},
timeout_clock_{frequency_clock_t()},
bool wait_for_multiple_responses,
const DiagnosticResponseDecoder decoder,
const DiagnosticResponseCallback callback,
- float frequencyHz)
+ float frequencyHz,
+ bool permanent)
: bus_{bus},
id_{id},
handle_{nullptr},
decoder_{decoder},
callback_{callback},
recurring_{frequencyHz ? true : false},
+ permanent_{permanent},
wait_for_multiple_responses_{wait_for_multiple_responses},
frequency_clock_{frequency_clock_t(frequencyHz)},
timeout_clock_{frequency_clock_t(10)},
return recurring_;
}
+bool active_diagnostic_request_t::get_permanent() const
+{
+ return permanent_;
+}
+
frequency_clock_t& active_diagnostic_request_t::get_frequency_clock()
{
return frequency_clock_;
///< response is received for this request.
bool recurring_; ///< bool recurring_ - If true, this is a recurring request and it will remain as active until explicitly cancelled.
///< The frequencyClock attribute controls how often a recurring request is made.
+ bool permanent_; ///< bool permanent_ - If true, this a permanent recurring request and will remain as active indefinitely (can't be cancelled).
bool wait_for_multiple_responses_; ///< wait_for_multiple_responses_ - False by default, when any response is received for a request
///< it will be removed from the active list. If true, the request will remain active until the timeout
///< clock expires, to allow it to receive multiple response (e.g. to a functional broadcast request).
active_diagnostic_request_t(const std::string& bus, uint32_t id,
const std::string& name, bool wait_for_multiple_responses,
const DiagnosticResponseDecoder decoder,
- const DiagnosticResponseCallback callback, float frequencyHz);
+ const DiagnosticResponseCallback callback, float frequencyHz, bool permanent);
~active_diagnostic_request_t();
uint32_t get_id() const;
DiagnosticResponseDecoder& get_decoder();
DiagnosticResponseCallback& get_callback();
bool get_recurring() const;
+ bool get_permanent() const;
frequency_clock_t& get_frequency_clock();
frequency_clock_t& get_timeout_clock();
utils::socketcan_bcm_t& get_socket();
if (non_recurring_requests_.size() <= MAX_SIMULTANEOUS_DIAG_REQUESTS)
{
active_diagnostic_request_t* entry = new active_diagnostic_request_t(bus_, request->arbitration_id, name,
- wait_for_multiple_responses, decoder, callback, 0);
+ wait_for_multiple_responses, decoder, callback, 0, false);
entry->set_handle(shims_, request);
char request_string[128] = {0};
/// was too much already running requests, or if the frequency was too high.
active_diagnostic_request_t* diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, const char* name,
bool wait_for_multiple_responses, const DiagnosticResponseDecoder decoder,
- const DiagnosticResponseCallback callback, float frequencyHz)
+ const DiagnosticResponseCallback callback, float frequencyHz, bool permanent)
{
active_diagnostic_request_t* entry = nullptr;
if(recurring_requests_.size() <= MAX_SIMULTANEOUS_DIAG_REQUESTS)
{
entry = new active_diagnostic_request_t(bus_, request->arbitration_id, name,
- wait_for_multiple_responses, decoder, callback, frequencyHz);
+ wait_for_multiple_responses, decoder, callback, frequencyHz, permanent);
recurring_requests_.push_back(entry);
entry->set_handle(shims_, request);
bool validate_optional_request_attributes(float frequencyHz);
active_diagnostic_request_t* add_recurring_request(DiagnosticRequest* request, const char* name,
bool waitForMultipleResponses, const DiagnosticResponseDecoder decoder,
- const DiagnosticResponseCallback callback, float frequencyHz);
+ const DiagnosticResponseCallback callback, float frequencyHz, bool permanent);
// Decoding part
openxc_VehicleMessage relay_diagnostic_response(active_diagnostic_request_t* adr, const DiagnosticResponse& response, const uint64_t timestamp);