protected async Task Handle(SerialResultEvent serialResultCommand) { var code = serialResultCommand.AsUint("Code"); var dipswitchCode = DipswitchCode.ParseCode(code); if (dipswitchCode == null) { Logger.LogWarning($"Unrecognized command parsed from code {code}"); return; } await MessageBroker.Publish(DipswitchEvent.Create(Uid, dipswitchCode.Unit.ToString(), dipswitchCode.System.ToString(), dipswitchCode.Command.ToString()), Uid); }
private async Task UpdateState(DipswitchCode code) { var codeShortValue = code.ToShortCode(); bool oldValue = false; if (_state.ContainsKey(codeShortValue)) { oldValue = _state[codeShortValue]; } var newValue = code.Command == RemoteSocketCommand.TurnOn; _state[code.ToShortCode()] = await UpdateState(PowerState.StateName, oldValue, newValue); }
private byte[] PreparePackage(Command message, string commandName, out DipswitchCode dipswitchCode) { var system = message.AsString(MessageProperties.System); var unit = message.AsString(MessageProperties.Unit); var repeat = message.AsInt(MessageProperties.Repeat, DEFAULT_REPEAT); dipswitchCode = DipswitchCode.ParseCode(system, unit, commandName); var package = new byte[8]; package[0] = 2; var code = BitConverter.GetBytes(dipswitchCode.Code); Array.Copy(code, 0, package, 1, 4); package[5] = 24; package[6] = (byte)repeat; package[7] = (byte)_pinNumber; return(package); }