summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-21 13:21:59 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-22 12:15:09 +0100
commitdae58e000ef198f7fa09718c60d7a7f2250fc2ce (patch)
treef02fecdb5da402561207bf4a92c1526ecf1bf513 /src
parentb157cc6c5942ed0dfae672d2d3e32e0d7c6cb2ad (diff)
Fix: force to pass a ref at threads launch
Change-Id: Ife4206d6f6dce6888157239cce56b0040e3d2cf4 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/can-signals.cpp21
-rw-r--r--src/can-signals.hpp11
-rw-r--r--src/can-utils.cpp8
-rw-r--r--src/can_decode_message.cpp10
-rw-r--r--src/can_event_push.cpp2
-rw-r--r--src/can_reader.cpp2
-rw-r--r--src/low-can-binding.hpp11
-rw-r--r--src/obd2.cpp18
-rw-r--r--src/obd2.hpp4
10 files changed, 38 insertions, 52 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4f95cce5..b08dead9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -65,7 +65,8 @@ link_libraries(${EXTRAS_LIBRARIES})
message(STATUS "Creation of ${PROJECT_NAME} binding for AFB-DAEMON")
###########################################################################
-add_library(${PROJECT_NAME}-binding MODULE ${PROJECT_NAME}-binding.cpp can-signals.cpp can-utils.cpp obd2.cpp)
+add_library(${PROJECT_NAME}-binding MODULE ${PROJECT_NAME}-binding.cpp can-signals.cpp can-utils.cpp can_reader.cpp can_decode_message.cpp can_event_push.cpp openxc-utils.cpp timer.cpp)
+#add_library(${PROJECT_NAME}-binding MODULE ${PROJECT_NAME}-binding.cpp can-signals.cpp can-utils.cpp obd2.cpp)
set_target_properties(${PROJECT_NAME}-binding PROPERTIES
PREFIX ""
diff --git a/src/can-signals.cpp b/src/can-signals.cpp
index c6a8ae9e..0348268a 100644
--- a/src/can-signals.cpp
+++ b/src/can-signals.cpp
@@ -57,23 +57,4 @@ std::vector<CanSignal> find_can_signals(openxc_DynamicField& key)
break;
}
return signals;
-}
-
- struct CanMessageDefinition* message;
- const char* genericName;
- uint8_t bitPosition;
- uint8_t bitSize;
- float factor;
- float offset;
- float minValue;
- float maxValue;
- FrequencyClock frequencyClock;
- bool sendSame;
- bool forceSendChanged;
- const CanSignalState* states;
- uint8_t stateCount;
- bool writable;
- SignalDecoder decoder;
- SignalEncoder encoder;
- bool received;
- float lastValue; \ No newline at end of file
+} \ No newline at end of file
diff --git a/src/can-signals.hpp b/src/can-signals.hpp
index 5e7e5816..6d15d8b2 100644
--- a/src/can-signals.hpp
+++ b/src/can-signals.hpp
@@ -31,21 +31,12 @@ extern "C"
#include <afb/afb-event-itf.h>
}
-#define MESSAGE_SET_ID 0
-
-/** 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;
-
/**
* @brief Dumb SIGNALS array. It is composed by CanMessageSet
* SIGNALS[MESSAGE_SET_ID][CanSignal]
*/
std::vector<std::vector<CanSignal>> SIGNALS {
- { // message set: example
- }
+ {}// message set: example
};
/** Public: Return the currently active CAN configuration. */
diff --git a/src/can-utils.cpp b/src/can-utils.cpp
index 55daf440..a156df44 100644
--- a/src/can-utils.cpp
+++ b/src/can-utils.cpp
@@ -234,8 +234,8 @@ canfd_frame can_bus_dev_t::read(const struct afb_binding_interface* interface)
*/
void can_bus_dev_t::start_reading()
{
- th_reading_ = std::thread(can_reader, *this);
- is_running_ = true;
+ th_reading_ = std::thread(can_reader, std::ref(*this));
+ is_running_ = true; is_running_ = true;
}
/*
@@ -339,8 +339,8 @@ can_bus_t::can_bus_t(const afb_binding_interface *itf, int& conf_file)
*/
void can_bus_t::start_threads()
{
- th_decoding_ = std::thread(can_decode_message, *this);
- th_pushing_ = std::thread(can_event_push, *this);
+ th_decoding_ = std::thread(can_decode_message, std::ref(*this));
+ th_pushing_ = std::thread(can_event_push, std::ref(*this));
}
/**
diff --git a/src/can_decode_message.cpp b/src/can_decode_message.cpp
index f5f530e5..46b2977f 100644
--- a/src/can_decode_message.cpp
+++ b/src/can_decode_message.cpp
@@ -16,13 +16,13 @@
* limitations under the License.
*/
-#include "low-can-binding.hpp"
+#include "can_decode_message.hpp"
void can_decode_message(can_bus_t &can_bus)
{
- can_message_t can_message;
- std:vector <CanSignal> signals;
- std:vector <CanSignal>::iterator signals_i;
+ can_message_t can_message(interface) ;
+ std::vector <CanSignal> signals;
+ std::vector <CanSignal>::iterator signals_i;
openxc_VehicleMessage vehicle_message;
openxc_DynamicField search_key, ret;
bool send = true;
@@ -34,7 +34,7 @@ void can_decode_message(can_bus_t &can_bus)
if(can_message = can_bus.next_can_message(interface))
{
/* First we have to found which CanSignal is */
- search_key = build_DynamicField(openxc_DynamicField_Type::openxc_DynamicField_Type_NUM, (double)can_message.get_id())
+ search_key = build_DynamicField((double)can_message.get_id())
signals = find_can_signals(search_key);
/* Decoding the message ! Don't kill the messenger ! */
diff --git a/src/can_event_push.cpp b/src/can_event_push.cpp
index bb691182..9251da65 100644
--- a/src/can_event_push.cpp
+++ b/src/can_event_push.cpp
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-#include "low-can-binding.hpp"
+#include "can_event_push.hpp"
void can_event_push(can_bus_t& can_bus)
{
diff --git a/src/can_reader.cpp b/src/can_reader.cpp
index 418e2929..6fc1e740 100644
--- a/src/can_reader.cpp
+++ b/src/can_reader.cpp
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-#include "low-can-binding.hpp"
+#include "can_reader.hpp"
void can_reader(can_bus_dev_t &can_bus)
{
diff --git a/src/low-can-binding.hpp b/src/low-can-binding.hpp
index a46da6af..5c43ded8 100644
--- a/src/low-can-binding.hpp
+++ b/src/low-can-binding.hpp
@@ -39,7 +39,6 @@
#include <linux/can/raw.h>
#include <systemd/sd-event.h>
-#include "obd2.hpp"
#include "timer.hpp"
#include "openxc.pb.h"
#include "can-utils.hpp"
@@ -47,6 +46,8 @@
#include "can-decoder.hpp"
#include "openxc-utils.hpp"
+#define MESSAGE_SET_ID 0
+
/*
* Interface between the daemon and the binding
*/
@@ -87,4 +88,10 @@ extern "C"
* @return Exit code, zero if success.
*/
int afbBindingV1ServiceInit(struct afb_service service);
-}; \ No newline at end of file
+};
+
+/** 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/obd2.cpp b/src/obd2.cpp
index 25416cd1..536df66e 100644
--- a/src/obd2.cpp
+++ b/src/obd2.cpp
@@ -15,10 +15,11 @@
* limitations under the License.
*/
+#include "obd2.hpp"
-void shims_logger(afb_binding_interface *itf)
+void shims_logger(const char* m, const struct afb_binding_interface *interface)
{
- //DEBUG(itf, "dd");
+ DEBUG(interface, "%s", m);
}
void shims_timer()
@@ -28,15 +29,16 @@ void shims_timer()
/*
* Will scan for supported Obd2 pids
*/
-obd2_handler_t::obd2_handler_t(afb_binding_interface *itf, can_bus_t cb)
+obd2_handler_t::obd2_handler_t(const struct afb_binding_interface *interface, can_bus_t can_bus)
+ : can_bus_{can_bus}
{
- can_bus_t can_bus = cb;
- DiagnosticShims shims = diagnostic_init_shims(shims_logger, can_bus.send_can_message, NULL);
+ can_bus_t can_bus_ = can_bus;
+ DiagnosticShims shims_ = diagnostic_init_shims(shims_logger, can_bus.send_can_message, NULL);
- int n_pids, i;
+ int n_pids_, i_;
- n_pids = size(Obd2Pid);
- for(i=0; i<=n_pids; i++)
+ n_pids_ = size(Obd2Pid);
+ for(i_=0; i_<=n_pids_; i_++)
{
}
}
diff --git a/src/obd2.hpp b/src/obd2.hpp
index 42ba9fa6..a1ba644a 100644
--- a/src/obd2.hpp
+++ b/src/obd2.hpp
@@ -15,8 +15,12 @@
* limitations under the License.
*/
+ #pragma once
+
#include <vector>
#include "uds/uds.h"
+#include "can-utils.hpp"
+
extern "C"
{
#include <afb/afb-binding.h>