Exemple #1
0
        private void Xiugai(MeterInfo temp, string state)
        {
            string re = temp.Meteriport;

            string[] tip = re.Split('@');
            switch (tip[3])
            {
            case "PlatComs":
                Myadapter_p.UpdatePlatCom(state, int.Parse(tip[0]));
                break;

            case "PlatIcs":
                Myadapter_p.UpdatePlatIc(state, int.Parse(tip[0]));
                break;

            case "PlatChus_msb":
                Myadapter_p.UpdatePlatChu_msb(state, int.Parse(tip[0]));
                break;

            case "PlatComs_xzy":
                Myadapter_p.UpdatePlatChu_xzy(state, int.Parse(tip[0]));
                break;

            case "PlatComs_csb":
                Myadapter_p.UpdatePlatChu_csb(state, int.Parse(tip[0]));
                break;

            case "PlatZhos":
                Myadapter_p.UpdatePlatZho(state, int.Parse(tip[0]));
                break;
            }
        }
Exemple #2
0
        private Boolean Xiugai(string[] s, string state, string cancel, Boolean ishege, bool issuc, bool isdanji)
        {
            try
            {
                switch (s[3])
                {
                case "PlatComs":
                    Myadapter_p.UpdatePlatCom("空闲", int.Parse(s[0]));
                    tempmeter.MeterComState = state;
                    Caozuo(cancel, ishege, issuc, "com");
                    break;

                case "PlatIcs":
                    Myadapter_p.UpdatePlatIc("空闲", int.Parse(s[0]));
                    tempmeter.MeterIcState = state;
                    Caozuo(cancel, ishege, issuc, "ic");
                    break;

                case "PlatChus_msb":
                    Myadapter_p.UpdatePlatChu_msb("空闲", int.Parse(s[0]));
                    tempmeter.MeterChuState = state;
                    Caozuo(cancel, ishege, issuc, "chu");
                    break;

                case "PlatChus_xzy":
                    Myadapter_p.UpdatePlatChu_xzy("空闲", int.Parse(s[0]));
                    tempmeter.MeterChuState = state;
                    Caozuo(cancel, ishege, issuc, "chu");
                    break;

                case "PlatChus_csb":
                    Myadapter_p.UpdatePlatChu_csb("空闲", int.Parse(s[0]));
                    tempmeter.MeterChuState = state;
                    Caozuo(cancel, ishege, issuc, "chu");
                    break;

                case "PlatZhos":
                    Myadapter_p.UpdatePlatZho("空闲", int.Parse(s[0]));
                    tempmeter.MeterZhongState = state;
                    Caozuo(cancel, ishege, issuc, "zho");
                    break;
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// 检测平台回复的alive(44)命令
        /// ip + port
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
        {
            lock (CommonFunction.obj_44)
            {
                Myadapter_p = new Dt_PlateInfoTableAdapter();
                var    info = requestInfo;
                int    id   = Convert.ToInt32(info.Data.Substring(2, 2), 16);
                string ip   = DataHelper.Str2IP(info.Data.Substring(4, 8));
                string port = Convert.ToInt32(info.Data.Substring(12, 4), 16).ToString();
                string type = info.Data.Substring(16, 2);
                if (CommonFunction.hearts.ContainsKey(id + type))
                {
                    CommonFunction.hearts[id + type].Ke_al = 00;
                    if (CommonFunction.hearts[id + type].State.Equals("异常"))
                    {
                        CommonFunction.hearts[id + type].State = "正常";
                        switch (CommonFunction.hearts[id + type].Type)
                        {
                        case "命令检测":
                            Myadapter_p.UpdatePlatCom("空闲", CommonFunction.hearts[id + type].Id);
                            break;

                        case "IC卡卡控":
                            Myadapter_p.UpdatePlatIc("空闲", CommonFunction.hearts[id + type].Id);
                            break;

                        case "膜式表初检":
                            Myadapter_p.UpdatePlatChu_msb("空闲", CommonFunction.hearts[id + type].Id);
                            break;

                        case "修正仪初检":
                            Myadapter_p.UpdatePlatChu_xzy("空闲", CommonFunction.hearts[id + type].Id);
                            break;

                        case "超声波初检":
                            Myadapter_p.UpdatePlatChu_csb("空闲", CommonFunction.hearts[id + type].Id);
                            break;

                        case "终检":
                            Myadapter_p.UpdatePlatZho("空闲", CommonFunction.hearts[id + type].Id);
                            break;
                        }
                        CommonFunction.platm.ChangePlat();
                    }
                    LogHelper.Info("心跳包");
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 心跳线程
        /// </summary>
        private void Heart()
        {
            while (CommonFunction.flag_listener)
            {
                lock (CommonFunction.obj_66)
                {
                    foreach (HeartInfo hi in CommonFunction.hearts.Values)
                    {
                        try
                        {
                            if (hi.Ke_al > 3)
                            {
                                hi.State = "异常";
                                hi.Ke_al = 00;
                                Showmsg(hi.Id + "/" + hi.Type);

                                //Thread me = new Thread(() => Message_f(hi))
                                //{
                                //    IsBackground = true
                                //};
                                //me.Start();
                                hi.State = "禁用";
                                //修改检测平台状态为异常
                                switch (hi.Type)
                                {
                                case "命令检测":
                                    Myadapter_p.UpdatePlatCom("异常", hi.Id);
                                    break;

                                case "IC卡卡控":
                                    Myadapter_p.UpdatePlatIc("异常", hi.Id);
                                    break;

                                case "膜式表初检":
                                    Myadapter_p.UpdatePlatChu_msb("异常", hi.Id);
                                    break;

                                case "修正仪初检":
                                    Myadapter_p.UpdatePlatChu_xzy("异常", hi.Id);
                                    break;

                                case "超声波初检":
                                    Myadapter_p.UpdatePlatChu_csb("异常", hi.Id);
                                    break;

                                case "终检":
                                    Myadapter_p.UpdatePlatZho("异常", hi.Id);
                                    break;
                                }
                                Thread.Sleep(50);
                                CommonFunction.platm.ChangePlat();
                                PostLl(hi.Id.ToString(), hi.Type, "异常");
                                DT_WaringPlatTableAdapter myadapter_wp = new DT_WaringPlatTableAdapter();
                                DataTable dtw = myadapter_wp.GetDataBy_it(hi.Id.ToString(), hi.Type, 0);
                                if (dtw.Rows.Count == 0)
                                {
                                    myadapter_wp.InsertWP(hi.Id.ToString(), hi.Type, DateTime.Now, 0, 0);
                                }
                                else
                                {
                                    myadapter_wp.UpdateMP(0, DateTime.Now, hi.Type, hi.Id.ToString(), 0);
                                }
                                //异常,给ll推送异常,修改检测平台状态为异常
                            }
                            if (hi.State.Equals("正常"))
                            {
                                try
                                {
                                    Debug.Print("2");
                                    if (CommonFunction.flag_listener)
                                    {
                                        Socket    socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                                        IPAddress ip     = IPAddress.Parse(hi.IP);
                                        int       port   = Convert.ToInt32(hi.Port);
                                        socket.Connect(ip, port);
                                        string s = DownCommond.GenerateCorekeep();
                                        socket.Send(DataHelper.Str2Byte(s));
                                        socket.Close();
                                    }
                                }
                                catch (Exception)
                                {
                                    Debug.Print("3");
                                    LogHelper.Info("检测平台异常");
                                }
                                hi.Ke_al++;
                            }
                            Thread.Sleep(500);
                        }
                        catch (Exception)
                        {
                            hi.Ke_al++;
                            //此处应警报,没有办法发送心跳包
                        }
                    }
                }
                Debug.Print("1");
                Thread.Sleep(10000);
            }
        }
Exemple #5
0
        /// <summary>
        /// tempi为表具在meterinfos的索引号
        /// tempmeter为收到请求的表具
        /// 调用logical中的函数来安排
        /// 将成功或失败的表移到成功和失败的表中,8E的时候从这两个表中查询
        /// 判断表具恢复出厂设置功能是否成功(8E)()
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
        {
            lock (obj)
            {
                Myadapter_r   = new DT_ResultTableAdapter();
                Myadapter_csb = new Dt_Chu_csbTableAdapter();
                Myadapter_xzy = new Dt_Chu_xzyTableAdapter();
                Myadapter_msb = new Dt_Chu_msbTableAdapter();
                Myadapter_Ic  = new Dt_IcTableAdapter();
                Myadapter_Mp  = new Dt_MPTableAdapter();
                Myadapter_p   = new Dt_PlateInfoTableAdapter();
                Myadapter     = new Dt_MeterInfoTableAdapter();
                bool     ishavepri = false;
                Boolean  flag_sen  = true;
                Boolean  flag_xiu  = true;
                Boolean  flag_xinx = true;
                var      info      = requestInfo;
                DateTime dtime2    = DateTime.Now;
                //LogHelper.Error(dtime2 + "  " + info.EquipmentID + "  " + info.Key + "获取锁");
                try
                {
                    dt = Myadapter.GetDataBy1(info.EquipmentID);
                    if (Myadapter.SQ_Privilege("1") != 0)
                    {
                        ishavepri = true;
                    }
                }
                catch (Exception e)
                {
                    LogHelper.Info("数据库连接异常90" + e);
                }
                tempmeter = DataHelper.Dt2Ob(dt);
                if (tempmeter != null)
                {
                    //随机数与datetime
                    tempmeter.MeterRand_num = info.Data.Substring(52, 8);
                    DateTime dtime = DateTime.Now;
                    tempmeter.MeterTime = dtime;
                    switch (tempmeter.MeterState)
                    {
                    case "完成":
                        //如果表上传,说明恢复出厂设置不成功
                        XiugaiSF(tempmeter, session, info);
                        break;

                    case "失败":
                        //不可能一旦失败表就会移入到meterfail表中
                        break;

                    case "不合格":
                        //不可能一旦失败表就会移入到meterfail表中
                        break;

                    case "合格":
                        //免检产品
                        Xiugaisuc(tempmeter, session, info);
                        break;

                    case "初始":
                        //查询测量标志位
                        if (tempmeter.MeterTest.Equals("正测") || tempmeter.MeterTest.Equals("准备") || tempmeter.MeterTest.Equals("就绪"))
                        {
                            //更新随机数
                            //下发1F
                            string send0F          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore0F("1F", 2, 1), info, true, true);
                            ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                            session.Send(f0);
                            LogHelper.Info("发送命令4" + send0F);
                            Myadapter.UpdateRand_num(tempmeter.MeterRand_num, tempmeter.MeterId);
                        }
                        else if (tempmeter.MeterTest.Equals("空闲"))
                        {
                            //安排分
                            string[] re = Logical.Meter_AnPai(tempmeter, ishavepri);
                            //LogHelper.Error(tempmeter.MeterId + re[1]);
                            //返回2222代表此表合格,其需要回复出厂设置并修改到正式服务器
                            if (re[1].Equals("成功"))
                            {
                                Xiugaisuc(tempmeter, session, info);
                            }
                            //返回3333代表此表的所有测试都失败
                            else if (re[1].Equals("失败"))
                            {
                                //Xiugaifai(tempmeter, session, info);
                            }
                            //返回安排的结果
                            else if (!re[1].Equals("空"))
                            {
                                //获取对应的IP与port
                                //下发8f与81命令
                                //并向检测平台下发33命令
                                //修改表的测试状态为准备2
                                //修改检测平台的测试状态为就绪
                                //保存表对应检测平台的IP与port
                                try
                                {
                                    IPAddress ip     = IPAddress.Parse(re[1]);
                                    int       port   = Convert.ToInt32(re[2]);
                                    Socket    socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                                    socket.Connect(ip, port);
                                    string send34 = null;
                                    try
                                    {
                                        switch (re[3])
                                        {
                                        case "PlatComs":
                                            string typee = "";
                                            if (tempmeter.MeterType.Equals("膜式表"))
                                            {
                                                dt_temp = Myadapter_msb.GetData(tempmeter.MeterId);
                                                typee   = "msb";
                                            }
                                            else if (tempmeter.MeterType.Equals("修正仪"))
                                            {
                                                dt_temp = Myadapter_xzy.GetData(tempmeter.MeterId);
                                                typee   = "xzy";
                                            }
                                            else if (tempmeter.MeterType.Equals("超声波"))
                                            {
                                                dt_temp = Myadapter_csb.GetData(tempmeter.MeterId);
                                                typee   = "csb";
                                            }
                                            send34 = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Com(dt_temp, typee), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, re[0], "-1", "-1", "-1");
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_Com(re[0], tempmeter.MeterId);
                                            }
                                            Myadapter_p.UpdatePlatCom("就绪", int.Parse(re[0]));
                                            break;

                                        case "PlatIcs":
                                            dt_temp = Myadapter_Ic.GetData(tempmeter.MeterId);
                                            send34  = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Ic(dt_temp), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", re[0], "-1", "-1");
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_IC(re[0], tempmeter.MeterId);
                                            }
                                            Myadapter_p.UpdatePlatIc("就绪", int.Parse(re[0]));
                                            break;

                                        case "PlatChus_msb":
                                            dt_temp = Myadapter_msb.GetData(tempmeter.MeterId);
                                            send34  = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Chu_msb(dt_temp), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", "-1", re[0], "-1");
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_Chu(re[0], tempmeter.MeterId);
                                            }
                                            Myadapter_p.UpdatePlatChu_msb("就绪", int.Parse(re[0]));
                                            break;

                                        case "PlatChus_xzy":
                                            dt_temp = Myadapter_xzy.GetData(tempmeter.MeterId);
                                            send34  = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Chu_xzy(dt_temp), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", "-1", re[0], "-1");
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_Chu(re[0], tempmeter.MeterId);
                                            }
                                            Myadapter_p.UpdatePlatChu_xzy("就绪", int.Parse(re[0]));
                                            break;

                                        case "PlatChus_csb":
                                            dt_temp = Myadapter_csb.GetData(tempmeter.MeterId);
                                            send34  = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Chu_csb(dt_temp), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", "-1", re[0], "-1");
                                            }
                                            else
                                            {
                                                Myadapter_p.UpdatePlatChu_csb("就绪", int.Parse(re[0]));
                                            }
                                            break;

                                        case "PlatZhos":
                                            //dt_temp =
                                            //send34 = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Zho(dt_temp), info, false, false);
                                            //socket.Send(DataHelper.Str2Byte(send34));
                                            socket.Close();
                                            Myadapter_p.UpdatePlatZho("就绪", int.Parse(re[0]));
                                            //有问题
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", "-1", "-1", re[0]);
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_Zho(re[0], tempmeter.MeterId);
                                            }
                                            break;
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        flag_xinx = false;
                                        flag_sen  = false;
                                        flag_xiu  = false;
                                        LogHelper.Error("检测平台修改数据库或读取燃气表测试信息异常" + e);
                                    }
                                    if (flag_xinx)
                                    {
                                        socket.Send(DataHelper.Str2Byte(send34));
                                        socket.Close();
                                        LogHelper.Info("发送命令33" + send34);
                                    }
                                }
                                catch (Exception e)
                                {
                                    flag_sen = false;
                                    flag_xiu = false;
                                    LogHelper.Error("检测平台异常或数据异常" + e);
                                }
                                if (flag_sen)
                                {
                                    try
                                    {
                                        string send8F3          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore8F(tempmeter.MeterRand_num), info, true, false);
                                        string send813          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore81(re[1], re[2], false, "", tempmeter.MeterRand_num), info, false, true);
                                        ArraySegment <byte> f3  = new ArraySegment <byte>(DataHelper.Str2Byte(send8F3));
                                        ArraySegment <byte> f23 = new ArraySegment <byte>(DataHelper.Str2Byte(send813));
                                        session.Send(f3);
                                        Thread.Sleep(1000);
                                        session.Send(f23);
                                        LogHelper.Info("发送命令8F" + send8F3);
                                        LogHelper.Info("发送命令81" + send813);
                                    }
                                    catch (Exception e)
                                    {
                                        flag_xiu = false;
                                        LogHelper.Error("修改网络参数下发失败" + e);
                                    }
                                }
                                else
                                {
                                    //更新随机数
                                    //下发1F
                                    string send0F          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore0F("1F", 2, 1), info, true, true);
                                    ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                                    session.Send(f0);
                                    LogHelper.Info("发送命令3" + send0F);
                                    Myadapter.UpdateRand_num(tempmeter.MeterRand_num, tempmeter.MeterId);
                                }
                                if (flag_xiu)
                                {
                                    tempmeter.MeterTest  = "准备";
                                    tempmeter.Meteriport = re[0] + "@" + re[1] + "@" + re[2] + "@" + re[3];
                                    Myadapter.UpdateMeterTest(tempmeter.MeterRand_num, tempmeter.Meteriport, tempmeter.MeterTime, tempmeter.MeterTest, tempmeter.MeterId);
                                }
                            }
                            else if (re[1].Equals("空"))
                            {
                                LogHelper.Info("无空闲检测平台");
                                Random rd              = new Random();
                                int    uplod_time      = rd.Next(10, 20);
                                string send0F          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore0F("1F", uplod_time, 5), info, true, true);
                                ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                                session.Send(f0);
                                LogHelper.Info("发送命令2" + send0F);
                                Myadapter.UpdateRand_num(tempmeter.MeterRand_num, tempmeter.MeterId);
                            }
                            else
                            {
                                LogHelper.Info("安排出错,大于检测平台数");
                            }
                        }
                        else
                        {
                            LogHelper.Info("非规定测量标志位");
                        }
                        break;

                    default:
                        LogHelper.Info("未知状态");
                        break;
                    }
                    CommonFunction.platm.ChangeMeter();
                    CommonFunction.platm.ChangePlat();
                }
                else
                {
                    try
                    {
                        dt = Myadapter_r.GetDataBy_r(info.EquipmentID, "合格", "初始", "失败");
                    }
                    catch (Exception e)
                    {
                        LogHelper.Info("数据库连接异常90" + e);
                    }
                    tempmeter = DataHelper.Dt2Ob(dt);
                    if (tempmeter != null)
                    {
                        //随机数与datetime
                        //在11之前修改为合格,表在metersuccess中,metertest=空闲,metercancel=合格
                        //如果测试状态为正测
                        tempmeter.MeterRand_num = info.Data.Substring(52, 8);
                        DateTime dtime = DateTime.Now;
                        tempmeter.MeterTime = dtime;
                        if ((tempmeter.MeterCancel.Equals("合格") && tempmeter.MeterTest.Equals("空闲")) || (tempmeter.MeterCancel.Equals("是") && tempmeter.MeterState.Equals("失败")))
                        {
                            Cancel_meter(tempmeter, session, info);
                        }
                        else if (tempmeter.MeterCancel.Equals("合格") && tempmeter.MeterTest.Equals("正测"))
                        {
                            //更新随机数
                            //下发1F
                            string send0F          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore0F("1F", 2, 1), info, true, true);
                            ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                            session.Send(f0);
                            LogHelper.Info("发送命令1" + send0F);
                            Myadapter_r.Update_wait(tempmeter.MeterTest, tempmeter.MeterRand_num, tempmeter.MeterTime, tempmeter.MeterState, tempmeter.MeterId);
                        }
                    }
                }
            }
        }