diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2019-11-06 09:46:31 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2019-11-06 09:46:31 +0100 |
commit | bd8c71dd8eb67e0f043636bedab9ad3b0cc8109f (patch) | |
tree | 00245ecb001492ffdeae1063589ae7708fe1737e | |
parent | e2faa2a60da4fddcd966fa04a77d995c0bcbfa71 (diff) |
converter: decoder: use appropriate int types
Change-Id: I7e977647b23ecd5be1f58486af857e3b7132b48f
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-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/utils/converter.cpp | 2 | ||||
-rw-r--r-- | low-can-binding/utils/converter.hpp | 2 |
4 files changed, 19 insertions, 49 deletions
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 37a7b246..94db19b0 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/utils/converter.cpp b/low-can-binding/utils/converter.cpp index d10888d0..e3db7f33 100644 --- a/low-can-binding/utils/converter.cpp +++ b/low-can-binding/utils/converter.cpp @@ -48,7 +48,7 @@ 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; 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); }; |