Beispiel #1
0
        public static void DefaultHandler(string filename, XRITHeader fileHeader)
        {
            string dir       = Path.GetDirectoryName(filename);
            string ofilename = fileHeader.Filename ?? Path.GetFileName(filename);

            // Workarround for multi-segment HRIT
            if (fileHeader.Product.ID == (int)NOAAProductID.GOES16_ABI)
            {
                if (fileHeader.SegmentIdentificationHeader != null && fileHeader.SegmentIdentificationHeader.MaxSegments > 1)
                {
                    string baseName = Path.GetFileNameWithoutExtension(ofilename);
                    string ext      = Path.GetExtension(ofilename);
                    string fileH    = fileHeader.SegmentIdentificationHeader.Sequence.ToString("D2");
                    string imageId  = fileHeader.SegmentIdentificationHeader.ImageID.ToString();
                    ofilename = $"{baseName}-img{imageId}-seg{fileH}{ext}";
                }
            }

            string f = PacketManager.FixFileFolder(dir, ofilename, fileHeader.Product, fileHeader.SubProduct);

            if (
                (fileHeader.Product.ID == (int)NOAAProductID.DCS && SkipDCS) ||
                (fileHeader.Product.ID == (int)NOAAProductID.EMWIN && SkipEMWIN) ||
                (fileHeader.Product.ID == (int)NOAAProductID.HRIT_EMWIN && SkipEMWIN) ||
                (fileHeader.Product.ID == (int)NOAAProductID.WEATHER_DATA && SkipWeatherData)
                )
            {
                try {
                    File.Delete(filename);
                } catch (IOException e) {
                    UIConsole.Error(String.Format("Error deleting file {0}: {1}", Path.GetFileName(filename), e));
                }
                return;
            }

            if (File.Exists(f))
            {
                string timestamp = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                string ext       = Path.GetExtension(f);
                string append    = String.Format("--dup-{0}{1}", timestamp, ext);
                f = f.Replace(String.Format("{0}", ext), append);
            }

            UIConsole.Log($"New {fileHeader.ToNameString()}");

            /*if (fileHeader.SubProduct.Name != "Unknown") {
             *  UIConsole.Log($"New {fileHeader.Product.Name} - {fileHeader.SubProduct.Name}");
             * } else {
             *  UIConsole.Log($"New {fileHeader.Product.Name}");
             * }*/

            EventMaster.Post(EventTypes.NewFileEvent, new NewFileReceivedEventData {
                Name     = Path.GetFileName(ofilename),
                Path     = ofilename,
                Metadata =
                {
                    { "product",      fileHeader.Product.Name             },
                    { "subProduct",   fileHeader.SubProduct.Name          },
                    { "productId",    fileHeader.Product.ID.ToString()    },
                    { "subProductId", fileHeader.SubProduct.ID.ToString() }
                }
            });

            try {
                File.Move(filename, f);
            } catch (IOException e) {
                UIConsole.Error(String.Format("Error moving file {0} to {1}: {2}", filename, f, e));
            }
        }
Beispiel #2
0
        public Main()
        {
            #region Create Config File
            config.RecordIntermediateFile  = config.RecordIntermediateFile;
            config.ChannelDataServerName   = config.ChannelDataServerName;
            config.ChannelDataServerPort   = config.ChannelDataServerPort;
            config.ConstellationServerName = config.ConstellationServerName;
            config.ConstellationServerPort = config.ConstellationServerPort;
            config.StatisticsServerName    = config.StatisticsServerName;
            config.StatisticsServerPort    = config.StatisticsServerPort;
            config.EnableDCS   = config.EnableDCS;
            config.EnableEMWIN = config.EnableEMWIN;
            config.EraseFilesAfterGeneratingFalseColor = config.EraseFilesAfterGeneratingFalseColor;
            config.GenerateFDFalseColor      = config.GenerateFDFalseColor;
            config.GenerateNHFalseColor      = config.GenerateNHFalseColor;
            config.GenerateSHFalseColor      = config.GenerateSHFalseColor;
            config.GenerateUSFalseColor      = config.GenerateUSFalseColor;
            config.GenerateXXFalseColor      = config.GenerateXXFalseColor;
            config.HTTPPort                  = config.HTTPPort;
            config.GenerateInfraredImages    = config.GenerateInfraredImages;
            config.GenerateVisibleImages     = config.GenerateVisibleImages;
            config.GenerateWaterVapourImages = config.GenerateWaterVapourImages;
            config.MaxGenerateRetry          = config.MaxGenerateRetry;
            config.SysLogServer              = config.SysLogServer;
            config.SysLogFacility            = config.SysLogFacility;
            config.UseNOAAFormat             = config.UseNOAAFormat;
            config.EnableWeatherData         = config.EnableWeatherData;
            config.TemporaryFileFolder       = config.TemporaryFileFolder;
            config.FinalFileFolder           = config.FinalFileFolder;
            config.Save();
            #endregion

            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            cfd = null;
            graphics.PreferredBackBufferWidth  = 1280;
            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferMultiSampling       = true;

            this.Exiting += (object sender, EventArgs e) => {
                //cn.Stop();
            };

            FileHandler.SkipEMWIN       = !config.EnableEMWIN;
            FileHandler.SkipDCS         = !config.EnableDCS;
            FileHandler.SkipWeatherData = !config.EnableWeatherData;

            if (config.TemporaryFileFolder != null)
            {
                if (!LLTools.TestFolderAccess(config.TemporaryFileFolder))
                {
                    UIConsole.GlobalConsole.Error($"Cannot write file to Temporary Folder {config.TemporaryFileFolder}");
                    throw new ApplicationException($"Cannot write file to Temporary Folder {config.TemporaryFileFolder}");
                }
                FileHandler.TemporaryFileFolder = config.TemporaryFileFolder;
            }

            if (config.FinalFileFolder != null)
            {
                if (!LLTools.TestFolderAccess(config.FinalFileFolder))
                {
                    UIConsole.GlobalConsole.Error($"Cannot write file to Final Folder {config.FinalFileFolder}");
                    throw new ApplicationException($"Cannot write file to Final Folder {config.FinalFileFolder}");
                }
                FileHandler.FinalFileFolder = config.FinalFileFolder;
            }

            ImageManager.EraseFiles          = config.EraseFilesAfterGeneratingFalseColor;
            ImageManager.GenerateInfrared    = config.GenerateInfraredImages;
            ImageManager.GenerateVisible     = config.GenerateVisibleImages;
            ImageManager.GenerateWaterVapour = config.GenerateWaterVapourImages;
            ImageManager.MaxRetryCount       = config.MaxGenerateRetry;
            ImageManager.UseNOAAFileFormat   = config.UseNOAAFormat;

            Connector.ChannelDataServerName   = config.ChannelDataServerName;
            Connector.StatisticsServerName    = config.StatisticsServerName;
            Connector.ConstellationServerName = config.ConstellationServerName;

            Connector.ChannelDataServerPort   = config.ChannelDataServerPort;
            Connector.StatisticsServerPort    = config.StatisticsServerPort;
            Connector.ConstellationServerPort = config.ConstellationServerPort;

            if (LLTools.IsLinux)
            {
                SyslogClient.SysLogServerIp = config.SysLogServer;
                try {
                    SyslogClient.Send(new Message(config.SysLogFacility, Level.Information, "Your syslog connection is working! OpenSatelliteProject is enabled to send logs."));
                } catch (SocketException) {
                    UIConsole.GlobalConsole.Warn("Your syslog is not enabled to receive UDP request. Please refer to https://opensatelliteproject.github.io/OpenSatelliteProject/");
                }
            }

            string fdFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_FULLDISK);
            string xxFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_AREA_OF_INTEREST);
            string nhFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_NORTHERN);
            string shFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_SOUTHERN);
            string usFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_UNITEDSTATES);
            string fmFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES16_ABI, (int)ScannerSubProduct.NONE);

            FDImageManager = new ImageManager(fdFolder);
            XXImageManager = new ImageManager(xxFolder);
            NHImageManager = new ImageManager(nhFolder);
            SHImageManager = new ImageManager(shFolder);
            USImageManager = new ImageManager(usFolder);
            FMImageManager = new ImageManager(fmFolder);
        }
Beispiel #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();
            };
        }
Beispiel #4
0
        public void Process(byte[] inData)
        {
            buffer = buffer.Concat(inData).ToArray();
            var pos = FindSyncMarker(buffer);

            if (pos == -1)
            {
                if (buffer.Length > MAX_FRAME_SIZE * 3)
                {
                    UIConsole.Warn($"EMWIN Buffer grown beyond {MAX_FRAME_SIZE * 3}! This should happen. Clearing buffer.");
                    buffer = new byte[0];
                }
                return;
            }

            var data = buffer.Skip(pos + 6).Take(MAX_FRAME_SIZE - 6).ToArray(); // 12 for the syncMark

            if (data.Length != MAX_FRAME_SIZE - 6)
            {
                // Not Enough Data
                return;
            }

            buffer = buffer.Skip(pos + MAX_FRAME_SIZE).ToArray();
            if (data.Length > 0)
            {
                var headerData = Encoding.GetEncoding("ISO-8859-1").GetString(data.Take(80).ToArray());
                data = data.Skip(80).ToArray();

                try {
                    var header = new EMWINHeader(headerData);
                    if (header.Filename.Equals(FILLFILENAME))
                    {
                        return;
                    }
                    //UIConsole.GlobalConsole.Log(string.Format("Received {0}/{1} of {2}", header.PartNumber, header.PartTotal, header.Filename));
                    if (header.PartNumber == 1)
                    {
                        if (files.ContainsKey(header.Filename))
                        {
                            UIConsole.Warn($"Files already has a key for file {header.Filename}");
                        }
                        else
                        {
                            string newfilename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + header.Filename;
                            files.Add(header.Filename, new EmwinFile());
                            files[header.Filename].Parts    = header.PartTotal;
                            files[header.Filename].Received = 0;
                            files[header.Filename].Output   = Path.Combine("channels", Path.Combine("tmp", newfilename));
                        }
                    }

                    if (!files.ContainsKey(header.Filename))
                    {
                        //UIConsole.GlobalConsole.Warn(string.Format("(EMWIN) Received incomplete part for {0}", header.Filename));
                        return;
                    }
                    else if (files[header.Filename].Received + 1 != header.PartNumber)
                    {
                        //UIConsole.GlobalConsole.Error(string.Format("(EMWIN) Missed {0} frames for file {1}", header.PartNumber - files[header.Filename].Received - 1, header.Filename));
                        files.Remove(header.Filename);
                        return;
                    }
                    else
                    {
                        string dir = Path.GetDirectoryName(files[header.Filename].Output);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        var f = File.Open(files[header.Filename].Output, header.PartNumber == 1 ? FileMode.Create : FileMode.Append);
                        f.Write(data, 0, data.Length);
                        f.Close();
                        files[header.Filename].Received += 1;
                    }

                    if (header.PartNumber == header.PartTotal && files.ContainsKey(header.Filename))
                    {
                        string output  = files[header.Filename].Output;
                        string basedir = new DirectoryInfo(Path.GetDirectoryName(output)).Parent.FullName;
                        string newdir  = Path.Combine(basedir, "EMWIN");

                        if (!Directory.Exists(newdir))
                        {
                            Directory.CreateDirectory(newdir);
                        }

                        string fname = Path.Combine(newdir, header.Filename);
                        if (File.Exists(fname))
                        {
                            fname = DateTime.Now.ToString("yyyyMMddHHmmssffff") + "-" + header.Filename;
                            fname = Path.Combine(newdir, fname);
                        }
                        File.Move(files[header.Filename].Output, fname);
                        UIConsole.Log(string.Format("New EMWIN ({0})", header.Filename));
                        files.Remove(header.Filename);
                        if (fname.Contains(".ZIS"))
                        {
                            PacketManager.ExtractZipFile(fname);
                        }
                    }
                } catch (Exception e) {
                    UIConsole.Error($"(EMWIN) Error: {e.Message}");
                }
            }
        }