Пример #1
0
        public override void Initialize()
        {
            AvaloniaXamlLoader.Load(this);

            _settingsManager = Kernel.Get <IApplicationSettingsManager>();
            _ugcsConnection  = Kernel.Get <UGCSConnection>();
            _vehiclesManager = Kernel.Get <VehiclesManager>();
            _ptzTransport    = Kernel.Get <IPTZDeviceMessagesTransport>();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        }
Пример #2
0
        public PelcoDeviceController(
            IPTZDeviceMessagesTransport transport,
            IApplicationSettingsManager settingsManager,
            PelcoRequestBuilder requestBuilder,
            PelcoResponseDecoder responseDecoder)
        {
            _transport = transport;
            _transport.MessageReceived += transport_MessageReceived;

            _settingsManager = settingsManager;
            _requestBuilder  = requestBuilder;
            _responseDecoder = responseDecoder;
        }
Пример #3
0
        static async Task Main(string[] args)
        {
            setupLogConfig();

            _logger.LogInfoMessage($"App started => args:{args.ToJson()}");

            Terminal.WriteLine("UGCS DroneTracker - PTZ Probe tool", ConsoleColor.Yellow);

            // create a new instance of the class that we want to parse the arguments into
            var options = new Options();

            // if everything went out fine the ParseArguments method will return true
            ArgumentParser.Current.ParseArguments(args, options);
            _logger.LogInfoMessage($"Options parsed => options:\n{options.ToJson()}");

            _transport = options.TransportType == PTZDeviceTransportType.Udp
                ? (IPTZDeviceMessagesTransport) new UdpPTZMessagesTransport(options.PTZUdpHost, options.PTZUdpPort)
                : new SerialPortPTZMessagesTransport(options.PTZSerialPortName, options.PTZSerialPortSpeed);

            logInfo("Initialize transport...");
            try
            {
                // TODO
                // await _transport.Initialize();
                _transport.Initialize();
                logOk("Transport initialized");
            }
            catch (Exception e)
            {
                _logger.LogException(e);
                Terminal.WriteLine("Transport initialize error! Check logs to details.", ConsoleColor.Red);

                Terminal.WriteLine("Press enter to exit...");
                Terminal.ReadLine();

                Environment.Exit(1);
            }

            logInfo("Create PTZ device controller");

            _settingsManager = new ApplicationSettingsManager(null);

            _defaultCoreOptions = _settingsManager.GetAppSettings();

            _requestBuilder  = new PelcoRequestBuilder(_defaultCoreOptions.PelcoCodesMapping);
            _responseDecoder = new PelcoResponseDecoder(_defaultCoreOptions.PelcoCodesMapping);

            _controller = new PelcoDeviceController(_transport, _settingsManager, _requestBuilder, _responseDecoder);

            logInfo("PTZ device controller created");

            await requestCurrentPan(options);

            await requestCurrentTilt(options);

            _transport.MessageSending  += _transport_MessageSending;
            _transport.MessageReceived += _transport_MessageReceived;

            await requestMaxPan(options);

            await requestMaxTilt(options);

            logInfo("Try to set pan by 0x71 opCode");
            if (_maxPan.HasValue)
            {
                await requestSetPan(options, (ushort)(_maxPan.Value / 2));
                await requestSetPan(options, (ushort)(_maxPan.Value));
                await requestSetPan(options, 0);
                await requestSetPan(options, (ushort)(_initialPan * 100));
            }
            else
            {
                await requestSetPan(options, 9000);
                await requestSetPan(options, 18000);
                await requestSetPan(options, 0);
                await requestSetPan(options, (ushort)(_initialPan * 100));
            }

            logInfo("Try to set pan by 0x4B opCode");
            byte pelcoSetPanCode = 0x4b;

            if (_maxPan.HasValue)
            {
                await requestSetPan(options, (ushort)(_maxPan.Value / 2), pelcoSetPanCode);
                await requestSetPan(options, (ushort)(_maxPan.Value), pelcoSetPanCode);
                await requestSetPan(options, 0, pelcoSetPanCode);
                await requestSetPan(options, (ushort)(_initialPan * 100), pelcoSetPanCode);
            }
            else
            {
                await requestSetPan(options, 9000, pelcoSetPanCode);
                await requestSetPan(options, 0, pelcoSetPanCode);
                await requestSetPan(options, (ushort)(_initialPan * 100), pelcoSetPanCode);
            }


            logInfo("Try to set tilt by 0x73 opCode");
            if (_maxTilt.HasValue)
            {
                await requestSetTilt(options, (ushort)(_maxTilt.Value / 2));
                await requestSetTilt(options, (ushort)(_maxTilt.Value));
                await requestSetTilt(options, 0);
                await requestSetTilt(options, (ushort)(_initialTilt * 100));
            }
            else
            {
                await requestSetTilt(options, 4500);
                await requestSetTilt(options, 0);
                await requestSetTilt(options, (ushort)(_initialTilt * 100));
            }

            byte pelcoSetTiltCode = 0x4d;

            logInfo("Try to set tilt by 0x4D opCode");
            if (_maxTilt.HasValue)
            {
                await requestSetTilt(options, (ushort)(_maxTilt.Value / 2), pelcoSetTiltCode);
                await requestSetTilt(options, (ushort)(_maxTilt.Value), pelcoSetTiltCode);
                await requestSetTilt(options, 0, pelcoSetTiltCode);
                await requestSetTilt(options, (ushort)(_initialTilt * 100), pelcoSetTiltCode);
            }
            else
            {
                await requestSetTilt(options, 4500, pelcoSetTiltCode);
                await requestSetTilt(options, 0, pelcoSetTiltCode);
                await requestSetTilt(options, (ushort)(_initialPan * 100), pelcoSetTiltCode);
            }


            _logger.LogInfoMessage($"Done. Waiting user to exit.");

            Terminal.WriteLine();
            Terminal.WriteLine("Done.", ConsoleColor.Yellow);
            Terminal.WriteLine("Press enter to exit...", ConsoleColor.Yellow);

            _transport.Teardown();

            Terminal.ReadLine();
        }