internal MessageEventArgs(DreamScreenResponse response) { Response = response; }
private void HandleIncomingMessages(byte[] data, IPEndPoint endpoint) { var remote = endpoint; var msg = new Message(data, endpoint.Address); var response = DreamScreenResponse.Create(msg); switch (response.Type) { case MessageType.DeviceDiscovery: if (msg.Flag != MessageFlag.SystemMessage) { msg.Identifier = _discoverSourceId; ProcessDeviceDiscoveryMessage(remote.Address, (DreamScreenResponse.StateResponse)response); } break; case MessageType.Subscribe: if (msg.Flag == MessageFlag.SystemMessage) { SubscriptionRequested?.Invoke(this, new DeviceSubscriptionEventArgs(msg.Target)); if (_subscribing && Equals(msg.Target, _subDevice)) { var resp = new Message(msg.Target, MessageType.Subscribe, MessageFlag.SubscriptionResponse, msg.Group) { Payload = new Payload(new object[] { (byte)0x01 }) }; BroadcastMessageAsync(resp).ConfigureAwait(false); } } if (msg.Flag == MessageFlag.SubscriptionResponse) { if (_announceSubscription) { _subscribers[msg.Target] = 3; } } break; case MessageType.ColorData: var cResp = (DreamScreenResponse.ColorResponse)response; if (_subscribing) { ColorsReceived?.Invoke(msg.Target, new DeviceColorEventArgs(cResp.Colors)); } break; default: switch (msg.Flag) { case MessageFlag.Response: _messages.Add(response); break; case MessageFlag.WriteGroup: case MessageFlag.WriteIndividual: case MessageFlag.WriteSomething: CommandReceived?.Invoke(msg.Target, new MessageEventArgs(response)); break; } break; } }