Click here to Skip to main content
15,881,882 members
Articles / Mobile Apps / Windows Mobile

A GPS tracer application for Windows Mobile CE 5

Rate me:
Please Sign up or sign in to vote.
4.80/5 (27 votes)
22 May 2007CPOL3 min read 288.5K   3.4K   199  
A simple GPS tracer developed for Windows Mobile 2005 on Compact Framework 2.0 SDK
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO.Ports;


namespace GpsTracer
{
    public class reader 
    {
        static private System.IO.Ports.SerialPort m_serialPort1;
        static private Thread m_th=null;
        static private bool m_run=false;
        static public String m_readed="";
        static private String m_port;
        static private bool m_demo;
        public delegate void DataReceivedEventHandler(string data);
        public event DataReceivedEventHandler dataReceived;

        public reader(String port)
        {
         m_port = port;
        }

        public void start(bool demo)
        {
            m_demo = demo;
            

            if (m_th == null)
            {
                if(!demo && m_serialPort1==null)
                {
                    m_serialPort1 = new System.IO.Ports.SerialPort(m_port);
                }
                m_th = new Thread(methodTh);
            }
            m_run = true;
            m_th.Start();
        }

        public void stop()
        {
            m_run = false;
            Thread.Sleep(500);
            if (!m_demo)
            {
                m_serialPort1.Close();
            }
            if (m_th != null)
            {
                m_th.Abort();
                m_th = null;
            }
        }

        

        private void methodTh()
        {
            if (!m_demo)
            {
                m_serialPort1.Open();
            }

            byte[] buffer= new byte[100];
            while (m_run)
            {
                Thread.Sleep(1000);
                if (m_demo)
                {
                    dataReceived(randomString());
                }
                else
                {
                    m_readed = m_serialPort1.ReadLine();
                    if (m_readed.Length > 0)
                    {
                        dataReceived(m_readed);
                    }
                }
            }
        }

        private String randomString()
        { 
            Random r = new Random();
            String rSecond1 = (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1);
            String rSecond2 = (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1);
            String rPrime1 = (int)(r.NextDouble() * 1 - 1) + "";
            String rPrime2 = (int)(r.NextDouble() * 1 - 1) + "";
            
            return "$GPRMC,170111,A,434"+ rPrime1 + "." + rSecond1+",N,0111" + rPrime2 + "." + rSecond2+",W,000.0,360.0,060199,017.5,W*73";
         }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Giuneco http://www.giuneco.it
Italy Italy
IT is not only work, it is a hobbie, for that i post here!

Comments and Discussions