private void UdpClientDataReceived(object sender, Spark.Universal.Net.DataReceivedEventArgs e) { // parse datagram byte[] datagram = e.Data; var tt = KnxNetTunnelingDatagram.FromBytes(e.Data); switch (tt.service_type) { case (ushort)KnxHelper.SERVICE_TYPE.CONNECT_RESPONSE: this.ProcessConnectResponse(datagram); break; case (ushort)KnxHelper.SERVICE_TYPE.CONNECTIONSTATE_RESPONSE: this.ProcessStateResponse(datagram); break; case (ushort)KnxHelper.SERVICE_TYPE.TUNNELLING_ACK: this.ProcessTunnelingAck(datagram); break; case (ushort)KnxHelper.SERVICE_TYPE.DISCONNECT_REQUEST: this.ProcessDisconnectRequest(datagram); break; case (ushort)KnxHelper.SERVICE_TYPE.TUNNELLING_REQUEST: ProcessDatagramHeaders(datagram); break; } }
private void ProcessStateResponse(byte[] datagram) { var knxDatagram = KnxNetTunnelingDatagram.FromBytes(datagram); if (knxDatagram == null) { return; } if (knxDatagram.status != 0x21) { return; /* TODO: status should be 0 */ } this.Disconnect(); }
private void ProcessDisconnectRequest(byte[] datagram) { var knxDatagram = KnxNetTunnelingDatagram.FromBytes(datagram); if (knxDatagram == null) { return; } if (knxDatagram.channel_id != _channelId) { return; } this.Disconnected?.Invoke(this, EventArgs.Empty); }
private void ProcessConnectResponse(byte[] datagram) { // HEADER var knxDatagram = KnxNetTunnelingDatagram.FromBytes(datagram); if (knxDatagram == null) { return; } if (knxDatagram.channel_id == 0x00 && knxDatagram.status == 0x24) /* TODO: status should be 0 */ { // no more connections available return; } _channelId = knxDatagram.channel_id; _sequenceNo = 0; this.Connected?.Invoke(this, EventArgs.Empty); }