From fee3b49099fb39731e15f9e26ad5a873bc109f59 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 26 Nov 2019 16:19:35 +0100 Subject: Replace all enum types with masks This commit allows to change all enum types by masks. Now to implement new protocol you don't need to add more attribute in class. All can be contained in the flags field. Bug-AGL : SPEC-2779 Bug-AGL: SPEC-2976 Change-Id: I814d0052139be5d5efefc9ff1b4b558f46b85e90 Signed-off-by: Arthur Guyader Signed-off-by: Romain Forlot --- low-can-binding/binding/application-generated.cpp | 50 +++++++++++----------- low-can-binding/binding/low-can-cb.cpp | 40 ++++++++--------- low-can-binding/binding/low-can-subscription.cpp | 49 +++++++++++---------- low-can-binding/binding/low-can-subscription.hpp | 2 +- low-can-binding/can/can-encoder.cpp | 23 ++++++++-- low-can-binding/can/message-definition.cpp | 27 ++++-------- low-can-binding/can/message-definition.hpp | 13 +++--- low-can-binding/can/message/can-message.cpp | 22 +++++----- low-can-binding/can/message/can-message.hpp | 3 +- low-can-binding/can/message/j1939-message.cpp | 18 +++----- low-can-binding/can/message/j1939-message.hpp | 4 +- low-can-binding/can/message/message.cpp | 26 +++-------- low-can-binding/can/message/message.hpp | 23 +++++----- low-can-binding/diagnostic/diagnostic-manager.cpp | 2 +- .../utils/socketcan-j1939/socketcan-j1939.cpp | 2 +- low-can-binding/utils/socketcan.hpp | 11 ----- 16 files changed, 143 insertions(+), 172 deletions(-) (limited to 'low-can-binding') diff --git a/low-can-binding/binding/application-generated.cpp b/low-can-binding/binding/application-generated.cpp index 65f72cdf..47fdafa5 100644 --- a/low-can-binding/binding/application-generated.cpp +++ b/low-can-binding/binding/application-generated.cpp @@ -7,7 +7,7 @@ application_t::application_t() , message_set_{ {std::make_shared(message_set_t{0,"AGL Virtual Car", { // beginning message_definition_ vector - {std::make_shared(message_definition_t{"ls",0x30,"",0,false,message_format_t::EXTENDED,frequency_clock_t(5.00000f),true, + {std::make_shared(message_definition_t{"ls",0x30,"",8,4,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "hvac.fan.speed",// generic_name @@ -22,7 +22,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable nullptr,// decoder nullptr,// encoder false,// received @@ -99,7 +99,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"hs",0x3D9,"",0,true,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"hs",0x3D9,"",8,2050,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "engine.speed",// generic_name @@ -169,7 +169,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"hs",0x3E9,"",0,false,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"hs",0x3E9,"",8,2,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "vehicle.average.speed",// generic_name @@ -195,7 +195,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"hs",0x4D1,"",0,false,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"hs",0x4D1,"",8,2,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "engine.oil.temp",// generic_name @@ -210,7 +210,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable nullptr,// decoder nullptr,// encoder false,// received @@ -232,7 +232,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -243,7 +243,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"hs",0x620,"",0,false,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"hs",0x620,"",8,2,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "doors.boot.open",// generic_name @@ -258,7 +258,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -280,7 +280,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -302,7 +302,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -324,7 +324,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -346,7 +346,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -357,7 +357,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"hs",0x799,"",0,false,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"hs",0x799,"",8,2,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "windows.front_left.open",// generic_name @@ -372,7 +372,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -394,7 +394,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -416,7 +416,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -438,7 +438,7 @@ application_t::application_t() false,// force_send_changed { },// states - false,// writable + true,// writable decoder_t::decode_boolean,// decoder nullptr,// encoder false,// received @@ -450,7 +450,7 @@ application_t::application_t() } // end signals vector })} // end message_definition entry #ifdef USE_FEATURE_J1939 -, {std::make_shared(message_definition_t{"j1939",61442,"ETC1",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"j1939",61442,"ETC1",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "Eng.Momentary.Overspeed.Enable",// generic_name @@ -724,7 +724,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"j1939",61444,"EEC1",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"j1939",61444,"EEC1",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "Actl.Eng.Prcnt.Trque.High.Resolution",// generic_name @@ -934,7 +934,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"j1939",61449,"VDC2",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"j1939",61449,"VDC2",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "Lateral.Acceleration",// generic_name @@ -1074,7 +1074,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"j1939",65215,"EBC2",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"j1939",65215,"EBC2",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "Front.Axle.Speed",// generic_name @@ -1232,7 +1232,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"j1939",65253,"HOURS",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"j1939",65253,"HOURS",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "Eng.Total.Hours.Of.Operation",// generic_name @@ -1280,7 +1280,7 @@ application_t::application_t() })} } // end signals vector })} // end message_definition entry -, {std::make_shared(message_definition_t{"j1939",65262,"ET1",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared(message_definition_t{"j1939",65262,"ET1",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared (signal_t{ "Eng.Coolant.Temp",// generic_name @@ -1701,5 +1701,3 @@ const std::string application_t::get_diagnostic_bus() const { return "hs"; } - - diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp index 32fc83d2..c677b172 100644 --- a/low-can-binding/binding/low-can-cb.cpp +++ b/low-can-binding/binding/low-can-cb.cpp @@ -102,7 +102,7 @@ int read_message(sd_event_source *event_source, int fd, uint32_t revents, void * std::shared_ptr message = s->read_message(); // Sure we got a valid CAN message ? - if (! message->get_id() == 0 && ! message->get_length() == 0 && message->get_msg_format() != message_format_t::INVALID) + if (! message->get_id() == 0 && ! message->get_length() == 0 && !(message->get_flags()&INVALID_FLAG)) { push_n_notify(message); } @@ -515,7 +515,7 @@ 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, socket_type type) +static int send_message(message_t *message, const std::string& bus_name, uint32_t flags) { if(bus_name.empty()) { @@ -530,12 +530,12 @@ static int send_message(message_t *message, const std::string& bus_name, socket_ } - if(type == socket_type::BCM) + if(flags&BCM_PROTOCOL) { return low_can_subscription_t::tx_send(*cd[bus_name], message, bus_name); } #ifdef USE_FEATURE_J1939 - else if(type == socket_type::J1939) + else if(flags&J1939_PROTOCOL) { return low_can_subscription_t::j1939_send(*cd[bus_name], message, bus_name); } @@ -547,7 +547,7 @@ static int send_message(message_t *message, const std::string& bus_name, socket_ } -static void write_raw_frame(afb_req_t request, const std::string& bus_name, message_t *message, struct json_object *can_data, socket_type type) +static void write_raw_frame(afb_req_t request, const std::string& bus_name, message_t *message, struct json_object *can_data, uint32_t flags) { struct utils::signals_found sf; @@ -557,7 +557,7 @@ static void write_raw_frame(afb_req_t request, const std::string& bus_name, mess if( !sf.signals.empty() ) { AFB_DEBUG("ID WRITE RAW : %d",sf.signals[0]->get_message()->get_id()); - if(type == socket_type::BCM) + if(flags&BCM_PROTOCOL) { if(sf.signals[0]->get_message()->is_fd()) { @@ -573,12 +573,12 @@ static void write_raw_frame(afb_req_t request, const std::string& bus_name, mess } if((message->get_length()> 0 && ( - ((type == socket_type::BCM) && ( + ((flags&BCM_PROTOCOL) && ( (message->get_length() <= CANFD_MAX_DLEN * MAX_BCM_CAN_FRAMES && message->get_flags() & CAN_FD_FRAME) || (message->get_length() <= CAN_MAX_DLEN * MAX_BCM_CAN_FRAMES && !(message->get_flags() & CAN_FD_FRAME)) )) #ifdef USE_FEATURE_J1939 - || (message->get_length() <= J1939_MAX_DLEN && type == socket_type::J1939) + || (message->get_length() <= J1939_MAX_DLEN && flags&J1939_PROTOCOL) #endif ))) { @@ -593,11 +593,11 @@ static void write_raw_frame(afb_req_t request, const std::string& bus_name, mess } else { - if(type == socket_type::BCM) + if(flags&BCM_PROTOCOL) { afb_req_fail(request, "Invalid", "Frame BCM"); } - else if(type == socket_type::J1939) + else if(flags&J1939_PROTOCOL) { afb_req_fail(request, "Invalid", "Frame J1939"); } @@ -608,7 +608,7 @@ static void write_raw_frame(afb_req_t request, const std::string& bus_name, mess return; } - if(! send_message(message, application_t::instance().get_can_bus_manager().get_can_device_name(bus_name),type)) + if(! send_message(message, application_t::instance().get_can_bus_manager().get_can_device_name(bus_name),flags)) { afb_req_success(request, nullptr, "Message correctly sent"); } @@ -639,8 +639,8 @@ static void write_frame(afb_req_t request, const std::string& bus_name, json_obj "can_dlc", &length, "can_data", &can_data)) { - message = new can_message_t(0,(uint32_t)id,(uint32_t)length,message_format_t::STANDARD,false,0,data,0); - write_raw_frame(request,bus_name,message,can_data,socket_type::BCM); + message = new can_message_t(0,(uint32_t)id,(uint32_t)length,false,0,data,0); + write_raw_frame(request,bus_name,message,can_data,BCM_PROTOCOL); } #ifdef USE_FEATURE_J1939 else if(!wrap_json_unpack(json_value, "{si, si, so !}", @@ -648,8 +648,8 @@ static void write_frame(afb_req_t request, const std::string& bus_name, json_obj "length", &length, "data", &can_data)) { - message = new j1939_message_t(J1939_MAX_DLEN,(uint32_t)length,message_format_t::J1939,data,0,J1939_NO_NAME,(pgn_t)id,J1939_NO_ADDR); - write_raw_frame(request,bus_name,message,can_data,socket_type::J1939); + message = new j1939_message_t((uint32_t)length,data,0,J1939_NO_NAME,(pgn_t)id,J1939_NO_ADDR); + write_raw_frame(request,bus_name,message,can_data,J1939_PROTOCOL); } #endif else @@ -690,21 +690,21 @@ static void write_signal(afb_req_t request, const std::string& name, json_object encoder(*sig, dynafield_value, &send) : encoder_t::encode_DynamicField(*sig, dynafield_value, &send); - socket_type type = socket_type::INVALID; + uint32_t flags = INVALID_FLAG; if(sig->get_message()->is_j1939()) { - type = socket_type::J1939; + flags = J1939_PROTOCOL; } else { - type = socket_type::BCM; + 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(), type) && send) + if(! send_message(message, sig->get_message()->get_bus_device_name(), flags) && send) { afb_req_success(request, nullptr, "Message correctly sent"); } @@ -912,7 +912,7 @@ int init_binding(afb_api_t api) ret = low_can_subscription_t::open_socket(*low_can_j1939, message_definition->get_bus_device_name(), - socket_type::J1939_ADDR_CLAIM); + J1939_ADDR_CLAIM_PROTOCOL); if(ret < 0) { AFB_ERROR("Error open socket address claiming for j1939 protocol"); diff --git a/low-can-binding/binding/low-can-subscription.cpp b/low-can-binding/binding/low-can-subscription.cpp index edc0a0b4..0f4bf0c9 100644 --- a/low-can-binding/binding/low-can-subscription.cpp +++ b/low-can-binding/binding/low-can-subscription.cpp @@ -241,14 +241,12 @@ void low_can_subscription_t::set_index(int index) /// it will open the socket with the required CAN bus device name. /// /// @return INVALID_SOCKET on failure, else positive integer -int low_can_subscription_t::open_socket(low_can_subscription_t &subscription, const std::string& bus_name, socket_type type) +int low_can_subscription_t::open_socket(low_can_subscription_t &subscription, const std::string& bus_name, uint32_t flags) { int ret = -1; if(! subscription.socket_) { - switch (type) - { - case socket_type::BCM: + if(flags&BCM_PROTOCOL) { if( subscription.signal_ != nullptr) { @@ -266,10 +264,9 @@ int low_can_subscription_t::open_socket(low_can_subscription_t &subscription, co ret = subscription.socket_->open(bus_name); } subscription.index_ = (int)subscription.socket_->socket(); - break; } #ifdef USE_FEATURE_J1939 - case socket_type::J1939_ADDR_CLAIM: + else if(flags&J1939_ADDR_CLAIM_PROTOCOL) { pgn_t pgn = J1939_NO_PGN; if(!bus_name.empty()) @@ -279,9 +276,8 @@ int low_can_subscription_t::open_socket(low_can_subscription_t &subscription, co subscription.socket_ = socket; } subscription.index_ = (int)subscription.socket_->socket(); - break; } - case socket_type::J1939: + else if(flags&J1939_PROTOCOL) { pgn_t pgn = J1939_NO_PGN; if(subscription.signal_ != nullptr) @@ -298,15 +294,12 @@ int low_can_subscription_t::open_socket(low_can_subscription_t &subscription, co subscription.socket_ = socket; } subscription.index_ = (int)subscription.socket_->socket(); - break; } #endif - default: + else { AFB_ERROR("Socket format not supported"); return INVALID_SOCKET; - break; - } } } else{ @@ -373,7 +366,7 @@ int low_can_subscription_t::create_rx_filter_j1939(low_can_subscription_t &subsc subscription.signal_= sig; // Make sure that socket is opened. - if(open_socket(subscription,"",socket_type::J1939) < 0) + if(open_socket(subscription,"",J1939_PROTOCOL) < 0) { return -1; } @@ -387,7 +380,7 @@ int low_can_subscription_t::create_rx_filter_j1939(low_can_subscription_t &subsc /// @return 0 if ok else -1 int low_can_subscription_t::create_rx_filter_can(low_can_subscription_t &subscription, std::shared_ptr sig) { - uint32_t flags; + uint32_t flags_bcm; float val; struct timeval freq, timeout = {0, 0}; struct canfd_frame cfd; @@ -414,21 +407,33 @@ int low_can_subscription_t::create_rx_filter_can(low_can_subscription_t &subscri if (is_fd) { - flags = SETTIMER|RX_NO_AUTOTIMER|CAN_FD_FRAME; + flags_bcm = SETTIMER|RX_NO_AUTOTIMER|CAN_FD_FRAME; cfd.len = CANFD_MAX_DLEN; - cm = can_message_t(CANFD_MAX_DLEN,sig->get_message()->get_id(),length_msg,sig->get_message()->get_format(),false,CAN_FD_FRAME,data,0); + cm = can_message_t( CANFD_MAX_DLEN, + sig->get_message()->get_id(), + length_msg, + false, + sig->get_message()->get_flags(), + data, + 0); } else { - flags = SETTIMER|RX_NO_AUTOTIMER; + flags_bcm = SETTIMER|RX_NO_AUTOTIMER; cfd.len = CAN_MAX_DLEN; - cm = can_message_t(CAN_MAX_DLEN,sig->get_message()->get_id(),length_msg,sig->get_message()->get_format(),false,0,data,0); + cm = can_message_t( CAN_MAX_DLEN, + sig->get_message()->get_id(), + length_msg, + false, + sig->get_message()->get_flags(), + data, + 0); } frequency_clock_t f = subscription.event_filter_.frequency == 0 ? subscription.signal_->get_frequency() : frequency_clock_t(subscription.event_filter_.frequency); freq = f.get_timeval_from_period(); - struct bcm_msg bcm_msg = subscription.make_bcm_head(RX_SETUP, subscription.signal_->get_message()->get_id(), flags, timeout, freq); + struct bcm_msg bcm_msg = subscription.make_bcm_head(RX_SETUP, subscription.signal_->get_message()->get_id(), flags_bcm, timeout, freq); std::vector cfd_vect = cm.convert_to_canfd_frame_vector(); @@ -499,7 +504,7 @@ int low_can_subscription_t::create_rx_filter(std::shared_ptr cfd_vect = cm->convert_to_canfd_frame_vector(); - if(subscription.open_socket(subscription, bus_name,socket_type::BCM) < 0) + if(subscription.open_socket(subscription, bus_name, BCM_PROTOCOL) < 0) { return -1; } @@ -586,7 +591,7 @@ int low_can_subscription_t::j1939_send(low_can_subscription_t &subscription, mes //struct bcm_msg bcm_msg = subscription.make_bcm_head(TX_SEND, cfd.can_id); //subscription.add_one_bcm_frame(cfd, bcm_msg); - if(subscription.open_socket(subscription, bus_name, socket_type::J1939) < 0) + if(subscription.open_socket(subscription, bus_name, J1939_PROTOCOL) < 0) { return -1; } diff --git a/low-can-binding/binding/low-can-subscription.hpp b/low-can-binding/binding/low-can-subscription.hpp index b5d4f7aa..b152e4b2 100644 --- a/low-can-binding/binding/low-can-subscription.hpp +++ b/low-can-binding/binding/low-can-subscription.hpp @@ -95,7 +95,7 @@ public: static void add_one_bcm_frame(struct canfd_frame& cfd, struct bcm_msg& bcm_msg); static void remove_last_bcm_frame(struct bcm_msg& bcm_msg); - static int open_socket(low_can_subscription_t &subscription, const std::string& bus_name = "", socket_type type = socket_type::INVALID); + static int open_socket(low_can_subscription_t &subscription, const std::string& bus_name = "", uint32_t flags = INVALID_FLAG); int create_rx_filter(std::shared_ptr sig); int create_rx_filter(std::shared_ptr sig); diff --git a/low-can-binding/can/can-encoder.cpp b/low-can-binding/can/can-encoder.cpp index 44b5d9b2..37a7b246 100644 --- a/low-can-binding/can/can-encoder.cpp +++ b/low-can-binding/can/can-encoder.cpp @@ -174,20 +174,37 @@ message_t* encoder_t::build_message(const std::shared_ptr& signal, uin std::vector data; if(signal->get_message()->is_fd()) { - message = new can_message_t(CANFD_MAX_DLEN,signal->get_message()->get_id(),CANFD_MAX_DLEN,signal->get_message()->get_format(),false,CAN_FD_FRAME,data,0); + message = new can_message_t( CANFD_MAX_DLEN, + signal->get_message()->get_id(), + CANFD_MAX_DLEN, + false, + signal->get_message()->get_flags(), + data, + 0); return build_frame(signal,value,message, factor, offset); } #ifdef USE_FEATURE_J1939 else if(signal->get_message()->is_j1939()) { - message = new j1939_message_t(J1939_MAX_DLEN,signal->get_message()->get_length(),signal->get_message()->get_format(),data,0,J1939_NO_NAME,signal->get_message()->get_id(),J1939_NO_ADDR); + message = new j1939_message_t( signal->get_message()->get_length(), + data, + 0, + J1939_NO_NAME, + signal->get_message()->get_id(), + J1939_NO_ADDR); return build_frame(signal,value,message, factor, offset); } #endif else { - message = new can_message_t(CAN_MAX_DLEN,signal->get_message()->get_id(),CAN_MAX_DLEN,signal->get_message()->get_format(),false,0,data,0); + message = new can_message_t(CAN_MAX_DLEN, + signal->get_message()->get_id(), + CAN_MAX_DLEN, + false, + signal->get_message()->get_flags(), + data, + 0); return build_frame(signal,value,message, factor, offset); } } diff --git a/low-can-binding/can/message-definition.cpp b/low-can-binding/can/message-definition.cpp index 064b2c17..407ad750 100644 --- a/low-can-binding/can/message-definition.cpp +++ b/low-can-binding/can/message-definition.cpp @@ -22,16 +22,14 @@ message_definition_t::message_definition_t( const std::string bus, uint32_t id, - bool is_fd, - message_format_t format, + uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed, const std::vector >& signals) : parent_{nullptr}, bus_{bus}, id_{id}, - is_fd_(is_fd), - format_{format}, + flags_{flags}, frequency_clock_{frequency_clock}, force_send_changed_{force_send_changed}, last_value_{CAN_MESSAGE_SIZE}, @@ -42,8 +40,7 @@ message_definition_t::message_definition_t(const std::string bus, uint32_t id, const std::string name, uint32_t length, - bool is_fd, - message_format_t format, + uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed, const std::vector >& signals) @@ -52,8 +49,7 @@ message_definition_t::message_definition_t(const std::string bus, id_{id}, name_{name}, length_{length}, - is_fd_(is_fd), - format_{format}, + flags_{flags}, frequency_clock_{frequency_clock}, force_send_changed_{force_send_changed}, last_value_{CAN_MESSAGE_SIZE}, @@ -73,19 +69,12 @@ uint32_t message_definition_t::get_id() const bool message_definition_t::is_fd() const { - return is_fd_; + return (flags_&FD_FRAME); } bool message_definition_t::is_j1939() const { - if(format_ == message_format_t::J1939) - { - return true; - } - else - { - return false; - } + return (flags_&J1939_PROTOCOL); } std::vector>& message_definition_t::get_signals() @@ -108,7 +97,7 @@ uint32_t message_definition_t::get_length() const return length_; } -message_format_t message_definition_t::get_format() const +uint32_t message_definition_t::get_flags() const { - return format_; + return flags_; } \ No newline at end of file diff --git a/low-can-binding/can/message-definition.hpp b/low-can-binding/can/message-definition.hpp index f39bb71e..13ae2289 100644 --- a/low-can-binding/can/message-definition.hpp +++ b/low-can-binding/can/message-definition.hpp @@ -45,8 +45,7 @@ private: uint32_t id_; ///< id_ - The ID or the PGN (if j1939) of the message.*/ std::string name_; ///< name_ - J1939 PGN name uint32_t length_; ///< length_ - Message data length in bytes. For J1939 message, this is the expected data size - bool is_fd_; /*!< uses_fd_ - Flags to enable an FD CAN message communication*/ - message_format_t format_; ///< format_ - the format of the message's ID.*/ + uint32_t flags_; ///< format_ - the format of the message's ID.*/ frequency_clock_t frequency_clock_; ///< clock_ - an optional frequency clock to control the output of this /// message, if sent raw, or simply to mark the max frequency for custom /// handlers to retrieve.*/ @@ -61,11 +60,10 @@ public: //message_definition_t(const message_definition_t& b); message_definition_t(const std::string bus); message_definition_t(const std::string bus, uint32_t id, frequency_clock_t frequency_clock, bool force_send_changed); - message_definition_t(const std::string bus, uint32_t id, message_format_t format, frequency_clock_t frequency_clock, bool force_send_changed); + message_definition_t(const std::string bus, uint32_t id, uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed); message_definition_t(const std::string bus, uint32_t id, - bool is_fd, - message_format_t format, + uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed, const std::vector >& signals); @@ -73,8 +71,7 @@ public: uint32_t id, std::string name, uint32_t length, - bool is_fd, - message_format_t format, + uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed, const std::vector >& signals); @@ -87,7 +84,7 @@ public: bool is_j1939() const; std::vector>& get_signals(); uint32_t get_length() const; - message_format_t get_format() const; + uint32_t get_flags() const; void set_parent(std::shared_ptr parent); void set_last_value(std::shared_ptr m); diff --git a/low-can-binding/can/message/can-message.cpp b/low-can-binding/can/message/can-message.cpp index 8a04992e..0ef693c7 100644 --- a/low-can-binding/can/message/can-message.cpp +++ b/low-can-binding/can/message/can-message.cpp @@ -35,12 +35,11 @@ can_message_t::can_message_t() can_message_t::can_message_t(uint32_t maxdlen, uint32_t id, uint32_t length, - message_format_t format, bool rtr_flag, uint32_t flags, std::vector& data, uint64_t timestamp) - : message_t(maxdlen, length, format, data, timestamp, flags), + : message_t(maxdlen, length, flags, data, timestamp), id_{id}, rtr_flag_{rtr_flag} {} @@ -62,7 +61,7 @@ uint32_t can_message_t::get_id() const /// @return True if object correctly initialized and false if not. bool can_message_t::is_correct_to_send() { - if (id_ != 0 && length_ != 0 && format_ != message_format_t::INVALID) + if (id_ != 0 && length_ != 0 && !(flags_&INVALID_FLAG)) { int i; for(i=0;i can_message_t::convert_from_frame(const struct canfd_frame& frame, size_t nbytes, uint64_t timestamp) { uint32_t maxdlen = 0, length = 0; - uint8_t flags = 0; + uint32_t flags = 0; uint32_t id; - message_format_t format; bool rtr_flag; std::vector data; @@ -106,17 +104,17 @@ std::shared_ptr can_message_t::convert_from_frame(const struct ca if (frame.can_id & CAN_ERR_FLAG) { - format = message_format_t::INVALID; + flags = flags|INVALID_FLAG; id = frame.can_id & (CAN_ERR_MASK|CAN_ERR_FLAG); } else if (frame.can_id & CAN_EFF_FLAG) { - format = message_format_t::EXTENDED; + flags = flags|EXTENDED_ID; id = frame.can_id & CAN_EFF_MASK; } else { - format = message_format_t::STANDARD; + flags = flags|STANDARD_ID; id = frame.can_id & CAN_SFF_MASK; } @@ -140,8 +138,8 @@ std::shared_ptr can_message_t::convert_from_frame(const struct ca length = (frame.len > maxdlen) ? maxdlen : frame.len; /* Flags field only present for CAN FD frames*/ - if(maxdlen == CANFD_MAX_DLEN) - flags = frame.flags & 0xF; + /*if(maxdlen == CANFD_MAX_DLEN) + flags = frame.flags & 0xF;*/ if (data.capacity() < maxdlen) data.reserve(maxdlen); @@ -155,10 +153,10 @@ std::shared_ptr can_message_t::convert_from_frame(const struct ca }; AFB_DEBUG("Found id: %X, format: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", - id, (uint8_t)format, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); + id, (uint32_t)flags, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); } - return std::make_shared(can_message_t(maxdlen, id, length, format, rtr_flag, flags, data, timestamp)); + return std::make_shared(can_message_t(maxdlen, id, length, rtr_flag, flags, data, timestamp)); } /// @brief Take all initialized class members and build a diff --git a/low-can-binding/can/message/can-message.hpp b/low-can-binding/can/message/can-message.hpp index 75e65c67..769899ea 100644 --- a/low-can-binding/can/message/can-message.hpp +++ b/low-can-binding/can/message/can-message.hpp @@ -39,8 +39,7 @@ class can_message_t : public message_t { public: can_message_t(); - can_message_t(uint32_t maxdlen, uint32_t id, uint32_t length, message_format_t format, bool rtr_flag_, uint32_t flags, std::vector& data, uint64_t timestamp); - + can_message_t(uint32_t maxdlen, uint32_t id, uint32_t length, bool rtr_flag_, uint32_t flags, std::vector& data, uint64_t timestamp); uint32_t get_id() const; static std::shared_ptr convert_from_frame(const canfd_frame& frame, size_t nbytes, uint64_t timestamp); diff --git a/low-can-binding/can/message/j1939-message.cpp b/low-can-binding/can/message/j1939-message.cpp index 2d600a1e..ec65cba4 100644 --- a/low-can-binding/can/message/j1939-message.cpp +++ b/low-can-binding/can/message/j1939-message.cpp @@ -45,13 +45,12 @@ j1939_message_t::j1939_message_t(): * @param addr The address of the message */ j1939_message_t::j1939_message_t(uint32_t length, - message_format_t format, std::vector& data, uint64_t timestamp, name_t name, pgn_t pgn, uint8_t addr): - message_t(J1939_MAX_DLEN,length, format, data, timestamp, 0), + message_t(J1939_MAX_DLEN, length, J1939_PROTOCOL, data, timestamp), name_{name}, pgn_{pgn}, addr_{addr} @@ -99,18 +98,13 @@ std::shared_ptr j1939_message_t::convert_from_addr(struct socka { int i; uint32_t length = 0; - message_format_t format; + uint32_t flags; std::vector data_vector; if(nbytes > J1939_MAX_DLEN) { AFB_DEBUG("Unsupported j1939 frame"); - format = message_format_t::INVALID; - } - else - { - //AFB_DEBUG("Got a j1939 frame"); - format = message_format_t::J1939; + return std::make_shared(j1939_message_t()); } length = (uint32_t) nbytes; @@ -126,10 +120,10 @@ std::shared_ptr j1939_message_t::convert_from_addr(struct socka data_vector.push_back(data[i]); }; - AFB_DEBUG("Found pgn: %X, format: %X, length: %X, data %s", - addr.can_addr.j1939.pgn, (uint8_t)format, length, data_string.c_str()); + AFB_DEBUG("Found pgn: %X, length: %X, data %s", + addr.can_addr.j1939.pgn, length, data_string.c_str()); - return std::make_shared(j1939_message_t(J1939_MAX_DLEN,length, format, data_vector, timestamp,addr.can_addr.j1939.name,addr.can_addr.j1939.pgn,addr.can_addr.j1939.addr)); + return std::make_shared(j1939_message_t(length, data_vector, timestamp,addr.can_addr.j1939.name,addr.can_addr.j1939.pgn,addr.can_addr.j1939.addr)); } /// @brief Test if members pgn_ and length are set. diff --git a/low-can-binding/can/message/j1939-message.hpp b/low-can-binding/can/message/j1939-message.hpp index 0d3736f1..9e9cea4a 100644 --- a/low-can-binding/can/message/j1939-message.hpp +++ b/low-can-binding/can/message/j1939-message.hpp @@ -67,7 +67,7 @@ class j1939_message_t : public message_t public: j1939_message_t(); - j1939_message_t(uint32_t maxdlen, uint32_t length, message_format_t format, std::vector& data, uint64_t timestamp, name_t name, pgn_t pgn, uint8_t addr); + j1939_message_t(uint32_t length, std::vector& data, uint64_t timestamp, name_t name, pgn_t pgn, uint8_t addr); uint64_t get_name() const; uint32_t get_pgn() const; uint8_t get_addr() const; @@ -78,4 +78,4 @@ class j1939_message_t : public message_t struct sockaddr_can get_sockname(); void set_sockname(struct sockaddr_can sockname); void set_sockname(pgn_t pgn, name_t name, uint8_t addr); -}; +}; \ No newline at end of file diff --git a/low-can-binding/can/message/message.cpp b/low-can-binding/can/message/message.cpp index 497304de..aaab99f5 100644 --- a/low-can-binding/can/message/message.cpp +++ b/low-can-binding/can/message/message.cpp @@ -28,10 +28,9 @@ message_t::message_t() : maxdlen_{0}, length_{0}, - format_{message_format_t::INVALID}, + flags_{INVALID_FLAG}, timestamp_{0}, - sub_id_{-1}, - flags_{0} + sub_id_{-1} {} /** @@ -45,17 +44,15 @@ message_t::message_t() */ message_t::message_t(uint32_t maxdlen, uint32_t length, - message_format_t format, + uint32_t flags, std::vector& data, - uint64_t timestamp, - uint32_t flags) + uint64_t timestamp) : maxdlen_{maxdlen}, length_{length}, - format_{format}, + flags_{flags}, data_{data}, timestamp_{timestamp}, - sub_id_{-1}, - flags_{flags} + sub_id_{-1} {} /** @@ -163,17 +160,6 @@ uint64_t message_t::get_timestamp() const return timestamp_; } -/** - * @brief Return the format of the message - * - * @return message_format_t The message format - */ -message_format_t message_t::get_msg_format() -{ - return format_; -} - - uint32_t message_t::get_flags() { return flags_; diff --git a/low-can-binding/can/message/message.hpp b/low-can-binding/can/message/message.hpp index 2182fe5b..6cef0185 100644 --- a/low-can-binding/can/message/message.hpp +++ b/low-can-binding/can/message/message.hpp @@ -32,16 +32,17 @@ /** - * @enum message_format_t - * @brief The ID format for a CAN message. + * FLAGS */ -enum class message_format_t { - STANDARD, ///< STANDARD - standard 11-bit CAN arbitration ID. */ - EXTENDED, ///< EXTENDED - an extended frame, with a 29-bit arbitration ID. */ - J1939, ///< J1939 - Format for j1939 messages - INVALID, ///< INVALID - INVALID code used at initialization to signify that it isn't usable'*/ -}; +#define INVALID_FLAG 0x0001 +#define STANDARD_ID 0x0002 +#define EXTENDED_ID 0x0004 +#define BCM_PROTOCOL 0x0008 +#define J1939_PROTOCOL 0x0010 +#define J1939_ADDR_CLAIM_PROTOCOL 0x0020 +#define ISOTP_PROTOCOL 0x0040 +#define FD_FRAME 0x0800 /// @class message_t /// @@ -51,15 +52,14 @@ class message_t { protected: uint32_t maxdlen_; ///< maxdlen_ - Max data length deduce from number of bytes read from the socket.*/ uint32_t length_; ///< length_ - the length of the data array. */ - message_format_t format_; ///< format_ - the format of the message's ID.*/ + uint32_t flags_; ///< format_ - the format mask of the message*/ std::vector data_; ///< data_ - The message's data field with a size of 8 which is the standard about CAN bus messages.*/ uint64_t timestamp_; ///< timestamp_ - timestamp of the received message*/ int sub_id_; ///< sub_id_ - Subscription index. */ - uint32_t flags_; ///< flags_ - flags of a CAN FD frame. Needed if we catch FD frames.*/ public: message_t(); - message_t(uint32_t maxdlen, uint32_t length, message_format_t format, std::vector& data, uint64_t timestamp, uint32_t flags); + message_t(uint32_t maxdlen, uint32_t length, uint32_t flags, std::vector& data, uint64_t timestamp); virtual ~message_t() = default; int get_sub_id() const; @@ -72,7 +72,6 @@ public: void set_data(std::vector &data); void set_sub_id(int sub_id); void set_timestamp(uint64_t timestamp); - message_format_t get_msg_format(); virtual bool is_set() = 0; virtual std::string get_debug_message() = 0; virtual uint32_t get_id() const = 0; diff --git a/low-can-binding/diagnostic/diagnostic-manager.cpp b/low-can-binding/diagnostic/diagnostic-manager.cpp index ad1f3a7f..5242c5bb 100644 --- a/low-can-binding/diagnostic/diagnostic-manager.cpp +++ b/low-can-binding/diagnostic/diagnostic-manager.cpp @@ -526,7 +526,7 @@ openxc_VehicleMessage diagnostic_manager_t::find_and_decode_adr(std::shared_ptr< /// @return True if the active diagnostic request match the response. bool diagnostic_manager_t::is_diagnostic_response(std::shared_ptr m) { - if(m->get_msg_format() == message_format_t::STANDARD || m->get_msg_format() == message_format_t::EXTENDED) + if(m->get_flags()&STANDARD_ID || m->get_flags()&EXTENDED_ID) { if (m->get_id() >= 0x7e8 && m->get_id() <= 0x7ef) return true; diff --git a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp index bb74c766..fdcfe3be 100644 --- a/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp +++ b/low-can-binding/utils/socketcan-j1939/socketcan-j1939.cpp @@ -256,7 +256,7 @@ namespace utils */ int socketcan_j1939_t::write_j1939_message(pgn_t pgn, std::vector &data, uint32_t len_data) { - j1939_message_t msg = j1939_message_t(J1939_MAX_DLEN, len_data, message_format_t::J1939, data, 0, 0, pgn, 0); + j1939_message_t msg = j1939_message_t(len_data, data, 0, 0, pgn, 0); msg.set_sockname(pgn,J1939_NO_NAME,J1939_NO_ADDR); return write_message(msg); } diff --git a/low-can-binding/utils/socketcan.hpp b/low-can-binding/utils/socketcan.hpp index 2a7077eb..6391d011 100644 --- a/low-can-binding/utils/socketcan.hpp +++ b/low-can-binding/utils/socketcan.hpp @@ -28,17 +28,6 @@ #define INVALID_SOCKET -1 -/** - * @enum socket_type - * @brief The type of socket - */ -enum class socket_type { - BCM, ///< BCM - Socket BCM - J1939_ADDR_CLAIM, ///< J1939 - Socket J1939 - J1939, ///< J1939 - Socket J1939 - INVALID -}; - namespace utils { -- cgit 1.2.3-korg