Skip to content

Commit 2f6728e

Browse files
author
Michael Kellner
committed
add CRC to doc
1 parent d3f8650 commit 2f6728e

File tree

1 file changed

+89
-2
lines changed

1 file changed

+89
-2
lines changed

documentation/data/data.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Data
22

33
Copyright 2017-2022 Moddable Tech, Inc.<BR>
4-
Revised: February 23, 2022
4+
Revised: March 7, 2022
55

66
**Warning**: These notes are preliminary. Omissions and errors are likely. If you encounter problems, please ask for assistance.
77

88
## Table of Contents
99

1010
* [Base64](#base64)
1111
* [Hex](#hex)
12+
* [CRC](#crc)
1213
* [QRCode](#qrcode)
1314
* [Text](#text)
1415
* [zlib](#zlib)
@@ -90,6 +91,92 @@ let s1 = Hex.toString(buffer);
9091
// s1 is 0123456789ABCDEF
9192
```
9293

94+
<a id="crc"></a>
95+
## class CRC8, CRC16
96+
97+
The `CRC8` and `CRC16` classes calculate CRC checksums on data.
98+
99+
```
100+
import {CRC8} from "crc";
101+
import {CRC16} from "crc";
102+
```
103+
104+
Include the module's manifest to use it in a project:
105+
106+
```json
107+
"include": [
108+
"$(MODULES)/data/crc/manifest.json"
109+
]
110+
```
111+
112+
#### `CRC8(polynomial [, initial [, reflectInput [, reflectOutput [, xorOutput]]]])`
113+
#### `CRC16(polynomial [, initial [, reflectInput [, reflectOutput [, xorOutput]]]])`
114+
115+
The `CRC8` and `CRC16` functions take a number of options used to specify the CRC checksum to calculate.
116+
117+
| Parameter | Default | Description |
118+
| :---: | :---: | :--- |
119+
| `polynomial` | (none) | Polynomial to use (required) |
120+
| `initial` | `0` | Initial CRC accumulator value (optional) |
121+
| `reflectInput` | `false` | If `true`, each input byte is reflected (bits used in reverse order) before being used (optional) |
122+
| `reflectOutput` | `false` | If `true`, each output byte is reflected before being returned. The output reflection is done over the whole CRC value (optional) |
123+
| `xorOutput` | `0` | Value to XOR to the final CRC value (optional) |
124+
125+
The `polynomial`, `initial` and `xorOutput` values are 8-bit integers for CRC8 and 16-bit integers for CRC16.
126+
127+
The [crc example](https://github.com/Moddable-OpenSource/moddable/blob/public/examples/data/crc/main.js) demonstrates the definition of the parameters for a number of common CRC checksums:
128+
129+
- `CRC-8`
130+
- `CRC-8/CDMA2000`
131+
- `CRC-8/DARC`
132+
- `CRC-8/DVB-S2`
133+
- `CRC-8/EBU`
134+
- `CRC-8/I-CODE`
135+
- `CRC-8/ITU`
136+
- `CRC-8/MAXIM`
137+
- `CRC-8/ROHC`
138+
- `CRC-8/WCDM`
139+
- `CRC-16/CCITT-FALSE`
140+
- `CRC-16/ARC`
141+
- `CRC-16/ARG-CCITT`
142+
- `CRC-16/BUYPASS`
143+
- `CRC-16/CDMA2000`
144+
- `CRC-16/DDS-110`
145+
- `CRC-16/DECT-R`
146+
- `CRC-16/DECT-X`
147+
- `CRC-16/DNP`
148+
- `CRC-16/EN-13757`
149+
- `CRC-16/GENIBUS`
150+
- `CRC-16/MAXIM`
151+
- `CRC-16/MCRF4XX`
152+
- `CRC-16/RIELLO`
153+
- `CRC-16/T10-DIF`
154+
- `CRC-16/TELEDISK`
155+
- `CRC-16/TMS37157`
156+
- `CRC-16/USB`
157+
- `CRC-A`
158+
- `CRC-16/KERMIT`
159+
- `CRC-16/MODBUS`
160+
- `CRC-16/X-25`
161+
- `CRC-16/XMODE`
162+
163+
164+
### `close()`
165+
166+
The `close` function frees resources associated with the CRC checksum calculation.
167+
168+
### `checksum(buffer)`
169+
170+
The `checksum` function applies the CRC calculation to the data provided in `buffer`. The CRC checksum is returned.
171+
172+
The `buffer` parameter may be a `String` or buffer.
173+
174+
The `checksum` function may be called multiple times. Each time it is called the CRC updated and returned. Call the `reset` function to start a new calculation.
175+
176+
### `reset()`
177+
178+
The `reset` function clears the CRC accumulator to the `initial` value.
179+
93180
<a id="qrcode"></a>
94181
## class QRCode
95182
The `QRCode` class generates QR Code data from Strings and buffers. The data may then be rendering in various ways. Extensions are provided to [Poco](https://github.com/Moddable-OpenSource/moddable/tree/public/modules/commodetto/qrcode) and [Piu](https://github.com/Moddable-OpenSource/moddable/tree/public/modules/piu/MC/qrcode) to efficiently render QR Codes. The core implementation is the QR Code Generator Library from [Project Nayuki](https://www.nayuki.io/page/qr-code-generator-library).
@@ -98,7 +185,7 @@ The `QRCode` class generates QR Code data from Strings and buffers. The data may
98185
import qrCode from "qrcode";
99186
```
100187

101-
Include the modules' manifest to use them in a project:
188+
Include the module's manifest to use them in a project:
102189

103190
```json
104191
"include": [

0 commit comments

Comments
 (0)