This also change the bit_position to retrieve the bit word starting from the left
or the right of the frame depending on the endianness of the frame layout.
Change-Id: I28658e9d46bd35d8ecabeece317331832229384a
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
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;
///
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,
{
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_);
+}
#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
///
uint32_t get_maxdlen();
void set_maxdlen(uint32_t maxdlen);
void set_length(uint32_t length);
+ void frame_swap();
};
, sign_{sign}
, bit_sign_position_{bit_sign_position}
, unit_{unit}
- ,bit_position_is_swapped_{false}
{}
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
{
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_;
-}
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:
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();
};
* @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
{
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));
}
-
+ */
}
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);
};