diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2019-11-05 19:33:29 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2020-01-08 00:17:29 +0100 |
commit | 64691cf96f9c4d7ff59dbd49e1fe01d26c1a00f6 (patch) | |
tree | 6e32fa6d9574223d5560508c76ce31d50bc42a14 /low-can-binding | |
parent | 3fb6ac3c3670499bee4ce02ff7813739017e8b8f (diff) |
all: Format one line 'if' or 'for' statement.
Bug-AGL: SPEC-2988
Change-Id: Ic3b9670a2ce9e982220c54f3632f690ee4eea686
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding')
-rw-r--r-- | low-can-binding/binding/low-can-cb.cpp | 93 | ||||
-rw-r--r-- | low-can-binding/binding/low-can-subscription.cpp | 26 | ||||
-rw-r--r-- | low-can-binding/can/can-bus.cpp | 8 | ||||
-rw-r--r-- | low-can-binding/can/can-decoder.cpp | 47 | ||||
-rw-r--r-- | low-can-binding/can/can-encoder.cpp | 17 | ||||
-rw-r--r-- | low-can-binding/diagnostic/diagnostic-manager.cpp | 8 | ||||
-rw-r--r-- | low-can-binding/utils/converter.cpp | 7 | ||||
-rw-r--r-- | low-can-binding/utils/converter.hpp | 2 | ||||
-rw-r--r-- | low-can-binding/utils/openxc-utils.cpp | 2 | ||||
-rw-r--r-- | low-can-binding/utils/socketcan-isotp.cpp | 10 | ||||
-rw-r--r-- | low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.cpp | 12 | ||||
-rw-r--r-- | low-can-binding/utils/socketcan-j1939/socketcan-j1939-data.cpp | 3 | ||||
-rw-r--r-- | low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp | 39 |
13 files changed, 65 insertions, 209 deletions
diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp index 8bb595e9..c64e06bc 100644 --- a/low-can-binding/binding/low-can-cb.cpp +++ b/low-can-binding/binding/low-can-cb.cpp @@ -226,7 +226,7 @@ static int subscribe_unsubscribe_diagnostic_messages(afb_req_t request, diag_m.add_recurring_request(diag_req, sig->get_name().c_str(), false, sig->get_decoder(), sig->get_callback(), event_filter.frequency, perm_rec_diag_req); if(can_subscription->create_rx_filter(sig) < 0) - {return -1;} + return -1; AFB_DEBUG("Signal: %s subscribed", sig->get_name().c_str()); if(it == s.end() && add_to_event_loop(can_subscription) < 0) { @@ -272,18 +272,18 @@ static int subscribe_unsubscribe_signals(afb_req_t request, }); std::shared_ptr<low_can_subscription_t> can_subscription; if(it != s.end()) - {can_subscription = it->second;} + can_subscription = it->second; else { can_subscription = std::make_shared<low_can_subscription_t>(low_can_subscription_t(event_filter)); if(can_subscription->create_rx_filter(sig) < 0) - {return -1;} + return -1; if(add_to_event_loop(can_subscription) < 0) - {return -1;} + return -1; } if(subscribe_unsubscribe_signal(request, subscribe, can_subscription, s) < 0) - {return -1;} + return -1; rets++; AFB_DEBUG("%s Signal: %s %ssubscribed", sig->get_message()->is_fd() ? "FD": "", sig->get_name().c_str(), subscribe ? "":"un"); @@ -328,19 +328,19 @@ static event_filter_t generate_filter(json_object* args) { if (json_object_object_get_ex(filter, "frequency", &obj) && (json_object_is_type(obj, json_type_double) || json_object_is_type(obj, json_type_int))) - {event_filter.frequency = (float)json_object_get_double(obj);} + event_filter.frequency = (float)json_object_get_double(obj); if (json_object_object_get_ex(filter, "min", &obj) && (json_object_is_type(obj, json_type_double) || json_object_is_type(obj, json_type_int))) - {event_filter.min = (float)json_object_get_double(obj);} + event_filter.min = (float)json_object_get_double(obj); if (json_object_object_get_ex(filter, "max", &obj) && (json_object_is_type(obj, json_type_double) || json_object_is_type(obj, json_type_int))) - {event_filter.max = (float)json_object_get_double(obj);} + event_filter.max = (float)json_object_get_double(obj); if (json_object_object_get_ex(filter, "rx_id", &obj) && (json_object_is_type(obj, json_type_int))) - {event_filter.rx_id = (canid_t) json_object_get_int(obj);} + event_filter.rx_id = (canid_t) json_object_get_int(obj); if (json_object_object_get_ex(filter, "tx_id", &obj) && (json_object_is_type(obj, json_type_int))) - {event_filter.tx_id = (canid_t) json_object_get_int(obj);} + event_filter.tx_id = (canid_t) json_object_get_int(obj); } return event_filter; } @@ -362,9 +362,8 @@ static int one_subscribe_unsubscribe_events(afb_req_t request, bool subscribe, c sf.signals.remove_if([](std::shared_ptr<signal_t> x){ bool isotp = x->get_message()->is_isotp(); if(isotp) - { AFB_NOTICE("ISO TP messages need to be subscribed one by one (rx, tx)"); - } + return isotp; }); } @@ -390,9 +389,7 @@ static int one_subscribe_unsubscribe_id(afb_req_t request, bool subscribe, const struct utils::signals_found sf; if(message_definition) - { sf.signals = list_ptr_signal_t(message_definition->get_signals().begin(),message_definition->get_signals().end()); - } if(sf.signals.empty()) { @@ -404,6 +401,7 @@ static int one_subscribe_unsubscribe_id(afb_req_t request, bool subscribe, const event_filter_t event_filter = generate_filter(args); ret = subscribe_unsubscribe_signals(request, subscribe, sf, event_filter); } + return ret; } @@ -419,9 +417,7 @@ static int process_one_subscribe_args(afb_req_t request, bool subscribe, json_ob json_object_object_get_ex(args,"event",&event); json_bool test_id = json_object_object_get_ex(args,"id",&id); if(!test_id) - { test_id = json_object_object_get_ex(args,"pgn",&id); - } if( args == NULL || (id && ((std::string)json_object_get_string(id)).compare("*") == 0)) { @@ -541,40 +537,28 @@ static int send_frame(struct canfd_frame& cfd, const std::string& bus_name, sock static int send_message(message_t *message, const std::string& bus_name, uint32_t flags, event_filter_t &event_filter, std::shared_ptr<signal_t> signal) { if(bus_name.empty()) - { return -1; - } std::map<std::string, std::shared_ptr<low_can_subscription_t> >& cd = application_t::instance().get_can_devices(); if( cd.count(bus_name) == 0) - { cd[bus_name] = std::make_shared<low_can_subscription_t>(low_can_subscription_t(event_filter)); - } cd[bus_name]->set_signal(signal); if(flags&BCM_PROTOCOL) - { return low_can_subscription_t::tx_send(*cd[bus_name], message, bus_name); - } #ifdef USE_FEATURE_ISOTP else if(flags&ISOTP_PROTOCOL) - { return low_can_subscription_t::isotp_send(*cd[bus_name], message, bus_name); - } #endif #ifdef USE_FEATURE_J1939 else if(flags&J1939_PROTOCOL) - { return low_can_subscription_t::j1939_send(*cd[bus_name], message, bus_name); - } #endif else - { return -1; - } } @@ -612,9 +596,7 @@ static void write_raw_frame(afb_req_t request, const std::string& bus_name, mess #ifdef USE_FEATURE_J1939 if(flags&J1939_PROTOCOL) - { message->set_maxdlen(J1939_MAX_DLEN); - } #endif if(message->get_length() > 0 && message->get_length() <= message->get_maxdlen()) @@ -631,32 +613,21 @@ static void write_raw_frame(afb_req_t request, const std::string& bus_name, mess else { if(flags&BCM_PROTOCOL) - { afb_req_fail(request, "Invalid", "Frame BCM"); - } else if(flags&J1939_PROTOCOL) - { afb_req_fail(request, "Invalid", "Frame J1939"); - } else if(flags&ISOTP_PROTOCOL) - { afb_req_fail(request, "Invalid", "Frame ISOTP"); - } else - { afb_req_fail(request, "Invalid", "Frame"); - } + return; } if(! send_message(message, application_t::instance().get_can_bus_manager().get_can_device_name(bus_name), flags, event_filter, sf.signals.front())) - { afb_req_success(request, nullptr, "Message correctly sent"); - } else - { afb_req_fail(request, "Error", "sending the message. See the log for more details."); - } } else { @@ -734,40 +705,28 @@ static void write_signal(afb_req_t request, const std::string& name, json_object uint32_t flags = INVALID_FLAG; if(sig->get_message()->is_j1939()) - { flags = J1939_PROTOCOL; - } else if(sig->get_message()->is_isotp()) - { flags = ISOTP_PROTOCOL; - } else - { flags = BCM_PROTOCOL; - } // cfd = encoder_t::build_frame(sig, value); message_t *message = encoder_t::build_message(sig,value,false,false); if(! send_message(message, sig->get_message()->get_bus_device_name(), flags, event_filter, sig) && send) - { afb_req_success(request, nullptr, "Message correctly sent"); - } else - { afb_req_fail(request, "Error", "Sending the message. See the log for more details."); - } if(sig->get_message()->is_j1939()) - { #ifdef USE_FEATURE_J1939 delete (j1939_message_t*) message; +#else + afb_req_fail(request, "Warning", "J1939 not implemented in your kernel."); #endif - } else - { delete (can_message_t*) message; - } } void write(afb_req_t request) @@ -782,26 +741,19 @@ void write(afb_req_t request) if(json_object_object_get_ex(args,"bus_name",&name)) { if(json_object_object_get_ex(args,"frame",&json_value)) - { write_frame(request, (std::string)json_object_get_string(name), json_value, event_filter); - } else - { afb_req_fail(request, "Error", "Request argument malformed"); - } } else if(json_object_object_get_ex(args,"signal_name",&name)) { if(json_object_object_get_ex(args,"signal_value",&json_value)) - { write_signal(request, (std::string)json_object_get_string(name), json_value, event_filter); - } else - { afb_req_fail(request, "Error", "Request argument malformed"); - } } - else { + else + { afb_req_fail(request, "Error", "Request argument malformed"); } } @@ -903,26 +855,19 @@ void list(afb_req_t request) const char *name; if ((args != nullptr) && (json_object_object_get_ex(args, "event", &json_name) && json_object_is_type(json_name, json_type_string))) - { name = json_object_get_string(json_name); - } else - { name = "*"; - } ans = list_can_message(name); if (!ans) rc = -1; if (rc >= 0) - { afb_req_success(request, ans, NULL); - } else - { afb_req_fail(request, "error", NULL); - } + } /// @brief Initialize the binding. @@ -991,9 +936,7 @@ int init_binding(afb_api_t api) #endif if(ret) - { AFB_ERROR("There was something wrong with CAN device Initialization."); - } return ret; } diff --git a/low-can-binding/binding/low-can-subscription.cpp b/low-can-binding/binding/low-can-subscription.cpp index 1e22d260..8b5f302e 100644 --- a/low-can-binding/binding/low-can-subscription.cpp +++ b/low-can-binding/binding/low-can-subscription.cpp @@ -514,9 +514,8 @@ int low_can_subscription_t::create_rx_filter_j1939(low_can_subscription_t &subsc // Make sure that socket is opened. if(open_socket(subscription, "", J1939_PROTOCOL) < 0) - { return -1; - } + return 0; } #endif @@ -534,9 +533,8 @@ int low_can_subscription_t::create_rx_filter_isotp(low_can_subscription_t &subsc // Make sure that socket is opened. if(open_socket(subscription, "", ISOTP_PROTOCOL|ISOTP_RECEIVE) < 0) - { return -1; - } + return 0; } @@ -624,7 +622,7 @@ int low_can_subscription_t::create_rx_filter(std::shared_ptr<signal_t> sig) #ifdef USE_FEATURE_ISOTP else if(sig->get_message()->is_isotp()) { - return low_can_subscription_t::create_rx_filter_isotp(*this,sig); + return low_can_subscription_t::create_rx_filter_isotp(*this, sig); } #endif #ifdef USE_FEATURE_J1939 @@ -669,7 +667,7 @@ int low_can_subscription_t::create_rx_filter_bcm(low_can_subscription_t &subscri { // Make sure that socket is opened. if(subscription.open_socket(subscription, "", BCM_PROTOCOL) < 0) - {return -1;} + 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. @@ -681,8 +679,8 @@ int low_can_subscription_t::create_rx_filter_bcm(low_can_subscription_t &subscri if(bcm_msg.msg_head.can_id != OBD2_FUNCTIONAL_BROADCAST_ID) { subscription.socket_->write_message(msg); - if(! subscription.socket_) - return -1; + if(! subscription.socket_) + return -1; } else { @@ -712,9 +710,7 @@ int low_can_subscription_t::tx_send(low_can_subscription_t &subscription, messag std::vector<canfd_frame> cfd_vect = cm->convert_to_canfd_frame_vector(); if(subscription.open_socket(subscription, bus_name, BCM_PROTOCOL) < 0) - { - return -1; - } + return -1; struct bcm_msg &bcm_cm = cm->get_bcm_msg(); @@ -742,9 +738,7 @@ int low_can_subscription_t::tx_send(low_can_subscription_t &subscription, messag } if(! subscription.socket_.get()) - { - return -1; - } + return -1; return 0; } @@ -764,9 +758,7 @@ int low_can_subscription_t::j1939_send(low_can_subscription_t &subscription, mes //subscription.add_one_bcm_frame(cfd, bcm_msg); if(subscription.open_socket(subscription, bus_name, J1939_PROTOCOL) < 0) - { return -1; - } j1939_message_t *jm = static_cast<j1939_message_t*>(message); jm->set_sockname(jm->get_pgn(), J1939_NO_NAME, J1939_NO_ADDR); @@ -795,9 +787,7 @@ int low_can_subscription_t::isotp_send(low_can_subscription_t &subscription, mes //subscription.add_one_bcm_frame(cfd, bcm_msg); if(subscription.open_socket(subscription, bus_name, ISOTP_PROTOCOL|ISOTP_SEND) < 0) - { return -1; - } can_message_t *cm = static_cast<can_message_t*>(message); if(subscription.socket_->write_message(*cm) < 0) diff --git a/low-can-binding/can/can-bus.cpp b/low-can-binding/can/can-bus.cpp index 6cd99ba3..ddf54918 100644 --- a/low-can-binding/can/can-bus.cpp +++ b/low-can-binding/can/can-bus.cpp @@ -120,7 +120,7 @@ void can_bus_t::process_diagnostic_signals(diagnostic_manager_t& manager, std::s openxc_VehicleMessage vehicle_message = manager.find_and_decode_adr(message); if (message->get_timestamp()) - {vehicle_message.timestamp = message->get_timestamp();} + vehicle_message.timestamp = message->get_timestamp(); if( (vehicle_message.has_simple_message && vehicle_message.simple_message.has_name) && s.find(subscription_id) != s.end() && afb_event_is_valid(s[subscription_id]->get_event())) { @@ -166,7 +166,7 @@ void can_bus_t::can_decode_message() process_diagnostic_signals(application_t::instance().get_diagnostic_manager(), message, s); } else - {process_signals(message, s);} + process_signals(message, s); } can_message_lock.lock(); } @@ -200,9 +200,9 @@ void can_bus_t::can_event_push() if(afb_event_push(s[v_message.first]->get_event(), jo) == 0) { if(v_message.second.has_diagnostic_response) - {on_no_clients(s[v_message.first], v_message.second.diagnostic_response.pid, s);} + on_no_clients(s[v_message.first], v_message.second.diagnostic_response.pid, s); else - {on_no_clients(s[v_message.first], s);} + on_no_clients(s[v_message.first], s); } } } diff --git a/low-can-binding/can/can-decoder.cpp b/low-can-binding/can/can-decoder.cpp index c19614c0..56626691 100644 --- a/low-can-binding/can/can-decoder.cpp +++ b/low-can-binding/can/can-decoder.cpp @@ -36,55 +36,30 @@ float decoder_t::parse_signal_bitfield(signal_t& signal, std::shared_ptr<message { const std::vector<uint8_t> data = message->get_data_vector(); std::vector<uint8_t> data_signal; - uint32_t bit_size = signal.get_bit_size(); + uint8_t bit_size = (uint8_t) signal.get_bit_size(); uint32_t bit_position = signal.get_bit_position(); int new_start_byte = 0; int new_end_byte = 0; - int new_start_bit = 0; - int new_end_bit = 0; + uint8_t new_start_bit = 0; + uint8_t new_end_bit = 0; converter_t::signal_to_bits_bytes(bit_position, bit_size, new_start_byte, new_end_byte, new_start_bit, new_end_bit); for(int i=new_start_byte;i<=new_end_byte;i++) - { data_signal.push_back(data[i]); - } - - uint8_t new_bit_size = 0; - - if(bit_size > 255) - { - AFB_ERROR("Error signal %s to long bit size",signal.get_name().c_str()); - } - else - { - new_bit_size = (uint8_t) bit_size; - } - uint8_t bit_offset = 0; - if(new_start_bit > 255) - { - AFB_ERROR("Too long signal offset %d", new_start_bit); - } - else - { - bit_offset = (uint8_t) new_start_bit; - } +// if(bit_size > 255) +// AFB_ERROR("Error signal %s to long bit size",signal.get_name().c_str()); - uint16_t length = 0; +// 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()); - } - else - { - length = (uint16_t) data_signal.size(); - } - return bitfield_parse_float(data_signal.data(), length, - bit_offset, new_bit_size, signal.get_factor(), + return bitfield_parse_float(data_signal.data(), (uint16_t) data_signal.size(), + new_start_bit, bit_size, signal.get_factor(), signal.get_offset()); } @@ -114,8 +89,8 @@ openxc_DynamicField decoder_t::decode_bytes(signal_t& signal, std::shared_ptr<me int new_start_byte = 0; int new_end_byte = 0; - int new_start_bit = 0; - int new_end_bit = 0; + uint8_t new_start_bit = 0; + uint8_t new_end_bit = 0; converter_t::signal_to_bits_bytes(bit_position, bit_size, new_start_byte, new_end_byte, new_start_bit, new_end_bit); diff --git a/low-can-binding/can/can-encoder.cpp b/low-can-binding/can/can-encoder.cpp index 2d836cf9..fb68b879 100644 --- a/low-can-binding/can/can-encoder.cpp +++ b/low-can-binding/can/can-encoder.cpp @@ -37,10 +37,10 @@ void encoder_t::encode_data(std::shared_ptr<signal_t> sig, std::vector<uint8_t> uint32_t bit_position = sig->get_bit_position(); int new_start_byte = 0; int new_end_byte = 0; - int new_start_bit_tmp = 0; - int new_end_bit = 0; + uint8_t new_start_bit = 0; + uint8_t new_end_bit = 0; - converter_t::signal_to_bits_bytes(bit_position, bit_size, new_start_byte, new_end_byte, new_start_bit_tmp, new_end_bit); + converter_t::signal_to_bits_bytes(bit_position, bit_size, new_start_byte, new_end_byte, new_start_bit, new_end_bit); int len_signal_bytes_tmp = new_end_byte - new_start_byte + 1; @@ -53,17 +53,12 @@ void encoder_t::encode_data(std::shared_ptr<signal_t> sig, std::vector<uint8_t> { len_signal_bytes = (uint8_t) len_signal_bytes_tmp; } - - uint8_t new_start_bit = 0; - if(new_start_bit_tmp > 255) +/* + if(new_start_bit > 255) { AFB_ERROR("Error signal %s too long",sig->get_name().c_str()); } - else - { - new_start_bit = (uint8_t) new_start_bit_tmp; - } - +*/ uint8_t new_bit_size = 0; if(bit_size > 255) { diff --git a/low-can-binding/diagnostic/diagnostic-manager.cpp b/low-can-binding/diagnostic/diagnostic-manager.cpp index 2b7fa9ba..91dba470 100644 --- a/low-can-binding/diagnostic/diagnostic-manager.cpp +++ b/low-can-binding/diagnostic/diagnostic-manager.cpp @@ -256,7 +256,7 @@ active_diagnostic_request_t* diagnostic_manager_t::find_recurring_request(Diagno if(entry != nullptr) { if(diagnostic_request_equals(&entry->get_handle()->request, &request)) - {return entry;} + return entry; } } return nullptr; @@ -390,7 +390,7 @@ active_diagnostic_request_t* diagnostic_manager_t::add_recurring_request(Diagnos } } else - { AFB_DEBUG("Can't add request, one already exists with same key");} + AFB_DEBUG("Can't add request, one already exists with same key"); return entry; } @@ -409,9 +409,7 @@ openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_response(active_dia found_signals = utils::signals_manager_t::instance().find_signals(build_DynamicField((double) adr->get_pid())); if(adr->get_decoder() != nullptr) - { value = adr->get_decoder()(&response, value); - } if((response.success && adr->get_name().size()) > 0) { @@ -440,9 +438,7 @@ openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_response(active_dia } if(adr->get_callback() != nullptr) - { adr->get_callback()(adr, &response, value); - } // Reset the completed flag handle to make sure that it will be reprocessed the next time. adr->get_handle()->success = false; diff --git a/low-can-binding/utils/converter.cpp b/low-can-binding/utils/converter.cpp index 5cfc8f5c..e3db7f33 100644 --- a/low-can-binding/utils/converter.cpp +++ b/low-can-binding/utils/converter.cpp @@ -32,9 +32,8 @@ std::string converter_t::to_hex(const 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(); } @@ -49,10 +48,10 @@ std::string converter_t::to_hex(const uint8_t data[], const size_t length) * @param new_start_bit The first bit of the signal in the frame * @param new_end_bit The last bit of the signal in the frame */ -void converter_t::signal_to_bits_bytes(uint32_t bit_position, uint32_t bit_size, int &new_start_byte, int &new_end_byte, int &new_start_bit, int &new_end_bit) +void converter_t::signal_to_bits_bytes(uint32_t bit_position, uint32_t bit_size, int &new_start_byte, int &new_end_byte, uint8_t &new_start_bit, uint8_t &new_end_bit) { new_start_byte = bit_position >> 3; new_start_bit = bit_position % 8; new_end_byte = (bit_position + bit_size - 1) >> 3; new_end_bit = (bit_position + bit_size - 1) % 8; -}
\ No newline at end of file +} diff --git a/low-can-binding/utils/converter.hpp b/low-can-binding/utils/converter.hpp index f388fd0a..d24096a6 100644 --- a/low-can-binding/utils/converter.hpp +++ b/low-can-binding/utils/converter.hpp @@ -23,5 +23,5 @@ class converter_t { public: static std::string to_hex(const uint8_t data[], const size_t length); - static void signal_to_bits_bytes(uint32_t bit_position, uint32_t bit_size, int &new_start_byte, int &new_end_byte, int &new_start_bit, int &new_end_bit); + static void signal_to_bits_bytes(uint32_t bit_position, uint32_t bit_size, int &new_start_byte, int &new_end_byte, uint8_t &new_start_bit, uint8_t &new_end_bit); }; diff --git a/low-can-binding/utils/openxc-utils.cpp b/low-can-binding/utils/openxc-utils.cpp index db19d1f3..e52676e1 100644 --- a/low-can-binding/utils/openxc-utils.cpp +++ b/low-can-binding/utils/openxc-utils.cpp @@ -237,9 +237,7 @@ const openxc_DynamicField build_DynamicField(std::vector<uint8_t> &array) for(int i=0;i<size;i++) - { d.bytes_value[i] = array[i]; - } return d; } diff --git a/low-can-binding/utils/socketcan-isotp.cpp b/low-can-binding/utils/socketcan-isotp.cpp index 1aab9afa..a3792a70 100644 --- a/low-can-binding/utils/socketcan-isotp.cpp +++ b/low-can-binding/utils/socketcan-isotp.cpp @@ -60,9 +60,7 @@ namespace utils } if(define_tx_address(device_name,rx_id,tx_id) < 0) - { return -1; - } struct can_isotp_options opts; memset(&opts,0,sizeof(opts)); @@ -100,9 +98,7 @@ namespace utils std::vector<uint8_t> data; for (int i=0; i < nbytes; i++) - { data.push_back(msg[i]); - } std::string data_string; data_string = converter_t::to_hex(msg,nbytes); @@ -138,9 +134,7 @@ namespace utils } if(ret != size) - { AFB_WARNING("ISOTP wrote only %zd byte",ret); - } } else { @@ -171,9 +165,7 @@ namespace utils close(); } else - { tx_address_.can_ifindex = ifr.ifr_ifindex; - } tx_address_.can_family = AF_CAN; @@ -188,4 +180,4 @@ namespace utils return 0; } -}
\ No newline at end of file +} 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 df994f59..83ba71a3 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939-addressclaiming.cpp @@ -139,9 +139,8 @@ namespace utils } else { - for (int i = start_addr; i <= end_addr; i++) { + for (int i = start_addr; i <= end_addr; i++) table_j1939_address_[i] = std::make_pair(0,true); - } } } } @@ -187,9 +186,7 @@ namespace utils if(table_j1939_address_[i].second && i!=current_address_) { if( table_j1939_address_[i].first >= htole64(J1939_NAME_ECU) || table_j1939_address_[i].first == 0) - { return (uint8_t) i; - } } } return J1939_IDLE_ADDR; @@ -344,9 +341,8 @@ namespace utils int ret = sendto(socket_, dat, sizeof(dat), 0, (const struct sockaddr *)&peername, sizeof(peername)); if(ret < 0) - { AFB_ERROR("Error pgn_request()"); - } + return ret; } */ @@ -362,9 +358,7 @@ namespace utils for(int i = 0; i < J1939_IDLE_ADDR; i++) { if(table_j1939_address_[i].first == name) - { return (uint8_t) i; - } } return J1939_IDLE_ADDR; } @@ -411,4 +405,4 @@ namespace utils return claiming_state_; } -}
\ No newline at end of file +} 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 b2f17c6e..4fd2b264 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939-data.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939-data.cpp @@ -35,9 +35,8 @@ namespace utils 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; diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp index d3996d4c..ea68f20a 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp @@ -51,12 +51,9 @@ namespace utils { filter.name = name; if(name_mask != J1939_NO_NAME) - { filter.name_mask = name_mask; - } else - { + else filter.name_mask = ~0ULL; - } ++filter_on; } @@ -64,30 +61,25 @@ namespace utils { filter.addr = addr; if(addr_mask != J1939_NO_ADDR) - { filter.addr_mask = addr_mask; - } else - { + else filter.addr_mask = ~0; - } + ++filter_on; } if (pgn <= J1939_PGN_MAX) { filter.pgn = pgn; if(pgn_mask != J1939_NO_PGN) - { filter.pgn_mask = pgn_mask; - } else - { + else filter.pgn_mask = ~0; - } + ++filter_on; } + if(filter_on) - { setopt(SOL_CAN_J1939, SO_J1939_FILTER, &filter, sizeof(filter)); - } } /** @@ -137,32 +129,18 @@ namespace utils if(addr <= 0 || addr >= UINT8_MAX ) - { tx_address_.can_addr.j1939.addr = J1939_NO_ADDR; - } else - { tx_address_.can_addr.j1939.addr = addr; - } - if(name <= 0 || name >= UINT64_MAX ) - { tx_address_.can_addr.j1939.name = J1939_NO_NAME; - } else - { tx_address_.can_addr.j1939.name = name; - } if(pgn <= 0 || pgn > J1939_PGN_MAX) - { tx_address_.can_addr.j1939.pgn = J1939_NO_PGN; - } else - { tx_address_.can_addr.j1939.pgn = pgn; - } - } @@ -229,9 +207,8 @@ namespace utils ssize_t nbytes = recvfrom(socket_, &data, sizeof(data), flag, (struct sockaddr *)&peername, &peernamelen); if(nbytes < 0) - { return nullptr; - } + //AFB_DEBUG("Data available: %i bytes read", (int)nbytes); struct timeval tv; @@ -270,9 +247,7 @@ namespace utils uint8_t data[jm.get_data_vector().size()]; for(int i=0; i<jm.get_data_vector().size(); i++) - { data[i] = jm.get_data_vector()[i]; - } if (sendto(socket_, &data, sizeof(data), 0, (const struct sockaddr *)&sockname, sizeof(sockname)) < 0) { |