예제 #1
0
        static void ManageConfig()
        {
            // Check if we need to migrate from XML
            if (ConfigurationManager.Get("migratedXML") == null)
            {
                // We need.
                UIConsole.Log("First run on SQLite mode. Migrating XML");
                var config = new XMLProgConfig();
                ProgConfig.SetConfigDefaults();
                ProgConfig.RecordIntermediateFile = config.RecordIntermediateFile;

                ProgConfig.ChannelDataServerName = config.ChannelDataServerName;
                ProgConfig.ChannelDataServerPort = config.ChannelDataServerPort;

                ProgConfig.ConstellationServerName = config.ConstellationServerName;
                ProgConfig.ConstellationServerPort = config.ConstellationServerPort;

                ProgConfig.StatisticsServerName = config.StatisticsServerName;
                ProgConfig.StatisticsServerPort = config.StatisticsServerPort;

                ProgConfig.EnableDCS         = config.EnableDCS;
                ProgConfig.EnableEMWIN       = config.EnableEMWIN;
                ProgConfig.EnableWeatherData = config.EnableWeatherData;

                ProgConfig.EraseFilesAfterGeneratingFalseColor = config.EraseFilesAfterGeneratingFalseColor;

                ProgConfig.GenerateFDFalseColor = config.GenerateFDFalseColor;
                ProgConfig.GenerateNHFalseColor = config.GenerateNHFalseColor;
                ProgConfig.GenerateSHFalseColor = config.GenerateSHFalseColor;
                ProgConfig.GenerateUSFalseColor = config.GenerateUSFalseColor;
                ProgConfig.GenerateXXFalseColor = config.GenerateXXFalseColor;

                ProgConfig.GenerateInfraredImages    = config.GenerateInfraredImages;
                ProgConfig.GenerateVisibleImages     = config.GenerateVisibleImages;
                ProgConfig.GenerateWaterVapourImages = config.GenerateWaterVapourImages;

                ProgConfig.MaxGenerateRetry = config.MaxGenerateRetry;
                ProgConfig.UseNOAAFormat    = config.UseNOAAFormat;

                ProgConfig.TemporaryFileFolder = config.TemporaryFileFolder;
                ProgConfig.FinalFileFolder     = config.FinalFileFolder;

                ProgConfig.SysLogServer   = config.SysLogServer;
                ProgConfig.SysLogFacility = config.SysLogFacility;
                ProgConfig.HTTPPort       = config.HTTPPort;

                ConfigurationManager.Set("migratedXML", true);
            }
            else
            {
                ProgConfig.FillConfigDefaults();
            }
        }
예제 #2
0
        protected override void OnMessage(MessageEventArgs e)
        {
            var d = e.Data;

            try {
                var json = (JObject)JsonConvert.DeserializeObject(d);
                if (json["type"] != null)
                {
                    var type = (string)json["type"];
                    switch (type)
                    {
                    case "config":
                        var variable = (string)json["variable"];
                        var value    = (string)json["value"];
                        UIConsole.Debug($"Received config change request of {variable} to {value}");
                        EventMaster.Post(EventTypes.ConfigChangeEvent, new ConfigChangeEventData {
                            Name = variable, Value = value
                        });
                        break;

                    case "dirlist":
                        var path = (string)json["path"];
                        UIConsole.Debug($"Received request for listing folder {path}");
                        if (dh != null)
                        {
                            var list = dh.ListDir(path);
                            var dl   = new DirList(list);
                            Send(dl.toJSON());
                        }
                        break;

                    case "configList":
                        var configList = ProgConfig.GetConfig();
                        UIConsole.Debug("Received request for listing config.");
                        try {
                            var cl = new ConfigEntryModel(configList);
                            Send(cl.toJSON());
                        } catch (Exception ex) {
                            UIConsole.Error($"Error serializing configList: {ex}");
                        }
                        break;
                    }
                }
            } catch (Exception) {
                UIConsole.Debug($"Received invalid message from ws client: {d}");
            }
        }
예제 #3
0
        public HeadlessMain()
        {
            AppDomain.CurrentDomain.UnhandledException += CrashReport.DefaultExceptionHandler;
            ManageConfig();

            EventMaster.On(EventTypes.ConfigChangeEvent, d => {
                var data = (ConfigChangeEventData)d.Data;
                ProgConfig.UpdateProperty(data.Name, data.Value);
                EventMaster.Post("configSaved", data.Name);
                SetConfigVars();
            });

            SetConfigVars();

            var fdFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_FULLDISK);
            var xxFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_AREA_OF_INTEREST);
            var nhFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_NORTHERN);
            var shFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_SOUTHERN);
            var usFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_UNITEDSTATES);
            var fmFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES16_ABI, (int)ScannerSubProduct.NONE);
            var unkFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.NONE); // Same for any unknown ABI

            FDImageManager  = new ImageManager(fdFolder, "Full Disk");
            XXImageManager  = new ImageManager(xxFolder, "Area of Interest");
            NHImageManager  = new ImageManager(nhFolder, "Northern Hemisphere");
            SHImageManager  = new ImageManager(shFolder, "Southern Hemisphere");
            USImageManager  = new ImageManager(usFolder, "United States");
            FMImageManager  = new ImageManager(fmFolder, "FM1");
            UNKImageManager = new ImageManager(unkFolder, "Unknown");

            FDImageManager.InitMapDrawer();
            XXImageManager.InitMapDrawer();
            NHImageManager.InitMapDrawer();
            SHImageManager.InitMapDrawer();
            USImageManager.InitMapDrawer();
            FMImageManager.InitMapDrawer();
            UNKImageManager.InitMapDrawer();

            directoryHandler = new DirectoryHandler(FileHandler.FinalFileFolder, "/data");

            mtx = new Mutex();
            cn  = new Connector();

            demuxManager = new DemuxManager {
                RecordToFile = ProgConfig.RecordIntermediateFile
            };
            cn.StatisticsAvailable += data => {
                mtx.WaitOne();
                statistics = data;
                mtx.ReleaseMutex();

                if (ProgConfig.SaveStatistics)
                {
                    ThreadPool.QueueUserWorkItem((a) => StatisticsManager.Update(new DBStatistics {
                        SCID                  = data.scid,
                        VCID                  = data.vcid,
                        PacketNumber          = (long)data.packetNumber,
                        VitErrors             = data.vitErrors,
                        FrameBits             = data.frameBits,
                        RSErrors0             = data.rsErrors [0],
                        RSErrors1             = data.rsErrors [1],
                        RSErrors2             = data.rsErrors [2],
                        RSErrors3             = data.rsErrors [3],
                        SignalQuality         = data.signalQuality,
                        SyncCorrelation       = data.syncCorrelation,
                        PhaseCorrection       = data.phaseCorrection,
                        LostPackets           = (long)data.lostPackets,
                        AverageVitCorrections = data.averageVitCorrections,
                        AverageRSCorrections  = data.averageRSCorrections,
                        DroppedPackets        = (long)data.droppedPackets,
                        SyncWord              =
                            $"{data.syncWord[0]:X02}{data.syncWord[1]:X02}{data.syncWord[2]:X02}{data.syncWord[3]:X02}",
                        FrameLock = data.frameLock > 0,
                    }));
                }

                stModel.Refresh(statistics);
                httpsv.WebSocketServices.Broadcast(stModel.toJSON());
            };

            cn.ChannelDataAvailable       += demuxManager.parseBytes;
            cn.ConstellationDataAvailable += data => {
                var cm = new ConstellationModel(data);
                if (httpsv.IsListening)
                {
                    httpsv.WebSocketServices.Broadcast(cm.toJSON());
                }
            };

            statistics = new Statistics_st();
            stModel    = new StatisticsModel(statistics);
            UIConsole.Log("Headless Main Created");
            UIConsole.Log($"HTTP Server at port {ProgConfig.HTTPPort}");
            httpsv = new HttpServer(ProgConfig.HTTPPort)
            {
                RootPath = Path.GetFullPath(Path.Combine(".", "web"))
            };

            httpsv.OnGet += HandleHTTPGet;
            httpsv.AddWebSocketService("/mainws", () => new WSHandler {
                dh = directoryHandler
            });

            UIConsole.MessageAvailable += (data) => {
                var cm = new ConsoleModel(data.Priority.ToString(), data.Message);
                if (httpsv.IsListening)
                {
                    httpsv.WebSocketServices["/mainws"].Sessions.Broadcast(cm.toJSON());
                }

                messageListMutex.WaitOne();
                if (messageList.Count >= MAX_CACHED_MESSAGES)
                {
                    messageList.RemoveAt(0);
                }
                messageList.Add(data);
                messageListMutex.ReleaseMutex();
            };
        }