Example #1
0
        public static string Decompressor(string filename, int pixels, int pixelsPerBlock, int mask)
        {
            /**
             *  Temporary Workarround. Needs to change directly on Demuxer
             */
            string outputFile = String.Format("{0}_decomp.lrit", filename);

            byte[] outputData = new byte[pixels];

            for (int i = 0; i < pixels; i++)
            {
                outputData[i] = 0x00;
            }

            try {
                byte[] inputData = File.ReadAllBytes(filename);
                AEC.LritRiceDecompress(ref outputData, inputData, 8, pixelsPerBlock, pixels, mask); //  AEC.ALLOW_K13_OPTION_MASK | AEC.MSB_OPTION_MASK | AEC.NN_OPTION_MASK
                File.Delete(filename);
            } catch (Exception e) {
                if (e is AECException)
                {
                    AECException aece = (AECException)e;
                    UIConsole.Error(string.Format("AEC Decompress Error: {0}", aece.status.ToString()));
                }
                else
                {
                    UIConsole.Error(string.Format("Decompress error: {0}", e.ToString()));
                }
            }

            File.WriteAllBytes(outputFile, outputData);
            return(outputFile);
        }
Example #2
0
 static Presets()
 {
     byte[] falsecolor = ReadFileFromAssembly("falsecolor.png");
     if (falsecolor != null)
     {
         using (var ms = new MemoryStream(falsecolor)) {
             Bitmap bmp = new Bitmap(ms);
             if (bmp.Width != 256 || bmp.Height != 256)
             {
                 UIConsole.Error("False Color LUT is not 256x256 pixels");
             }
             else
             {
                 for (int y = 0; y < 256; y++)
                 {
                     for (int x = 0; x < 256; x++)
                     {
                         FalseColorLUT [y * 256 + x] = bmp.GetPixel(x, y).ToArgb();
                     }
                 }
             }
             bmp.Dispose();
         }
     }
     else
     {
         UIConsole.Error("Cannot load file falsecolor.png from resources");
     }
     RadianceOffset = 0;
     ThermalOffset  = 0;
 }
Example #3
0
        static LibInfo()
        {
            var assembly = Assembly.GetExecutingAssembly();

            try {
                using (Stream stream = assembly.GetManifestResourceStream("OpenSatelliteProject.git-hash.txt"))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string result = reader.ReadToEnd();
                        _commitId = result;
                    }
            } catch (Exception) {
                UIConsole.Warn("Cannot load git-hash from library.");
            }

            try {
                using (Stream stream = assembly.GetManifestResourceStream("OpenSatelliteProject.git-log.txt"))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string result = reader.ReadToEnd();
                        _gitlog = result;
                    }
            } catch (Exception) {
                UIConsole.Warn("Cannot load git-log from library.");
            }
        }
Example #4
0
 static void Init()
 {
     if (GlobalConsole == null)
     {
         GlobalConsole = new UIConsole();
     }
 }
Example #5
0
        private static byte[] ReadFileFromAssembly(string filename)
        {
            byte[] data     = null;
            var    assembly = Assembly.GetExecutingAssembly();

            try {
                Stream stream = assembly.GetManifestResourceStream($"OpenSatelliteProject.ShapeFiles.{filename}");
                if (stream == null)
                {
                    stream = assembly.GetManifestResourceStream($"OpenSatelliteProject.{filename}");
                }
                using (stream) {
                    data = new byte[stream.Length];
                    int position = 0;
                    while (position < stream.Length)
                    {
                        int chunkSize = stream.Length - position > 4096 ? 4096 : (int)(stream.Length - position);
                        stream.Read(data, position, chunkSize);
                        position += chunkSize;
                    }
                }
            } catch (Exception e) {
                UIConsole.Warn($"ShapeFiles -- Cannot load {filename} from library.");
                UIConsole.Error($"ShapeFiles -- {e.Message}");
            }

            return(data);
        }
Example #6
0
        static int[] FalseColorLUT = new int[256 * 256]; // 256x256 LUT

        public static void SetVisibleFalseColorCurve(float[] visCurve)
        {
            if (visCurve.Length != 256)
            {
                throw new ArgumentException("The Curve should have 256 points.");
            }
            NEW_VIS_FALSE_CURVE = visCurve;
            UIConsole.Log("New false color visible curve set.");
        }
Example #7
0
        private static string ExtractFile(string filename)
        {
            string output = Path.Combine(Path.GetTempPath(), filename);

            UIConsole.Debug($"ShapeFiles -- Extracting {filename} to {output}");
            byte[] data = ReadFileFromAssembly(filename);
            File.WriteAllBytes(output, data);
            return(output);
        }
Example #8
0
        void SetConfigVars()
        {
            UIConsole.Log("Setting Configuration");
            FileHandler.SkipEMWIN       = !ProgConfig.EnableEMWIN;
            FileHandler.SkipDCS         = !ProgConfig.EnableDCS;
            FileHandler.SkipWeatherData = !ProgConfig.EnableWeatherData;

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

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

            ImageManager.EraseFiles             = ProgConfig.EraseFilesAfterGeneratingFalseColor;
            ImageManager.GenerateInfrared       = ProgConfig.GenerateInfraredImages;
            ImageManager.GenerateVisible        = ProgConfig.GenerateVisibleImages;
            ImageManager.GenerateWaterVapour    = ProgConfig.GenerateWaterVapourImages;
            ImageManager.MaxRetryCount          = ProgConfig.MaxGenerateRetry;
            ImageManager.UseNOAAFileFormat      = ProgConfig.UseNOAAFormat;
            ImageManager.GenerateLabels         = ProgConfig.GenerateLabels;
            ImageManager.GenerateLatLonOverlays = ProgConfig.GenerateLatLonOverlays;
            ImageManager.GenerateMapOverlays    = ProgConfig.GenerateMapOverlays;
            ImageManager.GenerateLatLonLabel    = ProgConfig.GenerateLatLonLabel;

            Connector.ChannelDataServerName   = ProgConfig.ChannelDataServerName;
            Connector.StatisticsServerName    = ProgConfig.StatisticsServerName;
            Connector.ConstellationServerName = ProgConfig.ConstellationServerName;

            Connector.ChannelDataServerPort   = ProgConfig.ChannelDataServerPort;
            Connector.StatisticsServerPort    = ProgConfig.StatisticsServerPort;
            Connector.ConstellationServerPort = ProgConfig.ConstellationServerPort;

            if (LLTools.IsLinux)
            {
                SyslogClient.SysLogServerIp = ProgConfig.SysLogServer;
                try {
                    SyslogClient.Send(ProgConfig.SysLogFacility, Level.Information, "Your syslog connection is working! OpenSatelliteProject is enabled to send logs.");
                } catch (SocketException) {
                    UIConsole.Warn("Your syslog is not enabled to receive UDP request. Please refer to https://opensatelliteproject.github.io/OpenSatelliteProject/");
                }
            }
        }
Example #9
0
        private void constellationDataLoop()
        {
            try {
                UIConsole.Log("Constellation Data Loop started");
                var data = new float[1024];
                for (var i = 0; i < 1024; i++)
                {
                    data[i] = 0;
                }

                var ipHostInfo = Dns.GetHostEntry(ConstellationServerName);
                var ipAddress  = new IPAddress(new byte[] { 127, 0, 0, 1 });
                foreach (var ip in ipHostInfo.AddressList)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        continue;
                    }
                    ipAddress = ip;
                    break;
                }

                var remoteEP  = new IPEndPoint(ipAddress, ConstellationServerPort);
                var udpClient = new UdpClient(ConstellationServerPort)
                {
                    Client = { ReceiveTimeout = 200 }
                };

                while (constellationDataThreadRunning)
                {
                    try {
                        var buffer = udpClient.Receive(ref remoteEP);
                        if (buffer.Length != 1024)
                        {
                            continue;
                        }
                        for (var i = 0; i < 1024; i++)
                        {
                            var t = (sbyte)buffer[i];
                            data[i]  = t;
                            data[i] /= 128f;
                        }
                        postConstellationData(data);
                    } catch (SocketException) {
                        // Do nothing, timeout on UDP
                    }
                }

                UIConsole.Log("Constellation Thread closed.");
            } catch (Exception e) {
                CrashReport.Report(e);
            }
        }
Example #10
0
        public static void Report(Exception e)
        {
            var cd = new CrashData(e, Username);

            try {
                UIConsole.Error($"Got {cd.ExceptionName} at {cd.Filename}:{cd.Line}");
            } catch (Exception) {
                Console.WriteLine($"Got {cd.ExceptionName} at {cd.Filename}:{cd.Line}");
            }
            SaveCrashDump(cd);
            SendCrashDump(cd);
        }
Example #11
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();
            }
        }
Example #12
0
 public static string InitShapeFiles()
 {
     try {
         UIConsole.Debug("ShapeFiles -- Initializing ShapeFiles");
         ExtractDBF();
         ExtractPRJ();
         ExtractSHX();
         return(ExtractSHP());
     } catch (Exception e) {
         UIConsole.Error($"ShapeFiles -- There was an error extracting ShapeFiles: {e}");
     }
     return(null);
 }
Example #13
0
        public ImageManager(string folder)
        {
            this.organizer   = new Organizer(folder);
            this.folder      = folder;
            this.imageThread = null;

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

            UIConsole.Debug($"Creating ImageManager on folder {folder}");
        }
Example #14
0
        /// <summary>
        /// Checks if any files in folder has reached the DaysToArchive days and archive them.
        /// </summary>
        /// <param name="folder">Folder.</param>
        /// <param name="groupName">Group name.</param>
        public static void ArchieveHandler(string folder, string groupName)
        {
            List <string> files          = Directory.GetFiles(folder).ToList();
            List <string> filesToArchive = new List <string> ();
            Dictionary <string, List <string> > dateMap = new Dictionary <string, List <string> > ();

            files.ForEach(f => {
                DateTime dt = File.GetCreationTime(f);
                var delta   = DateTime.Now.Date - dt.Date;
                if (delta.Days >= DaysToArchive)
                {
                    UIConsole.Debug($"{f} is to archive: {delta.Days}");
                    filesToArchive.Add(f);
                    string dir = Path.Combine(ArchiveFolder);
                    dir        = Path.Combine(dir, dt.Year.ToString());
                    dir        = Path.Combine(dir, dt.Month.ToString());
                    dir        = Path.Combine(dir, dt.Day.ToString());
                    dir        = Path.Combine(dir, groupName);
                    if (!dateMap.ContainsKey(dir))
                    {
                        dateMap.Add(dir, new List <string>());
                    }
                    dateMap[dir].Add(f);
                }
            });

            if (filesToArchive.Count > 0)
            {
                UIConsole.Debug($"{filesToArchive.Count} files to archive");
                dateMap.Keys.ToList().ForEach((d) => {
                    var fs = dateMap[d];
                    try {
                        if (!Directory.Exists(d))
                        {
                            Directory.CreateDirectory(d);
                        }
                    } catch (IOException e) {
                        UIConsole.Error($"Error creating Archive Directory ({d}): {e.Message}");
                        return;
                    }
                    fs.ForEach((f) => {
                        try {
                            File.Move(f, Path.Combine(d, Path.GetFileName(f)));
                        } catch (IOException e) {
                            UIConsole.Error($"Error archiving file {f}: {e.Message}");
                        }
                    });
                });
            }
        }
Example #15
0
        private void constellationDataLoop()
        {
            try {
                UIConsole.Log("Constellation Data Loop started");
                byte[]  buffer = null;
                float[] data   = new float[1024];
                for (int i = 0; i < 1024; i++)
                {
                    data[i] = 0;
                }

                IPHostEntry ipHostInfo = Dns.GetHostEntry(ConstellationServerName);
                IPAddress   ipAddress  = new IPAddress(new byte[] { 127, 0, 0, 1 });
                foreach (IPAddress ip in ipHostInfo.AddressList)
                {
                    if (ip.AddressFamily != AddressFamily.InterNetworkV6)
                    {
                        ipAddress = ip;
                        break;
                    }
                }

                IPEndPoint remoteEP  = new IPEndPoint(ipAddress, ConstellationServerPort);
                UdpClient  udpClient = new UdpClient(ConstellationServerPort);
                udpClient.Client.ReceiveTimeout = 200;

                while (constellationDataThreadRunning)
                {
                    try {
                        buffer = udpClient.Receive(ref remoteEP);
                        if (buffer != null && buffer.Length == 1024)
                        {
                            for (int i = 0; i < 1024; i++)
                            {
                                sbyte t = (sbyte)buffer[i];
                                data[i]  = t;
                                data[i] /= 128f;
                            }
                            this.postConstellationData(data);
                        }
                    } catch (SocketException) {
                        // Do nothing, timeout on UDP
                    }
                }

                UIConsole.Log("Constellation Thread closed.");
            } catch (Exception e) {
                CrashReport.Report(e);
            }
        }
Example #16
0
 /// <summary>
 /// Loads a mapDrawer with given SHP file
 /// </summary>
 /// <param name="filename">Filename.</param>
 public void InitMapDrawer(string filename)
 {
     try {
         UIConsole.Debug($"ImageManager -- Initializing MapDrawer with {filename}");
         mapDrawer = new MapDrawer(filename);
         if (mapDrawer.ShapeFile == null)
         {
             mapDrawer = null;
             throw new ArgumentException("Error loading ShapeFile");
         }
     } catch (Exception e) {
         UIConsole.Error($"ImageManager -- There was an error initializing MapDrawer: {e}");
     }
 }
Example #17
0
 /// <summary>
 /// Loads default map drawer
 /// </summary>
 public void InitMapDrawer()
 {
     try {
         UIConsole.Debug($"ImageManager -- Initializing MapDrawer with {DefaultShapeFile}");
         mapDrawer = new MapDrawer(DefaultShapeFile);
         if (mapDrawer.ShapeFile != null)
         {
             return;
         }
         mapDrawer = null;
         throw new ArgumentException("Error loading ShapeFile");
     } catch (Exception e) {
         UIConsole.Error($"ImageManager -- There was an error initializing MapDrawer: {e}");
     }
 }
Example #18
0
        public ImageManager(string folder)
        {
            this.organizer   = new Organizer(folder);
            this.folder      = folder;
            this.imageThread = null;

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

            var aFolder = folder[folder.Count() - 1] == '/' ? folder.Substring(0, folder.Count() - 1) : folder;

            this.archiveGroup = Path.GetFileName(aFolder);
            UIConsole.Debug($"Creating ImageManager on folder {folder}");
        }
Example #19
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}");
            }
        }
Example #20
0
        public static void UpdateProperty(string name, string value)
        {
            var prop = typeof(ProgConfig).GetProperty(name);

            if (prop != null)
            {
                switch (prop.PropertyType.Name.ToLower())
                {
                case "string":
                    prop.SetValue(null, value);
                    break;

                case "bool":
                case "boolean":
                    prop.SetValue(null, value.ToLower() == "true");
                    break;

                case "int":
                case "int32":
                    try {
                        prop.SetValue(null, int.Parse(value));
                    } catch (Exception) {
                        UIConsole.Error($"Cannot set config {name} to {value}: Failed to parse integer");
                    }
                    break;

                case "float":
                    try {
                        prop.SetValue(null, float.Parse(value));
                    } catch (Exception) {
                        UIConsole.Error($"Cannot set config {name} to {value}: Failed to parse float");
                    }
                    break;

                case "double":
                    try {
                        prop.SetValue(null, double.Parse(value));
                    } catch (Exception) {
                        UIConsole.Error($"Cannot set config {name} to {value}: Failed to parse double");
                    }
                    break;
                }
            }
        }
Example #21
0
 static void SaveCrashDump(CrashData cd)
 {
     if (EnableSaveCrashDump)
     {
         try {
             Directory.CreateDirectory(CrashLogFolder);
             string jsonData = cd.ToJSON();
             string filename = $"crashdata-{cd.ExceptionName}-{cd.ID}.json";
             try {
                 UIConsole.Error($"Saving Crash Dump to: {filename}");
             } catch (Exception) {
                 Console.WriteLine($"Saving Crash Dump to: {filename}");
             }
             File.WriteAllText(Path.Combine(CrashLogFolder, filename), jsonData);
         } catch (Exception e) {
             Console.WriteLine("FATAL: Cannot write crash dump: {0}", e);
         }
     }
 }
Example #22
0
        public static byte[] InMemoryDecompress(byte[] compressedData, int pixels, int pixelsPerBlock, int mask)
        {
            byte[] outputData = GenerateFillData(pixels);

            try {
                AEC.LritRiceDecompress(ref outputData, compressedData, 8, pixelsPerBlock, pixels, mask);
            } catch (Exception e) {
                if (e is AECException)
                {
                    AECException aece = (AECException)e;
                    UIConsole.Error(string.Format("AEC Decompress Error: {0}", aece.status.ToString()));
                }
                else
                {
                    UIConsole.Error(string.Format("Decompress error: {0}", e.ToString()));
                }
            }

            return(outputData);
        }
Example #23
0
        public void parseBytes(byte[] data)
        {
            try {
                int scid = ((data[0] & 0x3F) << 2) | ((data[1] & 0xC0) >> 6);
                int vcid = (data[1] & 0x3F);
                int vcnt = (data[2] << 16 | data[3] << 8 | data[4]);

                // UIConsole.Log($"Satellite ID: {scid}");

                EventMaster.Post(EventTypes.FrameEvent, new FrameEventData {
                    ChannelID = vcid, PacketNumber = vcnt
                });

                if (vcid != FILL_VCID)
                {
                    resetMutex.WaitOne();
                    lock (demuxers) {
                        if (!demuxers.ContainsKey(vcid))
                        {
                            UIConsole.Log($"I don't have a demuxer for VCID {vcid}. Creating...");
                            demuxers.Add(vcid, new Demuxer(this));
                        }
                    }
                    recordMutex.WaitOne();
                    if (RecordToFile)
                    {
                        try {
                            fStream.Write(data, 0, data.Length);
                        } catch (Exception e) {
                            UIConsole.Error($"Error writting demuxdump file: {e}");
                        }
                    }
                    recordMutex.ReleaseMutex();
                    demuxers[vcid].ParseBytes(data);
                    resetMutex.ReleaseMutex();
                }
            } catch (Exception e) {
                CrashReport.Report(e);
                throw e;
            }
        }
Example #24
0
        public static void LoadFalseColorLUT(string filename)
        {
            UIConsole.Log($"Loading custom LUT from {filename}");
            var bmp = (Bitmap)Image.FromFile(filename);

            if (bmp.Width != 256 || bmp.Height != 256)
            {
                throw new ArgumentException("The LUT image should be 256x256 px");
            }

            for (int y = 0; y < 256; y++)
            {
                for (int x = 0; x < 256; x++)
                {
                    FalseColorLUT[y * 256 + x] = bmp.GetPixel(x, y).ToArgb();
                }
            }

            bmp.Dispose();
            UIConsole.Log("Custom LUT loaded.");
        }
Example #25
0
        public static void LoadVisibleFalseColorCurve(string filename)
        {
            UIConsole.Log($"Loading false color visible curve from {filename}");
            var data   = File.ReadAllText(filename);
            var values = data.Replace("f", "").Replace("F", "").Replace("\r", "").Replace("\n", "").Trim().Split(',');

            if (values.Length < 256)
            {
                throw new ArgumentException("The curve should have 256 points.");
            }
            float[] newCurve = new float[256];
            for (var i = 0; i < 256; i++)
            {
                newCurve[i] = 0;
                if (!float.TryParse(values[i], NumberStyles.Any, CultureInfo.InvariantCulture, out newCurve[i]))
                {
                    UIConsole.Error($"Invalid values {values[i]} at number position {i}. Defaulting to 0");
                }
            }
            SetVisibleFalseColorCurve(newCurve);
        }
Example #26
0
        public void Start()
        {
            Console.CancelKeyPress += delegate {
                UIConsole.Log("Hit Ctrl + C! Closing...");
                running = false;
            };

            UIConsole.Log("Headless Main Starting");

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

            cn.Start();
            httpsv.Start();
            running = true;

            while (running)
            {
                Thread.Sleep(10);
            }

            UIConsole.Log("Closing program...");
            cn.Stop();
            httpsv.Stop();

            FDImageManager.Stop();
            XXImageManager.Stop();
            NHImageManager.Stop();
            SHImageManager.Stop();
            USImageManager.Stop();
            FMImageManager.Stop();
            UNKImageManager.Stop();
        }
Example #27
0
 public DemuxManager()
 {
     try {
         demuxers         = new Dictionary <int, Demuxer>();
         productsReceived = new Dictionary <int, long>();
         CRCFails         = 0;
         Bugs             = 0;
         Packets          = 0;
         LengthFails      = 0;
         FrameLoss        = 0;
         FrameJumps       = 0;
         recordMutex      = new Mutex();
         resetMutex       = new Mutex();
         if (RecordToFile)
         {
             fileName = string.Format("demuxdump-{0}.bin", LLTools.Timestamp());
             UIConsole.Log(string.Format("Demux Dump filename: {0}", Path.GetFileName(fileName)));
             fStream = File.OpenWrite(fileName);
         }
     } catch (Exception e) {
         CrashReport.Report(e);
         throw e;
     }
 }
Example #28
0
        public static void HandleTextData(string filename, XRITHeader header)
        {
            if (header.PrimaryHeader.FileType == FileTypeCode.TEXT)
            {
                string basedir = FileHandler.FinalFileFolder;
                basedir = Path.Combine(basedir, TextFolder);

                try {
                    UIConsole.Log($"New {header.ToNameString()}");
                    if (!Directory.Exists(basedir))
                    {
                        Directory.CreateDirectory(basedir);
                    }
                    TextHandler.Handler.HandleFile(filename, basedir);
                    File.Delete(filename);
                } catch (Exception e) {
                    UIConsole.Warn($"Failed to parse Weather Data Image at {Path.GetFileName(filename)}: {e}");
                }
            }
            else
            {
                FileHandler.DefaultHandler(filename, header);
            }
        }
Example #29
0
        public void Update()
        {
            try {
                List <string> files = Directory.GetFiles(folder).Where(f => f.EndsWith(".lrit")).ToList();
                foreach (string file in files)
                {
                    if (alreadyProcessed.Contains(file))
                    {
                        continue;
                    }
                    try {
                        var header    = FileParser.GetHeaderFromFile(file);
                        var anciliary = header.AncillaryHeader != null ? header.AncillaryHeader.Values : null;
                        var satellite = "Unknown";
                        var region    = "Unknown";
                        var satLon    = 0f;
                        var datetime  = header.TimestampHeader.DateTime; // Defaults to capture time
                        var channel   = 99;
                        var segmentId = header.SegmentIdentificationHeader != null ? header.SegmentIdentificationHeader.Sequence : 0;
                        var imageKey  = header.SegmentIdentificationHeader != null ? header.SegmentIdentificationHeader.ImageID : -1;

                        if (header.Product.ID == (int)NOAAProductID.HIMAWARI8_ABI)
                        {
                            channel   = header.SubProduct.ID;
                            satellite = "HIMAWARI8";
                            region    = "Full Disk";
                        }

                        var rgx      = new Regex(@".*\((.*)\)", RegexOptions.IgnoreCase);
                        var regMatch = rgx.Match(header.ImageNavigationHeader.ProjectionName);
                        satLon = float.Parse(regMatch.Groups[1].Captures[0].Value, CultureInfo.InvariantCulture);

                        if (anciliary != null)
                        {
                            if (anciliary.ContainsKey("Satellite"))
                            {
                                satellite = anciliary["Satellite"];
                            }

                            if (anciliary.ContainsKey("Region"))
                            {
                                region = anciliary["Region"];
                            }

                            if (anciliary.ContainsKey("Channel"))
                            {
                                channel = int.Parse(anciliary["Channel"]);
                            }

                            if (anciliary.ContainsKey("Time of frame start"))
                            {
                                var dtstring = anciliary["Time of frame start"];
                                // 2017/055/05:45:18
                                // or
                                // 2017-03-27T15:45:38.2Z
                                if (dtstring[4] == '/')
                                {
                                    var year      = dtstring.Substring(0, 4);
                                    var dayOfYear = dtstring.Substring(5, 3);
                                    var hours     = dtstring.Substring(9, 2);
                                    var minutes   = dtstring.Substring(12, 2);
                                    var seconds   = dtstring.Substring(15, 2);
                                    //Console.WriteLine("Year: {0}\nDay Of Year: {1}\nHours: {2}\nMinutes: {3}\nSeconds: {4}", year, dayOfYear, hours, minutes, seconds);
                                    datetime = new DateTime(int.Parse(year), 1, 1, int.Parse(hours), int.Parse(minutes), int.Parse(seconds));
                                    datetime = datetime.AddDays(int.Parse(dayOfYear));
                                }
                                else
                                {
                                    datetime = DateTime.Parse(dtstring, null, DateTimeStyles.RoundtripKind);
                                }
                            }
                            else
                            {
                                UIConsole.Debug("No Frame Time of Start found! Using capture time.");
                            }
                        }

                        var cropSection = region.ToLower().Contains("full disk") || header.IsFullDisk;
                        int timestamp   = 0;
                        if (datetime.Year < 2005 && file.Contains("OR_ABI"))
                        {
                            // Timestamp bug on G16
                            imageKey = header.SegmentIdentificationHeader != null ?
                                       header.SegmentIdentificationHeader.ImageID :
                                       (int)Math.Floor((datetime - UnixEpoch).TotalSeconds);
                            timestamp = (int)Math.Floor((datetime - UnixEpoch).TotalSeconds);
                        }
                        else if (datetime.Year < 2005 && file.Contains("IMG_DK"))
                        {
                            // Himawari-8 relay BUG
                            //IMG_DK01VIS_201704161550
                            string bfile  = Path.GetFileName(file);
                            string hdt    = bfile.Substring(12, 12);
                            var    year   = hdt.Substring(0, 4);
                            var    month  = hdt.Substring(4, 2);
                            var    day    = hdt.Substring(6, 2);
                            var    hour   = hdt.Substring(8, 2);
                            var    minute = hdt.Substring(10, 2);
                            datetime = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day), int.Parse(hour), int.Parse(minute), 0);
                            imageKey = timestamp = (int)Math.Floor((datetime - UnixEpoch).TotalSeconds);
                        }
                        else
                        {
                            imageKey = timestamp = (int)Math.Floor((datetime - UnixEpoch).TotalSeconds);
                        }

                        if (!groupData.ContainsKey(imageKey))
                        {
                            groupData[imageKey] = new GroupData();
                        }

                        var grp = groupData[imageKey];
                        grp.SatelliteName = satellite;
                        grp.RegionName    = region;
                        grp.FrameTime     = datetime;
                        if (segmentId == 0)
                        {
                            grp.CropImage          = cropSection;
                            grp.SatelliteLongitude = satLon;
                            if (
                                header.ImageNavigationHeader != null &&
                                header.ImageNavigationHeader.ColumnScalingFactor != 0 &&
                                header.ImageNavigationHeader.LineScalingFactor != 0
                                )
                            {
                                grp.HasNavigationData   = true;
                                grp.ColumnScalingFactor = header.ImageNavigationHeader.ColumnScalingFactor;
                                grp.LineScalingFactor   = header.ImageNavigationHeader.LineScalingFactor;
                                grp.ColumnOffset        = grp.ColumnOffset == -1 ? header.ImageNavigationHeader.ColumnOffset : grp.ColumnOffset;
                                grp.LineOffset          = grp.LineOffset == -1 ? header.ImageNavigationHeader.LineOffset : grp.LineOffset;
                            }
                        }
                        grp.Code = header.SegmentIdentificationHeader != null ?
                                   header.SegmentIdentificationHeader.ImageID + "_" + header.SubProduct.Name :
                                   header.Product.Name + "_" + header.SubProduct.Name;

                        var    od = new OrganizerData();
                        string z;
                        switch (channel)
                        {
                        case 1:     // Visible
                            od = grp.Visible;
                            break;

                        case 2:     // Visible for G16
                            if (satellite == "G16")
                            {
                                od = grp.Visible;
                            }
                            else
                            {
                                string p = $"{timestamp%1000}-{((NOAAProductID)header.Product.ID).ToString()}-{header.SubProduct.Name}";
                                if (!grp.OtherData.ContainsKey(p))
                                {
                                    grp.OtherData.Add(p, new OrganizerData());
                                }
                                od = grp.OtherData[p];
                            }
                            break;

                        case 3:     // Water Vapour
                            od = satellite == "HIMAWARI8" ? grp.Infrared : grp.WaterVapour;
                            break;

                        case 4:     // Infrared
                            od = grp.Infrared;
                            break;

                        case 7:
                            if (satellite == "HIMAWARI8")
                            {
                                od = grp.WaterVapour;
                                break;
                            }
                            z = $"{timestamp%1000}-{((NOAAProductID)header.Product.ID).ToString()}-{header.SubProduct.Name}";
                            if (!grp.OtherData.ContainsKey(z))
                            {
                                grp.OtherData.Add(z, new OrganizerData());
                            }
                            od = grp.OtherData[z];
                            break;

                        case 8:
                            if (satellite == "G16")
                            {
                                od = grp.WaterVapour;
                                break;
                            }
                            z = $"{timestamp%1000}-{((NOAAProductID)header.Product.ID).ToString()}-{header.SubProduct.Name}";
                            if (!grp.OtherData.ContainsKey(z))
                            {
                                grp.OtherData.Add(z, new OrganizerData());
                            }
                            od = grp.OtherData[z];
                            break;

                        case 13:     // Infrared for G16
                            if (satellite == "G16")
                            {
                                od = grp.Infrared;
                                break;
                            }
                            z = $"{timestamp%1000}-{((NOAAProductID)header.Product.ID).ToString()}-{header.SubProduct.Name}";
                            if (!grp.OtherData.ContainsKey(z))
                            {
                                grp.OtherData.Add(z, new OrganizerData());
                            }
                            od = grp.OtherData[z];
                            break;

                        default:
                            z = $"{timestamp%1000}-{((NOAAProductID)header.Product.ID).ToString()}-{header.SubProduct.Name}";
                            if (!grp.OtherData.ContainsKey(z))
                            {
                                grp.OtherData.Add(z, new OrganizerData());
                            }
                            od = grp.OtherData[z];
                            break;
                        }
                        od.Code                = grp.Code;
                        od.Timestamp           = timestamp;
                        od.Segments[segmentId] = file;
                        od.FirstSegment        = Math.Min(od.FirstSegment, segmentId);
                        od.FileHeader          = header;
                        if (od.Columns == -1)
                        {
                            od.Columns      = header.ImageStructureHeader.Columns;
                            od.Lines        = header.ImageStructureHeader.Lines;
                            od.PixelAspect  = header.ImageNavigationHeader.ColumnScalingFactor / (float)header.ImageNavigationHeader.LineScalingFactor;
                            od.ColumnOffset = header.ImageNavigationHeader.ColumnOffset;
                            od.MaxSegments  = header.SegmentIdentificationHeader != null ? header.SegmentIdentificationHeader.MaxSegments : 1;
                        }
                        else
                        {
                            od.Lines += header.ImageStructureHeader.Lines;
                        }
                        alreadyProcessed.Add(file);
                    } catch (Exception e) {
                        UIConsole.Error($"Error reading file {Path.GetFileName(file)}: {e}");
                        alreadyProcessed.Add(file);
                    }
                }
            } catch (Exception e) {
                UIConsole.Error($"Error checking folders: {e}");
            }
        }
Example #30
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));
            }
        }