Click here to Skip to main content
15,879,613 members
Articles / Web Development / ASP.NET

Store and forward GPS data for Smart Phones

Rate me:
Please Sign up or sign in to vote.
4.64/5 (6 votes)
28 Jul 2009CPOL3 min read 30.3K   911   35  
How to deliver GPS data asynchronously to the server over the internet without queues.
using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;

namespace MobileGps {
    public partial class Config : Form {
        string id = string.Empty;

        public Config() {
            InitializeComponent();
            LoadConfig();
            try {
                id = GetPhoneId();
                lblId.Text = id;
            } catch { }
        }

        internal string GetPhoneId() {
            PhoneAddress pa = Sim.GetPhoneNumber();
            return pa.Address;
        }

        private void LoadConfig() {
            string[] sp = System.IO.Ports.SerialPort.GetPortNames(); //discover the COM ports
            foreach (string s in sp) {
                ddlComPort.Items.Add(s.ToString());
            }
            ReadConfig();
        }

        private void ReadConfig() {
            try {
                XmlDocument xDoc = new XmlDocument();
                string fname = Util.GetConfigFile();
                if (string.IsNullOrEmpty(fname)) {
                    Util.Reset();
                    fname = Util.GetConfigFile();
                }
                xDoc.Load(fname);
                XmlNode comNode = xDoc.SelectSingleNode("//COM");
                if (comNode != null) {
                    ddlComPort.SelectedItem = comNode.InnerText;
                }

                XmlNode sendNode = xDoc.SelectSingleNode("//SendInterval");
                if (sendNode != null) {
                    ddlSendInterval.SelectedItem = sendNode.InnerText;
                }

            } catch (Exception ex) {
                MessageBox.Show("Read Config error:\r\n" + ex.Message);
            }
        }

        private void mnuSave_Click(object sender, EventArgs e) {
            XmlDocument xDoc = new XmlDocument();
            try {
                xDoc.Load(Util.GetConfigFile());
                XmlNode comNode = xDoc.SelectSingleNode("//COM");
                if (comNode != null) {
                    comNode.InnerText = ddlComPort.SelectedItem.ToString();
                }

                XmlNode idNode = xDoc.SelectSingleNode("//ID");
                if (idNode != null) {
                    idNode.InnerText = id;
                }

                XmlNode sendNode = xDoc.SelectSingleNode("//SendInterval");
                if (sendNode != null) {
                    sendNode.InnerText = ddlSendInterval.SelectedItem.ToString();
                }

                xDoc.Save(Util.GetConfigFile());
                this.Close();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }

        private void mnuReset_Click(object sender, EventArgs e) {
            Util.Reset();
        }



        private void mnuCallHome_Click(object sender, EventArgs e) {
            Phone.MakeCall("18587929250");
        }

        private void mnuClearLog_Click(object sender, EventArgs e) {
            Util.ClearLogFile(Util.GetLogFile());
        }

        private void mnuClose_Click(object sender, EventArgs e) {
            this.Close();
        }

        private void menuItem1_Click(object sender, EventArgs e) {
            Util.SaveGPSLog("test");
        }

        private void Config_KeyDown(object sender, KeyEventArgs e) {
            if ((e.KeyCode == System.Windows.Forms.Keys.F1)) {
                // Soft Key 1
                // Not handled when menu is present.
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.F2)) {
                // Soft Key 2
                // Not handled when menu is present.
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Up)) {
                // Up
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Down)) {
                // Down
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Left)) {
                // Left
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Right)) {
                // Right
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Enter)) {
                // Enter
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D1)) {
                // 1
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D2)) {
                // 2
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D3)) {
                // 3
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D4)) {
                // 4
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D5)) {
                // 5
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D6)) {
                // 6
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D7)) {
                // 7
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D8)) {
                // 8
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D9)) {
                // 9
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.F8)) {
                // *
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D0)) {
                // 0
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.F9)) {
                // #
            }
        }
    }
}

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
Software Developer (Senior) Tateeda Media Networks
United States United States

Software development is my passion as well as photography.


If you got a sec stop by to see my photography work at http://sk68.com


Tateeda Media Network

Comments and Discussions