Exemplo n.º 1
0
        public gpsPosition popObject()
        {
            gpsPosition temp = null;

            if (!isEmpty())
            {
                temp = data[top];
                if (top > 0)
                {
                    top--;
                }
            }
            else
            {
                Console.WriteLine("====popObject()空栈====");
            }
            return(temp);
        }
Exemplo n.º 2
0
 public void pushObject(gpsPosition obj)
 {
     if (isEmpty())
     {
         bottom = 0;
     }
     if (isFull())
     {
         //Console.WriteLine("====pushObject()栈满====");
         List <gpsPosition> list = data.ToList();
         list.RemoveAt(bottom);
         list.Add(null);
         gpsPosition[] newData = list.ToArray();
         data = newData;
         top--;
     }
     top++;
     data[top] = obj;
 }
Exemplo n.º 3
0
        public void GpsDataStack(object sender, ElapsedEventArgs e)
        {
            if (gpsData_list_.Count == 0)
            {
                return;
            }
            if (gpsData_list_.Count < count_)
            {
                timer3.Enabled = false;
                return;
            }
            var data = gpsData_list_[count_];

            if (data[2] == "V")
            {
                count_++;
                return;
            }
            else
            {
                double dLon = Convert.ToDouble(data[5]);
                dLon = dLon / 100.0;
                string[] lonArr = dLon.ToString().Split('.');
                string   lo     = (((Convert.ToDouble(lonArr[1]) / 60.0) * 10000)).ToString("#");
                for (int b = 0; b < lonArr[1].Length; b++)
                {
                    if (lonArr[1].Substring(b, 1) == "0")
                    {
                        lo = "0" + lo;
                    }
                    else
                    {
                        break;
                    }
                }
                Double dLat = Convert.ToDouble(data[3]);
                dLat = dLat / 100;
                string[] latArr = dLat.ToString().Split('.');
                string   la     = (((Convert.ToDouble(latArr[1]) / 60) * 10000)).ToString("#");
                for (int a = 0; a < latArr[1].Length; a++)
                {
                    if (latArr[1].Substring(a, 1) == "0")
                    {
                        la = "0" + la;
                    }
                    else
                    {
                        break;
                    }
                }
                string lon = lonArr[0].ToString() + "." + lo.Substring(0, 6);
                string lat = latArr[0].ToString() + "." + la.Substring(0, 6);
                test_lng = lon;
                test_lat = lat;
                gpsPosition gp = new gpsPosition();
                gp.lng = lon;
                gp.lat = lat;
                gpsTestQueue.pushObject(gp);
                int top = gpsTestQueue.getTop;
                //Console.WriteLine("gp: {0}, gpsLat: {1}", lon, lat);
                //Console.WriteLine("gpsLng: {0}, gpsLat: {1}", gpsTestStack[top].lng, gpsTestStack[top].lat);
            }
            count_++;
        }
Exemplo n.º 4
0
        private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            byte[] byteRead = new byte[serialcom.BytesToRead];
            serialcom.Read(byteRead, 0, byteRead.Length);
            string gpsData = null;
            string strRcv  = null;

            for (int i = 0; i < byteRead.Length; i++)
            {
                strRcv += ((char)Convert.ToInt32(byteRead[i]));
            }
            textBox1.Text += strRcv;
            gpsData        = strRcv;
            string[] gpsDataArr = gpsData.Split('$');
            try {
                gpsDataArr[1].Contains(",");
            }
            catch
            {
                return;
            }
            string[] gpsArr = gpsDataArr[1].Split(',');
            if (gpsArr[0] == "GNRMC")
            {
                if (gpsArr[2] == "V")
                {
                    return;
                }
                else
                {
                    double dLon = Convert.ToDouble(gpsArr[5]);
                    dLon = dLon / 100;
                    string[] lonArr = dLon.ToString().Split('.');
                    string   lo     = (((Convert.ToDouble(lonArr[1]) / 60) * 10000)).ToString("#");
                    for (int b = 0; b < lonArr[1].Length; b++)
                    {
                        if (lonArr[1].Substring(b, 1) == "0")
                        {
                            lo = "0" + lo;
                        }
                        else
                        {
                            break;
                        }
                    }
                    Double dLat = Convert.ToDouble(gpsArr[3]);
                    dLat = dLat / 100;
                    string[] latArr = dLat.ToString().Split('.');
                    string   la     = (((Convert.ToDouble(latArr[1]) / 60) * 10000)).ToString("#");
                    for (int a = 0; a < latArr[1].Length; a++)
                    {
                        if (latArr[1].Substring(a, 1) == "0")
                        {
                            la = "0" + la;
                        }
                        else
                        {
                            break;
                        }
                    }
                    string      lon = lonArr[0].ToString() + "." + lo.Substring(0, 5);
                    string      lat = latArr[0].ToString() + "." + la.Substring(0, 6);
                    gpsPosition gp  = new gpsPosition();
                    gp.lat = lat;
                    gp.lng = lon;
                    gpsQueue.pushObject(gp);
                    //Console.WriteLine("{0}, {1}", gp.lng, gp.lat);
                }
            }
        }