예제 #1
0
        internal static bool TryParse(byte[] datagram, out N1mmRadioInfo ri)
        {
            string str;

            try
            {
                str = Encoding.UTF8.GetString(datagram);
            }
            catch (Exception ex)
            {
                Program.Log("Exception: {0}", ex);
                ri = null;
                return(false);
            }

            try
            {
                var serialiser = new XmlSerializer(typeof(N1mmRadioInfo));
                using (var reader = new StringReader(str))
                {
                    ri = (N1mmRadioInfo)serialiser.Deserialize(reader);
                }
            }
            catch (Exception ex)
            {
                //Program.Log("Exception: {0}", ex);
                ri = null;
                return(false);
            }

            return(true);
        }
예제 #2
0
        private static void ProcessRadioInfo(N1mmRadioInfo ri)
        {
            //Log($"{ri.StationName} {ri.Freq} {ri.TXFreq}");

            RadioState rs = new RadioState
            {
                LastUpdated = DateTime.Now,
                Frequency   = Math.Round(ri.TXFreq / 100000.0, 4),
                ID          = ri.StationName,
            };

            PostObject(new[] { rs }, "radios");
        }
예제 #3
0
        static void ProcessDatagram(byte[] msg)
        {
            if (N1mmRadioInfo.TryParse(msg, out N1mmRadioInfo ri))
            {
                ProcessRadioInfo(ri);
                return;
            }

            string dg = Encoding.UTF8.GetString(msg);

            if (N1mmXmlContactInfo.TryParse(msg, out N1mmXmlContactInfo ci))
            {
                ProcessContactAdd(ci);
                writedg(msg);
            }
            else if (N1mmXmlContactReplace.TryParse(msg, out N1mmXmlContactReplace cr))
            {
                ProcessContactReplace(cr);
            }
            else if (ContactDelete.TryParse(msg, out ContactDelete cd))
            {
                ProcessContactDelete(cd);
            }
        }