Exemplo n.º 1
0
 /// <summary>
 /// ����δ������Ϣ������
 /// </summary>
 /// <param name="info"></param>
 public void AddInInfo(GPSInfo info)
 {
     lock(synIn)
     {
         inList.Add(info);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 加入未解析信息到队列
 /// </summary>
 /// <param name="info"></param>
 public void AddInInfo(GPSInfo info)
 {
     lock (synIn)
     {
         inList.Add(info);
     }
 }
Exemplo n.º 3
0
        public void modemOnRev(Socket socket, string rec)
        {
            try
            {
                if (rec.IndexOf(Constant.HEAD) == 0)
                {
                    //Console.WriteLine("rec modem:" + rec);
                    char   key  = rec[Constant.HEAD.Length];
                    String line = rec.Substring(Constant.HEAD.Length + 1, rec.IndexOf(Constant.FOOT) - Constant.HEAD.Length - 1);
                    switch (key)
                    {
                    case Constant.SMS_LOGIN:    //登陆
                        if (modemSocket == null && line == Config.ModemPw)
                        {
                            modemSocket = socket;
                            SendToModemSocket(modemSocket, new StringBuilder(Constant.HEAD).Append(Constant.SMS_LOGIN).Append(Constant.RESULT_OK).Append(Constant.FOOT).ToString());
                            labelModemCount.Text = (Int32.Parse(labelModemCount.Text) + 1).ToString();
                            if (FormMain.LOG_MSG)
                            {
                                logger.AddMsg("短信猫中转程序已登陆");
                            }
                        }
                        else
                        {
                            SendToModemSocket(modemSocket, new StringBuilder(Constant.HEAD).Append(Constant.SMS_LOGIN).Append(Constant.RESULT_FAIL).Append(Constant.FOOT).ToString());
                        }
                        break;

                    case Constant.SMS_MSG:    //新信息
                        try
                        {
                            String[] ss = line.Split(Constant.SPLIT1);
                            //if(FormMain.LOG_MSG)
                            //logger.AddMsg("短信猫终端信息:" + ss[1]);
                            GPSInfo gi = new GPSInfo(ss[1], ss[0]);
                            analyzer.AddInInfo(gi);
                        }
                        catch { }
                        break;

                    case Constant.C_TEST:    //连接测试
                        //SendToModemSocket(modemSocket, new StringBuilder(Constant.HEAD).Append(Constant.C_TEST).Append(Constant.FOOT).ToString());
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                if (FormMain.LOG_ERR)
                {
                    logger.AddErr(e, "");
                }
            }
        }
Exemplo n.º 4
0
 public void modemOnRev(Socket socket, string rec)
 {
     try
     {
         if(rec.IndexOf(Constant.HEAD) == 0)
         {
             //Console.WriteLine("rec modem:" + rec);
             char key = rec[Constant.HEAD.Length];
             String line = rec.Substring(Constant.HEAD.Length + 1, rec.IndexOf(Constant.FOOT) - Constant.HEAD.Length - 1);
             switch(key)
             {
                 case Constant.SMS_LOGIN://��½
                     if(modemSocket == null && line == Config.ModemPw)
                     {
                         modemSocket = socket;
                         SendToModemSocket(modemSocket, new StringBuilder(Constant.HEAD).Append(Constant.SMS_LOGIN).Append(Constant.RESULT_OK).Append(Constant.FOOT).ToString());
                         labelModemCount.Text = (Int32.Parse(labelModemCount.Text) + 1).ToString();
                         if(FormMain.LOG_MSG)
                             logger.AddMsg("����è��ת�����ѵ�½");
                     }
                     else
                         SendToModemSocket(modemSocket, new StringBuilder(Constant.HEAD).Append(Constant.SMS_LOGIN).Append(Constant.RESULT_FAIL).Append(Constant.FOOT).ToString());
                     break;
                 case Constant.SMS_MSG://����Ϣ
                     try
                     {
                         String[] ss = line.Split(Constant.SPLIT1);
                         //if(FormMain.LOG_MSG)
                             //logger.AddMsg("����è�ն���Ϣ:" + ss[1]);
                         GPSInfo gi = new GPSInfo(ss[1], ss[0]);
                         analyzer.AddInInfo(gi);
                     }
                     catch { }
                     break;
                 case Constant.C_TEST://���Ӳ���
                     //SendToModemSocket(modemSocket, new StringBuilder(Constant.HEAD).Append(Constant.C_TEST).Append(Constant.FOOT).ToString());
                     break;
                 default:
                     break;
             }
         }
     }
     catch(Exception e)
     {
         if(FormMain.LOG_ERR)
             logger.AddErr(e, "");
     }
 }
Exemplo n.º 5
0
        //gprs 接收事件
        void gprsServer_OnReceive(Socket socket, string msg)
        {
            try
            {
                TcpTerminal gc = (TcpTerminal)tcpTable[socket];
                if (gc != null)
                {
                    gc.Counter = 0;
                    //logger.AddMsg("tcp终端信息(ascii):" + msg);

                    if (msg.Substring(13, 4) == "UB00")
                    {
                        String str = "";
                        str = msg.Substring(0, 13) + "DB01" + msg.Substring(17, (msg.Length - 17));
                        gc.Send(str);
                    }

                    if (msg.Substring(13, 4) == "UB05")
                    {
                        String str = "", strt = "", sucess = "", fail = "";

                        str = msg.Substring(17, 15);
                        DBManager dbmj = DBManager.GetInstance(Config.DbHost, Config.DbName, Config.DbUser, Config.DbPw);

                        DataTable dt = dbmj.ExecuteQuery("select machineNO from tCar where machineNO=" + "'" + str + "';");
                        foreach (DataRow dr in dt.Rows)
                        {
                            strt = dr[0].ToString();
                        }

                        if (strt != "")
                        {
                            sucess = msg.Substring(0, 13) + "DX061^";
                            gc.Send(sucess);
                            sucess = "";
                            sucess = msg.Substring(0, 13) + "0014^";
                            gc.Send(sucess);
                            dbmj.Close();
                        }
                        else
                        {
                            fail = msg.Substring(0, 13) + "DX060^";
                            gc.Send(fail);
                            dbmj.Close();

                            goto kick;
                        }
                    }



                    //logger.AddMsg("tcp终端信息(hex):" + Pub.RealHexToStr(msg));

                    GPSInfo gi = new GPSInfo(msg, gc);
                    analyzer.AddInInfo(gi);
                    kick :;
                }
            }
            catch (Exception e)
            {
                if (FormMain.LOG_ERR)
                {
                    logger.AddErr(e, "");
                }
            }
        }
Exemplo n.º 6
0
        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, "");
                }
            }
        }
Exemplo n.º 7
0
 public void sms_OnRev(int index, string rec)
 {
     try
     {
         if(rec.IndexOf(Constant.HEAD) == 0)
         {
             //Console.WriteLine("rec sms:" + rec);
             char key = rec[Constant.HEAD.Length];
             String line = rec.Substring(Constant.HEAD.Length + 1, rec.IndexOf(Constant.FOOT) - Constant.HEAD.Length - 1);
             switch(key)
             {
                 case Constant.SMS_LOGIN://��½����
                     if(line[0] == Constant.RESULT_OK)
                     {
                         smsSockets[index].HasLogin = true;
                         smsSockets[index].ReConn = true;
                         smsSockets[index].TestOk = true;
                         listViewSmsList.Items[index].SubItems[1].Text = StrConst.STATUS_SMS_CONNECTED;
                         S_Message(new StringBuilder(Constant.HEAD).Append(Constant.S_MSG).Append(Constant.S_MSG_WARN).Append("����ר��(").Append(Config.SmsList[index].SmsName).Append(")������").Append(Constant.FOOT).ToString());
                         if(FormMain.LOG_MSG)
                             logger.AddMsg("�ƶ�ר��[" + Config.SmsList[index].SmsName + "]����");
                     }
                     else
                     {
                         smsSockets[index].ReConn = false;
                         smsSockets[index].NeedTest = false;
                         smsSockets[index].DisConnect();
                         MessageBox.Show(Config.SmsList[index].SmsName + StrConst.ERR_SMS_LOGIN);
                     }
                     break;
                 case Constant.SMS_MSG://����Ϣ
                     try
                     {
                         String[] ss = line.Split(Constant.SPLIT1);
                         //if(FormMain.LOG_MSG)
                         //logger.AddMsg("�ƶ�ר���ն���Ϣ:" + ss[1]);
                         //Console.WriteLine("modem:" + ss[0] + ";" + ss[1]);
                         GPSInfo gi = new GPSInfo(ss[1], ss[0]);
                         analyzer.AddInInfo(gi);
                     }
                     catch { }
                     break;
                 case Constant.C_TEST://���Ӳ���
                     smsSockets[index].TestOk = true;
                     break;
                 default:
                     break;
             }
         }
     }
     catch(Exception e)
     {
         if(FormMain.LOG_ERR)
             logger.AddErr(e, "");
     }
 }
Exemplo n.º 8
0
        //gprs �����¼�
        void gprsServer_OnReceive(Socket socket, string msg)
        {
            try
            {
                TcpTerminal gc = (TcpTerminal)tcpTable[socket];
                if(gc != null)
                {
                    gc.Counter = 0;
                    //logger.AddMsg("tcp�ն���Ϣ(ascii):" + msg);

                   if (msg.Substring(13, 4) == "UB00")
                   {
                       String str="";
                       str = msg.Substring(0, 13) + "DB01" + msg.Substring(17,(msg.Length-17));
                     gc.Send(str);
                   }

                   if (msg.Substring(13, 4) == "UB05")
                   {
                       String str = "",strt="",sucess="",fail="";

                       str = msg.Substring(17, 15);
                       DBManager dbmj = DBManager.GetInstance(Config.DbHost, Config.DbName, Config.DbUser, Config.DbPw);

                       DataTable dt = dbmj.ExecuteQuery("select machineNO from tCar where machineNO="+"'"+str+"';");
                       foreach (DataRow dr in dt.Rows)
                       {

                           strt = dr[0].ToString();

                       }

                       if (strt!= "")
                       {
                           sucess = msg.Substring(0, 13) + "DX061^";
                           gc.Send(sucess);
                           sucess = "";
                           sucess = msg.Substring(0, 13) + "0014^";
                           gc.Send(sucess);
                           dbmj.Close();

                       }
                        else
                       {
                           fail = msg.Substring(0, 13) + "DX060^";
                           gc.Send(fail);
                           dbmj.Close();

                           goto kick;

                       }

                   }

                    //logger.AddMsg("tcp�ն���Ϣ(hex):" + Pub.RealHexToStr(msg));

                   GPSInfo gi = new GPSInfo(msg, gc);
                   analyzer.AddInInfo(gi);
               kick: ;

                }
            }
            catch(Exception e)
            {
                if(FormMain.LOG_ERR)
                    logger.AddErr(e, "");
            }
        }
Exemplo n.º 9
0
        //内部线程
        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;
        }
Exemplo n.º 10
0
        public void sms_OnRev(int index, string rec)
        {
            try
            {
                if (rec.IndexOf(Constant.HEAD) == 0)
                {
                    //Console.WriteLine("rec sms:" + rec);
                    char   key  = rec[Constant.HEAD.Length];
                    String line = rec.Substring(Constant.HEAD.Length + 1, rec.IndexOf(Constant.FOOT) - Constant.HEAD.Length - 1);
                    switch (key)
                    {
                    case Constant.SMS_LOGIN:    //登陆返回
                        if (line[0] == Constant.RESULT_OK)
                        {
                            smsSockets[index].HasLogin = true;
                            smsSockets[index].ReConn   = true;
                            smsSockets[index].TestOk   = true;
                            listViewSmsList.Items[index].SubItems[1].Text = StrConst.STATUS_SMS_CONNECTED;
                            S_Message(new StringBuilder(Constant.HEAD).Append(Constant.S_MSG).Append(Constant.S_MSG_WARN).Append("短信专线(").Append(Config.SmsList[index].SmsName).Append(")已连接").Append(Constant.FOOT).ToString());
                            if (FormMain.LOG_MSG)
                            {
                                logger.AddMsg("移动专线[" + Config.SmsList[index].SmsName + "]连接");
                            }
                        }
                        else
                        {
                            smsSockets[index].ReConn   = false;
                            smsSockets[index].NeedTest = false;
                            smsSockets[index].DisConnect();
                            MessageBox.Show(Config.SmsList[index].SmsName + StrConst.ERR_SMS_LOGIN);
                        }
                        break;

                    case Constant.SMS_MSG:    //新信息
                        try
                        {
                            String[] ss = line.Split(Constant.SPLIT1);
                            //if(FormMain.LOG_MSG)
                            //logger.AddMsg("移动专线终端信息:" + ss[1]);
                            //Console.WriteLine("modem:" + ss[0] + ";" + ss[1]);
                            GPSInfo gi = new GPSInfo(ss[1], ss[0]);
                            analyzer.AddInInfo(gi);
                        }
                        catch { }
                        break;

                    case Constant.C_TEST:    //连接测试
                        smsSockets[index].TestOk = true;
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                if (FormMain.LOG_ERR)
                {
                    logger.AddErr(e, "");
                }
            }
        }
Exemplo n.º 11
0
        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, "");
            }
        }