Example #1
0
        public void ParseRsp(ProtocolStruct Data)
        {
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_EPC_MULT:
            case PassiveRcp.RCP_CMD_EPC_IDEN:
            case PassiveRcp.RCP_CMD_ISO6B_IDEN:
                if (Data.Length > 0 && (Data.Type == 0 || Data.Type == 0x32))
                {
                    List <CardParameters> tempArray    = new List <CardParameters>();
                    List <byte>           bytTempArray = new List <byte>(Data.ToArray());
                    if (PDataManage.InputManage(ref bytTempArray, ref tempArray))
                    {
                        cdgvShow.Add(tempArray);
                    }
                }
                break;

            case 0x22:
                Data.Code = 0x10;
                Data.Type = 0x32;
                List <CardParameters> tempArray2    = new List <CardParameters>();
                List <byte>           bytTempArray2 = new List <byte>(Data.ToArray());
                if (PDataManage.InputManage(ref bytTempArray2, ref tempArray2))
                {
                    cdgvShow.Add(tempArray2);
                }
                break;
            }
        }
Example #2
0
        private void __ParseRsp(ProtocolStruct Data)
        {
            tsStatusPortOpen.Text = "CONNECTED";
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_INFO:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    #region ---Parameter---
                    string strInfo = Encoding.ASCII.GetString(Data.Payload, 0, Data.Length);

                    tsFWVersion.Text = IniSettings.AppsLanguage == IniSettings.LngType.ENG ?
                                       "Type:" + SystemPub.ADRcp.Mode + SystemPub.ADRcp.Type + " - Version:" + SystemPub.ADRcp.Version + " - Address: " + SystemPub.ADRcp.Address :
                                       "类型:" + SystemPub.ADRcp.Mode + SystemPub.ADRcp.Type + " - 版本:" + SystemPub.ADRcp.Version + " - 地址: " + SystemPub.ADRcp.Address;
                    #endregion

                    switch (SystemPub.ADRcp.Mode)
                    {
                    case "P":
                        ucPassive1.Show();
                        ucPassive1.Parent = pnlInformation;
                        ucPassive1.Dock   = DockStyle.Fill;
                        break;
                    }
                }
                break;
            }

            if (ucPassive1 != null)
            {
                ucPassive1.ParseRsp(Data);
            }
            pDisplayStatusInfo(Data.Code, Data.Type, Data.Length);
        }
Example #3
0
        private void __ParseRsp(ProtocolStruct Data)
        {
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_INFO:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    m_bAlive = true;
                    #region ---Parameter---
                    string strInfo = Encoding.ASCII.GetString(Data.Payload, 0, Data.Length);

                    SystemPub.ADRcp.Type    = strInfo.Substring(17, 1);
                    SystemPub.ADRcp.Mode    = strInfo.Substring(18, 1);
                    SystemPub.ADRcp.Version = strInfo.Substring(19, 5);
                    SystemPub.ADRcp.Address = Convert.ToInt32(strInfo.Substring(29, 5));

                    if (SystemPub.ADRcp.Type != "W" && SystemPub.ADRcp.Type != "T")
                    {
                        SystemPub.ADRcp.Type = "C";
                    }
                    ReaderMode = SystemPub.ADRcp.Mode + SystemPub.ADRcp.Type;

                    tsFWVersion.Text = BaseSettings.AppsLanguage == BaseSettings.LngType.ENG ?
                                       "Type:" + ReaderMode + " - Version:" + SystemPub.ADRcp.Version + " - Address: " + SystemPub.ADRcp.Address :
                                       "类型:" + ReaderMode + " - 版本:" + SystemPub.ADRcp.Version + " - 地址: " + SystemPub.ADRcp.Address;
                    #endregion

                    switch (ReaderMode.Substring(0, 1))
                    {
                    case "P":
                        ucPassive1.Show();
                        ucPassive1.Parent   = pnlInformation;
                        ucPassive1.Dock     = DockStyle.Fill;
                        SystemPub.ADRcp.Sio = SystemPub.ADSio;
                        break;
                    }
                }
                break;
            }

            switch (ReaderMode.Substring(0, 1))
            {
            case "P":
                if (ucPassive1 != null)
                {
                    ucPassive1.ParseRsp(Data);
                }
                pDisplayStatusInfo(Data.Code, Data.Type, Data.Length);
                break;
            }
        }
Example #4
0
        public void ParseRsp(ProtocolStruct Data)
        {
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_EPC_IDEN:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    utxtCard.InputMask = GetUserTextBoxMask(Convert.ToInt32(Data.Length - 1));
                    utxtCard.Value     = ConvertData.ByteArrayToHexString(Data.Payload, 1, Data.Length - 1);
                }
                break;

            case PassiveRcp.RCP_CMD_EPC_RW:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    if (ActionType == WRITETYPE.CARD)
                    {
                        GetCard(Data.Payload);
                    }
                    else
                    {
                        utxtReadData.InputMask = GetUserTextBoxMask(Data.Length - 1);
                        utxtReadData.Value     = ConvertData.ByteArrayToHexString(Data.Payload, 1, Data.Length - 1);
                    }
                }
                else if (Data.Type == 0)
                {
                    if (ActionType == WRITETYPE.CARD)
                    {
                        LngSendDataP      = LngSendData;
                        txtWriteCard.Text = String.Format("{0} [HEX: {1} ]", ShowCard(LngSendDataP, false), ShowCard(LngSendDataP, true));
                        ShowState("写成功!", "Write Succeed!", lblWriteState, true);
                        ReadCard();
                    }
                }
                break;

            case PassiveRcp.RCP_CMD_SECRET:
                if (Data.Type == 0)
                {
                    ShowState("加密成功!", "Encrypt Succeed!", lblEncryptState, true);
                }
                else
                {
                    ShowState("加密失败,按F8重新加密!", "Encrypt fail,press F8 to encrypt again!", lblEncryptState, false);
                }
                break;
            }
        }
Example #5
0
        public void ParseRsp(ProtocolStruct Data)
        {
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_ISO6B_IDEN:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    utxtCard.InputMask = GetUserTextBoxMask(Convert.ToInt32(Data.Length - 1));
                    utxtCard.Value     = ConvertData.ByteArrayToHexString(Data.Payload, 1, Data.Length - 1);
                }
                break;

            case PassiveRcp.RCP_CMD_ISO6B_RW:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    utxtReadData.InputMask = GetUserTextBoxMask(Data.Length - 1);
                    utxtReadData.Value     = ConvertData.ByteArrayToHexString(Data.Payload, 1, Data.Length - 1);
                }
                break;
            }
        }
        public void ParseRsp(ProtocolStruct Data)
        {
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_PARA:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    PBasicParameters ppTemp = new PBasicParameters();
                    ppTemp.AddRange(Data.Payload);
                    ShowBasicParametersPnfo(ppTemp);
                    SystemPub.ADRcp.CommMode = ppTemp.WorkMode == 2 ? CommMode.ACTIVE : CommMode.PASSIVE;
                    if (UserSettings.Communication == UserSettings.CommType.USB)
                    {
                        if (!SystemPub.ADRcp.SendBytePkt(PassiveRcp.GetOutCard(SystemPub.ADRcp.Address)))
                        {
                        }
                    }
                }
                else if (Data.Type == 0)
                {
                    SystemPub.ADRcp.CommMode = cmbWorkMode.SelectedIndex == 1 ? CommMode.ACTIVE : CommMode.PASSIVE;
                    if (UserSettings.Communication == UserSettings.CommType.USB || grbOutType.Visible)
                    {
                        if (!SystemPub.ADRcp.SendBytePkt(PassiveRcp.SetOutCard(SystemPub.ADRcp.Address, (byte)(cmbOutType.SelectedIndex + 1), (byte)((cmbOutLen.SelectedIndex * 2) + 6), (byte)(chkEnter.Checked ? 1 : 0))))
                        {
                        }
                    }
                }
                break;

            case PassiveRcp.RCP_CMD_OUTCARD:
                if (Data.Length > 0)
                {
                    cmbOutType.SelectedIndex = Data.Payload[0] - 1;
                    cmbOutLen.Text           = Data.Payload[1].ToString();
                    chkEnter.Checked         = Data.Payload[2] > 0 ? true : false;
                }
                break;
            }
        }
        public void ParseRsp(ProtocolStruct Data)
        {
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_TCPIP:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    TcpipParameters bpiTemp = new TcpipParameters();
                    bpiTemp.AddRange(Data.Payload);
                    ShowTcpipParaInfo(bpiTemp);
                }
                else if (Data.Type == 0)
                {
                    string stren = "Set the IP parameters under the network connection need restart the equipment!";
                    string strcn = "设置IP参数需要重启设备!";
                    string aMsg  = IniSettings.GetLanguageString(stren, strcn);
                    MessageBox.Show(aMsg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                break;

            case PassiveRcp.RCP_CMD_INFO:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    string strInfo = Encoding.ASCII.GetString(Data.Payload, 0, Data.Length);

                    SystemPub.ADRcp.Mode    = strInfo.Substring(18, 1);
                    SystemPub.ADRcp.Version = strInfo.Substring(19, 5);
                    SystemPub.ADRcp.Address = Convert.ToInt32(strInfo.Substring(29, 5));

                    txtOldAddr.Text = SystemPub.ADRcp.Address.ToString();
                }
                else if (Data.Type == 0)
                {
                    PassiveCommand.GetInformation(SystemPub.ADRcp);
                    //if (!SystemPub.ADRcp.SendBytePkt(PassiveRcp.GetInformation())) { }
                }
                break;

            case PassiveRcp.RCP_CMD_SECRET:
                break;

            case PassiveRcp.RCP_CMD_SOFTRESET:
                break;

            case PassiveRcp.RCP_CMD_INITSYRIS:
                break;

            case PassiveRcp.RCP_CMD_REMOTE:
                break;

            case PassiveRcp.RCP_CMD_TIME:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    string y  = Data.Payload[0].ToString("00");
                    string m  = Data.Payload[1].ToString("00");
                    string d  = Data.Payload[2].ToString("00");
                    string w  = Data.Payload[3].ToString("00");
                    string h  = Data.Payload[4].ToString("00");
                    string mi = Data.Payload[5].ToString("00");
                    string se = Data.Payload[6].ToString("00");
                    string D  = string.Format("20{0}-{1}-{2} {3}:{4}:{5}", y, m, d, h, mi, se);         //2010-02-28 14:48:03
                    txtReaderTime.Text = DateTime.Parse(D).ToString();
                }
                break;
            }
        }
Example #8
0
        public void ParseRsp(ProtocolStruct Data)
        {
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_INFO:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    #region ---Parameter---
                    string strInfo = Encoding.ASCII.GetString(Data.Payload, 0, Data.Length);

                    if (Data.Payload[17] == 'W' && IniSettings.Communication == IniSettings.CommType.SERIAL)
                    {
                        if (!this.tabPassive.TabPages.Contains(this.tabWifiSettings))
                        {
                            this.tabPassive.TabPages.Add(this.tabWifiSettings);
                            this.tabPassive.Refresh();
                            ucWifiSettings1.mADRcp = SystemPub.ADRcp;
                        }
                    }
                    #endregion

                    ResetOperation();
                }
                ucPSeniorSettings1.ParseRsp(Data);
                break;

            case PassiveRcp.RCP_CMD_PARA:
            case PassiveRcp.RCP_CMD_OUTCARD:
                ucPBaseSettings1.ParseRsp(Data);
                break;

            case PassiveRcp.RCP_CMD_EPC_IDEN:
            case PassiveRcp.RCP_CMD_EPC_MULT:
                if (tabWriteEPC == tabPassive.SelectedTab)
                {
                    ucPWriteEPC1.ParseRsp(Data);
                }
                else
                {
                    ucPReadDemo1.ParseRsp(Data);
                }
                break;

            case PassiveRcp.RCP_CMD_ISO6B_IDEN:
                if (tabWriteISO == tabPassive.SelectedTab)
                {
                    ucPWriteISO1.ParseRsp(Data);
                }
                else
                {
                    ucPReadDemo1.ParseRsp(Data);
                }
                break;

            case PassiveRcp.RCP_CMD_ISO6B_RW:
                ucPWriteISO1.ParseRsp(Data);
                break;

            case PassiveRcp.RCP_CMD_SECRET:
                if (tabWriteEPC == tabPassive.SelectedTab)
                {
                    ucPWriteEPC1.ParseRsp(Data);
                }
                else
                {
                    ucPSeniorSettings1.ParseRsp(Data);
                }
                break;

            case PassiveRcp.RCP_CMD_EPC_RW:
                ucPWriteEPC1.ParseRsp(Data);
                break;

            case PassiveRcp.RCP_CMD_TIME:
            case PassiveRcp.RCP_CMD_TCPIP:
                ucPSeniorSettings1.ParseRsp(Data);
                break;

            case PassiveRcp.RCP_CMD_WIFI_DOWNLOAD:
            case PassiveRcp.RCP_CMD_WIFI_PUB:
            case PassiveRcp.RCP_CMD_WIFI_STA:
            case PassiveRcp.RCP_CMD_WIFI_AP:
                ucWifiSettings1.ParseRsp(Data);
                break;

            default:
                break;
            }
        }
        public void ParseRsp(ProtocolStruct Data)
        {
            int len = Data.Length;

            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_WIFI_DOWNLOAD:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    if (Data.Payload[0] == 1)
                    {
                        MessageBox.Show("Upload Data Succeed!");
                    }
                    else if (Data.Payload[0] == 2)
                    {
                        MessageBox.Show("Download Data Succeed!");
                    }
                }
                break;

            case PassiveRcp.RCP_CMD_WIFI_PUB:
                if (len > 0)
                {
                    wpp_pub.AddRange(Data.Payload);
                    try
                    {
                        cmbPType.SelectedIndex    = wpp_pub.Type;
                        cmbPMode.SelectedIndex    = wpp_pub.Mode;
                        cmbPHide.SelectedIndex    = wpp_pub.Hide;
                        txtTcpto.Text             = wpp_pub.Tcpto.ToString();
                        txtMaxsk.Text             = wpp_pub.Maxsk.ToString();
                        cmbPServer.SelectedIndex  = wpp_pub.Server;
                        cmbProtocol.SelectedIndex = wpp_pub.Protocol;
                        txtPRemotePort.Text       = wpp_pub.RemotePort.ToString();
                        txtPRemoteIP.Text         = wpp_pub.RemoteIP;
                        txtPMac.Text = wpp_pub.Mac;
                    }
                    catch { }
                }
                break;

            case PassiveRcp.RCP_CMD_WIFI_STA:
                if (len > 0)
                {
                    try
                    {
                        wsp_sta.AddRange(Data.Payload);

                        cmbSMode.SelectedIndex    = wsp_sta.Mode;
                        cmbSChannel.SelectedIndex = wsp_sta.Channel;
                        cmbSAuth.SelectedIndex    = wsp_sta.Auth;
                        cmbSEncry.SelectedIndex   = wsp_sta.Encry;
                        cmbSDHCP.SelectedIndex    = wsp_sta.DHCP;

                        txtSSSID.Text    = wsp_sta.SSID;
                        txtSKey.Text     = wsp_sta.Key;
                        txtSIP.Text      = wsp_sta.Ip;
                        txtSMask.Text    = wsp_sta.Mask;
                        txtSGateway.Text = wsp_sta.Gateway;
                    }
                    catch { }
                }
                break;

            case PassiveRcp.RCP_CMD_WIFI_AP:
                if (len > 0)
                {
                    wsp_ap.AddRange(Data.Payload);

                    try
                    {
                        cmbAMode.SelectedIndex    = wsp_ap.Mode;
                        cmbAChannel.SelectedIndex = wsp_ap.Channel;
                        cmbAAuth.SelectedIndex    = wsp_ap.Auth;
                        cmbAEncry.SelectedIndex   = wsp_ap.Encry;
                        cmbADHCP.SelectedIndex    = wsp_ap.DHCP;

                        txtASSID.Text    = wsp_ap.SSID;
                        txtAKey.Text     = wsp_ap.Key;
                        txtAIP.Text      = wsp_ap.Ip;
                        txtAMask.Text    = wsp_ap.Mask;
                        txtAGateway.Text = wsp_ap.Gateway;
                    }
                    catch { }
                }
                break;
            }
        }
Example #10
0
        void ParseRsp(ProtocolStruct Data)
        {
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_INFO:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    #region ---Parameter---
                    string strInfo = Encoding.ASCII.GetString(Data.Payload, 0, Data.Length);

                    /*
                     * if (Data.Payload[17] == 'W')
                     * {
                     *  if (!this.tabPassive.TabPages.Contains(this.tabWifiSettings))
                     *  {
                     *      this.tabPassive.TabPages.Add(this.tabWifiSettings);
                     *      this.tabPassive.Refresh();
                     *  }
                     * }
                     * else
                     * {
                     *  if (this.tabPassive.TabPages.Contains(this.tabWifiSettings))
                     *  {
                     *      this.tabPassive.TabPages.Remove(this.tabWifiSettings);
                     *      this.tabPassive.Refresh();
                     *  }
                     * }
                     */

                    SystemPub.ADRcp.Mode    = strInfo.Substring(18, 1);
                    SystemPub.ADRcp.Version = strInfo.Substring(19, 5);
                    SystemPub.ADRcp.Address = Convert.ToInt32(strInfo.Substring(29, 5));

                    //ucWifiSettings1.mADRcp = SystemPub.ADRcp;
                    #endregion

                    ResetOperation();
                }
                break;

            case PassiveRcp.RCP_CMD_EPC_IDEN:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    //utxtCard.InputMask = GetUserTextBoxMask(Convert.ToInt32(Data.Length - 1));
                    CardID.Text = ConvertData.ByteArrayToHexString(Data.Payload, 1, Data.Length - 1);
                }
                break;

                /*
                 * case PassiveRcp.RCP_CMD_EPC_MULT:
                 * case PassiveRcp.RCP_CMD_ISO6B_IDEN:
                 *  if (Data.Length > 0 && (Data.Type == 0 || Data.Type == 0x32))
                 *  {
                 *      CardID.Text = ConvertData.ByteArrayToHexString(Data.Payload, 1, Data.Length - 1);
                 *  }
                 *  break;
                 * case 0x22:
                 *  Data.Code = 0x10;
                 *  Data.Type = 0x32;
                 *  List<CardParameters> tempArray2 = new List<CardParameters>();
                 *  List<byte> bytTempArray2 = new List<byte>(Data.ToArray());
                 *  if (PDataManage.InputManage(ref bytTempArray2, ref tempArray2))
                 *  {
                 *      //cdgvShow.Add(tempArray2);
                 *      MessageBox.Show("Not Handled");
                 *
                 *  }
                 *  break;
                 */
            }
        }
Example #11
0
        // ucPassive ucPassive1 = new ucPassive();
        private void __ParseRsp(ProtocolStruct Data)
        {
            switch (Data.Code)
            {
            case PassiveRcp.RCP_CMD_INFO:
                if (Data.Length > 0 && Data.Type == 0)
                {
                    m_bAlive = true;
                    #region ---Parameter---
                    string strInfo = Encoding.ASCII.GetString(Data.Payload, 0, Data.Length);

                    SystemPub.ADRcp.Type    = strInfo.Substring(17, 1);
                    SystemPub.ADRcp.Mode    = strInfo.Substring(18, 1);
                    SystemPub.ADRcp.Version = strInfo.Substring(19, 5);
                    //   MessageBox.Show(strInfo.Substring(29, 5));
                    bool canConvert = int.TryParse(strInfo.Substring(29, 5), out SystemPub.ADRcp.Address);
                    if (canConvert == true)
                    {
                    }
                    else
                    {
                        SystemPub.ADSio.DisConnect();
                        InitCommunication();
                        m_bStopComm           = true;
                        BtnConnect.Content    = "Connect";
                        BtnConnect.Foreground = Brushes.Black;
                        BtnStartRead.Content  = "Start Read";
                    }

                    //SystemPub.ADRcp.Address = Convert.ToInt32(strInfo.Substring(29, 5));

                    if (SystemPub.ADRcp.Type != "W" && SystemPub.ADRcp.Type != "T")
                    {
                        SystemPub.ADRcp.Type = "C";
                    }
                    ReaderMode = SystemPub.ADRcp.Mode + SystemPub.ADRcp.Type;

                    // tsFWVersion.Text = IniSettings.AppsLanguage == IniSettings.LngType.ENG ?
                    //     "Type:" + ReaderMode + " - Version:" + SystemPub.ADRcp.Version + " - Address: " + SystemPub.ADRcp.Address :
                    //     "类型:" + ReaderMode + " - 版本:" + SystemPub.ADRcp.Version + " - 地址: " + SystemPub.ADRcp.Address;
                    #endregion

                    switch (ReaderMode.Substring(0, 1))
                    {
                    case "P":
                        //   ucPassive1.Show();
                        //  ucPassive1.Parent = pnlInformation;
                        //  ucPassive1.Dock = DockStyle.Fill;
                        SystemPub.ADRcp.Sio = SystemPub.ADSio;
                        break;
                    }
                }
                break;
            }

            switch (ReaderMode.Substring(0, 1))
            {
            case "P":
                ParseRsp(Data);
                // pDisplayStatusInfo(Data.Code, Data.Type, Data.Length);
                break;
            }
        }
Example #12
0
    //[MenuItem("Tools/Editor/Config/服务端/自动生成协议类脚本")]
    public static void ParseAllProtocolServer()
    {
        //string path = Application.dataPath + "/Script/Protocol/AutoProtocolStruct/";
        string path = ServerPath + "/MilkGameServer/Server/Protocol/AutoProtocolStruct/";
        float  time = 0;

        try
        {
            EditorUtility.DisplayProgressBar("自动生成协议类脚本", "开始自动生成", 0);
            if (!Directory.Exists(Application.dataPath + "/Script/Editor/ServerConfig/ProtocolStruct"))
            {
                Debug.LogError(Application.dataPath + "/Script/Editor/ServerConfig/ProtocolStruct is not exist!");
                return;
            }
            string[] files = Directory.GetFiles(Application.dataPath + "/Script/Editor/ServerConfig/ProtocolStruct", "*.json", SearchOption.TopDirectoryOnly);
            for (int index = 0; index < files.Length; index++)
            {
                string str = "";
                time += Time.deltaTime * 3;
                for (int k = 0; k < time % 7; k++)
                {
                    str += ".";
                }
                EditorUtility.DisplayProgressBar("自动生成协议类脚本", "正在进行中..." + str, (float)index / files.Length);
                FileStream   fileStream   = File.OpenRead(files[index]);
                StreamReader streamReader = new StreamReader(fileStream, Encoding.UTF8);
                string       text         = streamReader.ReadToEnd();
                if (!string.IsNullOrEmpty(text))
                {
                    ProtocolStruct protocolStruct = JsonUtility.FromJson <ProtocolStruct>(text);
                    string         fullPath       = path + protocolStruct.protocolName + ".cs";
                    if (File.Exists(fullPath))
                    {
                        File.Delete(fullPath);
                    }
                    //FileStream fs = File.Open(fullPath, FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite);
                    StringBuilder sb = new StringBuilder();
                    sb.Append("using System;").Append(LINK);
                    sb.Append("using System.Collections;").Append(LINK);
                    sb.Append("using System.Collections.Generic;").Append(LINK);
                    sb.Append("using GameServer.Protocol.Data;").Append(LINK);
                    sb.Append("using GameServer.Protocol;").Append(LINK);
                    sb.Append(string.Format("public class {0} : ProtocolData, ICloneable", protocolStruct.protocolName)).Append(LINK);
                    sb.Append(LEFT);
                    StringBuilder classMemberSb = new StringBuilder();
                    classMemberSb.Append(TAB).Append(TAB).Append("List<object> unPackMemberList = new List<object>();").Append(LINK);
                    for (int i = 0; i < protocolStruct.unPackMemberArr.Length; i++)
                    {
                        string tempType = "";
                        switch (protocolStruct.unPackMemberArr[i].val_type)
                        {
                        case "int":
                            tempType = "INT32";
                            break;

                        case "string":
                            tempType = "STRING";
                            break;

                        case "float":
                            tempType = "FLOAT";
                            break;

                        case "double":
                            tempType = "DOUBLE";
                            break;

                        case "char":
                            tempType = "CHAR";
                            break;

                        default:
                            tempType = "CLASS";
                            break;
                        }
                        sb.Append(TAB).Append("//" + protocolStruct.unPackMemberArr[i].val_describe).Append(LINK);
                        sb.Append(TAB).Append(string.Format("public {0} {1};", protocolStruct.unPackMemberArr[i].val_type, protocolStruct.unPackMemberArr[i].val_name)).Append(LINK);
                        classMemberSb.Append(TAB).Append(TAB).Append(string.Format("unPackMemberList.Add(DefaultVar.{0});", tempType)).Append(LINK);
                    }
                    classMemberSb.Append(TAB).Append(TAB).Append(string.Format("ProtocolMgr.Instance.AddProtocolUnPackMemberListToDict((ProtocolNo){0}, unPackMemberList);", protocolStruct.protocolID)).Append(LINK);
                    sb.Append(TAB).Append(string.Format("public {0} ()", protocolStruct.protocolName)).Append(LINK);
                    sb.Append(TAB).Append(LEFT);
                    sb.Append(classMemberSb.ToString()).Append(LINK);
                    sb.Append(TAB).Append(TAB).Append("List<object> packMemberList = new List<object>();").Append(LINK);
                    for (int i = 0; i < protocolStruct.packMemberArr.Length; i++)
                    {
                        string tempType = "";
                        switch (protocolStruct.packMemberArr[i].val_type)
                        {
                        case "int":
                            tempType = "INT32";
                            break;

                        case "string":
                            tempType = "STRING";
                            break;

                        case "float":
                            tempType = "FLOAT";
                            break;

                        case "double":
                            tempType = "DOUBLE";
                            break;

                        case "char":
                            tempType = "CHAR";
                            break;

                        default:
                            tempType = "CLASS";
                            break;
                        }
                        sb.Append(TAB).Append(TAB).Append(string.Format("packMemberList.Add(DefaultVar.{0});", tempType)).Append(LINK);
                    }
                    sb.Append(TAB).Append(TAB).Append(string.Format("ProtocolMgr.Instance.AddProtocolPackMemberListToDict((ProtocolNo){0}, packMemberList);", protocolStruct.protocolID)).Append(LINK);
                    sb.Append(TAB).Append(RIGHT);
                    sb.Append(LINK);
                    sb.Append(TAB).Append("public override void SetData(List<object> objectList)").Append(LINK);
                    sb.Append(TAB).Append(LEFT);
                    sb.Append(TAB).Append(TAB).Append("int index = 0;").Append(LINK);
                    for (int i = 0; i < protocolStruct.unPackMemberArr.Length; i++)
                    {
                        if (protocolStruct.unPackMemberArr[i].val_type == "int" || protocolStruct.unPackMemberArr[i].val_type == "string" ||
                            protocolStruct.unPackMemberArr[i].val_type == "float" || protocolStruct.unPackMemberArr[i].val_type == "double" ||
                            protocolStruct.unPackMemberArr[i].val_type == "char")
                        {
                            sb.Append(TAB).Append(TAB).Append(string.Format("{0} = ({1})objectList[index];", protocolStruct.unPackMemberArr[i].val_name, protocolStruct.unPackMemberArr[i].val_type)).Append(LINK);
                            sb.Append(TAB).Append(TAB).Append("index += 1;").Append(LINK);
                        }
                        else
                        {
                            sb.Append(TAB).Append(TAB).Append(string.Format("{0} = {1}.ToClass(objectList, ref index);", protocolStruct.unPackMemberArr[i].val_name, protocolStruct.unPackMemberArr[i].val_type)).Append(LINK);
                        }
                    }
                    sb.Append(TAB).Append(RIGHT);
                    sb.Append(LINK);
                    sb.Append(TAB).Append("public override object Clone()").Append(LINK);
                    sb.Append(TAB).Append(LEFT);
                    sb.Append(TAB).Append(TAB).Append("return MemberwiseClone();").Append(LINK);
                    sb.Append(TAB).Append(RIGHT);
                    sb.Append(RIGHT);
                    File.WriteAllText(fullPath, sb.ToString());
                    sb = null;
                    streamReader.Close();
                    fileStream.Close();
                    streamReader.Dispose();
                    fileStream.Dispose();
                    streamReader = null;
                    fileStream   = null;
                }
            }
            EditorUtility.DisplayProgressBar("自动生成协议类脚本", "已完成!", 1);
        }
        catch (Exception e)
        {
            EditorUtility.ClearProgressBar();
            Debug.LogError(e.ToString());
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }
        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();
    }