diff options
Diffstat (limited to 'low-can-binding/can')
-rw-r--r-- | low-can-binding/can/can-decoder.cpp | 6 | ||||
-rw-r--r-- | low-can-binding/can/message/can-message.cpp | 8 | ||||
-rw-r--r-- | low-can-binding/can/message/j1939-message.cpp | 49 |
3 files changed, 17 insertions, 46 deletions
diff --git a/low-can-binding/can/can-decoder.cpp b/low-can-binding/can/can-decoder.cpp index 7f92920f..f38840e4 100644 --- a/low-can-binding/can/can-decoder.cpp +++ b/low-can-binding/can/can-decoder.cpp @@ -111,12 +111,6 @@ float decoder_t::parse_signal_bitfield(signal_t& signal, std::shared_ptr<message int sign = handle_sign(signal, data_signal, new_end_bit, data); -// if(bit_size > 255) -// AFB_ERROR("Error signal %s to long bit size", signal.get_name().c_str()); - -// if(new_start_bit > 255) -// AFB_ERROR("Too long signal offset %d", new_start_bit); - if(data_signal.size() > 65535) AFB_ERROR("Too long data signal %s", signal.get_name().c_str()); diff --git a/low-can-binding/can/message/can-message.cpp b/low-can-binding/can/message/can-message.cpp index 5c3e0f0e..a8843b9f 100644 --- a/low-can-binding/can/message/can-message.cpp +++ b/low-can-binding/can/message/can-message.cpp @@ -131,9 +131,7 @@ std::shared_ptr<can_message_t> can_message_t::convert_from_frame(const struct ca if(rtr_flag) length = frame.len& 0xF; else - { length = (frame.len > maxdlen) ? maxdlen : frame.len; - } } } else @@ -178,7 +176,9 @@ struct canfd_frame can_message_t::convert_to_canfd_frame() ::memcpy(frame.data, get_data(), length_); } else + { AFB_ERROR("can_message_t not correctly initialized to be sent"); + } return frame; } @@ -261,7 +261,9 @@ struct can_frame can_message_t::convert_to_can_frame() ::memcpy(frame.data, get_data(), length_); } else + { AFB_ERROR("can_message_t not correctly initialized to be sent"); + } return frame; } @@ -276,9 +278,7 @@ std::string can_message_t::get_debug_message() std::string ret = ""; ret = ret + "Here is the next can message : id " + std::to_string(id_) + " length " + std::to_string(length_) + ", data "; for (size_t i = 0; i < data_.size(); i++) - { ret = ret + std::to_string(data_[i]); - } return ret; } diff --git a/low-can-binding/can/message/j1939-message.cpp b/low-can-binding/can/message/j1939-message.cpp index 0dff71f8..743898ff 100644 --- a/low-can-binding/can/message/j1939-message.cpp +++ b/low-can-binding/can/message/j1939-message.cpp @@ -92,13 +92,12 @@ uint8_t j1939_message_t::get_addr() const{ */ std::string to_hex( uint8_t data[], const size_t length) { - std::stringstream stream; - stream << std::hex << std::setfill('0'); - for(int i = 0; i < length; i++) - { - stream << std::hex << ((int) data[i]); - } - return stream.str(); + std::stringstream stream; + stream << std::hex << std::setfill('0'); + for(int i = 0; i < length; i++) + stream << std::hex << ((int) data[i]); + + return stream.str(); } /// @brief Take a sockaddr_can struct and array of data to initialize class members @@ -132,12 +131,10 @@ std::shared_ptr<j1939_message_t> j1939_message_t::convert_from_addr(struct socka data_string = converter_t::to_hex(data, length); for(i=0;i<length;i++) - { data_vector.push_back(data[i]); - }; AFB_DEBUG("Found pgn: %X, length: %X, data %s", - addr.can_addr.j1939.pgn, length, data_string.c_str()); + addr.can_addr.j1939.pgn, length, data_string.c_str()); return std::make_shared<j1939_message_t>(j1939_message_t(length, data_vector, timestamp, addr.can_addr.j1939.name, addr.can_addr.j1939.pgn, addr.can_addr.j1939.addr)); } @@ -214,30 +211,10 @@ void j1939_message_t::set_sockname(pgn_t pgn, name_t name, uint8_t addr) sockname_.can_family = AF_CAN; sockname_.can_ifindex = 0; - if(addr <= 0 || addr >= UINT8_MAX ) - { - sockname_.can_addr.j1939.addr = J1939_NO_ADDR; - } - else - { - sockname_.can_addr.j1939.addr = addr; - } - - if(name <= 0 || name >= UINT64_MAX ) - { - sockname_.can_addr.j1939.name = J1939_NO_NAME; - } - else - { - sockname_.can_addr.j1939.name = name; - } - - if(pgn <= 0 || pgn > J1939_PGN_MAX) - { - sockname_.can_addr.j1939.pgn = J1939_NO_PGN; - } - else - { - sockname_.can_addr.j1939.pgn = pgn; - } + sockname_.can_addr.j1939.addr = addr <= 0 || addr >= UINT8_MAX ? + J1939_NO_ADDR : addr; + sockname_.can_addr.j1939.name = name <= 0 || name >= UINT64_MAX ? + J1939_NO_NAME : name; + sockname_.can_addr.j1939.pgn = pgn <= 0 || pgn > J1939_PGN_MAX ? + J1939_NO_PGN : pgn; } |