@Test public void testSetMsgCRC() { byte[] msg = "12345678900".getBytes(); int checkSum = CrcCccitt.calculateCrcCccitt(msg,0,msg.length-2); assertEquals(0x31c3, checkSum); CrcCccitt.setMsgCRC(msg); assertEquals((byte)0x31, msg[msg.length-2]); assertEquals((byte)0xc3, msg[msg.length-1]); assertTrue(CrcCccitt.isValidMsgCRC(msg)); }
public static void setMsgCRC(byte[] msg) { if ( msg != null && msg.length > 2) { int checkSum = calculateCrcCccitt(msg, 0, msg.length-2); ByteBuffer buffer = ByteBuffer.allocate(2).order(ByteOrder.BIG_ENDIAN); buffer.putShort((short)checkSum); byte[] crcBytes = buffer.array(); System.arraycopy(crcBytes, 0, msg, msg.length-2, 2); } }
CrcCccitt { public static void setMsgCRC(byte[] msg) { if ( msg != null && msg.length > 2) { int checkSum = calculateCrcCccitt(msg, 0, msg.length-2); ByteBuffer buffer = ByteBuffer.allocate(2).order(ByteOrder.BIG_ENDIAN); buffer.putShort((short)checkSum); byte[] crcBytes = buffer.array(); System.arraycopy(crcBytes, 0, msg, msg.length-2, 2); } } }
CrcCccitt { public static void setMsgCRC(byte[] msg) { if ( msg != null && msg.length > 2) { int checkSum = calculateCrcCccitt(msg, 0, msg.length-2); ByteBuffer buffer = ByteBuffer.allocate(2).order(ByteOrder.BIG_ENDIAN); buffer.putShort((short)checkSum); byte[] crcBytes = buffer.array(); System.arraycopy(crcBytes, 0, msg, msg.length-2, 2); } }  }
CrcCccitt { public static void setMsgCRC(byte[] msg) { if ( msg != null && msg.length > 2) { int checkSum = calculateCrcCccitt(msg, 0, msg.length-2); ByteBuffer buffer = ByteBuffer.allocate(2).order(ByteOrder.BIG_ENDIAN); buffer.putShort((short)checkSum); byte[] crcBytes = buffer.array(); System.arraycopy(crcBytes, 0, msg, msg.length-2, 2); } }  static boolean isValidMsgCRC(byte[] msgIncludingMsgCRC); static boolean isValidMsgCRC(byte[] msgIncludingMsgCRC, int offset, int count); static void setMsgCRC(byte[] msg); static int calculateCrcCccitt(byte[] msg); static int calculateCrcCccitt(byte[] msg, int offset, int count); }
CrcCccitt { public static void setMsgCRC(byte[] msg) { if ( msg != null && msg.length > 2) { int checkSum = calculateCrcCccitt(msg, 0, msg.length-2); ByteBuffer buffer = ByteBuffer.allocate(2).order(ByteOrder.BIG_ENDIAN); buffer.putShort((short)checkSum); byte[] crcBytes = buffer.array(); System.arraycopy(crcBytes, 0, msg, msg.length-2, 2); } }  static boolean isValidMsgCRC(byte[] msgIncludingMsgCRC); static boolean isValidMsgCRC(byte[] msgIncludingMsgCRC, int offset, int count); static void setMsgCRC(byte[] msg); static int calculateCrcCccitt(byte[] msg); static int calculateCrcCccitt(byte[] msg, int offset, int count);  }