|
| 1 | +Port of the TinyFrame C library from https://github.com/MightyPork/TinyFrame |
| 2 | + |
| 3 | +Used an automated code conversion tool from to port https://github.com/MightyPork/PonyFrame from python to dart with some minor modifications |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +TinyFrame is a simple library for building and parsing data frames to be sent over a serial interface (e.g. UART, telnet, socket). |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +### Master |
| 12 | +```dart |
| 13 | +import 'dart:typed_data'; |
| 14 | +import 'package:tiny_frame/tiny_frame.dart'; |
| 15 | +
|
| 16 | +void write(Uint8List data) => print('write: $data'); |
| 17 | +void main() { |
| 18 | + const mainID = 1; |
| 19 | + // create a TinyFrame instance as master (peer id set) |
| 20 | + // the write method has to be implemented, tinyframe will call it |
| 21 | + // to send the data after building the frame |
| 22 | + final tf = TinyFrame(write); |
| 23 | + // some optional settings |
| 24 | + tf.cksumType = 'xor'; |
| 25 | + // generate a listener for the id 1 |
| 26 | + tf.addIdListener(mainID, (Uint8List frame) => print('main: $frame')); |
| 27 | + // if no listener is found for the id, this listener will be called |
| 28 | + tf.addFallbackListener((Uint8List frame) => print('fallback: $frame')); |
| 29 | + // send to slave on id 1 |
| 30 | + tf.send(mainID, Uint8List.fromList('abcde'.codeUnits)); |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +### Slave |
| 35 | + |
| 36 | +## TinyFrame |
| 37 | +```sh |
| 38 | +,-----+-----+-----+------+------------+- - - -+-------------, |
| 39 | +| SOF | ID | LEN | TYPE | HEAD_CKSUM | DATA | DATA_CKSUM | |
| 40 | +| 0-1 | 1-4 | 1-4 | 1-4 | 0-4 | ... | 0-4 | <- size (bytes) |
| 41 | +'-----+-----+-----+------+------------+- - - -+-------------' |
| 42 | + |
| 43 | +SOF ......... start of frame, usually 0x01 (optional, configurable) |
| 44 | +ID ......... the frame ID (MSb is the peer bit) |
| 45 | +LEN ......... number of data bytes in the frame |
| 46 | +TYPE ........ message type (used to run Type Listeners, pick any values you like) |
| 47 | +HEAD_CKSUM .. header checksum |
| 48 | + |
| 49 | +DATA ........ LEN bytes of data |
| 50 | +DATA_CKSUM .. data checksum (left out if LEN is 0) |
| 51 | +``` |
| 52 | +
|
0 commit comments