Beispiel #1
0
        public string[] GetCommand(string[] Stcds, string NFOINDEX, out string CommandCode)
        {
            YYPack.Pack pack     = new YYPack.Pack();
            string[]    commands = null;

            CommandCode = "0067";
            commands    = new string[Stcds.Length];
            for (int i = 0; i < Stcds.Length; i++)
            {
                if (NFOINDEX.ToLower() != "短信") //短信
                {
                    //打召测包
                    commands[i] = pack.GetAnswer("0001", CommandCode, GetAuto(Stcds[i]), GetWaterLevelOrder(Stcds[i]), GetRainfallOrder(Stcds[i]), GetPowerMode(Stcds[i]), GetCenterAddress(Stcds[i]), "FFFF", "FFFF", "FFFF");
                }
                else
                {
                    if (radTX_A.Checked)
                    {
                        commands[i] = pack.GetAnswer("0001", CommandCode, GetAuto(Stcds[i]), GetWaterLevelOrder(Stcds[i]), GetRainfallOrder(Stcds[i]), GetPowerMode(Stcds[i]), GetCenterAddress(Stcds[i]), "FFFF", "FFFF", "FFFF", "gsm");
                    }
                    else
                    {
                        commands[i] = pack.GetAnswer("0001", CommandCode, GetAuto(Stcds[i]), GetWaterLevelOrder(Stcds[i]), GetRainfallOrder(Stcds[i]), GetPowerMode(Stcds[i]), GetCenterAddress(Stcds[i]), "FFFF", "FFFF", "FFFF", "gprs");
                    }
                }
            }

            return(commands);
        }
        //自报
        internal static void Process_01(DLYY.Protocol.Solution <DLYY.Model.WaterLevelInfo> solution, Service.ServiceEnum.NFOINDEX NFOINDEX, object Server)
        {
            try{
                string STCD = SetSTCD(solution, NFOINDEX, Server);
                //打回复包 101=0065 ---C
                string Answer = pack.GetAnswer(solution.N, "0065", GetAuto(STCD), GetWaterLevelOrder(STCD), GetRainfallOrder(STCD), GetPowerMode(STCD), GetCenterAddress(STCD), "FFFF", "FFFF", "FFFF");

                #region tcp回复
                if ((int)NFOINDEX == 1)
                {
                    TcpService.TcpServer        TS = Server as TcpService.TcpServer;
                    List <TcpService.TcpSocket> Ts = TS.Ts;

                    var tcps = from t in Ts where t.STCD == STCD && t.TCPSOCKET != null select t;
                    List <TcpService.TcpSocket> Tcps = tcps.ToList <TcpService.TcpSocket>();
                    //没有该测站信息,不能向下执行,上“生成回复数据”没成功。
                    if (Answer == null)
                    {
                        ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "生成回复报出现异常!", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        return;
                    }

                    if (Tcps.Count() > 0)
                    {
                        byte[] sendData = Encoding.ASCII.GetBytes(Answer);
                        Tcps.First().TCPSOCKET.Send(sendData);
                        //回复通知界面
                        ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "回复数据", sendData, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                    }
                }
                #endregion
                #region udp回复
                if ((int)NFOINDEX == 2)
                {
                    UdpService.UdpServer        US = Server as UdpService.UdpServer;
                    List <UdpService.UdpSocket> Us = US.Us;
                    var udps = from u in Us where u.STCD == STCD && u.IpEndPoint != null select u;

                    //没有该测站信息,不能向下执行,上“生成回复数据”没成功。
                    if (Answer == null)
                    {
                        ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "生成回复报出现异常!", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        return;
                    }

                    if (udps.Count() > 0)
                    {
                        byte[] sendData = Encoding.ASCII.GetBytes(Answer);
                        US.UDPClient.Send(sendData, sendData.Length, udps.First().IpEndPoint);
                        ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "回复数据", sendData, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                    }
                }
                #endregion

                //是否解包成功
                if (solution.IsUnpack)
                {
                    int k = 0;
                    foreach (DLYY.Model.WaterLevelInfo waterlevel in solution.Items)
                    {
                        int Milliseconds = (Convert.ToInt32(solution.N, 16) % 10) * 100 + (10 * k++);
                        PublicBD.db.AddRealTimeData(STCD, waterlevel.ItemID, DateTime.Parse(waterlevel.TM).AddMilliseconds(Milliseconds), DateTime.Now, (int)NFOINDEX, decimal.Parse(waterlevel.DATAVALUE));
                        //k++;

                        string ItemName = GetItemName(waterlevel.ItemID);
                        #region tcp通知界面
                        if ((int)NFOINDEX == 1)
                        {
                            TcpService.TcpServer TS = Server as TcpService.TcpServer;
                            //回复通知界面
                            ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "接收到自报数据,数据特征[" + ItemName + "-" + waterlevel.ItemID + "],时间[" + waterlevel.TM + "],值[" + waterlevel.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        }
                        #endregion
                        #region udp通知界面
                        if ((int)NFOINDEX == 2)
                        {
                            UdpService.UdpServer US = Server as UdpService.UdpServer;
                            ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "接收到自报数据,数据特征[" + ItemName + "-" + waterlevel.ItemID + "],时间[" + waterlevel.TM + "],值[" + waterlevel.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        }
                        #endregion
                        #region gsm通知界面
                        if ((int)NFOINDEX == 3)
                        {
                            GsmService.GsmServer GS = Server as GsmService.GsmServer;
                            ServiceBussiness.WriteQUIM("GSM", GS.ServiceID, STCD, "接收到自报数据,数据特征[" + ItemName + "-" + waterlevel.ItemID + "],时间[" + waterlevel.TM + "],值[" + waterlevel.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        }
                        #endregion
                        #region com通知界面
                        if ((int)NFOINDEX == 4)
                        {
                            ComService.ComServer CS = Server as ComService.ComServer;
                            Service.ServiceBussiness.WriteQUIM("COM", CS.ServiceID, STCD, "接收到自报数据,数据特征[" + ItemName + "-" + waterlevel.ItemID + "],时间[" + waterlevel.TM + "],值[" + waterlevel.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text);
                        }
                        #endregion
                        if (solution.Items.Count == k)
                        {
                            ServiceBussiness.WriteQUIM(null, null, STCD, "packover", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(DateTime.Now + "01操作异常" + ex.ToString());
            }
        }
Beispiel #3
0
        public string[] GetCommand(string[] Stcds, string NFOINDEX, out string CommandCode)
        {
            YYPack.Pack pack     = new YYPack.Pack();
            string[]    commands = null;
            CommandCode = "0069";

            if (radioButton1.Checked)
            {
                string sjy = Validate();
                if (sjy == null)
                {
                    DevComponents.DotNetBar.MessageBoxEx.Show("输入开始或结束时间有误!", "[提示]", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(null);
                }


                commands = new string[Stcds.Length];
                for (int i = 0; i < Stcds.Length; i++)
                {
                    string Auto            = Convert.ToInt32(GetAuto(Stcds[i]), 16).ToString().PadLeft(4, '0');;
                    string CenterAddress   = Convert.ToInt32(GetCenterAddress(Stcds[i]), 16).ToString().PadLeft(4, '0');;
                    string RainfallOrder   = Convert.ToInt32(GetRainfallOrder(Stcds[i]), 16).ToString().PadLeft(4, '0');;
                    string WaterLevelOrder = Convert.ToInt32(GetWaterLevelOrder(Stcds[i]), 16).ToString().PadLeft(4, '0');;
                    string PowerMode       = Convert.ToInt32(GetPowerMode(Stcds[i]), 16).ToString().ToString().PadLeft(4, '0');
                    if (NFOINDEX.ToLower() != "短信") //短信
                    {
                        //打召测包
                        commands[i] = pack.GetAnswer("0001", CommandCode, Auto, WaterLevelOrder, RainfallOrder, PowerMode, CenterAddress, sjy, pack.GetBeginOrEndTime(dateTimePicker1.Value), pack.GetBeginOrEndTime(dateTimePicker2.Value));
                    }
                    else
                    {
                        if (radTX_A.Checked)
                        {
                            commands[i] = pack.GetAnswer("0001", CommandCode, Auto, WaterLevelOrder, RainfallOrder, PowerMode, CenterAddress, sjy, pack.GetBeginOrEndTime(dateTimePicker1.Value), pack.GetBeginOrEndTime(dateTimePicker2.Value), "gsm");
                        }
                        else
                        {
                            commands[i] = pack.GetAnswer("0001", CommandCode, Auto, WaterLevelOrder, RainfallOrder, PowerMode, CenterAddress, sjy, pack.GetBeginOrEndTime(dateTimePicker1.Value), pack.GetBeginOrEndTime(dateTimePicker2.Value), "gprs");
                        }
                    }
                }

                return(commands);
            }
            else
            {
                commands = new string[Stcds.Length];
                for (int i = 0; i < Stcds.Length; i++)
                {
                    string Auto            = Convert.ToInt32(GetAuto(Stcds[i]), 16).ToString().PadLeft(4, '0');;
                    string CenterAddress   = Convert.ToInt32(GetCenterAddress(Stcds[i]), 16).ToString().PadLeft(4, '0');;
                    string RainfallOrder   = Convert.ToInt32(GetRainfallOrder(Stcds[i]), 16).ToString().PadLeft(4, '0');;
                    string WaterLevelOrder = Convert.ToInt32(GetWaterLevelOrder(Stcds[i]), 16).ToString().PadLeft(4, '0');;
                    string PowerMode       = Convert.ToInt32(GetPowerMode(Stcds[i]), 16).ToString().ToString().PadLeft(4, '0');
                    if (NFOINDEX.ToLower() != "短信") //短信
                    {
                        //打召测包
                        commands[i] = pack.GetAnswer("0001", CommandCode, Auto, WaterLevelOrder, RainfallOrder, PowerMode, "0000", "FFFF", "FFFF", "FFFF");
                    }
                    else
                    {
                        if (radTX_C.Checked)
                        {
                            commands[i] = pack.GetAnswer("0001", CommandCode, Auto, WaterLevelOrder, RainfallOrder, PowerMode, "0000", "FFFF", "FFFF", "FFFF", "gsm");
                        }
                        else
                        {
                            commands[i] = pack.GetAnswer("0001", CommandCode, Auto, WaterLevelOrder, RainfallOrder, PowerMode, "0000", "FFFF", "FFFF", "FFFF", "gprs");
                        }
                    }
                }

                return(commands);
            }
        }