aboutsummaryrefslogtreecommitdiff
path: root/mavlink-library/src/main/twirl/org/mavlink/Crc.scala.txt
diff options
context:
space:
mode:
Diffstat (limited to 'mavlink-library/src/main/twirl/org/mavlink/Crc.scala.txt')
-rw-r--r--mavlink-library/src/main/twirl/org/mavlink/Crc.scala.txt28
1 files changed, 28 insertions, 0 deletions
diff --git a/mavlink-library/src/main/twirl/org/mavlink/Crc.scala.txt b/mavlink-library/src/main/twirl/org/mavlink/Crc.scala.txt
new file mode 100644
index 0000000..f6e3cce
--- /dev/null
+++ b/mavlink-library/src/main/twirl/org/mavlink/Crc.scala.txt
@@ -0,0 +1,28 @@
+@(__context: Context)@_header(__context)
+package org.mavlink
+
+/**
+ * X.25 CRC calculation for MAVlink messages. The checksum must be initialized,
+ * updated with each field of a message, and then finished with the message
+ * id.
+ */
+case class Crc(val crc: Int = 0xffff) extends AnyVal {
+
+ /**
+ * Accumulates data into a new checksum.
+ */
+ def accumulate(datum: Byte): Crc = {
+ val d = datum & 0xff
+ var tmp = d ^ (crc & 0xff)
+ tmp ^= (tmp << 4) & 0xff;
+ Crc(
+ ((crc >> 8) & 0xff) ^ (tmp << 8) ^ (tmp << 3) ^ ((tmp >> 4) & 0xff))
+ }
+
+ /** Least significant byte of checksum. */
+ def lsb: Byte = crc.toByte
+
+ /** Most significant byte of checksum. */
+ def msb: Byte = (crc >> 8).toByte
+
+} \ No newline at end of file