Skip to content
Open
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
25 changes: 22 additions & 3 deletions lib/communication/science_lab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ScienceLab {
List<DigitalChannel> dChannels = [];
Map<String, DACChannel> dacChannels = {};
static final double capacitorDischargeVoltage = 0.01 * 3.3;
static const double frequencyError = -1;

late CommunicationHandler mCommunicationHandler;
late SocketClient mSocketClient;
Expand Down Expand Up @@ -582,7 +583,7 @@ class ScienceLab {
}
} else {
logger.e("Error: Can't load data");
return -1;
return frequencyError;
}
Comment on lines 583 to 587
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetchLAChannelFrequency still uses temp! earlier in this method right after fetchIntDataFromLA(...). Since fetchIntDataFromLA can return null on communication errors, this path can still crash with a null-check-operator exception. Add a null guard for temp and return frequencyError before indexing/using temp.length.

Copilot uses AI. Check for mistakes.
dChan.loadData(tempMap, data);

Expand All @@ -609,9 +610,27 @@ class ScienceLab {
await Future.delayed(const Duration(milliseconds: 250));
} catch (e) {
logger.e("Error in getFrequency: $e");
return frequencyError;
}

// Null check to prevent crash when getLAInitialStates fails
if (data == null) {
logger.e("Error in getFrequency: getLAInitialStates returned null");
return frequencyError;
}

int? channelNumber = calculateDigitalChannel(channel);
if (channelNumber == null) {
logger.e("Error in getFrequency: invalid channel $channel");
return frequencyError;
}
Comment on lines +622 to +626
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In getFrequency, the channel validity is checked only after calling startOneChannelLA(...). Since startOneChannelLA catches its own exceptions (including null-asserts on invalid channels) and returns normally, getFrequency can continue in a partially-initialized state. Consider validating calculateDigitalChannel(channel) before starting the LA and returning frequencyError early for invalid channels.

Copilot uses AI. Check for mistakes.

try {
return await fetchLAChannelFrequency(channelNumber, data);
} catch (e) {
logger.e("Error in getFrequency while fetching LA channel frequency: $e");
return frequencyError;
}
return await fetchLAChannelFrequency(
calculateDigitalChannel(channel)!, data!);
}
Comment on lines +625 to 634
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getFrequency can still crash inside fetchLAChannelFrequency because that method force-unwraps the result of fetchIntDataFromLA (temp!), which can return null on communication errors. Consider making fetchLAChannelFrequency null-safe (returning frequencyError) or wrapping this call in a try/catch and converting failures to frequencyError.

Copilot uses AI. Check for mistakes.

Future<void> startOneChannelLA(String? channel, int? channelMode,
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"knobMarkerCh2": "CH2",
"voltage": "Voltage",
"unitHz": "Hz",
"cannotMeasure": "Cannot measure!",
Comment thread
marcnause marked this conversation as resolved.
"countPulse": "Count Pulse",
"measure": "Measure",
"connectDevice": "Connect Device",
Expand Down
6 changes: 6 additions & 0 deletions lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,12 @@ abstract class AppLocalizations {
/// **'Hz'**
String get unitHz;

/// No description provided for @cannotMeasure.
///
/// In en, this message translates to:
/// **'Cannot measure!'**
String get cannotMeasure;

/// No description provided for @countPulse.
///
/// In en, this message translates to:
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_he.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsHe extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_hi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsHi extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsId extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_ja.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_nb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsNb extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_pt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_uk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_vi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsVi extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get unitHz => 'Hz';

@override
String get cannotMeasure => 'Cannot measure!';

@override
String get countPulse => 'Count Pulse';

Expand Down
17 changes: 11 additions & 6 deletions lib/providers/multimeter_state_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class MultimeterStateProvider extends ChangeNotifier {
resistanceValue = avgResistance.toStringAsFixed(2);
resistanceUnit = "\u2126";
} else {
resistanceValue = "Cannot measure!";
resistanceValue = appLocalizations.cannotMeasure;
resistanceUnit = "\u2126";
Comment thread
marcnause marked this conversation as resolved.
}
}
Expand All @@ -172,7 +172,7 @@ class MultimeterStateProvider extends ChangeNotifier {
String capacitanceValue;
String capacitanceUnit;
if (capacitance == null) {
capacitanceValue = "Cannot measure!";
capacitanceValue = appLocalizations.cannotMeasure;
capacitanceUnit = "pF";
} else {
if (capacitance < 1e-9) {
Expand Down Expand Up @@ -245,17 +245,22 @@ class MultimeterStateProvider extends ChangeNotifier {
if (!isSwitchChecked) {
double frequency =
await _scienceLab.getFrequency(knobMarker[_selectedIndex]);
value = frequency.toStringAsFixed(2);
unit = appLocalizations.unitHz;
if (frequency == ScienceLab.frequencyError) {
value = appLocalizations.cannotMeasure;
unit = "";
} else {
value = frequency.toStringAsFixed(2);
unit = appLocalizations.unitHz;
}
} else {
await _scienceLab.countPulses(knobMarker[_selectedIndex]);
int pulseCount = await _scienceLab.readPulseCount();
value = pulseCount.toString();
unit = "";
}
} catch (e) {
value = "Cannot measure!";
unit = "null";
value = appLocalizations.cannotMeasure;
unit = "";
}
}

Expand Down
Loading