Example #1
0
            public VTSInfo[] Parse(byte[] pb, int offset, int length)
            {
                List <VTSInfo> result = new List <VTSInfo>();

                _buffer.Append(Encoding.Default.GetString(pb, offset, length));
                string[] msgs = parseMsg();
                foreach (string msg in msgs)
                {
                    VTSInfo info = parseInfo(msg);
                    if (info != null)
                    {
                        result.Add(info);
                    }
                }
                return(result.ToArray());
            }
Example #2
0
            private VTSInfo parseInfo(string msg)
            {
                try
                {
                    string[] strs = msg.Split(new char[] { ',' });
                    if (strs.Length > 38 && strs[0] != "TimeStamp")
                    {
                        VTSInfo info       = new VTSInfo();
                        double  minSeconds = 0;
                        double.TryParse(strs[0], out minSeconds);
                        info.DataTime = _baseTime.AddMilliseconds(minSeconds).ToLocalTime();
                        int.TryParse(strs[1], out info.SystemTrackId);
                        int.TryParse(strs[2], out info.Status);

                        byte[] pbName = Convert.FromBase64String(strs[3]);
                        info.Name = Encoding.Default.GetString(pbName);

                        info.ShortName = strs[4];
                        info.CallSign  = strs[5];
                        int.TryParse(strs[6], out info.ShipType);
                        int.TryParse(strs[7], out info.Length);
                        int.TryParse(strs[8], out info.Width);
                        double lat = 0;
                        double.TryParse(strs[9], out lat);
                        info.Latitude = lat * 180 / Math.PI;
                        double lon = 0;
                        double.TryParse(strs[10], out lon);
                        info.Longitude = lon * 180 / Math.PI;
                        double course = 0;
                        double.TryParse(strs[11], out course);
                        info.Course = course * 180 / Math.PI;
                        if (course < 0)
                        {
                            info.Course += 360;
                        }
                        double speed = 0;
                        double.TryParse(strs[12], out speed);
                        info.Speed = speed * 3600 / 1852;
                        double heading = 0;
                        double.TryParse(strs[13], out heading);
                        info.Heading = heading * 180 / Math.PI;
                        double timeLastUpdate = 0;
                        double.TryParse(strs[14], out timeLastUpdate);
                        info.TimeLastUpdate = _baseTime.AddSeconds(timeLastUpdate).ToLocalTime();
                        int.TryParse(strs[15], out info.ObjType);
                        int.TryParse(strs[16], out info.TargetType);
                        int.TryParse(strs[17], out info.PilotStatus);
                        int.TryParse(strs[18], out info.Rating);
                        int.TryParse(strs[19], out info.LabelColorIndex);
                        int.TryParse(strs[20], out info.Category);
                        info.TransponderId = strs[21];
                        int.TryParse(strs[22], out info.TransponderState);
                        int.TryParse(strs[23], out info.DBTrackId);
                        double.TryParse(strs[24], out info.Draught);

                        byte[] pbInfoTxt = Convert.FromBase64String(strs[25]);
                        info.InfoTxt = Encoding.Default.GetString(pbInfoTxt);

                        double.TryParse(strs[26], out info.ETA);
                        double.TryParse(strs[27], out info.ETAEndPoint);
                        int rot = 0;
                        int.TryParse(strs[28], out rot);
                        info.RateOfTurn = (rot / 4.733) * (rot / 4.733);
                        int.TryParse(strs[29], out info.AISNavStatus);
                        int.TryParse(strs[30], out info.AISRateOfTurn);
                        int.TryParse(strs[31], out info.AISSOG);
                        int.TryParse(strs[32], out info.AISLatitude);
                        int.TryParse(strs[33], out info.AISLongitude);
                        int.TryParse(strs[34], out info.AISCOG);
                        int.TryParse(strs[35], out info.AISTrueHeading);
                        int.TryParse(strs[36], out info.AISETA);
                        double.TryParse(strs[37], out info.AISDraught);
                        double.TryParse(strs[38], out info.AISTimeOfLastUpdate);
                        info.RecvTime = DateTime.Now;
                        return(info);
                    }
                    return(null);
                }
                catch (Exception)
                {
                    //TestTool.Common.LogService.Log.Error(err.ToString());//发现接收数据格式不正确,Convert.FromBase64String()时出错
                    return(null);
                }
            }