Add necessary to be able to initialize diagnostic manager shims.
authorRomain Forlot <romain.forlot@iot.bzh>
Thu, 9 Mar 2017 12:06:56 +0000 (13:06 +0100)
committerRomain Forlot <romain.forlot@iot.bzh>
Thu, 16 Mar 2017 16:10:40 +0000 (17:10 +0100)
We have to conform to functions signatures from isotp-c
 to have it working.

Change-Id: I429def66f54e53277e87aa99e66292cdb47c1c5f
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
src/can/can-bus-dev.cpp
src/can/can-bus-dev.hpp
src/diagnostic/diagnostic-manager.cpp
src/diagnostic/diagnostic-manager.hpp

index 157f7de..b8dadcf 100644 (file)
@@ -168,7 +168,7 @@ void can_bus_dev_t::can_reader(can_bus_t& can_bus)
 
 /// @brief Send a can message from a can_message_t object.
 /// @param[in] can_msg the can message object to send
-int can_bus_dev_t::send_can_message(can_message_t& can_msg)
+int can_bus_dev_t::send(can_message_t& can_msg)
 {
        ssize_t nbytes;
        canfd_frame f;
@@ -197,7 +197,7 @@ int can_bus_dev_t::send_can_message(can_message_t& can_msg)
 /// @brief Send a can message from a can_message_t object.
 /// @param[in] can bus used to send the message
 /// @param[in] can_msg the can message object to send
-bool can_bus_dev_t::send_can_message(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size)
+bool can_bus_dev_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size)
 {
        ssize_t nbytes;
        canfd_frame f;
@@ -206,9 +206,9 @@ bool can_bus_dev_t::send_can_message(const uint32_t arbitration_id, const uint8_
        f.len = size;
        ::memcpy(f.data, data, size);
 
-       if(socket.socket())
+       if(can_socket_.socket())
        {
-               nbytes = ::sendto(socket.socket(), &f, sizeof(struct canfd_frame), 0,
+               nbytes = ::sendto(can_socket_.socket(), &f, sizeof(struct canfd_frame), 0,
                        (struct sockaddr*)&txAddress_, sizeof(txAddress_));
                if (nbytes == -1)
                {
index 744f53f..e7184ff 100644 (file)
@@ -57,6 +57,6 @@ public:
 
        can_message_t read();
 
-       int send_can_message(can_message_t& can_msg);
-       static bool send_can_message(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size);
+       int send(can_message_t& can_msg);
+       bool shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size);
 };
index b811eda..1feac97 100644 (file)
@@ -17,7 +17,8 @@
 
 #include "obd2/diagnostic-manager.hpp"
 
-#include "low-can-binding.hpp"
+#include "../configuration.hpp"
+#include "../low-can-binding.hpp"
 
 diagnostic_manager_t::diagnostic_manager_t()
 {}
@@ -26,6 +27,12 @@ diagnostic_manager_t::diagnostic_manager_t(can_bus_dev_t& bus)
        : bus_(&bus)
 {}
 
+bool shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size)
+{
+       can_bus_dev_t *can_bus_dev = config->get_diagnostic_manager().get_can_bus_dev();
+       return can_bus_dev->shims_send(arbitration_id, data, size);
+}
+
 void diagnostic_manager_t::shims_logger(const char* m, ...)
 {
        DEBUG(binder_interface, "%s", m);
@@ -34,6 +41,10 @@ void diagnostic_manager_t::shims_logger(const char* m, ...)
 void diagnostic_manager_t::shims_timer()
 {}
 
+can_bus_dev_t* diagnostic_manager_t::get_can_bus_dev()
+{
+       return bus_;
+}
 /**
  * @brief initialize shims used by UDS lib and set initialized_ to true.
  *  It is needed before used the diagnostic manager fully because shims are
@@ -41,6 +52,6 @@ void diagnostic_manager_t::shims_timer()
  */
 void diagnostic_manager_t::init_diagnostic_shims()
 {
-       DiagnosticShims shims_ = diagnostic_init_shims(shims_logger, bus_.send_can_message, NULL);
+       DiagnosticShims shims_ = diagnostic_init_shims(shims_logger, shims_send, NULL);
        initialized_ = true;
 }
\ No newline at end of file
index aab233b..faf1eaf 100644 (file)
@@ -20,7 +20,7 @@
 #include <vector>
 
 #include "uds/uds.h"
-#include "can/can-bus.hpp"
+#include "can/can-bus-dev.hpp"
 #include "can/can-message.hpp"
 #include "obd2/active-diagnostic-request.hpp"
 
@@ -39,6 +39,7 @@
  */
 class diagnostic_manager_t {
 protected:
+       static bool shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size);
        static void shims_logger(const char* m, ...);
        static void shims_timer();
 
@@ -66,6 +67,8 @@ public:
 
        void init_diagnostic_shims();
 
+       can_bus_dev_t* get_can_bus_dev();
+
        void checkSupportedPids(const active_diagnostic_request_t& request,
        const DiagnosticResponse& response, float parsedPayload);