Beispiel #1
0
        private void OnSend(SerialPacket serialPacket)
        {
            Contract.Requires(serialPacket != null);

            serialPacket.WriteAsync(unpi.OutputStream).ConfigureAwait(false);
            _logger.Debug($"Transmitted: {serialPacket}");
        }
Beispiel #2
0
        private async void ReadSerialPort(UnifiedNetworkProcessorInterface port)
        {
            if (port == null)
            {
                throw new ArgumentNullException(nameof(port));
            }

            while (true)
            {
                try
                {
                    var serialPacket = await SerialPacket.ReadAsync(port.InputStream).ConfigureAwait(false);

                    if (serialPacket.Type == MessageType.SRSP)
                    {
                        _responseQueue.Add(serialPacket);
                        continue;
                    }

                    if (serialPacket.Type == MessageType.AREQ)
                    {
                        _areqQueue.Add(serialPacket);
                    }
                }
                catch (Exception e)
                {
                    // TODO improve this by adding a good error handling
                    OnError(e);
                }
            }
        }
Beispiel #3
0
        public async Task <byte[]> SendAsync(SerialPacket payload, Func <SerialPacket, bool> predicate, CancellationToken cancellationToken)
        {
            return(await RetryAsync(async() =>
            {
                _transmitQueue.Add(payload);

                var response = await WaitForResponseAsync((msg) => predicate(msg), cancellationToken).ConfigureAwait(false);

                return ((SerialPacket)response).Payload;
            }, $"{payload.Cmd0} {(payload != null ? BitConverter.ToString(payload.Payload) : string.Empty)}", cancellationToken));
        }
Beispiel #4
0
 private void OnReceive(SerialPacket asynchronousRequest)
 {
     _logger.Debug($"Received async message: {asynchronousRequest.GetType().Name}. ({asynchronousRequest})");
 }