diff options
-rw-r--r-- | low-can-binding/can/can-encoder.cpp | 111 |
1 files changed, 62 insertions, 49 deletions
diff --git a/low-can-binding/can/can-encoder.cpp b/low-can-binding/can/can-encoder.cpp index 1a5dcdc9..36be668c 100644 --- a/low-can-binding/can/can-encoder.cpp +++ b/low-can-binding/can/can-encoder.cpp @@ -167,41 +167,47 @@ message_t* encoder_t::build_message(const std::shared_ptr<signal_t>& signal, uin { message_t *message; std::vector<uint8_t> data; - if(signal->get_message()->is_fd()) + switch(signal->get_message()->get_flags()) { - 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); - } + case CAN_PROTOCOL_WITH_FD_FRAME: + 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( 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); - } + case J1939_PROTOCOL: + 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, - false, - signal->get_message()->get_flags(), - data, - 0); - return build_frame(signal, value, message, factor, offset); + case CAN_PROTOCOL: + 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); + default: + 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); } + } @@ -297,31 +303,38 @@ message_t* encoder_t::build_message(const std::shared_ptr<signal_t>& signal, uin { message_t *message; std::vector<uint8_t> data; - if(signal->get_message()->is_fd()) + + switch(signal->get_message()->get_flags()) { - message = new can_message_t(CANFD_MAX_DLEN, + case CAN_PROTOCOL_WITH_FD_FRAME: + 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_one_frame_message(signal, value, message); +#ifdef USE_FEATURE_J1939 + case J1939_PROTOCOL: + 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_multi_frame_message(signal, value, message); +#endif + case CAN_PROTOCOL: + message = new can_message_t(CAN_MAX_DLEN, signal->get_message()->get_id(), - CANFD_MAX_DLEN, + CAN_MAX_DLEN, false, signal->get_message()->get_flags(), data, 0); return build_one_frame_message(signal, value, message); - } -#ifdef USE_FEATURE_J1939 - else if(signal->get_message()->is_j1939()) - { - 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_multi_frame_message(signal, value, message); - } -#endif - else - { + default: message = new can_message_t(CAN_MAX_DLEN, signal->get_message()->get_id(), CAN_MAX_DLEN, |