diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2019-11-26 16:19:35 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2019-11-28 16:11:47 +0100 |
commit | fee3b49099fb39731e15f9e26ad5a873bc109f59 (patch) | |
tree | f925b8b2a744d9e94cedbd460e47ba533717c36c /low-can-binding/binding | |
parent | a8d5f5d3018da0b051dad4c143c6257b2fba9fac (diff) |
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 <arthur.guyader@iot.bzh>
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding/binding')
-rw-r--r-- | low-can-binding/binding/application-generated.cpp | 50 | ||||
-rw-r--r-- | low-can-binding/binding/low-can-cb.cpp | 40 | ||||
-rw-r--r-- | low-can-binding/binding/low-can-subscription.cpp | 49 | ||||
-rw-r--r-- | low-can-binding/binding/low-can-subscription.hpp | 2 |
4 files changed, 72 insertions, 69 deletions
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>(message_set_t{0,"AGL Virtual Car", { // beginning message_definition_ vector - {std::make_shared<message_definition_t>(message_definition_t{"ls",0x30,"",0,false,message_format_t::EXTENDED,frequency_clock_t(5.00000f),true, + {std::make_shared<message_definition_t>(message_definition_t{"ls",0x30,"",8,4,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"hs",0x3D9,"",0,true,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"hs",0x3D9,"",8,2050,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"hs",0x3E9,"",0,false,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"hs",0x3E9,"",8,2,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"hs",0x4D1,"",0,false,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"hs",0x4D1,"",8,2,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"hs",0x620,"",0,false,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"hs",0x620,"",8,2,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"hs",0x799,"",0,false,message_format_t::STANDARD,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"hs",0x799,"",8,2,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"j1939",61442,"ETC1",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"j1939",61442,"ETC1",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"j1939",61444,"EEC1",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"j1939",61444,"EEC1",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"j1939",61449,"VDC2",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"j1939",61449,"VDC2",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"j1939",65215,"EBC2",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"j1939",65215,"EBC2",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"j1939",65253,"HOURS",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"j1939",65253,"HOURS",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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>(message_definition_t{"j1939",65262,"ET1",8,false,message_format_t::J1939,frequency_clock_t(5.00000f),true, +, {std::make_shared<message_definition_t>(message_definition_t{"j1939",65262,"ET1",8,18,frequency_clock_t(5.00000f),true, { // beginning signals vector {std::make_shared<signal_t> (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_t> 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<signal_t> 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<canfd_frame> cfd_vect = cm.convert_to_canfd_frame_vector(); @@ -499,7 +504,7 @@ int low_can_subscription_t::create_rx_filter(std::shared_ptr<diagnostic_message_ int low_can_subscription_t::create_rx_filter_bcm(low_can_subscription_t &subscription, struct bcm_msg& bcm_msg) { // Make sure that socket is opened. - if(subscription.open_socket(subscription,"",socket_type::BCM) < 0) + if(subscription.open_socket(subscription,"",BCM_PROTOCOL) < 0) {return -1;} // If it's not an OBD2 CAN ID then just add a simple RX_SETUP job @@ -542,7 +547,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,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<signal_t> sig); int create_rx_filter(std::shared_ptr<diagnostic_message_t> sig); |