summaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/can
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-10 18:39:25 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-10 18:45:56 +0200
commitd253ada94487232ccd33b68a69fd44ff7840fab7 (patch)
tree67f5959138d0ddcad413f9ee692d087200e0b4df /CAN-binder/low-can-binding/can
parent3e2be4237ac6f3e8bcec8b10d295182cefe67330 (diff)
Use a tree instead of separated object lists. WIP
Now we respect JSON description file, which is can_message_set contains can_message_definition which contains can_signals. Diagnostic messages aren't processed for now. Change-Id: I94aaf5eded14dd84395bd4fd749df58dee5f533e Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/can')
-rw-r--r--CAN-binder/low-can-binding/can/can-decoder.cpp2
-rw-r--r--CAN-binder/low-can-binding/can/can-decoder.hpp2
-rw-r--r--CAN-binder/low-can-binding/can/can-message-definition.cpp56
-rw-r--r--CAN-binder/low-can-binding/can/can-message-definition.hpp16
-rw-r--r--CAN-binder/low-can-binding/can/can-message-set.cpp28
-rw-r--r--CAN-binder/low-can-binding/can/can-message-set.hpp12
-rw-r--r--CAN-binder/low-can-binding/can/can-signals.cpp37
-rw-r--r--CAN-binder/low-can-binding/can/can-signals.hpp13
8 files changed, 138 insertions, 28 deletions
diff --git a/CAN-binder/low-can-binding/can/can-decoder.cpp b/CAN-binder/low-can-binding/can/can-decoder.cpp
index 2ccbbb8e..419eac1b 100644
--- a/CAN-binder/low-can-binding/can/can-decoder.cpp
+++ b/CAN-binder/low-can-binding/can/can-decoder.cpp
@@ -154,7 +154,7 @@ openxc_DynamicField decoder_t::stateDecoder(can_signal_t& signal,
/// string or boolean.
///
openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, const can_message_t& message,
- const std::vector<can_signal_t>& signals, bool* send)
+ const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send)
{
float value = decoder_t::parseSignalBitfield(signal, message);
DEBUG(binder_interface, "%s: Decoded message from parseSignalBitfield: %f", __FUNCTION__, value);
diff --git a/CAN-binder/low-can-binding/can/can-decoder.hpp b/CAN-binder/low-can-binding/can/can-decoder.hpp
index d626eaad..1e7efc6b 100644
--- a/CAN-binder/low-can-binding/can/can-decoder.hpp
+++ b/CAN-binder/low-can-binding/can/can-decoder.hpp
@@ -36,7 +36,7 @@ public:
float value, bool* send);
static openxc_DynamicField translateSignal(can_signal_t& signal, const can_message_t& message,
- const std::vector<can_signal_t>& signals, bool* send);
+ const std::vector<std::shared_ptr<can_signal_t> >& signals, bool* send);
static openxc_DynamicField decodeSignal(can_signal_t& signal, const can_message_t& message,
const std::vector<can_signal_t>& signals, bool* send);
diff --git a/CAN-binder/low-can-binding/can/can-message-definition.cpp b/CAN-binder/low-can-binding/can/can-message-definition.cpp
index 3603bf27..18a07bb0 100644
--- a/CAN-binder/low-can-binding/can/can-message-definition.cpp
+++ b/CAN-binder/low-can-binding/can/can-message-definition.cpp
@@ -17,16 +17,16 @@
#include "can-message-definition.hpp"
-can_message_definition_t::can_message_definition_t(std::uint8_t message_set_id, const std::string bus)
- : message_set_id_{message_set_id}, bus_{bus}, last_value_{CAN_MESSAGE_SIZE}
+can_message_definition_t::can_message_definition_t(const std::string bus)
+ : parent_{nullptr}, bus_{bus}, last_value_{CAN_MESSAGE_SIZE}
{}
-can_message_definition_t::can_message_definition_t(std::uint8_t message_set_id,
+can_message_definition_t::can_message_definition_t(
const std::string bus,
uint32_t id,
frequency_clock_t frequency_clock,
bool force_send_changed)
- : message_set_id_{message_set_id},
+ : parent_{nullptr},
bus_{bus},
id_{id},
frequency_clock_{frequency_clock},
@@ -34,13 +34,13 @@ can_message_definition_t::can_message_definition_t(std::uint8_t message_set_id,
last_value_{CAN_MESSAGE_SIZE}
{}
-can_message_definition_t::can_message_definition_t(std::uint8_t message_set_id,
+can_message_definition_t::can_message_definition_t(
const std::string bus,
uint32_t id,
can_message_format_t format,
frequency_clock_t frequency_clock,
bool force_send_changed)
- : message_set_id_{message_set_id},
+ : parent_{nullptr},
bus_{bus},
id_{id},
format_{format},
@@ -49,6 +49,39 @@ can_message_definition_t::can_message_definition_t(std::uint8_t message_set_id,
last_value_{CAN_MESSAGE_SIZE}
{}
+can_message_definition_t::can_message_definition_t(
+ const std::string bus,
+ uint32_t id,
+ can_message_format_t format,
+ frequency_clock_t frequency_clock,
+ bool force_send_changed,
+ std::vector<std::shared_ptr<can_signal_t> > can_signals)
+ : parent_{nullptr},
+ bus_{bus},
+ id_{id},
+ format_{format},
+ frequency_clock_{frequency_clock},
+ force_send_changed_{force_send_changed},
+ last_value_{CAN_MESSAGE_SIZE},
+ can_signals_{std::move(can_signals)}
+{
+ for(auto& sig: can_signals_)
+ {
+ sig->set_parent(std::make_shared<can_signal_t>(this));
+ }
+}
+
+/*can_message_definition_t(const can_message_definition_t& b)
+ : parent_{b.parent_},
+ bus_{b.bus_},
+ id_{b.id_},
+ format_{b.format_},
+ frequency_clock_{b.frequency_clock_},
+ force_send_changed_{b.force_send_changed_},
+ last_value_{b.last_value_},
+ can_signals_{b.can_signals_}
+ {}*/
+
const std::string& can_message_definition_t::get_bus_name() const
{
return bus_;
@@ -57,6 +90,17 @@ const std::string& can_message_definition_t::get_bus_name() const
uint32_t can_message_definition_t::get_id() const
{
return id_;
+}
+
+std::vector<std::shared_ptr<can_signal_t> > can_message_definition_t::get_can_signals()
+{
+ return can_signals_;
+}
+
+void can_message_definition_t::set_parent(std::shared_ptr<can_message_set_t> parent)
+{
+ parent_= parent;
+}
void can_message_definition_t::set_last_value(const can_message_t& cm)
{
diff --git a/CAN-binder/low-can-binding/can/can-message-definition.hpp b/CAN-binder/low-can-binding/can/can-message-definition.hpp
index 42eef89f..612ce357 100644
--- a/CAN-binder/low-can-binding/can/can-message-definition.hpp
+++ b/CAN-binder/low-can-binding/can/can-message-definition.hpp
@@ -29,12 +29,15 @@
#include <memory>
#include "can-message.hpp"
+#include "can-signals.hpp"
#include "../utils/timer.hpp"
+class can_message_set_t;
+
class can_message_definition_t
{
private:
- std::uint8_t message_set_id_;
+ std::shared_ptr<can_message_set_t> parent_; /*!< parent_ - Pointer to the CAN message set holding this CAN message definition */
std::string bus_; /*!< bus_ - Address of CAN bus device. */
uint32_t id_; /*!< id_ - The ID of the message.*/
can_message_format_t format_; /*!< format_ - the format of the message's ID.*/
@@ -46,14 +49,19 @@ private:
std::vector<uint8_t> last_value_; /*!< last_value_ - The last received value of the message. Defaults to undefined.
* This is required for the forceSendChanged functionality, as the stack
* needs to compare an incoming CAN message with the previous frame.*/
+ std::vector<std::shared_ptr<can_signal_t> > can_signals_; /*!< can_signals_ - Vector holding can_signal_t object which share the same arbitration ID */
public:
- can_message_definition_t(std::uint8_t message_set_id, const std::string bus);
- can_message_definition_t(std::uint8_t message_set_id, const std::string bus, uint32_t id, frequency_clock_t frequency_clock, bool force_send_changed);
- can_message_definition_t(std::uint8_t message_set_id, const std::string bus, uint32_t id, can_message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed);
+ //can_message_definition_t(const can_message_definition_t& b);
+ can_message_definition_t(const std::string bus);
+ can_message_definition_t(const std::string bus, uint32_t id, frequency_clock_t frequency_clock, bool force_send_changed);
+ can_message_definition_t(const std::string bus, uint32_t id, can_message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed);
+ can_message_definition_t(const std::string bus, uint32_t id, can_message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed, std::vector<std::shared_ptr<can_signal_t> > can_signals);
const std::string& get_bus_name() const;
uint32_t get_id() const;
+ std::vector<std::shared_ptr<can_signal_t> > get_can_signals();
+ void set_parent(std::shared_ptr<can_message_set_t> parent);
void set_last_value(const can_message_t& cm);
};
diff --git a/CAN-binder/low-can-binding/can/can-message-set.cpp b/CAN-binder/low-can-binding/can/can-message-set.cpp
index a9f8cf23..1877f3a2 100644
--- a/CAN-binder/low-can-binding/can/can-message-set.cpp
+++ b/CAN-binder/low-can-binding/can/can-message-set.cpp
@@ -25,7 +25,8 @@ can_message_set_t::can_message_set_t(
unsigned short can_message_count,
unsigned short can_signal_count,
unsigned short can_command_count,
- unsigned short obd2_signal_count)
+ unsigned short obd2_signal_count,
+ std::vector<std::shared_ptr<can_message_definition_t> > can_messages_definition)
: index_{index}
, name_{name}
, can_bus_count_{can_bus_count}
@@ -33,5 +34,30 @@ can_message_set_t::can_message_set_t(
, can_signal_count_{can_signal_count}
, can_command_count_{can_command_count}
, obd2_signal_count_{obd2_signal_count}
+ , can_messages_definition_{can_messages_definition}
{
+ for(auto& cmd : can_messages_definition_)
+ {
+ cmd->set_parent(std::make_shared<can_message_set_t>(this));
+ }
}
+
+/// @brief Return vector holding all message definition handled by this message set.
+std::vector<std::shared_ptr<can_message_definition_t> > can_message_set_t::get_can_message_definition()
+{
+ return can_messages_definition_;
+}
+
+std::vector<std::shared_ptr<can_signal_t> > can_message_set_t::get_can_signals() const
+{
+ std::vector<std::shared_ptr<can_signal_t> > can_signals(can_signal_count_);
+ for(const auto& cmd: can_messages_definition_)
+ {
+ can_signals.insert( can_signals.end(),
+ cmd->get_can_signals().begin(),
+ cmd->get_can_signals().end()
+ );
+ }
+
+ return can_signals;
+} \ No newline at end of file
diff --git a/CAN-binder/low-can-binding/can/can-message-set.hpp b/CAN-binder/low-can-binding/can/can-message-set.hpp
index 94e2d8d5..3d917c11 100644
--- a/CAN-binder/low-can-binding/can/can-message-set.hpp
+++ b/CAN-binder/low-can-binding/can/can-message-set.hpp
@@ -20,6 +20,12 @@
#include <cstdint>
#include <string>
+#include <vector>
+#include <memory>
+
+#include "can-message-definition.hpp"
+
+class can_signal_t;
/// @brief A parent wrapper for a particular set of CAN messages and associated
/// CAN buses(e.g. a vehicle or program).
@@ -33,6 +39,7 @@ private:
uint16_t can_signal_count_; /// < The number of CAN signals (across all messages) defined for this message set.
uint16_t can_command_count_; /// < The number of CanCommmands defined for this message set.
uint16_t obd2_signal_count_; /// < The number of obd2 signals defined for this message set.
+ std::vector<std::shared_ptr<can_message_definition_t> > can_messages_definition_; ///< Vector holding all message definition handled by this message set.
public:
can_message_set_t(
@@ -42,6 +49,9 @@ public:
short unsigned int can_message_count,
short unsigned int can_signal_count,
short unsigned int can_command_count,
- short unsigned int obd2_signal_count);
+ short unsigned int obd2_signal_count,
+ std::vector<std::shared_ptr<can_message_definition_t> > can_messages_definition);
+ std::vector<std::shared_ptr<can_message_definition_t> > get_can_message_definition();
+ std::vector<std::shared_ptr<can_signal_t> > get_can_signals() const;
};
diff --git a/CAN-binder/low-can-binding/can/can-signals.cpp b/CAN-binder/low-can-binding/can/can-signals.cpp
index 7726bfc1..96d0b707 100644
--- a/CAN-binder/low-can-binding/can/can-signals.cpp
+++ b/CAN-binder/low-can-binding/can/can-signals.cpp
@@ -29,8 +29,7 @@
std::string can_signal_t::prefix_ = "messages";
-can_signal_t::can_signal_t(std::uint8_t message_set_id,
- std::uint8_t message_id,
+can_signal_t::can_signal_t(
std::string generic_name,
uint8_t bit_position,
uint8_t bit_size,
@@ -46,9 +45,8 @@ can_signal_t::can_signal_t(std::uint8_t message_set_id,
SignalDecoder decoder,
SignalEncoder encoder,
bool received)
- : message_set_id_{ message_set_id }
- , message_id_{ message_id }
- , generic_name_{ generic_name }
+ : parent_{nullptr},
+ generic_name_{ generic_name }
, bit_position_{ bit_position }
, bit_size_{ bit_size }
, factor_{ factor }
@@ -66,14 +64,34 @@ can_signal_t::can_signal_t(std::uint8_t message_set_id,
, last_value_{.0f}
{}
+/*can_signal_t::can_signal_t(const can_signal_t& b)
+ : parent_{b.parent_},
+ generic_name_{ b.generic_name_}
+ , bit_position_{ b.bit_position_}
+ , bit_size_{ b.bit_size_}
+ , factor_{ b.factor_ }
+ , offset_{ b.offset_}
+ , min_value_{b.min_value_}
+ , max_value_{b.max_value_}
+ , frequency_{b.frequency_}
+ , send_same_{b.send_same_}
+ , force_send_changed_{b.force_send_changed_}
+ , states_{b.states_}
+ , writable_{b.writable_}
+ , decoder_{b.decoder_}
+ , encoder_{b.encoder_}
+ , received_{b.received_}
+ , last_value_{b.last_value_}
+{}*/
+
utils::socketcan_bcm_t can_signal_t::get_socket() const
{
return socket_;
}
-can_message_definition_t& can_signal_t::get_message() const
+std::shared_ptr<can_message_definition_t> can_signal_t::get_message() const
{
- return configuration_t::instance().get_can_message_definition(message_set_id_, message_id_);
+ return parent_;
}
const std::string& can_signal_t::get_generic_name() const
@@ -177,6 +195,11 @@ float can_signal_t::get_last_value() const
return last_value_;
}
+void can_signal_t::set_parent(std::shared_ptr<can_message_definition_t> parent)
+{
+ parent_(parent);
+}
+
void can_signal_t::set_prefix(std::string val)
{
prefix_ = val;
diff --git a/CAN-binder/low-can-binding/can/can-signals.hpp b/CAN-binder/low-can-binding/can/can-signals.hpp
index 75faedf0..6497a3c6 100644
--- a/CAN-binder/low-can-binding/can/can-signals.hpp
+++ b/CAN-binder/low-can-binding/can/can-signals.hpp
@@ -19,15 +19,14 @@
#include <map>
#include <mutex>
-#include <queue>
#include <vector>
#include <string>
+#include <memory>
#include "openxc.pb.h"
#include "../utils/timer.hpp"
#include "../utils/socketcan-bcm.hpp"
#include "can-message.hpp"
-#include "can-message-definition.hpp"
#include "../diagnostic/diagnostic-message.hpp"
extern "C"
@@ -39,6 +38,7 @@ extern "C"
#define MESSAGE_SET_ID 0
class can_signal_t;
+class can_message_definition_t;
///
/// @brief The type signature for a CAN signal decoder.
@@ -76,9 +76,8 @@ typedef uint64_t (*SignalEncoder)(can_signal_t* signal,
class can_signal_t
{
private:
+ std::shared_ptr<can_message_definition_t> parent_; /*!< parent_ - pointer to the parent message definition holding this signal*/
utils::socketcan_bcm_t socket_; /*!< socket_ - Specific BCM socket that filter the signal read from CAN device */
- std::uint8_t message_set_id_; ///< message_set_id_ - Index number to the message_set_id container object
- std::uint8_t message_id_; ///< message_id_ - Index number to the message_definition_t container object
std::string generic_name_; /*!< generic_name_ - The name of the signal to be output.*/
static std::string prefix_; /*!< prefix_ - generic_name_ will be prefixed with it. It has to reflect the used protocol.
* which make easier to sort message when the come in.*/
@@ -112,9 +111,8 @@ private:
* this value is undefined. */
public:
+ //can_signal_t(const can_signal_t& b);
can_signal_t(
- std::uint8_t message_set_id,
- std::uint8_t message_id,
std::string generic_name,
uint8_t bit_position,
uint8_t bit_size,
@@ -132,7 +130,7 @@ public:
bool received);
utils::socketcan_bcm_t get_socket() const;
- can_message_definition_t& get_message() const;
+ std::shared_ptr<can_message_definition_t> get_message() const;
const std::string& get_generic_name() const;
const std::string get_name() const;
const std::string& get_prefix() const;
@@ -154,6 +152,7 @@ public:
bool get_received() const;
float get_last_value() const;
+ void set_parent(std::shared_ptr<can_message_definition_t> parent);
void set_prefix(std::string val);
void set_received(bool r);
void set_last_value(float val);