CCITT_CRC.java Change line endings from CRLF to LF

and remove trailing whitespaces.
This commit is contained in:
Tommy Sparber 2015-10-29 15:35:47 +11:00
parent a5f21feb4f
commit d817540f19

View file

@ -1,89 +1,88 @@
/** /**
* Copyright (c) 2008, Swedish Institute of Computer Science. * Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors * 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* This file is part of MSPSim. * This file is part of MSPSim.
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
* Author : Joakim Eriksson * Author : Joakim Eriksson
*/ */
package org.contikios.cooja.util; package org.contikios.cooja.util;
/* basic CRC-CCITT code */ /* basic CRC-CCITT code */
public class CCITT_CRC { public class CCITT_CRC {
int crc; int crc;
public int getCRC() { public int getCRC() {
return crc; return crc;
} }
/* this will only work with zero... */ /* this will only work with zero... */
public void setCRC(int val) { public void setCRC(int val) {
crc = val; crc = val;
} }
public void clr() { public void clr() {
crc = 0xffff; crc = 0xffff;
} }
public void addBitrev(int data) { public void addBitrev(int data) {
add(bitrev(data)); add(bitrev(data));
} }
public int getCRCLow() { public int getCRCLow() {
return bitrev(crc & 0xff); return bitrev(crc & 0xff);
} }
public int getCRCHi() { public int getCRCHi() {
return bitrev(crc >> 8); return bitrev(crc >> 8);
} }
public int add(int data) {
public int add(int data) { int newCrc = ((crc >> 8) & 0xff) | (crc << 8) & 0xffff;
int newCrc = ((crc >> 8) & 0xff) | (crc << 8) & 0xffff; newCrc ^= (data & 0xff);
newCrc ^= (data & 0xff); newCrc ^= (newCrc & 0xff) >> 4;
newCrc ^= (newCrc & 0xff) >> 4; newCrc ^= (newCrc << 12) & 0xffff;
newCrc ^= (newCrc << 12) & 0xffff; newCrc ^= (newCrc & 0xff) << 5;
newCrc ^= (newCrc & 0xff) << 5; crc = newCrc & 0xffff;
crc = newCrc & 0xffff; return crc;
return crc; }
}
public int getCRCBitrev() {
public int getCRCBitrev() { return getCRCLow() + (getCRCHi() << 8);
return getCRCLow() + (getCRCHi() << 8); }
}
public static final String hex = "0123456789abcdef";
public static final String hex = "0123456789abcdef";
private static int bitrev(int data) {
private static int bitrev(int data) { return ((data << 7) & 0x80) | ((data << 5) & 0x40) |
return ((data << 7) & 0x80) | ((data << 5) & 0x40) | (data << 3) & 0x20 | (data << 1) & 0x10 |
(data << 3) & 0x20 | (data << 1) & 0x10 | (data >> 7) & 0x01 | (data >> 5) & 0x02 |
(data >> 7) & 0x01 | (data >> 5) & 0x02 | (data >> 3) & 0x04 | (data >> 1) & 0x08;
(data >> 3) & 0x04 | (data >> 1) & 0x08; }
} }
}