UartBus source documentation
eu.javaexperience.electronic.uartbus.UartbusTools Class Reference
Collaboration diagram for eu.javaexperience.electronic.uartbus.UartbusTools:

Classes

enum  PacketFormattingMode
 

Static Public Member Functions

static byte crc8 (byte[] data)
 
static byte crc8 (byte[] data, int length)
 
static byte [] parseColonData (String data)
 
static String formatColonData (byte[] e)
 
static String formatColonDataWithValidation (byte[] e)
 
static String formatPacketWithMode (PacketFormattingMode mode, byte[] data)
 
static int packValue (boolean signed, int value, byte[] dst, int startIndex)
 
static int packValue (boolean signed, long value, byte[] dst, int startIndex)
 
static int packValue (boolean signed, BigInteger value, byte[] dst, int startIndex)
 
static int calcPackReqBytes (boolean signed, BigInteger value)
 
static int calcPackReqBytes (boolean signed, byte[] value)
 
static int packValue (Boolean negative, byte[] value, byte[] dst, int startIndex)
 
static byte [] packInt (boolean signed, int value)
 
static BigInteger unpackValue (boolean signed, byte[] data, int startIndex)
 
static BigInteger unpackValue (boolean signed, byte[] data, int startIndex, int[] usedBytes)
 
static byte [] getValidPacket (byte[] e)
 
static boolean isPacketCrc8Valid (byte[] data)
 
static void printPacketStdout (byte[] data)
 
static void initConnection (UartbusConnection conn)
 

Static Protected Attributes

static final Logger LOG = JavaExperienceLoggingFacility.getLogger(new Loggable("UartbusTools"))
 

Detailed Description

Definition at line 16 of file UartbusTools.java.

Member Function Documentation

◆ packValue()

static int eu.javaexperience.electronic.uartbus.UartbusTools.packValue ( Boolean  negative,
byte []  value,
byte []  dst,
int  startIndex 
)
inlinestatic

packed byte scheme: XN---—|X----—|X----—

first byte: X extended address (0 = no, 1 = yes) N negated value (0 = no, 1 = yes)

n'th byte: X value continued in the next byte + 7 bit number value

negative: null: unsigned value false: signed positive true: signed negative

Definition at line 218 of file UartbusTools.java.

219  {
220  if(0 == value.length)
221  {
222  if(Boolean.TRUE == negative)
223  {
224  dst[startIndex] = 0x40;
225  }
226  else
227  {
228  dst[startIndex] = 0;
229  }
230  return 1;
231  }
232 
233  int sReq = calcPackReqBytes(null != negative, value);
234 
235  int off = 0;
236  int index = value.length-1;
237 
238  for(int i = sReq-1;i >=0;--i,--index)
239  {
240  int val = 0;
241  if(0 == off)//value from the same byte
242  {
243  val = value[index];//bit offset
244  }
245  else//different bytes
246  {
247  val = (0xff & value[index+1]) >> (8-off);
248  if(index >= 0)
249  {
250  val |= (0xff & value[index]) << off;
251  }
252  }
253 
254  val &= 0x7f;
255 
256  if(++off == 8)
257  {
258  off = 0;
259  index += 1;
260  }
261 
262  if(i != sReq-1)
263  {
264  val |= 0x80;
265  }
266 
267  if(Boolean.TRUE == negative && i == 0)
268  {
269  val |= 0x40;
270  }
271 
272  dst[startIndex+i] = (byte) val;
273  }
274 
275  return sReq;
276  }

The documentation for this class was generated from the following file: