Example #1
0
 public void DoWork()
 {
     while (!_shouldStop)
     {
         if (!m_bIsPause && m_curPosId < m_pos.Count)
         {
             HGMessage msg = new HGMessage();
             msg.MessageHeader = HGMessage.creat_header(0,false,0);
             HGMessageBodyTracePlayback trace = new HGMessageBodyTracePlayback();
             trace.TraceCount = Convert.ToUInt16(m_pos.Count);
             GeoCoordinate geo = m_pos[m_curPosId] as GeoCoordinate;
             trace.Latitude = Convert.ToUInt16(geo.Latitude);
             trace.Longitude = Convert.ToUInt16(geo.Longitude);
             msg.MessageBody = trace;
             msg.PocketProtocol();
             byte [] buf = msg.getData();
             MainWindow.send(buf);
             m_curPosId++;
         }
     }
 }        
Example #2
0
        /// <summary>
        /// 网络数据接收回调函数
        /// </summary>
        /// <param name="pData">接收到的缓存数据的指针</param>
        /// <param name="nLen">缓存数据的大小</param>
        private /*static*/ void onReceiveCallback(IntPtr pData, int nLen)
        {
            byte[] bt = new byte[nLen];
            Marshal.Copy(pData, bt, 0, nLen);

            HGMessage msg = new HGMessage();
            msg.SetData(bt);
            if (!msg.ParseProtocol())
            {
                add_log("解析数据失败!", LOG_TYPE.kError);
                return;
            }
            string txt = "";
            if (msg.MessageBody.MsgType == 1)
            {
                HGMessageBodyStartPosition pos = msg.MessageBody as HGMessageBodyStartPosition;
                txt = string.Format("起点经度:{0},起点纬度:{1},地名:{2}",pos.Longitude/1000000,pos.Latitude/1000000,pos.Name);
            }
            else if (msg.MessageBody.MsgType == 2)
            {
                HGMessageBodyEndPosition pos = msg.MessageBody as HGMessageBodyEndPosition;
                txt = string.Format("起点经度:{0},起点纬度:{1},地名:{2}", pos.Longitude / 1000000, pos.Latitude / 1000000, pos.Name);
            }
            else if (msg.MessageBody.MsgType == 3)
            {
                HGMessageBodyNavigationState pos = msg.MessageBody as HGMessageBodyNavigationState;
                txt = string.Format("道路类型:{0}", pos.road());
            }
            else if (msg.MessageBody.MsgType == 4)
            {
                HGMessageBodyNavigationStateIdent pos = msg.MessageBody as HGMessageBodyNavigationStateIdent;
                txt = string.Format("导航状态:{0}", pos.state());
            }
            else
            {
                add_log("未识别类型!", LOG_TYPE.kError);
            }
            add_log(txt, LOG_TYPE.kNormalInfo);
        }
Example #3
0
        private void send_position()
        {
            if (!m_bIsConnected)
            {
                add_log("您需要先连接设备!", LOG_TYPE.kError);
                return;
            }
            HGMessage msg = new HGMessage();
            //创建消息头
            msg.MessageHeader = HGMessage.creat_header(0, false, 0);
            //创建消息体
            HGMessageBodyPosition pos = new HGMessageBodyPosition();
            UInt32 val32 = 0;
            bool bres = true;
            if (!UInt32.TryParse(tbDirection.Text, out val32))
            {
                bres = false;
                add_log("您需要输入一个位整数的方向!", LOG_TYPE.kError);
            }
            else
                pos.TravelDirection = val32;


            if (!UInt32.TryParse(tbLongtitude.Text, out val32))
            {
                bres = false;
                add_log("您需要输入一个位整数的经度!", LOG_TYPE.kError);
            }
            else
                pos.Longitude = val32;

            if (!UInt32.TryParse(tblatitude.Text, out val32))
            {
                bres = false;
                add_log("您需要输入一个位整数的纬度!", LOG_TYPE.kError);
            }
            else
                pos.Latitude = val32;
            msg.MessageBody = pos;
            if (!bres)
            {
                return;
            }
            //打包消息
            if (!msg.PocketProtocol())
            {
                add_log("消息打包失败!", LOG_TYPE.kError);
                return;
            }
            byte[] buf = msg.getData();
            if (send(buf))
            {
                add_log("发送数据成功!", LOG_TYPE.kSuccess);
            }
            else
            {
                add_log("发送数据失败!", LOG_TYPE.kError);
            }
        }
Example #4
0
        private void send_car()
        {
            if (!m_bIsConnected)
            {
                add_log("您需要先连接设备!", LOG_TYPE.kError);
                return;
            }
            HGMessage msg = new HGMessage();
            //创建消息头
            msg.MessageHeader = HGMessage.creat_header(0, false, 0);
            //创建消息体
            HGMessageBodyCarInfo car = new HGMessageBodyCarInfo();
            UInt16 val = 0;
            bool bres = true;
            if (!UInt16.TryParse(tbSpeed.Text, out val))
            {
                bres = false;
                add_log("您需要输入一个位整数的车速!", LOG_TYPE.kError);
            }
            else
                car.Speed = val;

            UInt32 val32 = 0;
            if (!UInt32.TryParse(tbDistance.Text, out val32))
            {
                bres = false;
                add_log("您需要输入一个位整数的里程!", LOG_TYPE.kError);
            }
            else
                car.Mileage = val32;

            if (!UInt32.TryParse(tbOil.Text, out val32))
            {
                bres = false;
                add_log("您需要输入一个位整数的油耗!", LOG_TYPE.kError);
            }
            else
                car.OilConsumption = val32;
            msg.MessageBody = car;
            if (!bres)
            {
                return;
            }
            //打包消息
            if (!msg.PocketProtocol())
            {
                add_log("消息打包失败!", LOG_TYPE.kError);
                return;
            }
            byte[] buf = msg.getData();
            if (send(buf))
            {
                add_log("发送数据成功!", LOG_TYPE.kSuccess);
            }
            else
            {
                add_log("发送数据失败!", LOG_TYPE.kError);
            }
        }