void udpConnection_OnReceive(MoonStudio.Udp.UDPConnection uc, string remote, int rPort, string msg) { try { //logger.AddMsg("udp终端信息(ascii):" + msg); //logger.AddMsg("udp终端信息(hex):" + Pub.RealHexToStr(msg)); // MessageBox.Show(msg); // MessageBox.Show(msg.Substring(5, 4)); if (msg.Substring(1, 5) == "SJHXL") { String str, str1 = ""; str = msg.Substring(6, 8); str = str.Substring(6, 2) + str.Substring(4, 2) + str.Substring(2, 2) + str.Substring(0, 2); DBManager dbms = DBManager.GetInstance(Config.DbHost, Config.DbName, Config.DbUser, Config.DbPw); // DataTable dt = dbms.ExecuteQuery("select * from Terminal where machineNO="+str+";"); //目前不使用该语句。使用下面的存储过程语句来判断是否存在记录 DataTable dt = dbms.ExecuteQuery("select_Terminal " + "'" + str + "'"); foreach (DataRow dr in dt.Rows) { str1 = dr[0].ToString(); } if (str1 == "") { // MessageBox.Show("a"); dbms.ExecuteUpdate("insert_Terminal " + "'" + str + "'" + "," + "'" + remote + "'" + "," + rPort); string order = Protocol_XunLuoShu.AutoOrder(false, str); udpConnection.Send(remote, rPort, order); dbms.ExecuteUpdate("insert_Terminal " + "'" + str + "'" + "," + "'" + remote + "'" + "," + rPort); order = Protocol_XunLuoShu.AutoOrder(false, str); udpConnection.Send(remote, rPort, order); dbms.ExecuteUpdate("insert_Terminal " + "'" + str + "'" + "," + "'" + remote + "'" + "," + rPort); order = Protocol_XunLuoShu.AutoOrder(false, str); udpConnection.Send(remote, rPort, order); } else { // MessageBox.Show("b"); dbms.ExecuteUpdate("update_Terminal " + "'" + str + "'" + "," + rPort + "," + "'" + remote + "'"); } dbms.Close(); } if (msg.Substring(5, 4) == "TEST") { udpConnection.Send(remote, rPort, msg); } /* 检测GPRS网络是否发生虚连接 巡逻鼠硬件 * E、判断车机与中心的连接情况 * 实例:设备定时向中心发送字符“$SJHXTEST,”中心收到后原样字符串“$SJHXTEST,”发送给此IP地址即可,而不用管是哪个设备ID号码发过来的。 * //*/ GPSInfo gi = new GPSInfo(msg, remote, rPort); analyzer.AddInInfo(gi); } catch (Exception e) { if (FormMain.LOG_ERR) { logger.AddErr(e, ""); } } }
//内部线程 private void AnalyzeInfo() { while (Active) { try { List <GPSInfo> list = GetInInfo(); if (list.Count == 0) { noneCount++; } else { noneCount = 0; for (int i = 0; i < list.Count; i++) { GPSInfo gi = list[i]; //短信信息 if (gi.SimNO != "") { if (gi.Msg.IndexOf(Protocol_TianHe.HEAD) >= 0) { gi.PosList = Protocol_TianHe.Analyze(gi.Msg, false); } else if (gi.Msg.IndexOf(Protocol_DaSanTong.HEAD) >= 0) { gi.PosList = Protocol_DaSanTong.Analyze(gi.Msg, false); } } else if (gi.TcpConn != null)//tcp信息 { // if(gi.Msg.IndexOf(Protocol_TianHe.HEAD) >= 0) // gi.PosList = Protocol_TianHe.Analyze(gi.Msg, true); // else if(gi.Msg.IndexOf(Protocol_DaSanTong.HEAD) >= 0) // gi.PosList = Protocol_DaSanTong.Analyze(gi.Msg, true); // else if(gi.Msg.IndexOf(Protocol_TianHe.HEAD_HEX_1) >= 0 || gi.Msg.IndexOf(Protocol_TianHe.HEAD_HEX_2) >= 0) // gi.PosList = Protocol_TianHe.AnalyzeEx(gi.Msg, true); if (gi.Msg.IndexOf(Protocol_VicZone.HEAD) >= 0) { gi.PosList = Protocol_VicZone.Analyze(gi.Msg, true); } } else//udp信息 { gi.PosList = Protocol_XunLuoShu.Analyze(gi.Msg, true); // if(gi.Msg.IndexOf(Protocol_TianHe.HEAD_HEX_1) >= 0 || gi.Msg.IndexOf(Protocol_TianHe.HEAD_HEX_2) >= 0) // gi.PosList = Protocol_TianHe.AnalyzeEx(gi.Msg, true); } if (gi.PosList == null) { list.RemoveAt(i); i--; } } AddOutInfo(list); if (OnAnalyze != null) { OnAnalyze(); } } if (noneCount > MAX_ADD_TIME) { noneCount = MAX_ADD_TIME; } try { System.Threading.Thread.Sleep(SLEEP_TIME + noneCount * 100); } catch { } } catch (Exception e) { if (onError != null) { onError(e); } } } thread = null; }