Esempio n. 1
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .Enrich.FromLogContext()
                         .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss.fff} {Level:u3}] {Properties:j} {Message:lj}{NewLine}{Exception}")
                         .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))
            {
                AutoRegisterTemplate        = true,
                AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6
            })
                         .CreateLogger();
            DeviceManager deviceManager = new DeviceManager();
            var           zoneA         = deviceManager.AddZone("ZoneA");
            var           zoneB         = deviceManager.AddZone("ZoneB");
            var           zoneC         = deviceManager.AddZone("ZoneC");

            Site.Site siteAA = zoneA.AddSite(new Site.Site("ZoneA-SiteA"));

            TplBooster         tplBooster         = CreateTplBooster();
            Rubidium           rubidium           = CreateRubidium();
            CricketTransciever cricketTransciever = CreateCricketTransciever();
            Apc7920B           apc = CreateApc();

            //Moxa moxa = CreateMoxa();

            siteAA.AddDeviceToSite(tplBooster);
            siteAA.AddDeviceToSite(rubidium);
            siteAA.AddDeviceToSite(cricketTransciever);
            siteAA.AddDeviceToSite(apc);
            //ControlledDevice powerSupply = DeviceFactory.CreateDevice(AvailableDeviceType.PowerSupply, new List<(AvailableApi, AvailableConnection, AvailableSyntax,ConnectionSettings)>
            //{
            //    //( AvailableApi.PowerSupplyApi, AvailableConnection.TcpConnection, AvailableSyntax.ScpiSyntax,new TcpConnectionSettings(new IPEndPoint(IPAddress.Loopback, 8888))),
            //    ( AvailableApi.PowerManagementApi, AvailableConnection.TcpConnection, AvailableSyntax.ScpiSyntax,new TcpConnectionSettings(new IPEndPoint(IPAddress.Loopback, 7777))),
            //});

            //ControlledDevice cricket = DeviceFactory.CreateDevice(AvailableDeviceType.CricketTransciever, new List<(AvailableApi, AvailableConnection, AvailableSyntax, ConnectionSettings)>
            //{
            //    ( AvailableApi.CricketTranscieverApi, AvailableConnection.UdpConnection, AvailableSyntax.ScpiSyntax, new UdpConnectionSettings(new IPEndPoint(IPAddress.Loopback, 11000))),
            //});

            //ControlledDevice rubidium = DeviceFactory.CreateDevice(AvailableDeviceType.Rubidium, new List<(AvailableApi, AvailableConnection, AvailableSyntax, ConnectionSettings)>
            //{
            //    ( AvailableApi.RubidiumApi, AvailableConnection.TcpConnection, AvailableSyntax.RubidiumSyntax, new TcpConnectionSettings(new IPEndPoint(IPAddress.Loopback, 8888))),
            //});

            //siteAA.AddDeviceToSite(powerSupply);
            //siteAA.AddDeviceToSite(cricket);
            //siteAA.AddDeviceToSite(rubidium);

            //RubidiumApi rubidiumApi = ApiFactory.ConfigureDeviceApis<RubidiumApi>(AvailableConnection.TcpConnection,
            //  new TcpConnectionSettings(new IPEndPoint(IPAddress.Parse("127.0.0.1"),8888)), new RubidiumSyntax());

            //Rubidium rubidium = new Rubidium(new PowerSupplySettings());
            //rubidium.AddApi(rubidiumApi);
            //var s = JsonConvert.SerializeObject(rubidium);
            //deviceManager.AddDevice(rubidium, true);

            //var rep = rubidium.GetApi<RubidiumApi>().GetBitReport();
            //var report = rubidiumApi.GetBitReport();
            //var report2 = rubidiumApi.GetSystemReport();
            //var report3 = rubidiumApi.GetTimeReport();

            //TplBoosterApi tplBoosterApi = ApiFactory.ConfigureDeviceApis<TplBoosterApi>(AvailableConnection.HttpConnection,
            //    new HttpConnectionSettings(new UriEndPoint(new Uri("http://localhost:9999"))), new TplBoosterSyntax());


            //PowerSupplyApi psApi = ApiFactory.ConfigureDeviceApis<PowerSupplyApi>(AvailableConnection.TcpConnection,
            //    new TcpConnectionSettings(new IPEndPoint(IPAddress.Loopback, 8888)), new ScpiSyntax());

            //psApi.TurnOn(2);

            //PowerSupply powerSupply =
            //    new PowerSupply(
            //        new PowerSupplySettings());

            ////powerSupply.AddApi(psApi);
            //powerSupply.AddLogic(new PingMonitor(new MonitorSettings(),psApi));
            //powerSupply.Init();

            //SerialEndPoint serialEndPoint = new SerialEndPoint("COM3");
            //DataAcquisition dataAcquisition =
            //    new DataAcquisition(
            //        new DataAcuisitionSettings(new SerialConnectionSettings(serialEndPoint)
            //        {
            //            BaudRate = 115200,
            //            DataBits = 8,
            //            Parity = Parity.None,
            //            StopBits = StopBits.One
            //        }));

            //dataAcquisition.Init();

            //PingMonitor pingMonitor = powerSupply.GetLogic<PingMonitor>();
            //pingMonitor.MonitorSettings.SamplingRate = TimeSpan.FromSeconds(1);

            while (true)
            {
                Console.WriteLine("Press A for activate monitor or D for deactivate");
                ConsoleKeyInfo key = Console.ReadKey();
                if (key.Key == ConsoleKey.A)
                {
                    foreach (var controlledDevice in siteAA.Devices)
                    {
                        controlledDevice.Value.StartAllMonitors();
                    }
                }
                else if (key.Key == ConsoleKey.D)
                {
                    foreach (var controlledDevice in siteAA.Devices)
                    {
                        controlledDevice.Value.StopAllMonitors();
                    }
                }
                else if (key.Key == ConsoleKey.T)
                {
                    //powerSupply.GetLogic<PowerSupplyControlLogic>()?.TurnOn(2);
                }
                else if (key.Key == ConsoleKey.S)
                {
                    Console.WriteLine();
                }
                else if (key.Key == ConsoleKey.Q)
                {
                    break;
                }
            }
        }
Esempio n. 2
0
 public Site.Site AddSite(Site.Site site)
 {
     Sites.Add(site);
     Log.Debug("Site: {@site} added successfully", site);
     return(site);
 }
Esempio n. 3
0
 public void AddSiteToZone(Site.Site site, Zone zone)
 {
     zone.AddSite(site);
 }