Skip to content

Commit

Permalink
Add guards against invalid messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed May 23, 2024
1 parent 5340ed6 commit ae34794
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
3 changes: 1 addition & 2 deletions ios/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ platform :ios do
archive_path: "../build/ios/archive/Runner.xcarchive",
)
upload_to_testflight(
skip_waiting_for_build_processing: true,
changelog: changelog,
build_number: ENV['BUILD_NUMBER'],
app_version: ENV['VERSION'],
#reject_build_waiting_for_review: true,
reject_build_waiting_for_review: true,
api_key_path:"APPLE_SECRETS.json"
)
end
Expand Down
21 changes: 17 additions & 4 deletions lib/Backend/Bluetooth/bluetooth_manager_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,24 @@ Future<void> initFlutterBluePlus(InitFlutterBluePlusRef ref) async {
if (bluetoothCharacteristic.characteristicUuid == Guid("2a19")) {
statefulDevice.batteryLevel.value = values.first.toDouble();
} else if (bluetoothCharacteristic.characteristicUuid == Guid("5073792e-4fc0-45a0-b0a5-78b6c1756c91")) {
String value = const Utf8Decoder().convert(values);
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: value));
statefulDevice.batteryCharging.value = value == "CHARGE ON";
try {
String value = const Utf8Decoder().convert(values);
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: value));
statefulDevice.batteryCharging.value = value == "CHARGE ON";
} catch (e, s) {
_bluetoothPlusLogger.warning("Unable to read values: $values", e, s);
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: "Unknown: ${values.toString()}"));
return;
}
} else if (bluetoothCharacteristic.characteristicUuid == Guid(statefulDevice.baseDeviceDefinition.bleRxCharacteristic)) {
String value = const Utf8Decoder().convert(values);
String value = "";
try {
value = const Utf8Decoder().convert(values);
} catch (e, s) {
_bluetoothPlusLogger.warning("Unable to read values: $values", e, s);
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: "Unknown: ${values.toString()}"));
return;
}
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: value));
// Firmware Version
if (value.startsWith("VER")) {
Expand Down
12 changes: 8 additions & 4 deletions lib/Backend/Definitions/Device/device_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ class BaseStatefulDevice extends ChangeNotifier {

BaseStatefulDevice(this.baseDeviceDefinition, this.baseStoredDevice, this.ref) {
commandQueue = CommandQueue(ref, this);
rxCharacteristicStream = FlutterBluePlus.events.onCharacteristicReceived
.asBroadcastStream()
.where((event) => event.device.remoteId.str == baseStoredDevice.btMACAddress && event.characteristic.characteristicUuid.str == baseDeviceDefinition.bleRxCharacteristic)
.map((event) => const Utf8Decoder().convert(event.value));
rxCharacteristicStream = FlutterBluePlus.events.onCharacteristicReceived.asBroadcastStream().where((event) => event.device.remoteId.str == baseStoredDevice.btMACAddress && event.characteristic.characteristicUuid.str == baseDeviceDefinition.bleRxCharacteristic).map((event) {
try {
return const Utf8Decoder().convert(event.value);
} catch (e, s) {
bluetoothLog.warning("Unable to read values: ${event.value}", e, s);
}
return "";
}).where((event) => event.isNotEmpty);
deviceConnectionState.addListener(() {
if (deviceConnectionState.value == ConnectivityState.disconnected) {
reset();
Expand Down

0 comments on commit ae34794

Please sign in to comment.