Permalink
Switch branches/tags
v0.0.8-alpha v0.0.7-alpha v0.0.6-alpha v0.0.5-alpha v0.0.4-alpha v0.0.3-alpha v0.0.2-alpha pre_profiles pre-profile alpha_0.0.1 Droidplanner_v2.1.1 Droidplanner_v2.1.1_RC1 Droidplanner_v2.1.0 Droidplanner_v2.1.0_RC1 Droidplanner_v2.0.1 Droidplanner_v2.0.1_RC1 Droidplanner_v2.0.0 Droidplanner_v2.0.0_RC3 Droidplanner_v2.0.0_RC2 Droidplanner_v2.0.0_RC1 Droidplanner_v1.2.0 Droidplanner_v1.1.0 Droidplanner_v1.0.2 Droidplanner_v1.0.1 Droidplanner_v1.0.0 Droidplanner_v0.16.0 Droidplanner_v0.15.0 Droidplanner_v0.14.2 Droidplanner_v0.14.1 Droidplanner_v0.14.0 Droidplanner_v0.13.1 Droidplanner_v0.13.0 Droidplanner_v0.12.4 Droidplanner_v0.12.4b Droidplanner_v0.12.3 Droidplanner_v0.12.2 Droidplanner_v0.12.1b Droidplanner_v0.12.0 Droidplanner_v0.11.4 Droidplanner_v0.11.3 Droidplanner_v0.11.2 Droidplanner_v0.11.1 Droidplanner_v0.11.0 Droidplanner_v0.10.3 Droidplanner_v0.10.2 Droidplanner_v0.10.1 Droidplanner_v0.10.0 Droidplanner_v0.9.3 Droidplanner_v0.9.2 Droidplanner_v0.9.1 Droidplanner_v0.9.0 Droidplanner_v0.8.4 Droidplanner_v0.8.3 Droidplanner_v0.8.2 Droidplanner_v0.8.1 Droidplanner_v0.8.0 Droidplanner_v0.7.8 Droidplanner_v0.7.7 Droidplanner_v0.7.6 Droidplanner_v0.7.5 Droidplanner_v0.7.4 Droidplanner_v0.7.3 Droidplanner_v0.7.2 Droidplanner_v0.7.1 Droidplanner_v0.7.0 Droidplanner_v0.6.0 Droidplanner_v0.5.4 DroidPlanner_v0.5.3 DroidPlanner_v0.5.2 DroidPlanner_v0.5.1 DroidPlanner_v0.5.0 DroidPlanner_v0.4.1 DroidPlanner_v0.4.0 DroidPlanner_v0.3.1 DroidPlanner_v0.3 DroidPlanner_v0.2
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (57 sloc) 2.42 KB
package com.MAVLink.Messages;
/**
* X.25 CRC calculation for MAVlink messages. The checksum must be initialized,
* updated with witch field of the message, and then finished with the message
* id.
*
*/
public class CRC {
private final int[] MAVLINK_MESSAGE_CRCS = {50, 124, 137, 0, 237, 217, 104, 119, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 214, 159, 220, 168, 24, 23, 170, 144, 67, 115, 39, 246, 185, 104, 237, 244, 222, 212, 9, 254, 230, 28, 28, 132, 221, 232, 11, 153, 41, 39, 0, 0, 0, 0, 15, 3, 0, 0, 0, 0, 0, 153, 183, 51, 82, 118, 148, 21, 0, 243, 124, 0, 0, 38, 20, 158, 152, 143, 0, 0, 0, 106, 49, 22, 29, 12, 241, 233, 0, 231, 183, 63, 54, 0, 0, 0, 0, 0, 0, 0, 175, 102, 158, 208, 56, 93, 211, 108, 32, 185, 84, 0, 0, 124, 119, 4, 76, 128, 56, 116, 134, 237, 203, 250, 87, 203, 220, 25, 226, 0, 29, 223, 85, 6, 229, 203, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 49, 0, 134, 219, 208, 188, 84, 22, 19, 21, 134, 0, 78, 68, 189, 127, 154, 21, 21, 144, 1, 234, 73, 181, 22, 83, 167, 138, 234, 240, 47, 189, 52, 174, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 204, 49, 170, 44, 83, 46, 0};
private static final int CRC_INIT_VALUE = 0xffff;
private int CRCvalue;
/**
* Accumulate the X.25 CRC by adding one char at a time.
*
* The checksum function adds the hash of one char at a time to the 16 bit
* checksum (uint16_t).
*
* @param data
* new char to hash
* @param crcAccum
* the already accumulated checksum
**/
public void update_checksum(int data) {
int tmp;
data= data & 0xff; //cast because we want an unsigned type
tmp = data ^ (CRCvalue & 0xff);
tmp ^= (tmp << 4) & 0xff;
CRCvalue = ((CRCvalue >> 8) & 0xff) ^ (tmp << 8) ^ (tmp << 3)
^ ((tmp >> 4) & 0xf);
}
/**
* Finish the CRC calculation of a message, by running the CRC with the
* Magic Byte. This Magic byte has been defined in MAVlink v1.0.
*
* @param msgid
* The message id number
*/
public void finish_checksum(int msgid) {
update_checksum(MAVLINK_MESSAGE_CRCS[msgid]);
}
/**
* Initialize the buffer for the X.25 CRC
*
*/
public void start_checksum() {
CRCvalue = CRC_INIT_VALUE;
}
public int getMSB() {
return ((CRCvalue >> 8) & 0xff);
}
public int getLSB() {
return (CRCvalue & 0xff);
}
public CRC() {
start_checksum();
}
}