diff options
Diffstat (limited to 'low-can-binding/utils')
4 files changed, 19 insertions, 17 deletions
diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.cpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.cpp index ebb39742..1ba590ba 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.cpp @@ -50,7 +50,7 @@ namespace utils { if(jm->get_addr() >= J1939_IDLE_ADDR) { - AFB_DEBUG("Get invalid address claiming by name : %x",(unsigned int)jm->get_name()); + AFB_DEBUG("Get invalid address claiming by name (maybe logout) : %x",(unsigned int)jm->get_name()); return invalid_message; } 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 08c13752..2be275d9 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939-data.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939-data.cpp @@ -31,15 +31,7 @@ namespace utils */ 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; + return socketcan_j1939_t::open(device_name, htole64(J1939_NAME_ECU), pgn, J1939_NO_ADDR); } /** diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp index 90e68218..0e5a671b 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp @@ -87,18 +87,16 @@ namespace utils /** * @brief Define some parameters on the socket * - * @param promisc - Allows to accept all packets that the socket receives even if they are not addressed directly to it - * @param recv_own_msgs - Allows you to receive your own packets * @param broadcast - Allows to write message with address brodcast (255) + * @param promisc - Allows to accept all packets that the socket receives even if they are not addressed directly to it */ - void socketcan_j1939_t::define_opt(bool promisc, bool recv_own_msgs, bool broadcast) + void socketcan_j1939_t::define_opt(bool broadcast, bool promisc) { - int promisc_i = promisc ? 1 : 0; - //int recv_own_msgs_i = recv_own_msgs ? 1 : 0; int broadcast_i = broadcast ? 1 : 0; + int promisc_i = promisc ? 1 : 0; - setopt(SOL_CAN_J1939, SO_J1939_PROMISC, &promisc_i, sizeof(promisc_i)); setopt(SOL_SOCKET, SO_BROADCAST, &broadcast_i, sizeof(broadcast_i)); + setopt(SOL_CAN_J1939, SO_J1939_PROMISC, &promisc_i, sizeof(promisc_i)); } diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.hpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.hpp index 1ae8d1c9..c68500fb 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.hpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.hpp @@ -29,6 +29,17 @@ #define J1939_NAME_ECU 0x1234 #endif +#define J1939_CAN_ID CAN_EFF_FLAG +#define J1939_CAN_MASK (CAN_EFF_FLAG | CAN_RTR_FLAG) + + +// PDU 1 = NO BROADCAST +// PDU 2 = BRODCAST +static inline bool j1939_pgn_is_pdu1(pgn_t pgn) +{ + return (pgn & 0xff00) < 0xf000; +} + namespace utils { @@ -54,6 +65,7 @@ namespace utils virtual std::shared_ptr<message_t> read_message(int flag); virtual int write_message(message_t& obj); virtual int write_j1939_message(pgn_t pgn, std::vector<uint8_t> &data, uint32_t len_data); + void define_opt(bool broadcast = true, bool promisc = false); protected: struct ifreq ifr_; @@ -61,7 +73,7 @@ namespace utils static std::condition_variable signal_address_claiming_; void define_tx_address(std::string device_name, name_t name, pgn_t pgn, uint8_t addr); int add_filter(name_t name, pgn_t pgn, uint8_t addr, name_t name_mask, pgn_t pgn_mask, uint8_t addr_mask); - void define_opt(bool promisc = true, bool recv_own_msgs = true, bool broadcast = true); + }; } |