Exemple #1
0
        /// <remarks/>
        public System.IAsyncResult BegindoDeviceStatusReport(DeviceStatusReport DeviceStatusReport, System.AsyncCallback callback, object asyncState)
        {
            doDeviceStatusReportRequest inValue = new doDeviceStatusReportRequest();

            inValue.DeviceStatusReport = DeviceStatusReport;
            return(((SNSR_STDSOAPPort)(this)).BegindoDeviceStatusReport(inValue, callback, asyncState));
        }
Exemple #2
0
 /// <summary>
 /// Send a custom <see cref="DeviceStatusReport"/> message to every mars client subscribed
 /// </summary>
 public void SendCustomDeviceStatusReport(DeviceStatusReport statusReport)
 {
     foreach (var client in _marsClients)
     {
         SendCustomDeviceStatusReport(statusReport, client.Key);
     }
 }
Exemple #3
0
        /// <remarks/>
        public void doDeviceStatusReport(ref DeviceStatusReport DeviceStatusReport)
        {
            doDeviceStatusReportRequest inValue = new doDeviceStatusReportRequest();

            inValue.DeviceStatusReport = DeviceStatusReport;
            doCommandMessageResponse retVal = ((SNSR_STDSOAPPort)(this)).doDeviceStatusReport(inValue);

            DeviceStatusReport = retVal.DeviceStatusReport;
        }
Exemple #4
0
        public Sensor(DeviceConfiguration configuration, DeviceStatusReport status)
        {
            Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            StatusReport  = status ?? throw new ArgumentNullException(nameof(status));

            _marsClients        = new Dictionary <string, MrsClient>();
            _pendingIndications = new List <IndicationType>(400);

            //_socket.NewMessageReceived += WebSocketMessageHandler;
            //_socket.Setup(IP, Port);

            _timer          = new Timer();
            _timer.Elapsed += Timer_Elapsed;
        }
Exemple #5
0
        private DeviceStatusReport GetEmptyStatus(DeviceStatusReport fullStatus)
        {
            // create new deep copy
            var status = fullStatus.Copy();

            // empty out status items
            status.Items = status.Items.OfType <SensorStatusReport>().Select(x => x.Copy()).ToArray();
            foreach (SensorStatusReport statusReport in status.Items)
            {
                statusReport.Item          = null;
                statusReport.PictureStatus = null;
            }
            return(status);
        }
Exemple #6
0
 /// <summary>
 /// Send a custom <see cref="DeviceStatusReport"/> message to a specific mars client
 /// </summary>
 /// <param name="statusReport">the status report</param>
 /// <param name="clientName">mars name (can be found in <see cref="_marsClients"/>)</param>
 public void SendCustomDeviceStatusReport(DeviceStatusReport statusReport, string clientName)
 {
     if (_marsClients.ContainsKey(clientName))
     {
         var emptyStatus = GetEmptyStatus(StatusReport);
         if (!ValidateMessages || emptyStatus.IsValid(out var exception))
         {
             _marsClients[clientName].SoapClient.BegindoDeviceStatusReport(emptyStatus, null, null);
             MessageSent?.BeginInvoke(statusReport, clientName, null, null);
         }
         else
         {
             ValidationErrorOccured?.Invoke(this, new InvalidMessageException(emptyStatus, exception));
         }
     }
 }
Exemple #7
0
        private void Device_MessageReceived(object sender, MrsMessage e)
        {
            Device dvc = (Device)sender;

            Console.WriteLine($"{e.MrsMessageType} received from {dvc.DeviceIP}:{dvc.DevicePort}");
            switch (e.MrsMessageType)
            {
            case MrsMessageTypes.DeviceConfiguration:
                // save config
                _deviceConfiguration = (DeviceConfiguration)e;
                // override ip and port
                _deviceConfiguration.NotificationServiceIPAddress = _configuration.ListenIP;
                _deviceConfiguration.NotificationServicePort      = _configuration.ListenPort.ToString();
                break;

            case MrsMessageTypes.DeviceStatusReport:
                // save status
                // if status contain already values - update
                _statusReport =
                    (DeviceStatusReport)(_statusReport == null
                            ? e
                            : _statusReport.UpdateValues(e));
                if (_sensor == null)
                {
                    // now that we have config and status, start the sensor (listening side)
                    _sensor = new Sensor(_deviceConfiguration, _statusReport)
                    {
                        ValidateMessages = false
                    };
                    _sensor.MessageSent            += Sensor_MessageSent;
                    _sensor.MessageReceived        += Sensor_MessageReceived;
                    _sensor.ValidationErrorOccured += Sensor_ValidationErrorOccured;
                    Console.WriteLine("Starting sensor...");
                    _sensor.Start();
                    Console.WriteLine($"Sensor started on {_sensor.IP}:{_sensor.Port}");
                }

                break;

            case MrsMessageTypes.DeviceIndicationReport:
                var indicationReport = (DeviceIndicationReport)e;
                _sensor?.RegisterIndications(ExtractIndications(indicationReport));
                break;
            }
        }
Exemple #8
0
        private DeviceStatusReport GetEmptyStatus(DeviceStatusReport fullStatus)
        {
            // create new deep copy
            var status = fullStatus.Copy();

            // empty out status items
            status.Items = status.Items.Select(x => x.Copy()).ToArray();
            foreach (var item in status.Items)
            {
                if (item is DeviceStatusReport deviceStatus)
                {
                    GetEmptyStatus(deviceStatus);
                }
                if (item is SensorStatusReport sensorStatus)
                {
                    sensorStatus.Item          = null;
                    sensorStatus.PictureStatus = null;
                }
            }

            //status.Items = status.Items.Where(x => x is SensorStatusReport || x is DetailedSensorBITType).ToArray();
            return(status);
        }
Exemple #9
0
        /// <summary>
        /// Class Constructor
        /// </summary>
        /// <param name="configuration">sensor's configuration</param>
        /// <param name="status">sensor's current FULL status report</param>
        public Sensor(DeviceConfiguration configuration, DeviceStatusReport status)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var pattern = @"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";

            IP = configuration.NotificationServiceIPAddress;

            if (!Regex.IsMatch(IP, pattern))
            {
                throw new ArgumentException("Invalid IP adderss!", nameof(configuration.NotificationServiceIPAddress));
            }

            if (int.TryParse(configuration.NotificationServicePort, out int port))
            {
                Port = port;
            }
            else
            {
                throw new ArgumentException("Invalid Port", nameof(configuration.NotificationServicePort));
            }

            if (Port <= 0 || Port > 65535)
            {
                throw new ArgumentException("Invaild port! port must be higher than zero and lower than 65535", nameof(port));
            }
            DeviceConfiguration = configuration;
            StatusReport        = status ?? throw new ArgumentNullException(nameof(status));

            _marsClients          = new Dictionary <string, MarsClient>();
            _sensorTimer          = new Timer(1000);
            _sensorTimer.Elapsed += SensorTimer_Elapsed;
        }
Exemple #10
0
        public Sensor(DeviceConfiguration configuration, DeviceStatusReport status)
        {
            Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            StatusReport  = status ?? throw new ArgumentNullException(nameof(status));

            _marsClients        = new Dictionary <string, MrsClient>();
            _pendingIndications = new List <IndicationType>(400);

            _socketHost = WebSocketHostBuilder.Create()
                          .ConfigureAppConfiguration((context, builder) =>
            {
                builder.AddInMemoryCollection(new Dictionary <string, string>
                {
                    { "serverOptions:name", "MrsSensorServer" },
                    { "serverOptions:listeners:0:ip", $"{IP}" },
                    { "serverOptions:listeners:0:port", $"{Port}" }
                });
            })
                          .UseWebSocketMessageHandler(WebSocketMessageHandler)
                          .Build();

            _timer          = new Timer();
            _timer.Elapsed += Timer_Elapsed;
        }
Exemple #11
0
        static void Main(string[] args)
        {
            var devieId = new DeviceIdentificationType
            {
                DeviceName = "Device",
                DeviceType = DeviceTypeType.AcousticDetectionSystem
            };
            var sensorId = new SensorIdentificationType
            {
                SensorName = "Sensor",
                SensorType = SensorTypeType.Acoustic
            };
            DeviceConfiguration configuration = new DeviceConfiguration
            {
                NotificationServiceIPAddress = "127.0.0.1",
                NotificationServicePort      = "41000",
                DeviceIdentification         = devieId,
                SensorConfiguration          = new[]
                {
                    new SensorConfiguration
                    {
                        SensorIdentification = sensorId
                    }
                }
            };
            DeviceStatusReport status = new DeviceStatusReport
            {
                DeviceIdentification = configuration.DeviceIdentification,
                Items = new object[]
                {
                    new DetailedSensorBITType
                    {
                        SensorIdentification = sensorId,
                        FaultCode            = new string[0]
                    },
                    new SensorStatusReport
                    {
                        SensorIdentification = sensorId,
                        CommunicationState   = BITResultType.OK,
                        PowerState           = StatusType.Yes,
                        SensorTechnicalState = BITResultType.OK,
                        SensorMode           = SensorModeType.Normal
                    }
                }
            };

            Sensor sensor = new Sensor(configuration, status)
            {
                ValidateMessages = false
            };

            sensor.MessageReceived        += Sensor_MessageReceived;
            sensor.MessageSent            += Sensor_MessageSent;
            sensor.ValidationErrorOccured += Sensor_ValidationErrorOccured;

            Console.WriteLine("Starting Sensor...");
            sensor.Start();
            Console.WriteLine($"Sensor Started on {sensor.IP}:{sensor.Port}");

            int i = 0;

            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                sensor.RegisterIndications(CreateIndocation(++i, 32.5, 34.5));
            }
            Console.ReadKey(true);

            sensor.Stop();
        }
Exemple #12
0
 public doDeviceStatusReportRequest(DeviceStatusReport DeviceStatusReport)
 {
     this.DeviceStatusReport = DeviceStatusReport;
 }
Exemple #13
0
 public doCommandMessageResponse(DeviceStatusReport DeviceStatusReport)
 {
     this.DeviceStatusReport = DeviceStatusReport;
 }