diff options
Diffstat (limited to 'low-can-binding/utils')
4 files changed, 74 insertions, 75 deletions
diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.hpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.hpp index 92c44c8c..5a950572 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.hpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.hpp @@ -24,29 +24,29 @@ namespace utils { class socketcan_j1939_addressclaiming_t : public socketcan_j1939_t { - public: - socketcan_j1939_addressclaiming_t(); - virtual std::shared_ptr<message_t> read_message(); - virtual int open(std::string device_name, pgn_t pgn); - virtual claiming_state get_state(); - TimerHandleT *timer_handle_; - std::pair<uint64_t, bool> table_j1939_address_[J1939_IDLE_ADDR]; + public: + socketcan_j1939_addressclaiming_t(); + virtual std::shared_ptr<message_t> read_message(); + virtual int open(std::string device_name, pgn_t pgn); + virtual claiming_state get_state(); + TimerHandleT *timer_handle_; + std::pair<uint64_t, bool> table_j1939_address_[J1939_IDLE_ADDR]; - private: - int claim_address(bool first_claim,bool new_address); - int pgn_request(); - void initialize_table_j1939_address(); - int save_addr_name(uint8_t addr,name_t name); - uint8_t choose_new_address(); - uint8_t get_addr_table(name_t name); - void change_state(claiming_state new_state); - void launch_timer(); - static int no_response_claiming(TimerHandleT *timerhandle); - static int free_timer_handle(void *timer_context); + private: + int claim_address(bool first_claim,bool new_address); + int pgn_request(); + void initialize_table_j1939_address(); + int save_addr_name(uint8_t addr,name_t name); + uint8_t choose_new_address(); + uint8_t get_addr_table(name_t name); + void change_state(claiming_state new_state); + void launch_timer(); + static int no_response_claiming(TimerHandleT *timerhandle); + static int free_timer_handle(void *timer_context); - uint8_t current_address_; - bool signal_stop_; - claiming_state claiming_state_; - std::string device_name_; + uint8_t current_address_; + bool signal_stop_; + claiming_state claiming_state_; + std::string device_name_; }; } diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939-data.cpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939-data.cpp index c9d3e0a6..b2f17c6e 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939-data.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939-data.cpp @@ -22,47 +22,47 @@ namespace utils { - /** - * @brief Open a socket for receive or send data - * - * @param device_name The device name to open the socket - * @param pgn The pgn to receive only him - * @return int Return the number of the socket - */ - int socketcan_j1939_data_t::open(std::string device_name, pgn_t pgn) - { - int ret = socketcan_j1939_t::open(device_name,htole64(J1939_NAME_ECU),pgn,J1939_NO_ADDR); - if(ret >= 0) - { - if(tx_address_.can_addr.j1939.pgn != J1939_NO_PGN) - { - add_filter(J1939_NO_NAME,tx_address_.can_addr.j1939.pgn,J1939_NO_ADDR,J1939_NO_NAME,J1939_NO_PGN,J1939_NO_ADDR); - } - define_opt(); - } - return ret; - } + /** + * @brief Open a socket for receive or send data + * + * @param device_name The device name to open the socket + * @param pgn The pgn to receive only him + * @return int Return the number of the socket + */ + int socketcan_j1939_data_t::open(std::string device_name, pgn_t pgn) + { + int ret = socketcan_j1939_t::open(device_name,htole64(J1939_NAME_ECU),pgn,J1939_NO_ADDR); + if(ret >= 0) + { + if(tx_address_.can_addr.j1939.pgn != J1939_NO_PGN) + { + add_filter(J1939_NO_NAME,tx_address_.can_addr.j1939.pgn,J1939_NO_ADDR,J1939_NO_NAME,J1939_NO_PGN,J1939_NO_ADDR); + } + define_opt(); + } + return ret; + } - /** - * @brief Write a message but check if the address claiming is operation before - * - * @param obj A j1939 message - * @return int 0 if the write is ok - */ - int socketcan_j1939_data_t::write_message(message_t& obj) - { - std::unique_lock<std::mutex> lock(mutex_claiming_); - application_t &application = application_t::instance(); - socketcan_j1939_addressclaiming_t *socket_addr_claimed = static_cast<socketcan_j1939_addressclaiming_t*>(application.get_socket_address_claiming().get()); - while(socket_addr_claimed->get_state() != claiming_state::OPERATIONAL) - { - socketcan_j1939_t::signal_address_claiming_.wait(lock); - if(socket_addr_claimed->get_state() == claiming_state::INVALID) - { - AFB_ERROR("Invalid state"); - return -1; - } - } - return socketcan_j1939_t::write_message(obj); - } + /** + * @brief Write a message but check if the address claiming is operation before + * + * @param obj A j1939 message + * @return int 0 if the write is ok + */ + int socketcan_j1939_data_t::write_message(message_t& obj) + { + std::unique_lock<std::mutex> lock(mutex_claiming_); + application_t &application = application_t::instance(); + socketcan_j1939_addressclaiming_t *socket_addr_claimed = static_cast<socketcan_j1939_addressclaiming_t*>(application.get_socket_address_claiming().get()); + while(socket_addr_claimed->get_state() != claiming_state::OPERATIONAL) + { + socketcan_j1939_t::signal_address_claiming_.wait(lock); + if(socket_addr_claimed->get_state() == claiming_state::INVALID) + { + AFB_ERROR("Invalid state"); + return -1; + } + } + return socketcan_j1939_t::write_message(obj); + } } diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp index 25d0f76e..bb74c766 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp @@ -96,7 +96,7 @@ namespace utils * @param recv_own_msgs - Allows you to receive your own packets * @param broadcast - Allows to write message with address brodcast (255) */ - void socketcan_j1939_t::define_opt(bool promisc, bool recv_own_msgs, bool broadcast) + void socketcan_j1939_t::define_opt(bool promisc, bool recv_own_msgs, bool broadcast) { int promisc_i = 0; int recv_own_msgs_i = 0; diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.hpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.hpp index 6c2ea696..f9132972 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.hpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.hpp @@ -33,15 +33,15 @@ namespace utils { /** - * @enum state - * @brief The state of the address claiming - */ - enum class claiming_state { - INITIAL, ///< INITIAL - INITIAL state - CLAIMING, ///< CLAIMING - CLAIMING state - OPERATIONAL, ///< OPERATIONAL - OPERATIONAL state - INVALID - }; + * @enum state + * @brief The state of the address claiming + */ + enum class claiming_state { + INITIAL, ///< INITIAL - INITIAL state + CLAIMING, ///< CLAIMING - CLAIMING state + OPERATIONAL, ///< OPERATIONAL - OPERATIONAL state + INVALID + }; class socketcan_j1939_addressclaiming_t; class socketcan_j1939_t : public socketcan_t @@ -65,4 +65,3 @@ namespace utils }; } - |