From b1ec93cb50703c17896fe2897a75a13cdec54c63 Mon Sep 17 00:00:00 2001 From: AtomicNicos Date: Wed, 26 Feb 2020 17:13:29 +0100 Subject: [PATCH] Data Handler, Documentation, Data Header start. --- .flutter-plugins-dependencies | 2 +- lib/animation/forward_animation.dart | 4 ++++ lib/animation/slide_animation.dart | 27 +++++++++++++++++---------- lib/enums/device_screen_type.dart | 1 + lib/handlers/data_handler.dart | 26 +++++++++++++++++++------- lib/logic/data_header.dart | 27 +++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 lib/logic/data_header.dart diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 3e04891..64f6226 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-02-25 22:17:56.836840","version":"1.15.4-pre.158"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-02-26 14:24:43.145334","version":"1.14.6"} \ No newline at end of file diff --git a/lib/animation/forward_animation.dart b/lib/animation/forward_animation.dart index bd37d42..e5adb16 100644 --- a/lib/animation/forward_animation.dart +++ b/lib/animation/forward_animation.dart @@ -1,7 +1,11 @@ import 'package:flutter/material.dart'; +/// [PageRoute] that is supposed to pop forward using a scale effect. class PopForwardRoute extends PageRouteBuilder { + /// The [Widget] that this should display. final Widget page; + + /// [PageRoute] constructor override. PopForwardRoute({this.page}) : super( pageBuilder: ( BuildContext context, diff --git a/lib/animation/slide_animation.dart b/lib/animation/slide_animation.dart index 8bb6a38..7b8e03c 100644 --- a/lib/animation/slide_animation.dart +++ b/lib/animation/slide_animation.dart @@ -1,22 +1,29 @@ import 'package:flutter/material.dart'; +/// [PageRoute] that is supposed to slide up or down using a slide effect. class SlideUpRoute extends PageRouteBuilder { + /// The [Widget] that this should display. final Widget page; + + /// [PageRoute] constructor override. SlideUpRoute({this.page}) : super( - pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation, ) => - page, + pageBuilder: ( + BuildContext context, + Animation animation, + Animation secondaryAnimation, + ) => page, transitionsBuilder: ( BuildContext context, Animation animation, Animation secondaryAnimation, Widget child, - ) => - SlideTransition( - position: Tween( - begin: const Offset(0, -1), - end: Offset.zero, - ).animate(animation), - child: child, - ), + ) => SlideTransition( + position: Tween( + // Define slide on vertical axis. + begin: const Offset(0, -1), + end: Offset.zero, + ).animate(animation), + child: child, + ), ); } \ No newline at end of file diff --git a/lib/enums/device_screen_type.dart b/lib/enums/device_screen_type.dart index 2f28654..3082cb9 100644 --- a/lib/enums/device_screen_type.dart +++ b/lib/enums/device_screen_type.dart @@ -1,3 +1,4 @@ +/// Represents different screen types, useful for [TODO:LayoutManager]. enum DeviceScreenType { MOBILE, TABLET, diff --git a/lib/handlers/data_handler.dart b/lib/handlers/data_handler.dart index a6c2a09..5bf0a4d 100644 --- a/lib/handlers/data_handler.dart +++ b/lib/handlers/data_handler.dart @@ -1,3 +1,5 @@ +import 'package:logair_application/handlers/bluetooth_le_handler.dart'; + class DataHandler { factory DataHandler() => _singleton; @@ -5,24 +7,34 @@ class DataHandler { static final DataHandler _singleton = new DataHandler._internal(); + /// [List] containing all of the data received by this. List _data = []; + /// [List] containing separate packet instances received by this. List> _sortedData = []; - addData(List data) { + /// Allows the [BTLEHandler] to add acquired information to this, and effects + /// a primary triage. + void addData(List data) { _data.addAll(data); - int index = _data.indexWhere((e) => e == 13); - if (index >= 0 && _data.length >= index && _data[index + 1] == 10) { - _sortedData.add(_data.getRange(0, index).where((e) => e != 10).toList()); - _data.removeRange(0, index + 1); + // Index of the packet termination symbol in ASCII. + int index = _data.indexWhere((e) => e == 36); + if (index >= 0 && _data.length > index + 1 && _data[index + 1] == 13 && _data[index + 2] == 10) { + _sortedData.add(_data.getRange(0, index + 1).where((e) => e != 10 && e != 13).toList()); + _data.removeRange(0, index + 2); } } - doPrint() => _sortedData.map((x) => String.fromCharCodes(x)).forEach(print); + doPrint() { + print(""); + _sortedData.map((x) => String.fromCharCodes(x)).forEach(print); + print("Size : ${_sortedData.length}"); + } + /// Stream the latest confirmed data packet received by the device. Stream> getLatestData() async* { while(true) { - yield _sortedData.last; + yield (_sortedData.length > 0) ? _sortedData.last : "No Data"; await Future.delayed(Duration(milliseconds: 500)); } } diff --git a/lib/logic/data_header.dart b/lib/logic/data_header.dart new file mode 100644 index 0000000..fba51be --- /dev/null +++ b/lib/logic/data_header.dart @@ -0,0 +1,27 @@ +import 'package:collection/collection.dart'; + +class DataHeader { + factory DataHeader() => _singleton; + + DataHeader._internal() { + _headerData = []; + } + + static final DataHeader _singleton = new DataHeader._internal(); + + List _headerData; + + int _detection; + + int _total; + + String _representation; + + bool _headerSet; + + bool isHeaderSet() => _headerSet; + + bool isEqual(List that) => ListEquality().equals(_headerData, that); + + double _confidence() => _detection / _total; +} \ No newline at end of file -- GitLab