because of wrong header files inclusion.
Some variables are now accessible using functions
rather than using global variables that can not
be accessed through separated files.
Also fix timer returning function type.
Change-Id: I36138ff671c2537f595235273abaa34783be18e1
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
#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];
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
#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();
* @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
*********************************************************************************/
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}
{
}
*/
class can_bus_t {
private:
- const struct afb_binding_interface *interface_;
int conf_file_;
std::thread th_decoding_;
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();
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;
/* 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);
#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
{
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));
#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
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
#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
//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;
}
*/
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;
* 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)
{
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)
#pragma once
+#include <string>
+#include <json-c/json.h>
+#include <sys/timeb.h>
+
#include "openxc.pb.h"
/**
#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
#include <sys/timeb.h>
-typedef unsigned long (*TimeFunction)();
+typedef long long int (*TimeFunction)();
/**
* @brief: A frequency counting clock.