Exemplo n.º 1
0
            private void replyTeleArrived(Telegram replyTelegram)
            {
                switch (replyTelegram.type)
                {
                    case TelegramType.AckOrNackSentOK:
                        if (_lastReplyPec == ((LastReplyPrecondition) replyTelegram.lastReplyPrecondition))
                        {
                            if (replyTelegram.numOfLastReplyPackets != -1)
                            {
                                _replyPreconditionCnt--;
                                if (_replyPreconditionCnt == 0)
                                {
                                    execTelegramSeries();
                                }
                                return;
                            }
                            execTelegramSeries();
                        }
                        return;

                    case TelegramType.AcknowledgeOK:
                        _mainWin.showLocalLog("< ACK\n");
                        _gotACKforCommand = true;
                        if (replyTelegram.lastReplyPrecondition == LastReplyPrecondition.ACK)
                        {
                            _replyPreconditionCnt--;
                            if (_replyPreconditionCnt > 0)
                            {
                                return;
                            }
                            execTelegramSeries();
                        }
                        return;

                    case TelegramType.AcknowledgeERROR:
                        _mainWin.showLocalLog("< NACK\n");
                        execTelegramSeries();
                        return;

                    case TelegramType.DataAcknowledgeOK:
                        _mainWin.showLocalLog("< " + WDSConverters.ToHexString(replyTelegram.data.Buf, replyTelegram.data.NumItems) + "\n");
                        if (_savedEvent != null)
                        {
                            _savedEvent(replyTelegram);
                        }
                        if (replyTelegram.lastReplyPrecondition == LastReplyPrecondition.DataACK)
                        {
                            if (replyTelegram.numOfLastReplyPackets == -1)
                            {
                                execTelegramSeries();
                                return;
                            }
                            _replyPreconditionCnt--;
                            if (_replyPreconditionCnt != 0)
                            {
                                return;
                            }
                            execTelegramSeries();
                        }
                        return;

                    case TelegramType.PacketRecOK:
                        if ((((replyTelegram.protocol == Protocol.DCP) || (replyTelegram.protocol == Protocol.DCP2)) && ((replyTelegram.DCPCmdSet == 4) || (replyTelegram.DCPCmdSet == 0x1c))) && (replyTelegram.DCPMsgType == 0))
                        {
                            _mainWin.showLocalLog("< " + WDSConverters.ToHexString(replyTelegram.data.Buf, replyTelegram.data.NumItems) + "\n");
                            switch (replyTelegram.data[0])
                            {
                                case 0x11:
                                case 0x2c:
                                    if (!_gotACKforCommand)
                                    {
                                        _mainWin.showLocalLog(" Unexpected intication, did not got ACK!\n");
                                        return;
                                    }
                                    waitForDevice();
                                    send_Ack(new Telegram.Callback(replyTeleArrived));
                                    _lastReplyPec = LastReplyPrecondition.Indication;
                                    if (_savedEvent == null)
                                        return;
                                    _savedEvent(replyTelegram);
                                    break;
                            }
                        }
                        return;

                    case TelegramType.Terminated:
                        if (_savedEvent != null)
                        {
                            _savedEvent(replyTelegram);
                        }
                        execTelegramSeries();
                        return;
                }
                if (_savedEvent != null)
                {
                    _savedEvent(replyTelegram);
                }
            }
Exemplo n.º 2
0
 private TelegramContainer createSeries(Task task, int numOfCommands, LastReplyPrecondition[] teleStopPrec, byte[][] teleData, Telegram.Callback callback, bool isGeneralCmd)
 {
     TelegramContainer container = new TelegramContainer();
     container.clear();
     for (int i = 0; i < numOfCommands; i++)
     {
         Telegram tele = new Telegram(5) {
             uniqId = GlobalServices.uniqTelegramId(),
             parentUniqId = -1,
             type = TelegramType.Command
         };
         if (_ioph is IOPH_DATA)
         {
             tele.protocol = Protocol.DCP2;
             if (isGeneralCmd)
             {
                 tele.DCPCmdSet = 0x18;
             }
             else
             {
                 tele.DCPCmdSet = 0x1c;
             }
         }
         else
         {
             tele.protocol = Protocol.DCP;
             tele.DCPCmdSet = 4;
         }
         tele.lastReplyPrecondition = teleStopPrec[i];
         tele.UserDataExt.addUserData("Task", task);
         tele.portHandler = _ioph;
         tele.mainWin = this;
         tele.clearEventHandler();
         tele.CallbackEvent += callback;
         tele.data.copy(teleData[i]);
         container.addTelegramContainerItem(new TelegramContainerItem(tele));
     }
     return container;
 }
Exemplo n.º 3
0
 public void execTelegramSeries()
 {
     waitForDevice();
     if (_mainWin._ioph.getAdtRecord().isSimuation)
     {
         while ((_teleIterator = _telegramSeries.getNextItem()) != null)
         {
             _mainWin.statusBarPanel4.Step();
             if ((_teleIterator.telegram.SenderInfo != null) && (_teleIterator.telegram.SenderInfo.Length > 0))
             {
                 _mainWin.showLocalLog(((string) _teleIterator.telegram.SenderInfo[0]) + "\n");
             }
             if (_teleIterator.telegram.type == TelegramType.ExecuteTclScript)
             {
                 _mainWin.showLocalLog("> " + _teleIterator.telegram.data.BufToStr + "\n");
             }
             else
             {
                 _mainWin.showLocalLog("> " + WDSConverters.ToHexString(_teleIterator.telegram.data.Buf, _teleIterator.telegram.data.NumItems) + "\n");
             }
         }
         _mainWin.statusBarPanel4.Reset();
     }
     else
     {
         _lastReplyPec = LastReplyPrecondition.None;
         _replyPreconditionCnt = 0;
         _gotACKforCommand = false;
         _teleIterator = _telegramSeries.getNextItem();
         if (_teleIterator != null)
         {
             _mainWin.statusBarPanel4.Step();
             _mainWin.showLocalLog("\n");
             if (_teleIterator.telegram.UserDataExt.hasStoredValue("Task"))
             {
                 _mainWin.sbDeviceStatePane.Text = _mainWin.getStatusString((AppWin_SPITool_PRO.Task) _teleIterator.telegram.UserDataExt.StoredUserData["Task"]);
             }
             if (_teleIterator.isTelegram)
             {
                 _teleIterator.telegram.copyEventHandler(out _savedEvent);
                 _teleIterator.telegram.clearEventHandler();
                 _teleIterator.telegram.CallbackEvent += new Telegram.Callback(replyTeleArrived);
                 _lastReplyPec = _teleIterator.telegram.lastReplyPrecondition;
                 _replyPreconditionCnt = _teleIterator.telegram.numOfLastReplyPackets;
                 if (_mainWin._ioph.telegramFromMainWin(_teleIterator.telegram) == 0)
                 {
                     if ((_teleIterator.telegram.SenderInfo != null) && (_teleIterator.telegram.SenderInfo.Length > 0))
                     {
                         _mainWin.showLocalLog(((string) _teleIterator.telegram.SenderInfo[0]) + "\n");
                     }
                     if (_teleIterator.telegram.type == TelegramType.ExecuteTclScript)
                     {
                         _mainWin.showLocalLog("> " + _teleIterator.telegram.data.BufToStr + "\n");
                     }
                     else
                     {
                         _mainWin.showLocalLog("> " + WDSConverters.ToHexString(_teleIterator.telegram.data.Buf, _teleIterator.telegram.data.NumItems) + "\n");
                     }
                 }
                 else
                 {
                     _mainWin.showLocalLog(">! IOPH is busy!\n");
                     AppWin_SPITool_PRO._log.Error("Error at register execution!");
                 }
             }
         }
         else
         {
             _mainWin.statusBarPanel4.Reset();
             _mainWin.sbDeviceStatePane.Text = _mainWin.getStatusString(AppWin_SPITool_PRO.Task.None);
             if (_mainWin.tsrMainToolStrip.IsContCurrentReadOn && !_currentReadDone)
             {
                 _currentReadDone = true;
                 _mainWin.tsrMainToolStrip_AmmeteringRequested(null, null);
             }
             else
             {
                 _currentReadDone = false;
             }
         }
     }
 }
Exemplo n.º 4
0
 public void execTelegramSeries()
 {
     this.waitForDevice();
     if (this._mainWin._ioph.getAdtRecord().isSimuation)
     {
         while ((this._teleIterator = this._telegramSeries.getNextItem()) != null)
         {
             this._mainWin.showLocalLog("> " + WDSConverters.ToHexString(this._teleIterator.telegram.data.Buf, this._teleIterator.telegram.data.NumItems) + "\n");
         }
     }
     else
     {
         this._teleIterator = this._telegramSeries.getNextItem();
         if (this._teleIterator != null)
         {
             this._mainWin.sbDeviceStatePane.Text = this._mainWin.getStatusString((Task)this._teleIterator.telegram.userData);
             if (this._teleIterator.isTelegram)
             {
                 this._teleIterator.telegram.copyEventHandler(out this._savedEvent);
                 this._teleIterator.telegram.clearEventHandler();
                 this._teleIterator.telegram.CallbackEvent += new Telegram.Callback(this.replyTeleArrived);
                 this._lastReplyPec = this._teleIterator.telegram.lastReplyPrecondition;
                 this._replyPreconditionCnt = this._teleIterator.telegram.numOfLastReplyPackets;
                 if (this._mainWin._ioph.telegramFromMainWin(this._teleIterator.telegram) == 0)
                 {
                     this._mainWin._deviceBusy = true;
                     this._mainWin.showLocalLog("> " + WDSConverters.ToHexString(this._teleIterator.telegram.data.Buf, this._teleIterator.telegram.data.NumItems) + "\n");
                 }
                 else
                 {
                     this._mainWin.showLocalLog(">! IOPH is busy!\n");
                     AppWin_Si4012_CP._log.Error("Error at register execution!");
                 }
             }
         }
         else
         {
             this._mainWin.showLocalLog("\n");
             this._mainWin._deviceBusy = false;
             this._mainWin.sbDeviceStatePane.Text = this._mainWin.getStatusString(AppWin_Si4012_CP.Task.None);
             if (this._mainWin.tsrMainToolStrip.IsContCurrentReadOn && !this._currentReadDone)
             {
                 this._currentReadDone = true;
                 this._mainWin.tsrMainToolStrip_AmmeteringRequested(null, null);
             }
             else
             {
                 this._currentReadDone = false;
             }
         }
     }
 }
Exemplo n.º 5
0
            private void replyTeleArrived(Telegram replyTelegram)
            {
                TelegramType type = replyTelegram.type;
                switch (type)
                {
                    case TelegramType.AckOrNackSentOK:
                        if (this._lastReplyPec == ((LastReplyPrecondition) replyTelegram.lastReplyPrecondition))
                        {
                            if (replyTelegram.numOfLastReplyPackets != -1)
                            {
                                this._replyPreconditionCnt--;
                                if (this._replyPreconditionCnt == 0)
                                {
                                    this.execTelegramSeries();
                                }
                                return;
                            }
                            this.execTelegramSeries();
                        }
                        return;

                    case TelegramType.AcknowledgeOK:
                        this._mainWin.showLocalLog("< ACK \n");
                        if (replyTelegram.lastReplyPrecondition == LastReplyPrecondition.ACK)
                        {
                            if (replyTelegram.numOfLastReplyPackets != -1)
                            {
                                this._replyPreconditionCnt--;
                                if (this._replyPreconditionCnt == 0)
                                {
                                    this.execTelegramSeries();
                                }
                                return;
                            }
                            this.execTelegramSeries();
                        }
                        return;

                    case TelegramType.AcknowledgeERROR:
                        break;

                    case TelegramType.DataAcknowledgeOK:
                        this._mainWin.showLocalLog("< " + WDSConverters.ToHexString(replyTelegram.data.Buf, replyTelegram.data.NumItems) + "\n");
                        if (this._savedEvent != null)
                        {
                            this._savedEvent(replyTelegram);
                        }
                        if (replyTelegram.lastReplyPrecondition == LastReplyPrecondition.DataACK)
                        {
                            if (replyTelegram.numOfLastReplyPackets == -1)
                            {
                                this.execTelegramSeries();
                                return;
                            }
                            this._replyPreconditionCnt--;
                            if (this._replyPreconditionCnt != 0)
                            {
                                return;
                            }
                            this.execTelegramSeries();
                        }
                        return;

                    case TelegramType.DataAcknowledgeERROR:
                        this._mainWin.showLocalLog("< NACK\n");
                        this.execTelegramSeries();
                        return;

                    case TelegramType.PacketRecOK:
                        if (((replyTelegram.protocol == Protocol.DCP) && (replyTelegram.DCPCmdSet == 4)) && (replyTelegram.DCPMsgType == 0))
                        {
                            this._mainWin.showLocalLog("< " + WDSConverters.ToHexString(replyTelegram.data.Buf, replyTelegram.data.NumItems) + "\n");
                            switch (replyTelegram.data[0])
                            {
                                case 0x29:
                                case 0x2c:
                                    this.waitForDevice();
                                    this.send_Ack(new Telegram.Callback(this.replyTeleArrived));
                                    this._lastReplyPec = LastReplyPrecondition.Indication;
                                    if (this._savedEvent != null)
                                    {
                                        this._savedEvent(replyTelegram);
                                    }
                                    return;
                            }
                        }
                        return;

                    default:
                        if (type != TelegramType.Terminated)
                        {
                            break;
                        }
                        if (this._savedEvent != null)
                        {
                            this._savedEvent(replyTelegram);
                        }
                        this.execTelegramSeries();
                        return;
                }
                if (this._savedEvent != null)
                {
                    this._savedEvent(replyTelegram);
                }
            }
Exemplo n.º 6
0
 private TelegramContainer createSeries(Task task, int numOfCommands, LastReplyPrecondition[] teleStopPrec, byte[][] teleData, Telegram.Callback callback)
 {
     TelegramContainer container = new TelegramContainer();
     container.clear();
     for (int i = 0; i < numOfCommands; i++)
     {
         Telegram tele = new Telegram(5) {
             uniqId = GlobalServices.uniqTelegramId(),
             parentUniqId = -1,
             type = TelegramType.Command,
             protocol = Protocol.DCP,
             DCPCmdSet = 4,
             lastReplyPrecondition = teleStopPrec[i],
             userData = (int) task,
             portHandler = this._ioph,
             mainWin = this
         };
         tele.clearEventHandler();
         tele.CallbackEvent += callback;
         tele.data.copy(teleData[i]);
         if (i == (numOfCommands - 1))
         {
             tele.UserDataExt.addUserData("RetVal", 0);
         }
         container.addTelegramContainerItem(new TelegramContainerItem(tele));
     }
     return container;
 }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
Arquivo: Telegram.cs Projeto: 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;
 }
Exemplo n.º 9
0
Arquivo: Telegram.cs Projeto: x893/WDS
 public void clear()
 {
     int num;
     this.replySize = num = -1;
     this.uniqId = this.parentUniqId = num;
     this.type = 0;
     this.lastReplyPrecondition = LastReplyPrecondition.Unknown;
     this.numOfLastReplyPackets = -1;
     this.protocol = Protocol.Invalid;
     this.data.NumItems = 0;
     this.replySize = -1;
     this.appFuncId = -1;
     this.userData = -1;
     this._hasHeader = false;
     this.DCPCmdSet = 0;
     this.DCPMsgType = 0;
     this.UserDataExt.clear();
 }
Exemplo n.º 10
0
 public void execTelegramSeries()
 {
     this.waitForDevice();
     if (this._ioph.getAdtRecord().isSimuation)
     {
         while ((this._teleIterator = this._telegramSeries.getNextItem()) != null)
         {
             if ((this._teleIterator.telegram.SenderInfo != null) && (this._teleIterator.telegram.SenderInfo.Length > 0))
             {
                 this.communicationLog((string) this._teleIterator.telegram.SenderInfo[0]);
             }
             if (this._teleIterator.telegram.type == TelegramType.ExecuteTclScript)
             {
                 this.communicationLog("> " + this._teleIterator.telegram.data.BufToStr);
             }
             else
             {
                 this.communicationLog("> " + WDSConverters.ToHexString(this._teleIterator.telegram.data.Buf, this._teleIterator.telegram.data.NumItems));
             }
             if (this._teleIterator.telegram.UserDataExt.hasStoredValue("Task") && (this.taskBeingProcessed != null))
             {
                 this.taskBeingProcessed(this._teleIterator.telegram.UserDataExt.StoredUserData["Task"]);
             }
             if (this.telegramFinished != null)
             {
                 this.telegramFinished(this, null);
             }
         }
         if (this.telegramSeriesFinished != null)
         {
             this.telegramSeriesFinished(this, null);
         }
     }
     else
     {
         this._teleIterator = this._telegramSeries.getNextItem();
         if (this._teleIterator != null)
         {
             if (this._isFirstTelegram)
             {
                 this._isFirstTelegram = false;
             }
             else if (this.telegramFinished != null)
             {
                 this.telegramFinished(this, null);
             }
             if (this._teleIterator.telegram.UserDataExt.hasStoredValue("Task") && (this.taskBeingProcessed != null))
             {
                 this.taskBeingProcessed(this._teleIterator.telegram.UserDataExt.StoredUserData["Task"]);
             }
             if (this._teleIterator.isTelegram)
             {
                 this._teleIterator.telegram.copyEventHandler(out this._savedEvent);
                 this._teleIterator.telegram.clearEventHandler();
                 this._teleIterator.telegram.CallbackEvent += new Telegram.Callback(this.replyTeleArrived);
                 this._lastReplyPec = this._teleIterator.telegram.lastReplyPrecondition;
                 this._replyPreconditionCnt = this._teleIterator.telegram.numOfLastReplyPackets;
                 if (this._ioph.telegramFromMainWin(this._teleIterator.telegram) == 0)
                 {
                     if ((this._teleIterator.telegram.SenderInfo != null) && (this._teleIterator.telegram.SenderInfo.Length > 0))
                     {
                         this.communicationLog((string) this._teleIterator.telegram.SenderInfo[0]);
                     }
                     if (this._teleIterator.telegram.type == TelegramType.ExecuteTclScript)
                     {
                         this.communicationLog("> " + this._teleIterator.telegram.data.BufToStr);
                     }
                     else
                     {
                         this.communicationLog("> " + WDSConverters.ToHexString(this._teleIterator.telegram.data.Buf, this._teleIterator.telegram.data.NumItems));
                     }
                 }
                 else
                 {
                     this.communicationLog(">! IOPH is busy!");
                 }
             }
         }
         else
         {
             if (this.telegramFinished != null)
             {
                 this.telegramFinished(this, null);
             }
             if (this.telegramSeriesFinished != null)
             {
                 this.telegramSeriesFinished(this, null);
             }
         }
     }
 }