Here you can find the source of calcChecksum(byte[] buffer, int offset, int length)
Parameter | Description |
---|---|
buffer | the buffer where the bytes are in. |
offset | the offset from where to start calculating the checksum. |
length | the length of bytes to calculate the checksum for. |
public static byte calcChecksum(byte[] buffer, int offset, int length)
//package com.java2s; /**//from w ww .j a v a 2s. c o m * Copyright (c) 2010-2015, openHAB.org and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * Returns the checksum for the specified bytes. * * @param buffer * the buffer where the bytes are in. * @param offset * the offset from where to start calculating the checksum. * @param length * the length of bytes to calculate the checksum for. * @return the checksum for the specified bytes. */ public static byte calcChecksum(byte[] buffer, int offset, int length) { byte crc = 0x7F; for (int i = 0; i < length; i++) { crc = (byte) ((crc - buffer[offset + i]) & 0x7F); } return crc; } }