Esempio n. 1
0
 public IOPH_DATA(ADTRecord adtRec, IAppMainWindow mainWin)
 {
     _adtRec = adtRec;
     _mainWin = mainWin;
     _teleToWin = new Telegram(GlobalServices.maxReplyDataLen);
     _teleFromWin = new Telegram(GlobalServices.maxReplyDataLen);
 }
Esempio n. 2
0
 public IOPH_EZLinkDongle(ADTRecord adtRec, IAppMainWindow mainWin)
 {
     this._adtRec = adtRec;
     this._mainWin = mainWin;
     this._teleFromWin = new Telegram(0x3e8);
     this._teleToWin = new Telegram(0x3e8);
     this._replyData = new DataBuffer(0x3e8);
     this._isSeries = false;
     this._seriesExecStat = SeriesExecutionState.Stop;
     this._taskEvent = new AutoResetEvent(false);
     this._taskState = TaskState.TaskReady_OK;
     if (adtRec.isUsbEZLinkDevice())
     {
         this._ddi = DDI_EZLinkDongle.instance();
     }
     else if (adtRec.isTESTDevice())
     {
         this._ddi = DDI_TEST.instance();
     }
     else
     {
         GlobalServices.ErrMsg("FATAL ERROR: IOPH_EZLinkDongle", "I/O port type not supported, exit WDS!");
         Application.Exit();
     }
     this._iot = new Thread(new ThreadStart(this.doDeviceIO));
     this._iot.IsBackground = true;
     this._iot.Name = "IOPH_EZLink thread";
     this._isTelegramRequest = false;
     this._isRxTimerRequest = false;
     this._isReadRxPacketEnabled = false;
     this._iot.Start();
 }
Esempio n. 3
0
File: IOPH_DCP.cs Progetto: x893/WDS
 public IOPH_DCP(ADTRecord adtRec, IAppMainWindow mainWin)
 {
     _adtRec = adtRec;
     _mainWin = mainWin;
     _teleFromWin = new Telegram(GlobalServices.maxCommandDataLen);
     _teleToWin = new Telegram(GlobalServices.maxReplyDataLen);
     _replyData = new DataBuffer(GlobalServices.maxReplyDataLen);
     _isSeries = false;
     _seriesExecStat = SeriesExecutionState.Stop;
     _taskState = TaskState.TaskReady_OK;
     int num = int.Parse(ConfigurationManager.AppSettings["DCPMaxDataLen"]);
     int num2 = int.Parse(ConfigurationManager.AppSettings["DCPMsgRepeatNr"]);
     int num3 = int.Parse(ConfigurationManager.AppSettings["DCPRecTimeout"]);
     byte num4 = byte.Parse(ConfigurationManager.AppSettings["DCPSOFByte"]);
     _dcpProtocolEngine = new DCPProtocol(this, num, num2, num3, 10, num4);
     _DCPRXMsg = new DCPFrame(num, num4);
     _DCPAnswerMsg = new DCPFrame(num, num4);
     _DCPTXMsg = new DCPFrame(num, num4);
     _DCPTXBuf = new DCPFrame(num, num4);
     if (adtRec.isUsbFtdiDevice())
     {
         _ddi = DDI_USB.instance();
     }
     else if (adtRec.isRS232Device())
     {
         _ddi = DDI_RS232.instance();
     }
     else if (adtRec.isTESTDevice())
     {
         _ddi = DDI_TEST.instance();
     }
     else if (adtRec.isHIDDevice())
     {
         _ddi = DDI_HID.instance();
     }
     else
     {
         GlobalServices.ErrMsg("IOPH_DCP.IOPH_DCP()", "FATAL ERROR: Unknown I/O port type, exit WDS!");
         Application.Exit();
     }
     _iot = new Thread(new ThreadStart(doDeviceIO));
     _iot.IsBackground = true;
     _iot.Name = "IOPH_DCP thread";
     _isTelegramRequest = false;
     _iot.Start();
 }
Esempio n. 4
0
 public IOPH_LoadBoard(ADTRecord adtRec, IAppMainWindow mainWin)
 {
     this._adtRec = adtRec;
     this._mainWin = mainWin;
     this._teleFromWin = new Telegram(GlobalServices.maxCommandDataLen);
     this._teleToWin = new Telegram(GlobalServices.maxReplyDataLen);
     this._replyData = new DataBuffer(GlobalServices.maxReplyDataLen, Data_Type.ASCII);
     this._isSeries = false;
     this._seriesExecStat = SeriesExecutionState.Stop;
     this._taskEvent = new AutoResetEvent(false);
     this._taskState = TaskState.TaskReady_OK;
     if (adtRec.isUsbFtdiDevice())
     {
         this._ddi = DDI_USB.instance();
         this._isTestDevice = false;
     }
     else if (adtRec.isRS232Device())
     {
         this._ddi = DDI_RS232.instance();
         this._isTestDevice = false;
     }
     else if (adtRec.isTESTDevice())
     {
         this._ddi = DDI_TEST.instance();
         this._isTestDevice = true;
     }
     else if (adtRec.isHIDDevice())
     {
         this._ddi = DDI_HID.instance();
         this._isTestDevice = false;
     }
     else
     {
         GlobalServices.ErrMsg("IOPH_LoadBoard.IOPH_LoadBoard()", "FATAL ERROR: Unknown I/O port type, exit WDS!");
         GlobalServices.msgBox("FATAL ERROR: Unknown I/O port type, exit WDS!", "IOPH_LoadBoard.IOPH_LoadBoard()");
         Application.Exit();
     }
     this.ReadReplytimerDelegate = new TimerCallback(this.rxReadReplyTimerTickHandler);
     this._iot = new Thread(new ThreadStart(this.doDeviceIO));
     this._iot.IsBackground = true;
     this._iot.Name = "IOPH_LoadBoard thread";
     this._iot.Start();
 }
Esempio n. 5
0
 public int setWindows(IAppMainWindow mainWin, IAppWindow[] helperWins)
 {
     this._mainWin = mainWin;
     this._appWinReadyToClose[this._mainWin] = false;
     this._helperWins = helperWins;
     if (helperWins != null)
     {
         foreach (IAppWindow window in this._helperWins)
         {
             this._appWinReadyToClose[window] = false;
         }
     }
     return 0;
 }
Esempio n. 6
0
        public static TelegramContainerItem[] createTelegramsFromBatchString(string commands, IIOPortHandler ioph, IAppMainWindow mainWin, bool ctsPoll, DeviceRegisterSet deviceRegSet, ChipCommandAndPpropertyDescriptor chipApiDescriptor, out string errorMessage)
        {
            errorMessage = "No Error";
            string[] strArray = commands.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            List<TelegramContainerItem> list = new List<TelegramContainerItem>();
            bool flag = false;
            for (int i = 0; i < strArray.Length; i++)
            {
                Telegram telegram;
                LastReplyPrecondition invalid;
                byte[] buffer;
                byte[][] bufferArray4;
                byte[] buffer8;
                flag = false;
                if ((strArray[i].Trim().Length >= 2) && !strArray[i].Trim().StartsWith("#"))
                {
                    if (strArray[i].Trim().ToUpper().StartsWith("DELAY"))
                    {
                        int num2;
                        if (int.TryParse(strArray[i].Trim().ToUpper().Replace("DELAY", "").Trim(), out num2))
                        {
                            list.Add(new TelegramContainerItem(num2));
                        }
                    }
                    else if (strArray[i].Trim().ToUpper().StartsWith("RESET"))
                    {
                        bufferArray4 = new byte[5][];
                        bufferArray4[0] = new byte[] { 0x12, 6, 1, 0 };
                        bufferArray4[1] = new byte[] { 0x13, 6, 1 };
                        buffer8 = new byte[3];
                        buffer8[0] = 0x13;
                        buffer8[1] = 6;
                        bufferArray4[2] = buffer8;
                        byte[] buffer9 = new byte[4];
                        buffer9[0] = 0x12;
                        buffer9[1] = 0x1b;
                        bufferArray4[3] = buffer9;
                        bufferArray4[4] = new byte[] { 20, 0x1b };
                        byte[][] bufferArray = bufferArray4;
                        LastReplyPrecondition[] preconditionArray = new LastReplyPrecondition[] { LastReplyPrecondition.ACK, LastReplyPrecondition.ACK, LastReplyPrecondition.ACK, LastReplyPrecondition.ACK, LastReplyPrecondition.DataACK };
                        for (int j = 0; j < bufferArray.Length; j++)
                        {
                            telegram = new Telegram(bufferArray[j].Length) {
                                uniqId = GlobalServices.uniqTelegramId(),
                                parentUniqId = -1,
                                type = TelegramType.Command
                            };
                            if (ioph is IOPH_DCP)
                            {
                                telegram.protocol = Protocol.DCP;
                                telegram.DCPCmdSet = 4;
                            }
                            else
                            {
                                telegram.protocol = Protocol.DCP2;
                                telegram.DCPCmdSet = 0x1c;
                            }
                            telegram.lastReplyPrecondition = preconditionArray[j];
                            telegram.replySize = 15;
                            telegram.UserData = new object[] { false };
                            if (j == 0)
                            {
                                telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() };
                                telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim());
                            }
                            if (telegram.replySize == -1)
                            {
                                throw new Exception("Not supported command.");
                            }
                            telegram.data.copy(bufferArray[j]);
                            telegram.portHandler = ioph;
                            telegram.mainWin = mainWin;
                            list.Add(new TelegramContainerItem(telegram));
                        }
                    }
                    else if (strArray[i].Trim().ToUpper().StartsWith("SHUTDOWN"))
                    {
                        byte[][] bufferArray2 = new byte[][] { new byte[] { 0x12, 6, 1, 0 }, new byte[] { 0x13, 6, 1 } };
                        LastReplyPrecondition[] preconditionArray2 = new LastReplyPrecondition[] { LastReplyPrecondition.ACK, LastReplyPrecondition.ACK };
                        for (int k = 0; k < bufferArray2.Length; k++)
                        {
                            telegram = new Telegram(bufferArray2[k].Length) {
                                uniqId = GlobalServices.uniqTelegramId(),
                                parentUniqId = -1,
                                type = TelegramType.Command
                            };
                            if (ioph is IOPH_DCP)
                            {
                                telegram.protocol = Protocol.DCP;
                                telegram.DCPCmdSet = 4;
                            }
                            else
                            {
                                telegram.protocol = Protocol.DCP2;
                                telegram.DCPCmdSet = 0x1c;
                            }
                            telegram.lastReplyPrecondition = preconditionArray2[k];
                            telegram.replySize = 15;
                            telegram.UserData = new object[] { false };
                            if (k == 0)
                            {
                                telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim());
                                telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() };
                            }
                            if (telegram.replySize == -1)
                            {
                                throw new Exception("Not supported command.");
                            }
                            telegram.data.copy(bufferArray2[k]);
                            telegram.portHandler = ioph;
                            telegram.mainWin = mainWin;
                            list.Add(new TelegramContainerItem(telegram));
                        }
                    }
                    else
                    {
                        if (!strArray[i].Trim().ToUpper().StartsWith("DCP"))
                        {
                            goto Label_064D;
                        }
                        invalid = LastReplyPrecondition.Invalid;
                        buffer = new byte[1];
                        if (strArray[i].Trim().Length <= 3)
                        {
                            goto Label_0523;
                        }
                        switch (strArray[i].Trim().ToUpper()[3])
                        {
                            case 'A':
                                invalid = LastReplyPrecondition.ACK;
                                goto Label_04F9;

                            case 'D':
                                invalid = LastReplyPrecondition.DataACK;
                                goto Label_04F9;

                            case 'I':
                                invalid = LastReplyPrecondition.Indication;
                                goto Label_04F9;
                        }
                    }
                }
                continue;
            Label_04F9:
                buffer = WDSConverters.ToByteArray(strArray[i].Substring(4).Trim().Replace(" ", "").ToUpper());
            Label_0523:
                telegram = new Telegram(buffer.Length);
                telegram.uniqId = GlobalServices.uniqTelegramId();
                telegram.parentUniqId = -1;
                telegram.type = TelegramType.Command;
                if (ioph is IOPH_DCP)
                {
                    telegram.protocol = Protocol.DCP;
                    telegram.DCPCmdSet = 4;
                }
                else
                {
                    telegram.protocol = Protocol.DCP2;
                    telegram.DCPCmdSet = 0x1c;
                }
                telegram.lastReplyPrecondition = invalid;
                telegram.replySize = 15;
                telegram.UserData = new object[] { false };
                telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() };
                telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim());
                if (telegram.replySize == -1)
                {
                    throw new Exception("Not supported command.");
                }
                telegram.data.copy(buffer);
                telegram.portHandler = ioph;
                telegram.mainWin = mainWin;
                list.Add(new TelegramContainerItem(telegram));
                continue;
            Label_064D:
                if (strArray[i].Trim().ToUpper().StartsWith("RAM"))
                {
                    string str;
                    if (!getDataFromFwLoadCommand(strArray[i].Trim(), out str))
                    {
                        _log.Error("Cannot create RAM Load telegram from command string");
                    }
                    else
                    {
                        string str2;
                        StreamReader reader = File.OpenText(str);
                        byte[] buf = new byte[0x800];
                        int index = 0;
                        while (((str2 = reader.ReadLine()) != null) && (index < buf.Length))
                        {
                            if (byte.TryParse(str2, NumberStyles.HexNumber, (IFormatProvider) null, out buf[index]))
                            {
                                index++;
                            }
                        }
                        if (index == 0)
                        {
                            _log.Error("Could not read any RAM data from the RAM Load file");
                        }
                        else
                        {
                            bufferArray4 = new byte[0x11][];
                            buffer8 = new byte[4];
                            buffer8[0] = 0x10;
                            buffer8[3] = 1;
                            bufferArray4[0] = buffer8;
                            bufferArray4[1] = new byte[] { 0x10, 3, 0, 7, 80 };
                            bufferArray4[2] = new byte[] { 0x10, 4, 0, 7, 80, 0 };
                            bufferArray4[3] = new byte[] { 0x10, 4, 0, 7, 80, 0 };
                            bufferArray4[4] = new byte[] { 0x10, 3, 0, 7, 80 };
                            bufferArray4[5] = new byte[] { 0x10, 4, 0, 0x6d, 80, 1 };
                            bufferArray4[6] = new byte[] { 0x10, 4, 0, 1, 80, 0xff };
                            bufferArray4[7] = new byte[] { 0x10, 4, 0, 0xac, 80, 0x1f };
                            bufferArray4[8] = new byte[] { 0x10, 7, 0, 0x94, 0x54, 0x53 };
                            bufferArray4[9] = new byte[] { 0x10, 7, 0, 0x95, 0x54, 0x30 };
                            bufferArray4[10] = new byte[] { 0x10, 0x45, 0, 0x88 };
                            buffer8 = new byte[3];
                            buffer8[0] = 0x10;
                            buffer8[1] = 0x85;
                            bufferArray4[11] = buffer8;
                            buffer8 = new byte[3];
                            buffer8[0] = 0x10;
                            buffer8[1] = 0xc5;
                            bufferArray4[12] = buffer8;
                            bufferArray4[13] = new byte[] { 0x10, 3, 0, 7, 80 };
                            bufferArray4[14] = new byte[] { 0x10, 4, 0, 7, 80, 9 };
                            bufferArray4[15] = new byte[] { 0x10, 4, 0, 7, 80, 9 };
                            bufferArray4[0x10] = new byte[] { 0x10, 3, 0, 7, 80 };
                            byte[][] bufferArray3 = bufferArray4;
                            int num6 = 0;
                            for (int m = 0; m < bufferArray3.Length; m++)
                            {
                                telegram = new Telegram(bufferArray3[m].Length) {
                                    uniqId = GlobalServices.uniqTelegramId(),
                                    parentUniqId = -1,
                                    type = TelegramType.Command
                                };
                                if (ioph is IOPH_DCP)
                                {
                                    telegram.protocol = Protocol.DCP;
                                    telegram.DCPCmdSet = 4;
                                }
                                else
                                {
                                    telegram.protocol = Protocol.DCP2;
                                    telegram.DCPCmdSet = 0x1c;
                                }
                                telegram.lastReplyPrecondition = LastReplyPrecondition.Indication;
                                telegram.replySize = 15;
                                telegram.UserData = new object[] { false };
                                if (m == 0)
                                {
                                    telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim());
                                    telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() };
                                }
                                if (telegram.replySize == -1)
                                {
                                    throw new Exception("Not supported command.");
                                }
                                telegram.data.copy(bufferArray3[m]);
                                if ((m == 11) && (num6 < 0x10))
                                {
                                    telegram.data.appendFromStartIdx(buf, num6 * 0x79, 0x79);
                                    num6++;
                                    m--;
                                }
                                else if (m == 12)
                                {
                                    telegram.data.appendFromStartIdx(buf, buf.Length - 0x70, 0x70);
                                }
                                else if (m == 11)
                                {
                                    continue;
                                }
                                telegram.portHandler = ioph;
                                telegram.mainWin = mainWin;
                                list.Add(new TelegramContainerItem(telegram));
                            }
                        }
                    }
                }
                else if (strArray[i].Trim().ToUpper().StartsWith("PATCH"))
                {
                    string str3;
                    if (!getDataFromFwLoadCommand(strArray[i].Trim(), out str3))
                    {
                        _log.Error("Cannot create PATCH Load telegram from command string");
                    }
                    else
                    {
                        string str4;
                        StreamReader reader2 = File.OpenText(str3);
                        List<byte[]> list2 = new List<byte[]>();
                        while ((str4 = reader2.ReadLine()) != null)
                        {
                            byte[] item = new byte[8];
                            if (!str4.Trim().StartsWith("#"))
                            {
                                string[] strArray2 = str4.Split(new char[] { ',' });
                                for (int n = 0; (n < strArray2.Length) && (n < item.Length); n++)
                                {
                                    string s = strArray2[n];
                                    if (strArray2[n].StartsWith("0x"))
                                    {
                                        s = s.Substring(2);
                                    }
                                    if (!byte.TryParse(s, NumberStyles.HexNumber, (IFormatProvider) null, out item[n]))
                                    {
                                        _log.Error("Invalid data in PATCH Load file");
                                    }
                                }
                                list2.Add(item);
                            }
                        }
                        if (list2.Count == 0)
                        {
                            _log.Error("Could not read any PATCH data from the RAM Load file");
                        }
                        else
                        {
                            buffer8 = new byte[3];
                            buffer8[0] = 0x10;
                            byte[] buffer4 = buffer8;
                            byte[] buffer5 = new byte[] { 0x10, 0, 0, 0x44, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
                            for (int num9 = 0; num9 < (list2.Count * 2); num9++)
                            {
                                telegram = new Telegram(10) {
                                    uniqId = GlobalServices.uniqTelegramId(),
                                    parentUniqId = -1,
                                    type = TelegramType.Command
                                };
                                if (ioph is IOPH_DCP)
                                {
                                    telegram.protocol = Protocol.DCP;
                                    telegram.DCPCmdSet = 4;
                                }
                                else
                                {
                                    telegram.protocol = Protocol.DCP2;
                                    telegram.DCPCmdSet = 0x1c;
                                }
                                telegram.lastReplyPrecondition = LastReplyPrecondition.Indication;
                                telegram.replySize = 15;
                                if (num9 == 0)
                                {
                                    telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim());
                                    telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() };
                                }
                                if (telegram.replySize == -1)
                                {
                                    throw new Exception("Not supported command.");
                                }
                                if ((num9 % 2) == 0)
                                {
                                    telegram.data.copy(buffer4);
                                    telegram.data.appendFromStartIdx(list2[num9 / 2], 0, list2[num9 / 2].Length);
                                }
                                else
                                {
                                    telegram.data.copy(buffer5);
                                }
                                telegram.portHandler = ioph;
                                telegram.mainWin = mainWin;
                                list.Add(new TelegramContainerItem(telegram));
                            }
                        }
                    }
                }
                else if (strArray[i].Trim().ToUpper().StartsWith("TCL"))
                {
                    int num10;
                    string str6;
                    if (!getDataFromTclCommand(strArray[i].Trim(), out num10, out str6))
                    {
                        _log.Error("Cannot create TCL telegram from command string");
                    }
                    else
                    {
                        telegram = new Telegram(str6.Length) {
                            TimeOut = num10 * 0x3e8,
                            uniqId = GlobalServices.uniqTelegramId(),
                            parentUniqId = -1,
                            type = TelegramType.ExecuteTclScript
                        };
                        if (ioph is IOPH_DCP)
                        {
                            telegram.protocol = Protocol.DCP;
                            telegram.DCPCmdSet = 4;
                        }
                        else
                        {
                            telegram.protocol = Protocol.DCP2;
                            telegram.DCPCmdSet = 0x1c;
                        }
                        telegram.replySize = 15;
                        telegram.UserData = new object[] { false };
                        telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() };
                        telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim());
                        if (telegram.replySize == -1)
                        {
                            throw new Exception("Not supported command.");
                        }
                        telegram.data.copy(str6);
                        telegram.userData = 3;
                        telegram.portHandler = ioph;
                        telegram.mainWin = mainWin;
                        list.Add(new TelegramContainerItem(telegram));
                    }
                }
                else
                {
                    int numberOfReplyData = 0;
                    List<byte> list3 = new List<byte>();
                    string[] strArray3 = strArray[i].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    bool flag2 = false;
                    bool isPeekPoke = false;
                    byte num12 = 0;
                    bool flag4 = false;
                    bool flag5 = false;
                    for (int num13 = 0; num13 < strArray3.Length; num13++)
                    {
                        if ((strArray3[num13].Trim().ToUpper() == "DW") || (strArray3[num13].Trim().ToUpper() == "DR"))
                        {
                            flag2 = true;
                            isPeekPoke = false;
                            flag4 = true;
                            if (strArray3[num13].Trim() == "DW")
                            {
                                num12 = 4;
                            }
                            else
                            {
                                num12 = 3;
                                flag5 = true;
                            }
                        }
                        else
                        {
                            if ((strArray3[num13].Trim().ToUpper() == "'PEEK'") || (strArray3[num13].Trim().ToUpper() == "'POKE'"))
                            {
                                isPeekPoke = true;
                            }
                            byte[] array = null;
                            if (strArray3[num13].Trim().StartsWith("'"))
                            {
                                if (!isPeekPoke || (num13 == 0))
                                {
                                    array = chipApiDescriptor.getByteRepresentationByAPIName(strArray3[num13].Trim(new char[] { '\'' }));
                                }
                                if (array == null)
                                {
                                    array = SPI_tools.getByteRepresentationByRegisterName(strArray3[num13].Trim(new char[] { '\'' }), isPeekPoke, deviceRegSet);
                                }
                                if (array == null)
                                {
                                    errorMessage = "Line number: " + i.ToString() + "\nInvalid command: " + strArray[i].Trim();
                                    return null;
                                }
                                if ((num13 == 0) && (chipApiDescriptor.getCommandById(array[0]).NumberOfReplyData > 1))
                                {
                                    flag = true;
                                    numberOfReplyData = chipApiDescriptor.getCommandById(array[0]).NumberOfReplyData;
                                }
                                if (flag2)
                                {
                                    Array.Reverse(array);
                                    flag2 = false;
                                }
                                if (((list3.Count == 1) && ((list3[0] == chipApiDescriptor.SetPropertyCommandId) || (list3[0] == chipApiDescriptor.GetPropertyCommandId))) && (array.Length == 2))
                                {
                                    List<byte> list4 = new List<byte>(array);
                                    list4.Insert(1, 1);
                                    array = list4.ToArray();
                                }
                                if ((flag4 && (array.Length == 2)) && (array[1] == 0x54))
                                {
                                    num12 = (byte) (num12 + 3);
                                }
                                if ((isPeekPoke && (array.Length == 2)) && (array[0] == 0x54))
                                {
                                    array[0] = 0;
                                }
                                foreach (byte num14 in array)
                                {
                                    list3.Add(num14);
                                }
                            }
                            else
                            {
                                byte num15;
                                if ((strArray3[num13].Trim().Length <= 2) && byte.TryParse(strArray3[num13].Trim(), NumberStyles.HexNumber, (IFormatProvider) null, out num15))
                                {
                                    if ((num13 == 0) && (chipApiDescriptor.getCommandById(num15).NumberOfReplyData > 1))
                                    {
                                        flag = true;
                                        numberOfReplyData = chipApiDescriptor.getCommandById(num15).NumberOfReplyData;
                                    }
                                    list3.Add(num15);
                                }
                                else
                                {
                                    errorMessage = "Line number: " + i.ToString() + "\nInvalid command: " + strArray[i].Trim();
                                    return null;
                                }
                            }
                        }
                    }
                    if (list3.Count != 0)
                    {
                        if (list3.Count == 1)
                        {
                            list3.Add(0);
                        }
                        telegram = new Telegram(list3.Count + 3) {
                            uniqId = GlobalServices.uniqTelegramId(),
                            parentUniqId = -1,
                            type = TelegramType.Command,
                            lastReplyPrecondition = LastReplyPrecondition.Indication,
                        };
                        if (ioph is IOPH_DCP)
                        {
                            telegram.protocol = Protocol.DCP;
                            telegram.DCPCmdSet = 4;
                        }
                        else
                        {
                            telegram.protocol = Protocol.DCP2;
                            telegram.DCPCmdSet = 0x1c;
                        }
                        buffer8 = new byte[3];
                        buffer8[0] = 0x10;
                        buffer8[1] = num12;
                        telegram.data.copy(buffer8);
                        telegram.data.append(list3.ToArray(), list3.Count);
                        telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() };
                        telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim());
                        telegram.portHandler = ioph;
                        telegram.mainWin = mainWin;
                        list.Add(new TelegramContainerItem(telegram));
                        if (flag)
                        {
                            telegram = new Telegram(13) {
                                uniqId = GlobalServices.uniqTelegramId(),
                                parentUniqId = -1,
                                type = TelegramType.Command,
                                lastReplyPrecondition = LastReplyPrecondition.Indication
                            };
                            if (ioph is IOPH_DCP)
                            {
                                telegram.protocol = Protocol.DCP;
                                telegram.DCPCmdSet = 4;
                            }
                            else
                            {
                                telegram.protocol = Protocol.DCP2;
                                telegram.DCPCmdSet = 0x1c;
                            }
                            buffer8 = new byte[4];
                            buffer8[0] = 0x10;
                            buffer8[3] = 0x44;
                            telegram.data.copy(buffer8);
                            byte[] buffer7 = new byte[numberOfReplyData];
                            for (int num16 = 0; num16 < buffer7.Length; num16++)
                            {
                                buffer7[num16] = 0xff;
                            }
                            telegram.data.append(buffer7, buffer7.Length);
                            telegram.UserDataExt.addUserData("normalLogReply", true);
                            telegram.portHandler = ioph;
                            telegram.mainWin = mainWin;
                            list.Add(new TelegramContainerItem(telegram));
                        }
                        else if (((list[list.Count - 1].telegram.data.NumItems != 5) || (list[list.Count - 1].telegram.data.Buf[3] != 0x34)) && ctsPoll)
                        {
                            if (!flag4)
                            {
                                telegram = new Telegram(13) {
                                    uniqId = GlobalServices.uniqTelegramId(),
                                    parentUniqId = -1,
                                    type = TelegramType.Command,
                                    lastReplyPrecondition = LastReplyPrecondition.Indication
                                };
                                if (ioph is IOPH_DCP)
                                {
                                    telegram.protocol = Protocol.DCP;
                                    telegram.DCPCmdSet = 4;
                                }
                                else
                                {
                                    telegram.protocol = Protocol.DCP2;
                                    telegram.DCPCmdSet = 0x1c;
                                }
                                telegram.data.copy(new byte[] { 0x10, 0, 0, 0x44, 0xff });
                                telegram.UserDataExt.addUserData("normalLogReply", true);
                                telegram.portHandler = ioph;
                                telegram.mainWin = mainWin;
                                list.Add(new TelegramContainerItem(telegram));
                            }
                            else if (flag5)
                            {
                                list[list.Count - 1].telegram.UserDataExt.addUserData("debugLogReply", true);
                            }
                        }
                    }
                }
            }
            if (list.Count == 0)
            {
                errorMessage = "Did not recognized any executable commands!";
                return null;
            }
            return list.ToArray();
        }
Esempio n. 7
0
        public int startPlugAndPlayApplication(WDSApplicationType appType, List<ADTRecord> adtRecList, ADCRRecord a_selectedADCRRecord)
        {
            ADTRecord[] adtRecs = new ADTRecord[adtRecList.Count];
            for (int i = 0; i < adtRecList.Count; i++)
                adtRecs[i] = adtRecList[i];

            if (!ADCRManager.instance().canAppAcceptSelDevs(appType, adtRecs))
            {
                GlobalServices.ErrMsg("WDSFrameWindow.startPlugAndPlayApplication()", "Application cannot accept selected devices!");
                return -1;
            }
            WDSApplication app = new WDSApplication(appType);
            IAppMainWindow mainWin = _lastCreatedMainWin = ADCRManager.instance().createAppMainWin(appType);
            if (mainWin == null)
            {
                GlobalServices.ErrMsg("startPlugAndPlayApplication()", "createAppMainWin() failed to create application's main window");
                return -1;
            }
            adtRecList[0].addAssociatedApp(a_selectedADCRRecord);
            _lastCreatedMainWin.associatedADCRRecord = a_selectedADCRRecord;
            IAppWindow[] helperWins = mainWin.createHelperWindows();
            if (helperWins != null)
                foreach (IAppWindow window2 in helperWins)
                    window2.createCloseWindowController();

            IIOPortHandler[] portHandlers = mainWin.createPortHandlers(adtRecs);
            mainWin.createCloseWindowController();
            app.setWindows(mainWin, helperWins);
            app.setPortHandlers(portHandlers);
            try
            {
                if (mainWin.initialize() == -1)
                {
                    GlobalServices.ErrMsg("startPlugAndPlayApplication()", "Application's main window initialization failed!");
                    return -1;
                }
                ((Form) mainWin).MdiParent = this;
                ((Form) mainWin).Show();
                if (helperWins != null)
                {
                    foreach (IAppWindow window3 in helperWins)
                    {
                        ((Form) window3).MdiParent = this;
                        ((Form) window3).Show();
                    }
                }
                WDSApplicationManager.instance().addApplication(app);
                return 0;
            }
            catch
            {
                return -1;
            }
        }
Esempio n. 8
0
File: Telegram.cs Progetto: x893/WDS
 public int copy(Telegram another)
 {
     this.data.copy(another.data);
     this.uniqId = another.uniqId;
     this.parentUniqId = another.parentUniqId;
     this.type = another.type;
     this.lastReplyPrecondition = another.lastReplyPrecondition;
     this.numOfLastReplyPackets = another.numOfLastReplyPackets;
     this._TimeOut = another.TimeOut;
     this._userData = another._userData;
     this._userDataExt.copy(another.UserDataExt);
     this.CallbackEvent = another.CallbackEvent;
     this.protocol = another.protocol;
     this.replySize = another.replySize;
     this.mainWin = another.mainWin;
     this.portHandler = another.portHandler;
     this.appFuncId = another.appFuncId;
     this.userData = another.userData;
     this._hasHeader = another.HasHeader;
     this.DCPCmdSet = another.DCPCmdSet;
     this.DCPMsgType = another.DCPMsgType;
     return 0;
 }
Esempio n. 9
0
 public TelegramSeriesLocalProcessor(IAppMainWindow mainWin, IIOPortHandler ioph)
 {
     this._mainWin = mainWin;
     this._ioph = (IOPH_DCP) ioph;
 }