summaryrefslogtreecommitdiffstats
path: root/src/can_decode_message.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/can_decode_message.cpp')
-rw-r--r--src/can_decode_message.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/can_decode_message.cpp b/src/can_decode_message.cpp
index 8d81f8b8..3c1825d1 100644
--- a/src/can_decode_message.cpp
+++ b/src/can_decode_message.cpp
@@ -31,41 +31,44 @@ void can_decode_message(can_bus_t &can_bus)
std::vector <CanSignal> signals;
std::vector <CanSignal>::iterator signals_i;
openxc_VehicleMessage vehicle_message;
- openxc_DynamicField search_key, ret;
+ openxc_DynamicField search_key, decoded_message;
bool send = true;
decoder_t decoder;
- while(can_bus.has_can_message())
+ while(can_bus.is_decoding())
{
- std::unique_lock<std::mutex> can_message_lock(can_message_mutex);
- new_can_message.wait(can_message_lock);
+ {
+ std::unique_lock<std::mutex> can_message_lock(can_message_mutex);
+ new_can_message.wait(can_message_lock);
can_message = can_bus.next_can_message();
- can_message_mutex.unlock();
+ }
- std::lock_guard<std::mutex> decoded_can_message_lock(decoded_can_message_mutex);
- /* First we have to found which CanSignal is */
- search_key = build_DynamicField((double)can_message.get_id());
- signals = find_can_signals(search_key);
-
- /* Decoding the message ! Don't kill the messenger ! */
- for(const auto& sig : signals)
- {
+ /* First we have to found which CanSignal it is */
+ search_key = build_DynamicField((double)can_message.get_id());
+ signals = find_can_signals(search_key);
+
+ /* Decoding the message ! Don't kill the messenger ! */
+ for(const auto& sig : signals)
+ {
+ {
+ std::lock_guard<std::mutex> subscribed_signals_lock(subscribed_signals_mutex);
std::map<std::string, struct afb_event> subscribed_signals = get_subscribed_signals();
const auto& it_event = subscribed_signals.find(sig.genericName);
if(it_event != subscribed_signals.end() &&
afb_event_is_valid(it_event->second))
{
- ret = decoder.decodeSignal(sig, can_message, getSignals(), &send);
-
- openxc_SimpleMessage s_message = build_SimpleMessage(sig.genericName, ret);
+ decoded_message = decoder.decodeSignal(sig, can_message, getSignals(), &send);
+ openxc_SimpleMessage s_message = build_SimpleMessage(sig.genericName, decoded_message);
vehicle_message = build_VehicleMessage_with_SimpleMessage(openxc_DynamicField_Type::openxc_DynamicField_Type_NUM, s_message);
+
+ std::lock_guard<std::mutex> decoded_can_message_lock(decoded_can_message_mutex);
can_bus.push_new_vehicle_message(vehicle_message);
}
+ new_decoded_can_message.notify_one();
}
- decoded_can_message_mutex.unlock();
- new_decoded_can_message.notify_one();
+ }
}
}