Exemple #1
0
        /**
         * Return true if
         */
        private TelemetryFormat GetMetadataForTelemetry(SignalTelemetry signalData)
        {
            if (this.GatewayConfig.ReportedTelemetry.ContainsKey(signalData.Name))
            {
                TelemetryMetadataModel gwConfigMetadata = this.GatewayConfig.ReportedTelemetry.GetValueOrDefault(signalData.Name);

                // Construct metadata
                TelemetryFormat telemetryMetaData = new TelemetryFormat()
                {
                    Name        = signalData.Name,
                    DisplayName = gwConfigMetadata.DisplayName,
                    Type        = signalData.ValueType.ToLowerInvariant()
                };
                // Check if we have metadata description in monitoring device
                if (!this.GatewayDeviceConfig.Telemetry.Contains(telemetryMetaData))
                {
                    this.GatewayDeviceConfig.Telemetry.Add(telemetryMetaData);
                    Console.WriteLine(String.Format("Telemetry configured for remote monitoring: Name: {0}, Type: {1}, DisplayName: {2}",
                                                    telemetryMetaData.Name, telemetryMetaData.Type, telemetryMetaData.DisplayName));
                    this.IsDeviceInfoUpdated = true;
                }

                return(telemetryMetaData);
            }
            else
            {
                Console.WriteLine("Signal {0} is not configured for reporting at the module Twin ", signalData.Name);
                return(null);
            }
        }
Exemple #2
0
        public async Task ProcessAbbDriveProfileTelemetry(List <SignalTelemetry> telemetryData)
        {
            await Task.Run(() => {
                bool hasMutex = false;

                try{
                    hasMutex = this.telemetryMutex.WaitOne(this.GatewayConfig.ReportingInterval);
                    if (hasMutex)
                    {
                        foreach (SignalTelemetry signalData in telemetryData)
                        {
                            TelemetryFormat telemetryMetaData = GetMetadataForTelemetry(signalData);
                            if (telemetryMetaData != null && !String.IsNullOrEmpty(signalData.Value))
                            {
                                object value = null;
                                // convert telemetry value based on specified data type
                                if (telemetryMetaData.Type.Equals("double"))
                                {
                                    value = double.Parse(signalData.Value);
                                }
                                else if (telemetryMetaData.Type.Equals("int"))
                                {
                                    value = int.Parse(signalData.Value);
                                }
                                else
                                {
                                    // Use string as a default value type
                                    value = signalData.Value;
                                }

                                if (this.Telemetry.ContainsKey(signalData.Name))
                                {
                                    this.Telemetry[signalData.Name] = value;
                                }
                                else
                                {
                                    this.Telemetry.Add(signalData.Name, value);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Error processing signal {0} value {1}", signalData.Name, signalData.Value);
                            }
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException(String.Format("Can't handle telemetry. Timeout after {0} ms. ", this.GatewayConfig.ReportingInterval));
                    }
                }
                finally{
                    if (hasMutex)
                    {
                        this.telemetryMutex.ReleaseMutex();
                    }
                }
            });
        }