Example #1
0
        private static async Task SendMessage(ITransceiver transceiver, string input)
        {
            string data = null;

            switch (CurrentService.Value)
            {
            case Service.Chat:
                data = BuildChatRequest(input);
                break;

            case Service.Ping:
                data = BuildPingRequest(input);
                break;

            case Service.Configure:
                data = BuildConfigureRequest(input);
                break;

            case Service.File:
                data = BuildFileRequest(input);
                break;
            }

            if (!string.IsNullOrEmpty(data))
            {
                await transceiver.Transmit(data);
            }
        }
        /// <summary>
        /// Send a message with no timeout.
        /// </summary>
        private async Task SendMessage(ITransceiver loraTransceiver, byte[] message)
        {
            var stopwatch = new Stopwatch(); // Only out of pure interest...

            stopwatch.Start();

            bool successfullySent = await loraTransceiver.Transmit(message).ConfigureAwait(false);

            stopwatch.Stop();
            WriteLog(successfullySent
                ? $"Successfully sent in {stopwatch.ElapsedMilliseconds} milliseconds."
                : $"Failed after {stopwatch.ElapsedMilliseconds} milliseconds.");
        }
Example #3
0
        /// <summary>
        /// Send a message with a timeout.
        /// </summary>
        private async Task SendMessage(ITransceiver loraTransceiver, byte[] message, TimeSpan timeout)
        {
            using (var cancellationTokenSource = new CancellationTokenSource(timeout))
            {
                var stopwatch = new Stopwatch(); // Only out of pure interest...
                stopwatch.Start();

                bool successfullySent = await loraTransceiver.Transmit(message, cancellationTokenSource.Token).ConfigureAwait(false);

                stopwatch.Stop();
                WriteLog(successfullySent
                    ? $"Successfully sent in {stopwatch.ElapsedMilliseconds} milliseconds."
                    : $"Failed after {stopwatch.ElapsedMilliseconds} milliseconds.");
            }
        }
Example #4
0
        private async Task tranceivePacketAsync()
        {
            var request = await _cache.DequeueAsync();

            if (request.ExpectsAnswer)
            {
                var response = await _transceiver.TransceiveAsync(request);

                await _cache.EnqueueAsync(request, response);
            }
            else
            {
                _transceiver.Transmit(request);
            }
        }
Example #5
0
 /// <summary>
 /// Sends a message to the session.
 /// </summary>
 /// <param name="message"></param>
 public void Send(T message)
 {
     try {
         Transceiver.Transmit(Stream, message);
     }
     catch (Exception x) {
         var source = $"{GetType().Name}.{MethodBase.GetCurrentMethod().Name}";
         if (String.IsNullOrEmpty(x.Source))
         {
             x.Source = source;
         }
         else
         {
             x.Source += $"; {source}";
         }
         ExceptionThrown?.Invoke(this, new ExceptionEventArgs(x));
     }
 }