summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--low-can-binding/can/can-decoder.cpp13
-rw-r--r--low-can-binding/can/message/message.cpp11
-rw-r--r--low-can-binding/can/message/message.hpp3
-rwxr-xr-xlow-can-binding/can/signals.cpp12
-rwxr-xr-xlow-can-binding/can/signals.hpp4
-rw-r--r--low-can-binding/utils/converter.cpp20
-rw-r--r--low-can-binding/utils/converter.hpp3
7 files changed, 35 insertions, 31 deletions
diff --git a/low-can-binding/can/can-decoder.cpp b/low-can-binding/can/can-decoder.cpp
index cf4306a5..0e64cccd 100644
--- a/low-can-binding/can/can-decoder.cpp
+++ b/low-can-binding/can/can-decoder.cpp
@@ -99,6 +99,14 @@ float decoder_t::parse_signal_bitfield(signal_t& signal, std::shared_ptr<message
uint8_t bit_size = (uint8_t) signal.get_bit_size();
uint32_t bit_position = signal.get_bit_position();
+ if(!signal.get_message()->frame_layout_is_little())
+ {
+ bit_position = converter_t::bit_position_swap(message->get_length(),
+ signal.get_bit_position(),
+ signal.get_bit_size());
+ message->frame_swap();
+ }
+
int new_start_byte = 0;
int new_end_byte = 0;
uint8_t new_start_bit = 0;
@@ -320,11 +328,6 @@ openxc_DynamicField decoder_t::decode_state(signal_t& signal, std::shared_ptr<me
///
openxc_DynamicField decoder_t::translate_signal(signal_t& signal, std::shared_ptr<message_t> message, bool* send)
{
- if(!signal.get_message()->frame_layout_is_little() && !signal.bit_position_is_swapped())
- {
- signal.set_bit_position(converter_t::bit_position_swap(signal.get_bit_position(),signal.get_bit_size()));
- signal.bit_position_is_swapped_reverse();
- }
// Must call the decoders every time, regardless of if we are going to
// decide to send the signal or not.
openxc_DynamicField decoded_value = decoder_t::decode_signal(signal,
diff --git a/low-can-binding/can/message/message.cpp b/low-can-binding/can/message/message.cpp
index 22887c9a..56e9379f 100644
--- a/low-can-binding/can/message/message.cpp
+++ b/low-can-binding/can/message/message.cpp
@@ -177,3 +177,14 @@ void message_t::set_length(uint32_t length)
{
length_ = length;
}
+
+void message_t::frame_swap()
+{
+ int i;
+ uint8_t *temp = (uint8_t*)alloca(length_);
+
+ for(i = 0; i < length_; i++)
+ temp[i] = data_[length_ - i - 1];
+
+ memcpy(data_.data(), temp, length_);
+}
diff --git a/low-can-binding/can/message/message.hpp b/low-can-binding/can/message/message.hpp
index 9a074e31..e5e6769b 100644
--- a/low-can-binding/can/message/message.hpp
+++ b/low-can-binding/can/message/message.hpp
@@ -44,7 +44,7 @@
#define ISOTP_SEND 0x0020
#define ISOTP_RECEIVE 0x0040
#define CAN_PROTOCOL_WITH_FD_FRAME 0x0080
-#define FRAME_LAYOUT_IS_LE 0x0100
+#define FRAME_LAYOUT_IS_LE 0x0100 // LE stand for Little Endian
/// @class message_t
///
@@ -84,4 +84,5 @@ public:
uint32_t get_maxdlen();
void set_maxdlen(uint32_t maxdlen);
void set_length(uint32_t length);
+ void frame_swap();
};
diff --git a/low-can-binding/can/signals.cpp b/low-can-binding/can/signals.cpp
index 28246a05..da8df988 100755
--- a/low-can-binding/can/signals.cpp
+++ b/low-can-binding/can/signals.cpp
@@ -71,7 +71,6 @@ signal_t::signal_t(
, sign_{sign}
, bit_sign_position_{bit_sign_position}
, unit_{unit}
- ,bit_position_is_swapped_{false}
{}
signal_t::signal_t(
@@ -105,7 +104,6 @@ signal_t::signal_t(
, decoder_{decoder}
, encoder_{encoder}
, received_{received}
- , bit_position_is_swapped_{false}
{}
std::shared_ptr<message_definition_t> signal_t::get_message() const
@@ -253,13 +251,3 @@ const std::string signal_t::get_unit() const
{
return unit_;
}
-
-bool signal_t::bit_position_is_swapped() const
-{
- return bit_position_is_swapped_;
-}
-
-void signal_t::bit_position_is_swapped_reverse()
-{
- bit_position_is_swapped_ = !bit_position_is_swapped_;
-}
diff --git a/low-can-binding/can/signals.hpp b/low-can-binding/can/signals.hpp
index 5f143753..bf779981 100755
--- a/low-can-binding/can/signals.hpp
+++ b/low-can-binding/can/signals.hpp
@@ -111,8 +111,6 @@ private:
sign_t sign_; /* !< sign_ - if the data is signed it indicates the encode */
int32_t bit_sign_position_; /*!< bit_sign_position_ - The bit that indicates the sign of the signal in its CAN message*/
std::string unit_; /* !< unit_ - The unit of the data */
- bool bit_position_is_swapped_; /* !<bit_position_is_swapped_- True if the signal's bit position has been
- swapped (refer to converter_t::bit_position_swap()). Default is false.*/
public:
@@ -179,12 +177,10 @@ public:
sign_t get_sign() const;
int32_t get_bit_sign_position() const;
const std::string get_unit() const;
- bool bit_position_is_swapped() const;
void set_parent(std::shared_ptr<message_definition_t> parent);
void set_received(bool r);
void set_last_value(float val);
void set_timestamp(uint64_t timestamp);
void set_bit_position(uint32_t bit_position);
- void bit_position_is_swapped_reverse();
};
diff --git a/low-can-binding/utils/converter.cpp b/low-can-binding/utils/converter.cpp
index 0a09125f..6392fbdf 100644
--- a/low-can-binding/utils/converter.cpp
+++ b/low-can-binding/utils/converter.cpp
@@ -65,20 +65,24 @@ void converter_t::signal_to_bits_bytes(unsigned int bit_position, unsigned int b
* @param bit_size Size of the data.
* @return uint32_t New bit position.
*/
-uint32_t converter_t::bit_position_swap(uint32_t bit_position,uint32_t bit_size)
+uint32_t converter_t::bit_position_swap(unsigned int msg_length, unsigned int bit_position, unsigned int bit_size)
{
- uint32_t start_byte_position = (uint32_t)(bit_position/8);
- uint32_t bit_size_rest = bit_size;
+ return msg_length - bit_position - bit_size;
+ /*
+ unsigned int start_byte_position = (unsigned int)(bit_position/8);
+ unsigned int bit_size_rest = bit_size;
- if((int)(bit_size-(8 + start_byte_position*8-bit_position%8))>0)
+ if((int)(bit_size-(8 + start_byte_position * 8 - bit_position % 8)) > 0)
{
AFB_ERROR("Error: bit_position and bit_size getting out of range");
return bit_position;
}
- if(bit_size<=8 && ((bit_position+bit_size)%8==bit_size || (bit_position+bit_size)%8==0))
+ if(bit_size <= 8 &&
+ ((bit_position+bit_size) % 8 == bit_size ||
+ (bit_position+bit_size)%8==0))
{
- return (uint32_t)(start_byte_position*8 + (8-bit_size));
+ return (unsigned int)(start_byte_position*8 + (8-bit_size));
}
else
{
@@ -88,7 +92,7 @@ uint32_t converter_t::bit_position_swap(uint32_t bit_position,uint32_t bit_size)
start_byte_position--;
bit_position = start_byte_position*8;
} while (bit_size_rest>8);
- return (uint32_t)(start_byte_position*8 + (8-bit_size_rest));
+ return (unsigned int)(start_byte_position*8 + (8-bit_size_rest));
}
-
+ */
}
diff --git a/low-can-binding/utils/converter.hpp b/low-can-binding/utils/converter.hpp
index 32c898f1..23f8ae77 100644
--- a/low-can-binding/utils/converter.hpp
+++ b/low-can-binding/utils/converter.hpp
@@ -29,6 +29,7 @@ class converter_t
int &new_end_byte,
uint8_t &new_start_bit,
uint8_t &new_end_bit);
- static uint32_t bit_position_swap(unsigned int bit_position,
+ static uint32_t bit_position_swap(unsigned int msg_length,
+ unsigned int bit_position,
unsigned int bit_size);
};