summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/can-signals.cpp18
-rw-r--r--src/can-signals.hpp37
-rw-r--r--src/can-utils.cpp2
-rw-r--r--src/can-utils.hpp3
-rw-r--r--src/can_decode_message.cpp11
-rw-r--r--src/can_decode_message.hpp5
-rw-r--r--src/can_event_push.cpp1
-rw-r--r--src/can_event_push.hpp4
-rw-r--r--src/can_reader.cpp4
-rw-r--r--src/can_reader.hpp1
-rw-r--r--src/low-can-binding.cpp2
-rw-r--r--src/low-can-binding.hpp6
-rw-r--r--src/openxc-utils.cpp8
-rw-r--r--src/openxc-utils.hpp4
-rw-r--r--src/timer.cpp8
-rw-r--r--src/timer.hpp2
16 files changed, 75 insertions, 41 deletions
diff --git a/src/can-signals.cpp b/src/can-signals.cpp
index 1ccc7c30..ee682f9f 100644
--- a/src/can-signals.cpp
+++ b/src/can-signals.cpp
@@ -17,6 +17,14 @@
#include "can-signals.hpp"
+/**
+ * @brief Dumb SIGNALS array. It is composed by CanMessageSet
+ * SIGNALS[MESSAGE_SET_ID][CanSignal]
+ */
+std::vector<std::vector<CanSignal>> SIGNALS {
+ {}// message set: example
+};
+
const std::vector<CanSignal> getSignals()
{
return SIGNALS[MESSAGE_SET_ID];
@@ -57,4 +65,14 @@ std::vector<CanSignal> find_can_signals(const struct afb_binding_interface* inte
break;
}
return signals;
+}
+
+inline uint32_t get_CanSignal_id(const CanSignal& sig)
+{
+ return sig.message->id;
+}
+
+const std::map<std::string, struct afb_event> get_subscribed_signals()
+{
+ return subscribed_signals;
} \ No newline at end of file
diff --git a/src/can-signals.hpp b/src/can-signals.hpp
index 37724867..e0fe2230 100644
--- a/src/can-signals.hpp
+++ b/src/can-signals.hpp
@@ -32,13 +32,15 @@ extern "C"
#define MESSAGE_SET_ID 0
-/**
- * @brief Dumb SIGNALS array. It is composed by CanMessageSet
- * SIGNALS[MESSAGE_SET_ID][CanSignal]
+/**
+ * @brief Can signal event map making access to afb_event
+ * externaly to an openxc existing structure.
+ *
+ * @desc Event map is making relation between CanSignal generic name
+ * and the afb_event struct used by application framework to pushed
+ * to the subscriber.
*/
-std::vector<std::vector<CanSignal>> SIGNALS {
- {}// message set: example
-};
+static std::map<std::string, struct afb_event> subscribed_signals;
/** Public: Return the currently active CAN configuration. */
CanMessageSet* getActiveMessageSet();
@@ -94,14 +96,25 @@ CanBus* getCanBuses();
* @brief Find one or many signals based on its name or id
* passed through openxc_DynamicField.
*
- * params[openxc_DynamicField&] - a const reference with the key to search into signal.
+ * @param[in] openxc_DynamicField& - a const reference with the key to search into signal.
* Key is either a signal name or its CAN arbitration id.
*
- * return[std::vector<std::string>] return found CanSignal generic name vector.
+ * @return std::vector<std::string> return found CanSignal generic name vector.
*/
std::vector<CanSignal> find_can_signals(const struct afb_binding_interface* interface, const openxc_DynamicField &key);
-uint32_t get_CanSignal_id(const CanSignal& sig)
-{
- return sig.message->id;
-} \ No newline at end of file
+/**
+ * @brief Retrieve can arbitration id of a given CanSignal
+ *
+ * @param[in] CanSignal& - a const reference to a CanSignal
+ *
+ * @return uint32_t - unsigned integer representing the arbitration id.
+ */
+inline uint32_t get_CanSignal_id(const CanSignal& sig);
+
+/**
+ * @brief return the subscribed_signals map.
+ *
+ * return std::map<std::string, struct afb_event> - map of subscribed signals.
+ */
+const std::map<std::string, struct afb_event> get_subscribed_signals(); \ No newline at end of file
diff --git a/src/can-utils.cpp b/src/can-utils.cpp
index 868eb235..fb6025ce 100644
--- a/src/can-utils.cpp
+++ b/src/can-utils.cpp
@@ -284,7 +284,7 @@ int can_bus_dev_t::send_can_message(can_message_t& can_msg, const struct afb_bin
*********************************************************************************/
can_bus_t::can_bus_t(const struct afb_binding_interface *interface, int& conf_file)
- : interface_{interface}, conf_file_{conf_file}
+ : conf_file_{conf_file}, interface_{interface}
{
}
diff --git a/src/can-utils.hpp b/src/can-utils.hpp
index c709af43..d945be4c 100644
--- a/src/can-utils.hpp
+++ b/src/can-utils.hpp
@@ -147,7 +147,6 @@ class can_message_t {
*/
class can_bus_t {
private:
- const struct afb_binding_interface *interface_;
int conf_file_;
std::thread th_decoding_;
@@ -160,6 +159,8 @@ class can_bus_t {
std::queue <openxc_VehicleMessage> vehicle_message_q_;
public:
+ const struct afb_binding_interface *interface_;
+
can_bus_t(const struct afb_binding_interface *itf, int& conf_file);
int init_can_dev();
std::vector<std::string> read_conf();
diff --git a/src/can_decode_message.cpp b/src/can_decode_message.cpp
index 126c4fac..8b087cfc 100644
--- a/src/can_decode_message.cpp
+++ b/src/can_decode_message.cpp
@@ -20,7 +20,7 @@
void can_decode_message(can_bus_t &can_bus)
{
- can_message_t can_message(interface) ;
+ can_message_t can_message(can_bus.interface_) ;
std::vector <CanSignal> signals;
std::vector <CanSignal>::iterator signals_i;
openxc_VehicleMessage vehicle_message;
@@ -35,15 +35,16 @@ void can_decode_message(can_bus_t &can_bus)
/* First we have to found which CanSignal is */
search_key = build_DynamicField((double)can_message.get_id());
- signals = find_can_signals(interface, search_key);
+ signals = find_can_signals(can_bus.interface_, search_key);
/* Decoding the message ! Don't kill the messenger ! */
for(const auto& sig : signals)
{
- subscribed_signals_i = subscribed_signals.find(sig.genericName);
+ std::map<std::string, struct afb_event> subscribed_signals = get_subscribed_signals();
+ const auto& it_event = subscribed_signals.find(sig.genericName);
- if(subscribed_signals_i != subscribed_signals.end() &&
- afb_event_is_valid(subscribed_signals_i->second))
+ if(it_event != subscribed_signals.end() &&
+ afb_event_is_valid(it_event->second))
{
ret = decoder.decodeSignal(sig, can_message, getSignals(), &send);
diff --git a/src/can_decode_message.hpp b/src/can_decode_message.hpp
index 833b992f..118dac04 100644
--- a/src/can_decode_message.hpp
+++ b/src/can_decode_message.hpp
@@ -18,6 +18,9 @@
#pragma once
-#include "low-can-binding.hpp"
+#include "can-utils.hpp"
+#include "openxc-utils.hpp"
+#include "can-signals.hpp"
+#include "can-decoder.hpp"
void can_decode_message(can_bus_t &can_bus); \ No newline at end of file
diff --git a/src/can_event_push.cpp b/src/can_event_push.cpp
index 07ae8d3c..703a242c 100644
--- a/src/can_event_push.cpp
+++ b/src/can_event_push.cpp
@@ -27,6 +27,7 @@ void can_event_push(can_bus_t& can_bus)
{
v_message = can_bus.next_vehicle_message();
s_message = get_simple_message(v_message);
+ std::map<std::string, struct afb_event> subscribed_signals = get_subscribed_signals();
const auto& it_event = subscribed_signals.find(s_message.name);
if(it_event != subscribed_signals.end() && afb_event_is_valid(it_event->second))
afb_event_push(it_event->second, jsonify_simple(s_message));
diff --git a/src/can_event_push.hpp b/src/can_event_push.hpp
index 787766eb..7497a1c7 100644
--- a/src/can_event_push.hpp
+++ b/src/can_event_push.hpp
@@ -18,6 +18,8 @@
#pragma once
-#include "low-can-binding.hpp"
+#include "can-utils.hpp"
+#include "can-signals.hpp"
+#include "openxc-utils.hpp"
void can_event_push(can_bus_t& can_bus); \ No newline at end of file
diff --git a/src/can_reader.cpp b/src/can_reader.cpp
index 4be15469..24bc6004 100644
--- a/src/can_reader.cpp
+++ b/src/can_reader.cpp
@@ -20,11 +20,11 @@
void can_reader(can_bus_dev_t &can_bus_dev, can_bus_t& can_bus)
{
- can_message_t can_message(interface);
+ can_message_t can_message(can_bus.interface_);
while(can_bus_dev.is_running())
{
- can_message.convert_from_canfd_frame(can_bus_dev.read(interface));
+ can_message.convert_from_canfd_frame(can_bus_dev.read(can_bus.interface_));
can_bus.push_new_can_message(can_message);
}
} \ No newline at end of file
diff --git a/src/can_reader.hpp b/src/can_reader.hpp
index 2e33897d..714a94de 100644
--- a/src/can_reader.hpp
+++ b/src/can_reader.hpp
@@ -19,6 +19,5 @@
#pragma once
#include "can-utils.hpp"
-#include "low-can-binding.hpp"
void can_reader(can_bus_dev_t& can_bus_dev, can_bus_t& can_bus); \ No newline at end of file
diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp
index a3351445..1812d818 100644
--- a/src/low-can-binding.cpp
+++ b/src/low-can-binding.cpp
@@ -96,7 +96,7 @@ static int subscribe_unsubscribe_all(struct afb_req request, bool subscribe)
//for (const auto& sig : SIGNALS)
// e += !subscribe_unsubscribe_signals(request, subscribe, sig);
- e += !subscribe_unsubscribe_signals(request, subscribe, SIGNALS[MESSAGE_SET_ID]);
+ e += !subscribe_unsubscribe_signals(request, subscribe, getSignals());
return e == 0;
}
diff --git a/src/low-can-binding.hpp b/src/low-can-binding.hpp
index a1d3169a..6927826e 100644
--- a/src/low-can-binding.hpp
+++ b/src/low-can-binding.hpp
@@ -87,9 +87,3 @@ extern "C"
*/
int afbBindingV1ServiceInit(struct afb_service service);
};
-
-/** Can signal event map making access to afb_event
- * external to openxc existing structure.
- */
-static std::map<std::string, struct afb_event> subscribed_signals;
-static std::map<std::string, struct afb_event>::iterator subscribed_signals_i;
diff --git a/src/openxc-utils.cpp b/src/openxc-utils.cpp
index 5f001d41..cef86811 100644
--- a/src/openxc-utils.cpp
+++ b/src/openxc-utils.cpp
@@ -16,11 +16,6 @@
* limitations under the License.
*/
-#include <string>
-#include <json-c/json.h>
-#include <sys/timeb.h>
-
-#include "openxc.pb.h"
#include "openxc-utils.hpp"
openxc_VehicleMessage build_VehicleMessage_with_SimpleMessage(openxc_DynamicField_Type type, const openxc_SimpleMessage& message)
@@ -115,6 +110,9 @@ openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg)
{
if (v_msg.has_simple_message)
return v_msg.simple_message;
+
+ openxc_SimpleMessage s_msg = { true, "", false, build_DynamicField(false), false, build_DynamicField(false)};
+ return s_msg;
}
json_object* jsonify_simple(const openxc_SimpleMessage& s_msg)
diff --git a/src/openxc-utils.hpp b/src/openxc-utils.hpp
index c2614436..ad2d1c55 100644
--- a/src/openxc-utils.hpp
+++ b/src/openxc-utils.hpp
@@ -18,6 +18,10 @@
#pragma once
+#include <string>
+#include <json-c/json.h>
+#include <sys/timeb.h>
+
#include "openxc.pb.h"
/**
diff --git a/src/timer.cpp b/src/timer.cpp
index b0ccb628..01fd7636 100644
--- a/src/timer.cpp
+++ b/src/timer.cpp
@@ -17,15 +17,15 @@
#include "timer.hpp"
-inline unsigned long systemTimeMs()
+long long int systemTimeMs()
{
struct timeb t_msec;
- unsigned long int timestamp_msec;
+ long long int timestamp_msec;
if(!::ftime(&t_msec))
{
- timestamp_msec = ((unsigned long int) t_msec.time) * 1000ll +
- (unsigned long int) t_msec.millitm;
+ timestamp_msec = (t_msec.time) * 1000ll +
+ t_msec.millitm;
}
return timestamp_msec;
} \ No newline at end of file
diff --git a/src/timer.hpp b/src/timer.hpp
index 798baa26..0454a802 100644
--- a/src/timer.hpp
+++ b/src/timer.hpp
@@ -19,7 +19,7 @@
#include <sys/timeb.h>
-typedef unsigned long (*TimeFunction)();
+typedef long long int (*TimeFunction)();
/**
* @brief: A frequency counting clock.