<commit_before>#include "diagnostics.h"
#include "signals.h"
#include "can/canwrite.h"
#include "can/canread.h"
#include "util/log.h"
#include "util/timer.h"
#include <bitfield/bitfield.h>
#include <limits.h>

#define MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ 10
#define DIAGNOSTIC_RESPONSE_ARBITRATION_ID_OFFSET 0x8

using openxc::diagnostics::ActiveDiagnosticRequest;
using openxc::diagnostics::DiagnosticRequestListEntry;
using openxc::diagnostics::DiagnosticsManager;
using openxc::util::log::debug;
using openxc::can::lookupBus;
using openxc::can::addAcceptanceFilter;
using openxc::can::removeAcceptanceFilter;
using openxc::can::read::sendNumericalMessage;
using openxc::pipeline::Pipeline;
using openxc::signals::getCanBuses;
using openxc::signals::getCanBusCount;

namespace time = openxc::util::time;
namespace pipeline = openxc::pipeline;

static bool timedOut(ActiveDiagnosticRequest* request) {
    // don't use staggered start with the timeout clock
    return time::elapsed(&request->timeoutClock, false);
}

/* Private: Returns true if the request has timed out waiting for a response,
 *      or the request handle is completed and it wasn't a functional broadcast
 *      request. Functional broadcast requests are never complete until they
 *      time out.
 */
static bool requestCompleted(ActiveDiagnosticRequest* request) {
    return (request->arbitration_id != OBD2_FUNCTIONAL_BROADCAST_ID &&
                 request->handle.completed) || (
                     timedOut(request) &&
                        diagnostic_request_sent(&request->handle));
}

/* Private: Move the entry to the free list and decrement the lock count for any
 * CAN filters it used.
 */
static void cancelRequest(DiagnosticsManager* manager,
        DiagnosticRequestListEntry* entry) {
    LIST_INSERT_HEAD(&manager->freeActiveRequests, entry, listEntries);
    removeAcceptanceFilter(entry->request.bus,
            entry->request.arbitration_id +
                DIAGNOSTIC_RESPONSE_ARBITRATION_ID_OFFSET,
            getCanBuses(), getCanBusCount());
}
<commit_msg>Decrement filter count for broadcast responses after closing a request.<commit_after>#include "diagnostics.h"
#include "signals.h"
#include "can/canwrite.h"
#include "can/canread.h"
#include "util/log.h"
#include "util/timer.h"
#include <bitfield/bitfield.h>
#include <limits.h>

#define MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ 10
#define DIAGNOSTIC_RESPONSE_ARBITRATION_ID_OFFSET 0x8

using openxc::diagnostics::ActiveDiagnosticRequest;
using openxc::diagnostics::DiagnosticRequestListEntry;
using openxc::diagnostics::DiagnosticsManager;
using openxc::util::log::debug;
using openxc::can::lookupBus;
using openxc::can::addAcceptanceFilter;
using openxc::can::removeAcceptanceFilter;
using openxc::can::read::sendNumericalMessage;
using openxc::pipeline::Pipeline;
using openxc::signals::getCanBuses;
using openxc::signals::getCanBusCount;

namespace time = openxc::util::time;
namespace pipeline = openxc::pipeline;

static bool timedOut(ActiveDiagnosticRequest* request) {
    // don't use staggered start with the timeout clock
    return time::elapsed(&request->timeoutClock, false);
}

/* Private: Returns true if the request has timed out waiting for a response,
 *      or the request handle is completed and it wasn't a functional broadcast
 *      request. Functional broadcast requests are never complete until they
 *      time out.
 */
static bool requestCompleted(ActiveDiagnosticRequest* request) {
    return (request->arbitration_id != OBD2_FUNCTIONAL_BROADCAST_ID &&
                 request->handle.completed) || (
                     timedOut(request) &&
                        diagnostic_request_sent(&request->handle));
}

/* Private: Move the entry to the free list and decrement the lock count for any
 * CAN filters it used.
 */
static void cancelRequest(DiagnosticsManager* manager,
        DiagnosticRequestListEntry* entry) {
    LIST_INSERT_HEAD(&manager->freeActiveRequests, entry, listEntries);
    if(entry->request.arbitration_id == OBD2_FUNCTIONAL_BROADCAST_ID) {
        for(uint32_t filter = OBD2_FUNCTIONAL_RESPONSE_START;
                filter < OBD2_FUNCTIONAL_RESPONSE_START +
                    OBD2_FUNCTIONAL_RESPONSE_COUNT;
                filter++) {
            removeAcceptanceFilter(entry->request.bus, filter, getCanBuses(),
                    getCanBusCount());
        }
    } else {
        removeAcceptanceFilter(entry->request.bus,
                entry->request.arbitration_id +
                    DIAGNOSTIC_RESPONSE_ARBITRATION_ID_OFFSET,
                getCanBuses(), getCanBusCount());
    }
}

{'fraction_non_alphanumeric': 0.09818339100346021, 'fraction_numerical': 0.0034602076124567475, 'mean_word_length': 4.261660978384528, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4583711', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1340, 'n_words': 311}