Skip to content

Commit de28214

Browse files
committed
feat: steering rack control(closes #99)
* refactor: move MotorGear and MotorRollDirection models to separate files
1 parent bb270a5 commit de28214

33 files changed

+563
-534
lines changed

lib/app/scopes/flows/selected_data_source_scope.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,9 @@ class SelectedDataSourceScope extends AutoRouter {
199199
),
200200
),
201201
BlocProvider(
202-
create: (context) => ChangeWheelSteeringBloc(
202+
create: (context) => SteeringRackControlBloc(
203203
dataSource: context.read(),
204-
generalDataCubit: context.read(),
205-
),
204+
)..add(const SteeringRackControlEvent.get()),
206205
),
207206
BlocProvider(
208207
create: (context) =>

lib/data/services/data_source/demo_data_source.dart

+49-24
Original file line numberDiff line numberDiff line change
@@ -592,24 +592,16 @@ class DemoDataSource extends DataSource
592592
},
593593
unavailableForSubscriptionIds: {},
594594
respondCallback: (id, version, manager, [package]) async {
595-
final data = (package?.data).checkNotNull('Package data');
596-
final requestType = data.first;
597-
assert(
598-
[
599-
FunctionId.requestValue.value,
600-
FunctionId.setValueWithParam.value,
601-
].contains(requestType),
602-
'Supported only "set" and "get" request types',
603-
);
595+
final functionId = package.functionId
596+
..assertIsRequestValueOrSetValue();
604597

605598
await manager.updateCallback(
606599
id,
607600
SetUint8ResultBody(
608601
success: !generateRandomErrors() || randomBool,
609-
value: (generateRandomErrors() ||
610-
requestType == FunctionId.requestValue.value)
602+
value: (generateRandomErrors() || functionId.isRequestValue)
611603
? SuspensionMode.random.id
612-
: package?.data.last ?? 0,
604+
: package.dataNotNull.last,
613605
),
614606
version,
615607
);
@@ -619,28 +611,43 @@ class DemoDataSource extends DataSource
619611
),
620612
MainEcuMockResponseWrapper(
621613
ids: {
622-
const DataSourceParameterId.suspensionValue(),
614+
const DataSourceParameterId.steeringRack(),
623615
},
624616
unavailableForSubscriptionIds: {},
625617
respondCallback: (id, version, manager, [package]) async {
626-
final data = (package?.data).checkNotNull('Package data');
627-
final requestType = data.first;
628-
assert(
629-
[
630-
FunctionId.requestValue.value,
631-
FunctionId.setValueWithParam.value,
632-
].contains(requestType),
633-
'Supported only "set" and "get" request types',
618+
final functionId = package.functionId
619+
..assertIsRequestValueOrSetValue();
620+
621+
await manager.updateCallback(
622+
id,
623+
SetUint8ResultBody(
624+
success: !generateRandomErrors() || randomBool,
625+
value: (generateRandomErrors() || functionId.isRequestValue)
626+
? SteeringRack.random.id
627+
: package.dataNotNull.last,
628+
),
629+
version,
634630
);
635631

632+
return const Result.value(null);
633+
},
634+
),
635+
MainEcuMockResponseWrapper(
636+
ids: {
637+
const DataSourceParameterId.suspensionValue(),
638+
},
639+
unavailableForSubscriptionIds: {},
640+
respondCallback: (id, version, manager, [package]) async {
641+
final functionId = package.functionId
642+
..assertIsRequestValueOrSetValue();
643+
636644
await manager.updateCallback(
637645
id,
638646
SetUint8ResultBody(
639647
success: !generateRandomErrors() || randomBool,
640-
value: (generateRandomErrors() ||
641-
requestType == FunctionId.requestValue.value)
648+
value: (generateRandomErrors() || functionId.isRequestValue)
642649
? Random().nextInt(SuspensionMode.kMaxManualValue)
643-
: package?.data.last ?? 0,
650+
: package.dataNotNull.last,
644651
),
645652
version,
646653
);
@@ -781,6 +788,24 @@ extension on int {
781788
bool get toBool => this == 255;
782789
}
783790

791+
extension on DataSourceOutgoingPackage? {
792+
List<int> get dataNotNull => checkNotNull('Package').data;
793+
794+
FunctionId get functionId => FunctionId.fromValue(dataNotNull.first);
795+
}
796+
797+
extension on FunctionId {
798+
void assertIsRequestValueOrSetValue() {
799+
assert(
800+
[
801+
FunctionId.requestValue,
802+
FunctionId.setValueWithParam,
803+
].contains(this),
804+
'Supported only "set" and "get" request types',
805+
);
806+
}
807+
}
808+
784809
@visibleForTesting
785810
final class MainEcuMockManager {
786811
const MainEcuMockManager({

lib/domain/data_source/blocs/change_wheel_steering_bloc.dart

-67
This file was deleted.

lib/domain/data_source/blocs/general_data_cubit.dart

+8-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:pixel_app_flutter/domain/app/app.dart';
55
import 'package:pixel_app_flutter/domain/data_source/data_source.dart';
66
import 'package:pixel_app_flutter/domain/data_source/models/package/incoming/battery_percent.dart';
77
import 'package:pixel_app_flutter/domain/data_source/models/package/incoming/incoming_data_source_packages.dart';
8-
import 'package:pixel_app_flutter/domain/data_source/models/package/incoming/wheelSteering.dart';
98
import 'package:pixel_app_flutter/domain/data_source/models/package_data/package_data.dart';
109
import 'package:re_seedwork/re_seedwork.dart';
1110

@@ -16,7 +15,6 @@ typedef _IntValueModifier = (
1615

1716
extension _SequenceExt on Sequence<IntWithStatus> {
1817
static int avgFold(int a, int b) => a + b;
19-
2018
static int maxFold(int a, int b) => a > b ? a : b;
2119

2220
static _IntValueModifier avg =
@@ -52,7 +50,6 @@ final class GeneralDataState with EquatableMixin {
5250
required this.odometer,
5351
required this.speed,
5452
required this.gear,
55-
required this.wheelSteering,
5653
});
5754

5855
GeneralDataState.initial({
@@ -73,8 +70,7 @@ final class GeneralDataState with EquatableMixin {
7370
gear = Sequence.fill(
7471
hardwareCount.motors,
7572
MotorGear.unknown,
76-
),
77-
wheelSteering = WheelSteering.free;
73+
);
7874

7975
factory GeneralDataState.fromMap(Map<String, dynamic> map) {
8076
return GeneralDataState(
@@ -92,7 +88,6 @@ final class GeneralDataState with EquatableMixin {
9288
gear: Sequence.fromIterable(
9389
map.tryParseAndMapList('gear', MotorGear.fromId),
9490
),
95-
wheelSteering: map.parseAndMap('wheelSteering', WheelSteering.fromId),
9691
);
9792
}
9893

@@ -102,7 +97,6 @@ final class GeneralDataState with EquatableMixin {
10297
final Sequence<IntWithStatus> speed;
10398
final Sequence<MotorGear> gear;
10499
final Sequence<IntWithStatus> batteryPercent;
105-
final WheelSteering wheelSteering;
106100

107101
// TODO(Radomir): hardcoded temporarily because there is only one battery
108102
// at the moment, and the merged value(mean) is irrelevant
@@ -126,16 +120,20 @@ final class GeneralDataState with EquatableMixin {
126120
}
127121

128122
@override
129-
List<Object?> get props =>
130-
[power, batteryPercent, odometer, speed, gear, wheelSteering];
123+
List<Object?> get props => [
124+
power,
125+
batteryPercent,
126+
odometer,
127+
speed,
128+
gear,
129+
];
131130

132131
GeneralDataState copyWith({
133132
Sequence<IntWithStatus>? power,
134133
Sequence<IntWithStatus>? batteryPercent,
135134
IntWithStatus? odometer,
136135
Sequence<IntWithStatus>? speed,
137136
Sequence<MotorGear>? gear,
138-
WheelSteering? wheelSteering,
139137
}) {
140138
return GeneralDataState(
141139
hardwareCount: hardwareCount,
@@ -144,7 +142,6 @@ final class GeneralDataState with EquatableMixin {
144142
odometer: odometer ?? this.odometer,
145143
speed: speed ?? this.speed,
146144
gear: gear ?? this.gear,
147-
wheelSteering: wheelSteering ?? this.wheelSteering,
148145
);
149146
}
150147

@@ -156,7 +153,6 @@ final class GeneralDataState with EquatableMixin {
156153
'odometer': odometer.toMap(),
157154
'speed': [for (final e in speed) e.toMap()],
158155
'gear': [for (final e in gear) e.id],
159-
'wheelSteering': wheelSteering.id,
160156
};
161157
}
162158
}
@@ -220,14 +216,6 @@ class GeneralDataCubit extends Cubit<GeneralDataState> with ConsumerBlocMixin {
220216
odometer: IntWithStatus.fromBytesConvertible(model, km),
221217
),
222218
);
223-
})
224-
..voidOnModel<Uint8WithStatusBody,
225-
WheelSteeringIncomingDataSourcePackage>((model) {
226-
emit(
227-
state.copyWith(
228-
wheelSteering: WheelSteering.fromId(model.value) ,
229-
),
230-
);
231219
});
232220
});
233221
}
@@ -246,7 +234,6 @@ class GeneralDataCubit extends Cubit<GeneralDataState> with ConsumerBlocMixin {
246234
const DataSourceParameterId.batteryPercent2(),
247235
const DataSourceParameterId.batteryPower1(),
248236
const DataSourceParameterId.batteryPower2(),
249-
const DataSourceParameterId.wheelSteering(),
250237
};
251238

252239
@protected

0 commit comments

Comments
 (0)