/// <summary>
        /// Receive a Balloon Message, need to transmit the data in a new TrackerMessage
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task <bool> Receive(BalloonMessage balloonMessage, IModuleClient moduleClient)
        {
            Logger.LogInfo($"Received Balloon Message.");
            UpdatePacketReceiveHistory(true);
            packetReceiptTimer.Change(packetReceiptInterval, packetReceiptInterval);

            this.FlightId = balloonMessage.FlightId;

            var trackerMessage = new TrackerMessage()
            {
                Location   = this.Location,
                DeviceName = this.DeviceName,
                FlightId   = balloonMessage.FlightId,
                PacketReceivedPercentage = CalculatePacketReceivedPercentage()
            };

            try
            {
                Message balloonMessageRaw = new Message(balloonMessage.ToRawBytes());
                await moduleClient.SendEventAsync(TrackerOutputName, balloonMessageRaw);

                Message trackerMessageRaw = new Message(trackerMessage.ToRawBytes());
                await moduleClient.SendEventAsync(TrackerOutputName, trackerMessageRaw);

                Logger.LogInfo($"transmitted message: {JsonConvert.SerializeObject(trackerMessage)}.");
            }
            catch (Exception ex)
            {
                // Todo - wire in with application insights
                Logger.LogWarning($"Error Transmitter tracker message: {ex.Message}");
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        private async Task <bool> SendBalloonMessage(BalloonMessage balloonMessage)
        {
            Message message = new Message(balloonMessage.ToRawBytes());

            try
            {
                await moduleClient.SendEventAsync(SerialOutputName, message);

                Logger.LogInfo($"transmitted message: {JsonConvert.SerializeObject(balloonMessage)}.");
            }
            catch (Exception ex)
            {
                Logger.LogError($"Failed to transmit iot balloon message.");
                Logger.LogException(ex);
                return(false);
            }

            return(true);
        }