This commit is contained in:
parent
66eadaf43d
commit
8bd5e5c6f5
|
@ -113,6 +113,7 @@ void CanTxMessage::setBus(size_t bus) {
|
||||||
busIndex = bus;
|
busIndex = bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LSB Little-endian System, "Intel"
|
||||||
void CanTxMessage::setShortValue(uint16_t value, size_t offset) {
|
void CanTxMessage::setShortValue(uint16_t value, size_t offset) {
|
||||||
m_frame.data8[offset] = value & 0xFF;
|
m_frame.data8[offset] = value & 0xFF;
|
||||||
m_frame.data8[offset + 1] = value >> 8;
|
m_frame.data8[offset + 1] = value >> 8;
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
uint8_t& operator[](size_t);
|
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);
|
void setShortValue(uint16_t value, size_t offset);
|
||||||
|
|
||||||
|
|
|
@ -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]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue