File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -256,16 +256,7 @@ private async ValueTask DeviceMessageControl(DeviceControlPayload control)
256256 return ;
257257 }
258258
259- await Control ( [
260- ..control . Controls . Select ( cmd => new ShockerCommand
261- {
262- Model = FlatbuffersMappers . ToFbsModelType ( cmd . Model ) ,
263- Id = cmd . RfId ,
264- Type = FlatbuffersMappers . ToFbsCommandType ( cmd . Type ) ,
265- Intensity = cmd . Intensity ,
266- Duration = cmd . Duration
267- } )
268- ] ) ;
259+ await Control ( control . Controls . Select ( FbsMapper . ToFbsShockerCommand ) . ToArray ( ) ) ;
269260 }
270261
271262 /// <summary>
@@ -349,9 +340,9 @@ private async Task Update()
349340 . Where ( kvp => kvp . Value . ActiveUntil < now || kvp . Value . ExclusiveUntil >= now )
350341 . Select ( kvp => new ShockerCommand
351342 {
352- Model = FlatbuffersMappers . ToFbsModelType ( kvp . Value . Model ) ,
343+ Model = FbsMapper . ToFbsModelType ( kvp . Value . Model ) ,
353344 Id = kvp . Value . RfId ,
354- Type = FlatbuffersMappers . ToFbsCommandType ( kvp . Value . LastType ) ,
345+ Type = FbsMapper . ToFbsCommandType ( kvp . Value . LastType ) ,
355346 Intensity = kvp . Value . LastIntensity ,
356347 Duration = _commandDuration ,
357348 } )
Original file line number Diff line number Diff line change @@ -223,14 +223,7 @@ public async Task RemoveDeviceConnection(IHubController hubController)
223223 IReadOnlyList < DeviceControlPayload . ShockerControlInfo > shocks )
224224 {
225225 if ( ! _lifetimes . TryGetValue ( device , out var deviceLifetime ) ) return new DeviceNotFound ( ) ;
226- await deviceLifetime . Control ( [ .. shocks . Select ( shock => new ShockerCommand
227- {
228- Model = FlatbuffersMappers . ToFbsModelType ( shock . Model ) ,
229- Id = shock . RfId ,
230- Type = FlatbuffersMappers . ToFbsCommandType ( shock . Type ) ,
231- Intensity = shock . Intensity ,
232- Duration = shock . Duration
233- } ) ] ) ;
226+ await deviceLifetime . Control ( shocks . Select ( FbsMapper . ToFbsShockerCommand ) . ToArray ( ) ) ;
234227 return new Success ( ) ;
235228 }
236229
Original file line number Diff line number Diff line change 11using OpenShock . Common . Models ;
2+ using OpenShock . Common . Redis . PubSub ;
3+ using OpenShock . Serialization . Gateway ;
24using OpenShock . Serialization . Types ;
35
46namespace OpenShock . LiveControlGateway . Mappers ;
57
6- public static class FlatbuffersMappers
8+ public static class FbsMapper
79{
810 public static Serialization . Types . ShockerModelType ToFbsModelType ( Common . Models . ShockerModelType type )
911 {
@@ -27,4 +29,16 @@ public static ShockerCommandType ToFbsCommandType(ControlType type)
2729 _ => throw new NotImplementedException ( ) ,
2830 } ;
2931 }
32+
33+ public static ShockerCommand ToFbsShockerCommand ( DeviceControlPayload . ShockerControlInfo control )
34+ {
35+ return new ShockerCommand
36+ {
37+ Model = ToFbsModelType ( control . Model ) ,
38+ Id = control . RfId ,
39+ Type = ToFbsCommandType ( control . Type ) ,
40+ Intensity = control . Intensity ,
41+ Duration = control . Duration
42+ } ;
43+ }
3044}
You can’t perform that action at this time.
0 commit comments