コード例 #1
0
ファイル: Program.cs プロジェクト: M0LTE/ft8push
        static void AddLogEntryToWorkedBandSquares(string call, int band)
        {
            var matches = GetMatches(call);

            if (matches.Count == 0)
            {
#warning Check log
                return;
            }
            else if (matches.Count > 1)
            {
#warning Do something
                return;
            }

            if (band == 70)
            {
#warning 70cm n1mm weird
                return;
            }

            var m = matches.Single();

            lock (BandSquares)
            {
                if (!BandSquares.Any(mem => mem.Band == band && mem.Prefix == m.PrimaryPrefix))
                {
                    Console.WriteLine($"Adding band square {m.CountryName} ({m.PrimaryPrefix}) / {band}MHz");
                    BandSquares.Add(new BandSquare {
                        Band = band, Country = m.CountryName, Prefix = m.PrimaryPrefix
                    });
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: M0LTE/ft8push
        static void RefreshDB()
        {
            string sql = $"select ts Timestamp, Call, Band, Mode from DXLOG where contestnr = {contestnr}";

            var csb = new SQLiteConnectionStringBuilder();

            string dir = @"C:\Users\tomandels\Nextcloud\Radio\N1MM Logger+\Databases";
            string fn  = "m0lte.s3db";

            csb.DataSource = Path.Combine(dir, fn);

            csb.ReadOnly = true;

            List <LogEntry> dbResults;

            using (var conn = new SQLiteConnection(csb.ToString()))
            {
                conn.Open();
                dbResults = conn.Query <LogEntry>(sql).ToList();
            }

            foreach (LogEntry dbrow in dbResults)
            {
                var matches = GetMatches(dbrow.Call);
                if (matches.Count != 1)
                {
                    continue;
                }

                var m = matches.Single();

                lock (BandSquares)
                {
                    if (!BandSquares.Any(mem => mem.Band == dbrow.Band && mem.Prefix == m.PrimaryPrefix))
                    {
                        BandSquares.Add(new BandSquare {
                            Band = dbrow.Band, Country = m.CountryName, Prefix = m.PrimaryPrefix
                        });
                    }
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: M0LTE/ft8push
        static void Main(string[] args)
        {
            Task.Factory.StartNew(SpotPusher, TaskCreationOptions.LongRunning);

            Task.Factory.StartNew(N1mmListener, TaskCreationOptions.LongRunning);

            Task.Factory.StartNew(ProcessQueue, TaskCreationOptions.LongRunning);

            using (var client = new UdpClient(2237, AddressFamily.InterNetwork))
            {
                //int lastSlotSec = -1;
                DateTime lastQuantisedNow = DateTime.MinValue;

                while (true)
                {
                    var ipep = new IPEndPoint(IPAddress.Loopback, 0);

                    byte[] msg = client.Receive(ref ipep);

                    if (msg.Length < 55)
                    {
                        continue;
                    }

                    if (msg[11] == 0x02)
                    {
                        string heardCall = GetHeardCall(msg);

                        if (heardCall == null)
                        {
                            continue;
                        }

                        const int tolerateSecsLate = 2;
                        int       slotSec;

                        var utcNow = DateTime.UtcNow;
                        if (utcNow.Second > 7.5 + 0 * 15 && utcNow.Second <= 1 * 15 + tolerateSecsLate)
                        {
                            slotSec = 0;
                        }
                        else if (utcNow.Second > 7.5 + 1 * 15 && utcNow.Second <= 2 * 15 + tolerateSecsLate)
                        {
                            slotSec = 15;
                        }
                        else if (utcNow.Second > 7.5 + 2 * 15 && utcNow.Second <= 3 * 15 + tolerateSecsLate)
                        {
                            slotSec = 30;
                        }
                        else
                        {
                            slotSec = 45;
                        }

                        var quantisedNow = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, utcNow.Hour, utcNow.Minute, utcNow.Second);
                        while (quantisedNow.Second != slotSec)
                        {
                            quantisedNow = quantisedNow.Subtract(TimeSpan.FromSeconds(1));
                        }

                        var matches = GetMatches(heardCall);

                        if (matches.Count == 1)
                        {
                            bool found;
                            lock (BandSquares)
                            {
                                found = BandSquares.Any(b => b.Band == band && b.Prefix == matches.Single().PrimaryPrefix);
                            }

                            if (!found)
                            {
                                if (quantisedNow != lastQuantisedNow)
                                {
                                    lastQuantisedNow = quantisedNow;
                                    Console.WriteLine($"---{quantisedNow:HH:mm:ss}---");
                                }

                                string mtch = String.Join(" or ", matches.Select(m => $"{m.CountryName} ({m.PrimaryPrefix})"));

                                SendTelegram($"{band}MHz - {heardCall} - {mtch}");

                                Console.ForegroundColor = ConsoleColor.White;
                                Console.Write($"{heardCall}");
                                Console.SetCursorPosition(20, Console.CursorTop);
                                Console.Write(mtch);
                                //Console.SetCursorPosition(40, Console.CursorTop);
                                //Console.WriteLine("        <------ new slot!");
                                Console.WriteLine();

                                Console.ForegroundColor = ConsoleColor.Gray;
                            }
                            else
                            {
                                /*
                                 * Console.ForegroundColor = ConsoleColor.DarkCyan;
                                 * Console.WriteLine(matches[0].CountryName);
                                 * Console.ForegroundColor = ConsoleColor.Gray;
                                 */
                            }
                        }
                        else if (matches.Count > 1)
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.Write($"{heardCall}");
                            Console.SetCursorPosition(20, Console.CursorTop);
                            Console.Write("ambiguous: ");
                            Console.WriteLine(String.Join(", ", matches.Select(m => m.CountryName)));
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write($"{heardCall}");
                            Console.SetCursorPosition(20, Console.CursorTop);
                            Console.WriteLine("unknown");
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }


                        /*string heardLoc;
                         *
                         * if (CallLocatorCache.TryGetValue(heardCall, out string loc)) // from cache
                         * {
                         *  heardLoc = loc;
                         * }
                         * else if (LookupCallLocator(heardCall, out loc)) // from hamqth.com, from address
                         * {
                         *  heardLoc = loc;
                         *  CallLocatorCache.Add(heardCall, heardLoc); // add to cache
                         * }
                         * else // rely on the low res version in the
                         * {
                         *  if (IsLocator(split[2]) && split[2] != "RR73")
                         *  {
                         *      heardLoc = split[2];
                         *  }
                         *  else
                         *  {
                         *      heardLoc = null;
                         *  }
                         * }
                         *
                         * if (heardLoc != null)
                         * {
                         *  double distkm;
                         *  try
                         *  {
                         *      distkm = MaidenheadLocator.Distance(myLocator, heardLoc);
                         *  }
                         *  catch (Exception ex)
                         *  {
                         *      Console.WriteLine(ex);
                         *      continue;
                         *  }
                         *
                         *  var spot = new Spot { TheirCall = heardCall, TheirLocator = heardLoc, Distance = distkm };
                         *
                         *  lock (spots)
                         *  {
                         *      if (!spots.Any(s => s.TheirCall == heardCall))
                         *      {
                         *          spots.Add(spot);
                         *      }
                         *  }
                         *
                         *  quietTimer.Restart();
                         * }*/
                    }
                }
            }
        }