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++; } } }
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); } }
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); } }