Exemplo n.º 1
0
        public static Statistics_st fromByteArray(byte[] data)
        {
            GCHandle      handle = GCHandle.Alloc(data, GCHandleType.Pinned);
            Statistics_st stuff  = (Statistics_st)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Statistics_st));

            handle.Free();
            return(stuff);
        }
Exemplo n.º 2
0
 public void Refresh(Statistics_st data)
 {
     this.satelliteID      = data.scid;
     this.virtualChannelID = data.vcid;
     this.packetNumber     = data.packetNumber;
     this.totalBits        = data.frameBits;
     this.viterbiErrors    = data.vitErrors;
     this.signalQuality    = data.signalQuality;
     this.syncCorrelation  = data.syncCorrelation;
     if (data.syncWord != null)
     {
         this.syncWord = string.Format("{0:X02}{1:X02}{2:X02}{3:X02}", data.syncWord[0], data.syncWord[1], data.syncWord[2], data.syncWord[3]);
     }
     else
     {
         this.syncWord = "00000000";
     }
     this.reedSolomon = data.rsErrors;
     this.frameLock   = data.frameLock > 0;
     this.startTime   = LLTools.UnixTimeStampToDateTime(data.startTime);
     this.runningTime = DateTime.Now.Subtract(startTime);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            mtx          = new Mutex();
            cn           = new Connector();
            demuxManager = new DemuxManager();
            demuxManager.RecordToFile = config.RecordIntermediateFile;
            cn.StatisticsAvailable   += (Statistics_st data) => {
                mtx.WaitOne();
                statistics = data;
                mtx.ReleaseMutex();

                if (data.phaseCorrection != lastPhaseCorrection && lastPhaseCorrection != -1)
                {
                    //UIConsole.GlobalConsole.Error(String.Format("Costas Loop Desync! Phase correction was {0} and now is {1}.", lastPhaseCorrection, data.phaseCorrection));
                    //desyncCount++;
                }
                frameLockLed.Color     = data.frameLock == 1 ? Color.Lime : Color.Red;
                lastPhaseCorrection    = data.phaseCorrection;
                satelliteBusyLed.Color = data.vcid != 63 && data.frameLock == 1 ? Color.Lime : Color.Red;
                if (heartBeatLed.Color != Color.Lime)
                {
                    heartBeatLed.Color = Color.Lime;
                    heartBeatCount     = 0;
                }
            };
            cn.ChannelDataAvailable       += (byte[] data) => demuxManager.parseBytes(data);
            cn.ConstellationDataAvailable += (float[] data) => cons.updateConstellationData(data);
            statistics = new Statistics_st();
            cn.Start();

            FDImageManager.Start();
            XXImageManager.Start();
            NHImageManager.Start();
            SHImageManager.Start();
            USImageManager.Start();
            FMImageManager.Start();
        }
Exemplo n.º 4
0
 public StatisticsModel(Statistics_st data) : base("statisticsData")
 {
     Refresh(data);
 }
Exemplo n.º 5
0
        private void statisticsLoop()
        {
            try {
                UIConsole.Log("Statistics Thread Started");
                byte[] buffer = new byte[4165];

                IPHostEntry ipHostInfo = Dns.GetHostEntry(StatisticsServerName);
                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, StatisticsServerPort);
                Socket     sender   = null;
                bool       isConnected;

                while (statisticsThreadRunning)
                {
                    try {
                        UIConsole.Log("Statistics Thread connect");
                        sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        sender.ReceiveTimeout = 5000;
                        sender.Connect(remoteEP);
                        isConnected = true;

                        UIConsole.Log(String.Format("Socket connected to {0}", sender.RemoteEndPoint.ToString()));
                        int nullReceive = 0;
                        while (isConnected)
                        {
                            try {
                                var receivedBytes = sender.Receive(buffer);
                                if (receivedBytes < buffer.Length && receivedBytes != 0)
                                {
                                    nullReceive = 0;
                                    UIConsole.Error("Received less than Statistics Packet size!");
                                    Thread.Sleep(200);
                                }
                                else if (receivedBytes == 0)
                                {
                                    nullReceive++;
                                    if (nullReceive == 5)
                                    {
                                        UIConsole.Error("Cannot reach server. Dropping connection!");
                                        isConnected = false;
                                        sender.Shutdown(SocketShutdown.Both);
                                        sender.Disconnect(false);
                                        sender.Close();
                                    }
                                }
                                else
                                {
                                    nullReceive = 0;
                                    Statistics_st sst = Statistics_st.fromByteArray(buffer);
                                    this.postStatistics(sst);
                                }
                            } catch (ArgumentNullException ane) {
                                UIConsole.Error(String.Format("ArgumentNullException : {0}", ane.ToString()));
                                isConnected = false;
                            } catch (SocketException se) {
                                // That's usually timeout.  I would say that is best to handle and show some message
                                // But for now, that would make it confusing for the users. So let's keep without a notice.
                                //UIConsole.GlobalConsole.Error(String.Format("SocketException : {0}", se.ToString()));
                                isConnected = false;
                            } catch (Exception e) {
                                UIConsole.Error(String.Format("Unexpected exception : {0}", e.ToString()));
                                isConnected = false;
                            }

                            StatisticsConnected = isConnected;

                            if (!statisticsThreadRunning)
                            {
                                break;
                            }
                            Thread.Sleep(1);
                        }

                        sender.Shutdown(SocketShutdown.Both);
                        sender.Disconnect(false);
                        sender.Close();
                    } catch (ArgumentNullException ane) {
                        UIConsole.Error(String.Format("ArgumentNullException : {0}", ane.ToString()));
                    } catch (SocketException se) {
                        UIConsole.Error(String.Format("SocketException : {0}", se.ToString()));
                    } catch (Exception e) {
                        UIConsole.Error(String.Format("Unexpected exception : {0}", e.ToString()));
                    }

                    if (statisticsThreadRunning)
                    {
                        UIConsole.Warn("Socket closed. Waiting 1s before trying again.");
                        Thread.Sleep(1000);
                    }
                }
                Console.WriteLine("Requested to close Statistics Thread!");
                try {
                    if (sender != null)
                    {
                        sender.Shutdown(SocketShutdown.Both);
                        sender.Disconnect(false);
                        sender.Close();
                    }
                } catch (Exception e) {
                    UIConsole.Debug(String.Format("Exception thrown when closing socket: {0} Ignoring.", e.ToString()));
                }
                UIConsole.Log("Statistics Thread closed");
            } catch (Exception e) {
                CrashReport.Report(e);
            }
        }
Exemplo n.º 6
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();
            };
        }