diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2019-12-04 17:56:16 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2020-01-09 15:55:03 +0100 |
commit | fad26418db56cf029d0b32f1fcc1309c545dac96 (patch) | |
tree | 363c09f9b709b179b87360ffc1c9f6529f7ff177 /low-can-binding | |
parent | 92a9d02e999eb72ff08fa0fea375553dbb76a4e6 (diff) |
all: format
Remove unecessary brackets and replace if possible
if...else by ternary operator.
Bug-AGL: SPEC-2991
Change-Id: Ibe46b83dea976e050b9cd9eb7ee7ab2c33b63905
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding')
-rw-r--r-- | low-can-binding/binding/application.cpp | 4 | ||||
-rw-r--r-- | low-can-binding/binding/low-can-subscription.cpp | 9 | ||||
-rw-r--r-- | low-can-binding/can/message/can-message.cpp | 8 | ||||
-rw-r--r-- | low-can-binding/can/message/j1939-message.cpp | 54 |
4 files changed, 30 insertions, 45 deletions
diff --git a/low-can-binding/binding/application.cpp b/low-can-binding/binding/application.cpp index bb3bf15b..0b8963cb 100644 --- a/low-can-binding/binding/application.cpp +++ b/low-can-binding/binding/application.cpp @@ -171,13 +171,9 @@ bool application_t::is_engine_on() if(sf.diagnostic_messages.front()->get_last_value_with_timestamp().first > 0 && std::difftime(std::time(nullptr), last_timestamp_in_s) < ENGINE_VALUE_TIMEOUT) - { engine_on = true; - } else - { AFB_NOTICE("is_engine_on: engine.speed diagnostic message found, but engine seems off"); - } } else { diff --git a/low-can-binding/binding/low-can-subscription.cpp b/low-can-binding/binding/low-can-subscription.cpp index 05367b79..0f1d1da7 100644 --- a/low-can-binding/binding/low-can-subscription.cpp +++ b/low-can-binding/binding/low-can-subscription.cpp @@ -648,7 +648,6 @@ int low_can_subscription_t::create_rx_filter(std::shared_ptr<diagnostic_message_ diagnostic_message_.push_back(sig); struct timeval freq = frequency_clock_t(event_filter_.frequency).get_timeval_from_period(); - //struct timeval timeout = frequency_clock_t(10).get_timeval_from_period(); struct timeval timeout = {0, 0}; struct bcm_msg bcm_msg = make_bcm_head(RX_SETUP, OBD2_FUNCTIONAL_BROADCAST_ID, SETTIMER | RX_NO_AUTOTIMER | RX_FILTER_ID, timeout, freq); @@ -669,13 +668,11 @@ int low_can_subscription_t::create_rx_filter_bcm(low_can_subscription_t &subscri if(subscription.open_socket(subscription, "", CAN_PROTOCOL) < 0) return -1; - // If it's not an OBD2 CAN ID then just add a simple RX_SETUP job - // else monitor all standard 8 CAN OBD2 ID response. - can_message_t msg = can_message_t(); - msg.set_bcm_msg(bcm_msg); + // If it's not an OBD2 CAN ID then just add a simple RX_SETUP job + // else monitor all standard 8 CAN OBD2 ID response. if(bcm_msg.msg_head.can_id != OBD2_FUNCTIONAL_BROADCAST_ID) { subscription.socket_->write_message(msg); @@ -714,8 +711,6 @@ int low_can_subscription_t::tx_send(low_can_subscription_t &subscription, messag struct bcm_msg &bcm_cm = cm->get_bcm_msg(); - - if(cfd_vect.size() > 1) { AFB_ERROR("Multi frame BCM not implemented"); 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 3740ea20..743898ff 100644 --- a/low-can-binding/can/message/j1939-message.cpp +++ b/low-can-binding/can/message/j1939-message.cpp @@ -83,6 +83,22 @@ uint8_t j1939_message_t::get_addr() const{ return addr_; } +/** + * @brief Convert hex data to string + * + * @param data An array of data + * @param length The length of the data + * @return std::string The string data + */ +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(); +} /// @brief Take a sockaddr_can struct and array of data to initialize class members /// @@ -115,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)); } @@ -197,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; - } -}
\ No newline at end of file + 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; +} |