diff --git a/firmware/hw_layer/drivers/can/can_msg_tx.cpp b/firmware/hw_layer/drivers/can/can_msg_tx.cpp index 84105fbeea..2be22ce98a 100644 --- a/firmware/hw_layer/drivers/can/can_msg_tx.cpp +++ b/firmware/hw_layer/drivers/can/can_msg_tx.cpp @@ -2,7 +2,7 @@ * @file can_msg_tx.cpp * * CAN message transmission - * + * * @date Mar 13, 2020 * @author Matthew Kennedy, (c) 2012-2020 */ @@ -113,6 +113,7 @@ void CanTxMessage::setBus(size_t bus) { busIndex = bus; } +// LSB Little-endian System, "Intel" void CanTxMessage::setShortValue(uint16_t value, size_t offset) { m_frame.data8[offset] = value & 0xFF; m_frame.data8[offset + 1] = value >> 8; diff --git a/firmware/hw_layer/drivers/can/can_msg_tx.h b/firmware/hw_layer/drivers/can/can_msg_tx.h index 953a0142a0..54f18a9968 100644 --- a/firmware/hw_layer/drivers/can/can_msg_tx.h +++ b/firmware/hw_layer/drivers/can/can_msg_tx.h @@ -2,7 +2,7 @@ * @file can_msg_tx.h * * CAN message transmission - * + * * @date Mar 13, 2020 * @author Matthew Kennedy, (c) 2012-2020 */ @@ -17,7 +17,7 @@ /** * Represent a message to be transmitted over CAN. - * + * * Usage: * * Create an instance of CanTxMessage * * Set any data you'd like to transmit either using the subscript operator to directly access bytes, or any of the helper functions. @@ -53,7 +53,7 @@ public: uint8_t& operator[](size_t); /** - * @brief Write a 16-bit short value to the buffer. Note: this writes in big endian byte order. + * @brief Write a 16-bit short value to the buffer. Note: this writes in little endian byte order. */ void setShortValue(uint16_t value, size_t offset); @@ -98,8 +98,8 @@ public: #if EFI_CAN_SUPPORT /** - * Access members of the templated type. - * + * Access members of the templated type. + * * So you can do: * CanTxTyped d; * d->memberOfMyType = 23; diff --git a/java_console/shared_io/src/test/java/com/rusefi/core/FileUtilTest.java b/java_console/shared_io/src/test/java/com/rusefi/core/FileUtilTest.java new file mode 100644 index 0000000000..4d19f9a244 --- /dev/null +++ b/java_console/shared_io/src/test/java/com/rusefi/core/FileUtilTest.java @@ -0,0 +1,31 @@ +package com.rusefi.core; + +import org.junit.jupiter.api.Test; + +import java.nio.ByteBuffer; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class FileUtilTest { + + static void setShortValue(byte[] data8, int value, int offset) { + data8[offset] = (byte) (value & 0xFF); + data8[offset + 1] = (byte) (value >> 8); + } + + @Test + public void damnItWhichOneIsLittleEndian() { + byte[] testArrayForLittleEndianByteBuffer = new byte[2]; + // LSB Little-endian System, "Intel" + ByteBuffer littleEndianBuffer = FileUtil.littleEndianWrap(testArrayForLittleEndianByteBuffer, 0, 2); + short testValue = 0x1122; + littleEndianBuffer.putShort(testValue); + assertEquals(testArrayForLittleEndianByteBuffer[0], 0x22); + + byte[] testArrayForJavaCodeWhichMimicsCanTxMessageSetShortValue = new byte[2]; + setShortValue(testArrayForJavaCodeWhichMimicsCanTxMessageSetShortValue, testValue, 0); + + assertEquals(testArrayForJavaCodeWhichMimicsCanTxMessageSetShortValue[0], 0x22); + assertEquals(testArrayForJavaCodeWhichMimicsCanTxMessageSetShortValue[1], testArrayForLittleEndianByteBuffer[1]); + } +}