Skip to content

Commit cc32c72

Browse files
author
globi
committed
Initial Release
0 parents  commit cc32c72

9 files changed

+563
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# https://dart.dev/guides/libraries/private-files
2+
# Created by `dart pub`
3+
.dart_tool/
4+
5+
# Avoid committing pubspec.lock for library packages; see
6+
# https://dart.dev/guides/libraries/private-files#pubspeclock.
7+
pubspec.lock

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+

analysis_options.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
include: package:dart_flutter_team_lints/analysis_options.yaml
2+
3+
linter:
4+
rules:
5+
- avoid_private_typedef_functions
6+
- avoid_unused_constructor_parameters
7+
- avoid_void_async
8+
- cancel_subscriptions
9+
- join_return_with_assignment
10+
- missing_whitespace_between_adjacent_strings
11+
- no_runtimeType_toString
12+
- package_api_docs
13+
- prefer_const_declarations
14+
- prefer_expression_function_bodies
15+
- prefer_final_locals
16+
- unnecessary_breaks
17+
- use_string_buffers

example/example.dart

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'dart:typed_data';
2+
3+
import 'package:tiny_frame/tiny_frame.dart';
4+
5+
void write(Uint8List data) => print('write: $data');
6+
void main() {
7+
const mainID = 1;
8+
// create a TinyFrame instance as master (peer id set)
9+
// the write method has to be implemented, tinyframe will call it
10+
// to send the data after building the frame
11+
final tf = TinyFrame(write);
12+
// some optional settings
13+
tf.cksumType = 'xor';
14+
// generate a listener for the id 1
15+
tf.addIdListener(mainID, (Uint8List frame) => print('main: $frame'));
16+
// if no listener is found for the id, this listener will be called
17+
tf.addFallbackListener((Uint8List frame) => print('fallback: $frame'));
18+
19+
// send to slave on id 1
20+
tf.send(mainID, Uint8List.fromList('abcde'.codeUnits));
21+
}

0 commit comments

Comments
 (0)