Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto-reconnect on windows localhost #195

Merged
merged 3 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions bin/science.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import "dart:convert";
import "dart:io";

import "package:protobuf/protobuf.dart" as proto;
import "package:burt_network/generated.dart";
import "package:burt_network/protobuf.dart";

/// A cleaner name for any message generated by Protobuf.
typedef Message = proto.GeneratedMessage;

/// Return true to keep this data in the dataset, or false to remove it.
///
///
/// Not only are the sensors on the rover wonky, but the CAN bus can corrupt data along the way.
/// This function can be used to remove any unwanted bad data.
bool shouldKeepData(Timestamp timestamp, ScienceData data) {
Expand All @@ -21,25 +21,25 @@ bool shouldKeepData(Timestamp timestamp, ScienceData data) {
if (data.humidity.isOutOfBounds(min: 0, max: 50)) return false;
if (data.temperature.isOutOfBounds(min: 0, max: 100)) return false;

// Any other conditions should go here:
// Any other conditions should go here:
if (elapsed >= 30 * 60) return false;

return true; // if none of the above rules are broken, then keep this data
}

/// Returns new data based on this one. To remove data, use [shouldKeepData] instead.
///
/// Returns new data based on this one. To remove data, use [shouldKeepData] instead.
///
/// You shouldn't need this unless you specifically need to change the *values* of the data. For example,
/// if the CO2 sensor was consistently 100ppm off, you could use this function to add 100ppm to each data.
///
/// NOTE: Do not modify fields that are zero, because they are likely sent in another "packet". For
///
/// NOTE: Do not modify fields that are zero, because they are likely sent in another "packet". For
/// example, if you want to modify CO2 but `data.co2 == 0`, this packet could be, eg, a methane packet
/// and isn't meant to have any CO2 data.
WrappedMessage modifyData(Timestamp timestamp, ScienceData data) { // ignore: prefer_expression_function_bodies
// Example 1: Add 100 ppm to all CO2:
// Example 1: Add 100 ppm to all CO2:
// if (data.co2 != 0) data.co2 += 100;
//
// Example 2: Add one second to all the timestamps:
//
// Example 2: Add one second to all the timestamps:
// timestamp += Duration(seconds: 1)

// Wrap the data and return it. Do not delete.
Expand All @@ -50,17 +50,17 @@ WrappedMessage modifyData(Timestamp timestamp, ScienceData data) { // ignore: p
/// Use this to add new data to your dataset.
List<WrappedMessage> newData = [
// Adds methane=1 for every second from t=1 to t=100 seconds
for (int t = 0; t < 100; t++)
for (int t = 0; t < 100; t++)
ScienceData(methane: 1).wrap(DateTime.now().add(Duration(seconds: t))),

// Adds some random methane in an increasing line between t=100 and t=200 seconds
for (int t = 100; t < 200; t++)
for (int t = 100; t < 200; t++)
ScienceData(methane: t + random.nextDouble() * 20).wrap(DateTime.now().add(Duration(seconds: t))),

// Adds completely random data for t=0 to t=20 seconds, for all three samples
for (int s = 0; s < 3; s++)
for (int s = 0; s < 3; s++)
for (int t = 0; t < 20; t++) ScienceData(
// sample: s,
// sample: s,
temperature: t + s + (random.nextInt(10).toDouble()),
methane: t + s + (random.nextInt(7).toDouble()),
co2: t + s + (random.nextInt(5).toDouble()),
Expand Down
2 changes: 1 addition & 1 deletion lib/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// library should import any other library.
library data;

export "package:burt_network/generated.dart";
export "package:burt_network/protobuf.dart";

export "src/data/metrics/arm.dart";
export "src/data/metrics/drive.dart";
Expand Down
1 change: 1 addition & 0 deletions lib/src/data/protobuf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ extension DeviceUtils on Device {
case Device.DRIVE: return "Drive";
case Device.BASE_STATION: return "Base Station";
case Device.ANTENNA: return "Antenna";
case Device.RELAY: return "Relays";
}
// Do not use default or else you'll lose exhaustiveness checking.
throw ArgumentError("Unrecognized device: $this");
Expand Down
2 changes: 1 addition & 1 deletion lib/src/services/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DashboardSocket extends BurtSocket {
double get frequency => models.settings.network.connectionTimeout;

/// Listens for incoming messages on a UDP socket and sends heartbeats to the [device].
DashboardSocket({required super.device}) : super(port: null, quiet: true);
DashboardSocket({required super.device}) : super(port: null, quiet: true, keepDestination: true);

@override
Duration get heartbeatInterval => Duration(milliseconds: 1000 ~/ frequency);
Expand Down
62 changes: 31 additions & 31 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
url: "https://pub.dev"
source: hosted
version: "2.11.0"
version: "2.12.0"
audio_session:
dependency: transitive
description:
Expand All @@ -37,19 +37,19 @@ packages:
dependency: transitive
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
burt_network:
dependency: "direct main"
description:
path: "."
ref: "2.1.0"
resolved-ref: "61c1952afe2210099ccde59220356db647dc79ae"
url: "https://github.com/BinghamtonRover/Networking.git"
path: burt_network
ref: "2.5.0"
resolved-ref: a52c8a984fcc4f6b022fa540c0ea13b55168ac22
url: "https://github.com/BinghamtonRover/Rover-Code.git"
source: git
version: "2.1.0"
version: "2.4.0"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -78,18 +78,18 @@ packages:
dependency: transitive
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
url: "https://pub.dev"
source: hosted
version: "1.1.1"
version: "1.1.2"
collection:
dependency: "direct main"
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.19.0"
console:
dependency: transitive
description:
Expand Down Expand Up @@ -134,10 +134,10 @@ packages:
dependency: transitive
description:
name: fake_async
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
version: "1.3.2"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -303,18 +303,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
url: "https://pub.dev"
source: hosted
version: "10.0.5"
version: "10.0.8"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
url: "https://pub.dev"
source: hosted
version: "3.0.5"
version: "3.0.9"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -399,10 +399,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
url: "https://pub.dev"
source: hosted
version: "1.9.0"
version: "1.9.1"
path_provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -519,7 +519,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
version: "0.0.0"
source_span:
dependency: transitive
description:
Expand All @@ -540,10 +540,10 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.12.0"
stream_channel:
dependency: transitive
description:
Expand All @@ -556,10 +556,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
sha256: "0bd04f5bb74fcd6ff0606a888a30e917af9bd52820b178eaa464beb11dca84b6"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.4.0"
term_glyph:
dependency: transitive
description:
Expand All @@ -572,10 +572,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.7.3"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -684,10 +684,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
url: "https://pub.dev"
source: hosted
version: "14.2.5"
version: "14.3.1"
web:
dependency: transitive
description:
Expand Down Expand Up @@ -729,5 +729,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.5.3 <4.0.0"
dart: ">=3.6.0 <4.0.0"
flutter: ">=3.24.0"
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ dependencies:
sdk: flutter
burt_network:
git:
url: https://github.com/BinghamtonRover/Networking.git
ref: 2.1.0
url: https://github.com/BinghamtonRover/Rover-Code.git
path: burt_network
ref: 2.5.0
file_picker: ^8.0.0+1
fl_chart: ^0.69.0
flutter_libserialport: ^0.4.0
Expand Down
Loading