Exemplo n.º 1
0
        public byte[] GetTestTextData(int testGroup)
        {
            System.IO.MemoryStream ms= new System.IO.MemoryStream();
              TestValue tval;

               if (TestGroupValues.Count == 0 ||  testGroup>=TestGroupValues.Count) return null;

               ms.WriteByte(this.cmd);
               if (subCmd != 0xff)
               ms.WriteByte(subCmd);

            System.Collections.IEnumerator  ie=this.GetTestEnum(testGroup).GetEnumerator();

            while (ie.MoveNext())
            {

              //  int repeatCnt = 0;
            tval = (TestValue)ie.Current;
            for (int i = tval.cmdItem.Bytes - 1; i >= 0; i--)
                ms.WriteByte((byte)(((tval.value >> (i * 8)) & 0x00ff)));

            //ms.WriteByte((byte)tval.value);
            if (tval.SubValueCnt > 0)
            {
                    TestValue[] t = new TestValue[tval.subValues.Count];
                    for (int j = 0; j < tval.subValues.Count; j++)
                    {
                        ie.MoveNext();

                        t[j] = (TestValue)ie.Current;

                    }
                for (int k = 0; k < tval.value; k++)
                {
                    for (int j = 0; j < tval.subValues.Count; j++)
                    {
                        //TestValue t;
                        //ie.MoveNext();
                        //t = (TestValue)ie.Current;
                        for (int i = t[j].cmdItem.Bytes - 1; i >= 0; i--)
                            ms.WriteByte((byte)(((t[j].value >> (i * 8)) & 0x00ff)));
                    }

                }
            }

            //      for(int i=0;i<tval.value;i++)
            //ms.WriteByte((byte)tval

            }

               //  byte[] ret=new byte[ms.Length];
               //  System.Array.Copy(ms.GetBuffer(), ret, ms.Length);
            return ms.ToArray();
        }
Exemplo n.º 2
0
        protected override Object CreateObject(NonterminalToken token)
        {
            string name;
               int bytes, inx, value;
               CmdItem cmdItem;
               TestValue testval;
               try
               {
               switch (token.Rule.Id)
               {

                   case (int)RuleConstants.RULE_TESTGROUPEXPRESS_TESTEQ:
                       CanTest = false;
                       break;
                   case (int)RuleConstants.RULE_VERSION_VERSIONEQ_FLOAT:
                       this.version = token.Tokens[1].UserObject.ToString();
                       break;
                   case (int)RuleConstants.RULE_TESTGROUPEXPRESS_TESTEQ2:
                       CanTest = true;
                       break;
                   case (int)RuleConstants.RULE_TESTEXPRESS_ATCMD:
                       tmpTestExpress.Add(tmpTestValues);
                       tmpTestValues = new System.Collections.ArrayList(10);
                       break;
                   case (int)RuleConstants.RULE_TESTREPEATITEMS_LBRACE_RBRACE:

                       testval = (TestValue)token.Tokens[0].UserObject;
                       inx = tmpTestValues.IndexOf(testval);
                       for (int i = inx + 1; i < tmpTestValues.Count; i++)
                           testval.subValues.Add(tmpTestValues[i]);
                       for (int i = tmpTestValues.Count - 1; i > inx; i--)
                           tmpTestValues.RemoveAt(i);
                       break;
                   case (int)RuleConstants.RULE_TESTSELECTVALUE_NUMBER:

                       return token.Tokens[0].ToString();
                   case (int)RuleConstants.RULE_TESTSELECTVALUES:
                       return token.Tokens[0].UserObject;

                   case (int)RuleConstants.RULE_TESTSELECTITEM_IDENTIFIER_LPARAN_RPARAN:

                       name = token.Tokens[0].UserObject.ToString();
                       value = Convert.ToInt32(token.Tokens[2].UserObject.ToString());
                       tmpTestValues.Add(testval = new TestValue(name, value));
                       return testval;

                   case (int)RuleConstants.RULE_TESTITEM2:

                       return token.Tokens[0].UserObject;

                   case (int)RuleConstants.RULE_RANGEITEM_IDENTIFIER_LPARAN_RPARAN:
                       NonterminalToken ntok;
                       name = token.Tokens[getTokenInx(token, "Identifier")].UserObject.ToString();
                       ntok = findToken(token, "Bytes");
                       bytes = Convert.ToInt32(ntok.Tokens[0].UserObject.ToString());
                       ntok = findToken(token, "LValue");
                       int lval = Convert.ToInt32(ntok.Tokens[0].UserObject.ToString());
                       ntok = findToken(token, "HValue");
                       int hval = Convert.ToInt32(ntok.Tokens[0].UserObject.ToString());
                       TmpCmdItems.Add(cmdItem = new CmdItem(name, bytes, lval, hval));
                       return cmdItem;

                   case (int)RuleConstants.RULE_SELECTITEM_IDENTIFIER_LPARAN_RPARAN:
                       SelectValue[] selectvalues;
                       name = token.Tokens[0].UserObject.ToString();
                       bytes = Convert.ToInt32(findToken(token, "Bytes").Tokens[0].UserObject.ToString());
                       selectvalues = new SelectValue[TmpSelectValues.Count];
                       for (int i = 0; i < TmpSelectValues.Count; i++)
                       {
                           selectvalues[i] = (SelectValue)TmpSelectValues[i];
                       }
                       TmpCmdItems.Add(cmdItem = new CmdItem(name, bytes, selectvalues));
                       TmpSelectValues.Clear();
                       return cmdItem;

                   case (int)RuleConstants.RULE_SELECTVALUE_NUMBER:
                       SelectValue sVal = new SelectValue();
                       sVal.value = Convert.ToInt32(token.Tokens[0].UserObject.ToString());
                       sVal.valueName = findToken(token, "ValueDescription").Tokens[0].UserObject.ToString();
                       TmpSelectValues.Add(sVal);

                       break;
                   case (int)RuleConstants.RULE_EXPRESSITEM:
                       return token.Tokens[0].UserObject;

                   case (int)RuleConstants.RULE_REPEATEXPRESS_LBRACE_RBRACE:
                       inx = TmpCmdItems.IndexOf(token.Tokens[0].UserObject);
                       for (int i = inx + 1; i < TmpCmdItems.Count; i++)
                           ((CmdItem)TmpCmdItems[inx]).AddSubItems((CmdItem)TmpCmdItems[i]);//reduce repeat item
                       for (int i = TmpCmdItems.Count - 1; i > inx; i--)
                           TmpCmdItems.RemoveAt(i);
                       return TmpCmdItems[inx];
                   case (int)RuleConstants.RULE_SENDEXPRESS_SENDEQ:  //send express
                       tmpSendExpress.Clear();
                       break;
                   case (int)RuleConstants.RULE_SENDEXPRESS_SENDEQ2: //sendexpress
                       tmpSendExpress = (System.Collections.ArrayList)TmpCmdItems.Clone();
                       TmpCmdItems.Clear();
                       break;
                   case (int)RuleConstants.RULE_RETURNEXPRESS_RETURNEQ:
                       tmpReturnExpress.Clear();
                       break;
                   case (int)RuleConstants.RULE_RETURNEXPRESS_RETURNEQ2:
                       tmpReturnExpress = (System.Collections.ArrayList)TmpCmdItems.Clone();
                       TmpCmdItems.Clear();
                       break;
                   case (int)RuleConstants.RULE_DEVICETYPE_DEVICETYPEEQ_IDENTIFIER:
                       this.DeviceType = token.Tokens[1].UserObject.ToString();
                       break;
                   case (int)RuleConstants.RULE_IP_IPEQ_IP:
                       ip = token.Tokens[1].UserObject.ToString();
                       break;
                   case (int)RuleConstants.RULE_PORT_PORTEQ_NUMBER:
                       port = int.Parse(token.Tokens[1].UserObject.ToString());
                       break;
                   case (int)RuleConstants.RULE_DEVICEID_DEVICEIDEQ_DEVICEID:
                       deviceId = Convert.ToInt32(token.Tokens[1].ToString(), 16);
                       break;
                   case (int)RuleConstants.RULE_CMD_CMDEQ_CMD:
                       //Cmd cmd;
                       //if(token.Tokens[2].UserObject==null)
                       //  cmd=new Cmd(Convert.ToByte(token.Tokens[1].UserObject.ToString(),16));
                       //else
                       //cmd=new Cmd(Convert.ToByte(token.Tokens[1].UserObject.ToString(),16),
                       //    Convert.ToByte(token.Tokens[2].UserObject.ToString(),16));
                       //  return cmd;

                       break;
                   case (int)RuleConstants.RULE_COMMAND:

                       //CmdClass cls;
                       //CmdType type;
                       //string desc;
                       //string func_name;
                       //byte cmdcode;
                       Cmd cmd = new Cmd(this);

                       // inx  = getTokenInx(token, "Description");

                       for (int i = 0; i < token.Tokens.Length; i++)
                       {
                           NonterminalToken ttok;
                           ttok = (NonterminalToken)token.Tokens[i];
                           if (token.Rule.Rhs[i].Name == "Description")
                           {
                               cmd.description = ((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString().Trim(new char[] { '\"' });
                           }
                           else if (token.Rule.Rhs[i].Name == "FuncName")
                           {
                               cmd.cmdName = ((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString().Trim(new char[] { '\"' });
                           }
                           else if (token.Rule.Rhs[i].Name == "CmdClass")
                           {
                               switch (((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString()[0])
                               {
                                   case 'A':
                                       cmd.cmdClass = CmdClass.A;
                                       break;
                                   case 'B':
                                       cmd.cmdClass = CmdClass.B;
                                       break;
                                   case 'C':
                                       cmd.cmdClass = CmdClass.C;
                                       break;
                                   case 'D':
                                       cmd.cmdClass = CmdClass.D;
                                       break;
                               }
                           }
                           else if (token.Rule.Rhs[i].Name == "CmdType")
                           {
                               if (((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString() == "Set")
                                   cmd.cmdType = CmdType.CmdSet;
                               else if (((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString() == "Query")
                                   cmd.cmdType = CmdType.CmdQuery;
                               else if (((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString() == "Report")
                                   cmd.cmdType = CmdType.CmdReport;
                               else
                                   cmd.cmdType = CmdType.CmdUnkonwn;
                           }
                           else if (token.Rule.Rhs[i].Name == "Cmd")
                           {
                               cmd.cmd = Convert.ToByte(ttok.Tokens[1].UserObject.ToString(), 16);  //cmd
                               if (((NonterminalToken)ttok.Tokens[2]).Tokens.Length > 0)
                                   cmd.subCmd = Convert.ToByte(((NonterminalToken)ttok.Tokens[2]).Tokens[0].UserObject.ToString(), 16); //subCmd
                           }

                       } //for
                       cmd.SendCmdItems = (System.Collections.ArrayList)tmpSendExpress.Clone();
                       cmd.ReturnCmdItems = (System.Collections.ArrayList)tmpReturnExpress.Clone();
                       cmd.TestGroupValues = tmpTestExpress;
                       cmd.CanTest = CanTest;
                       tmpReturnExpress.Clear();
                       tmpSendExpress.Clear();
                       tmpTestValues.Clear();
                       tmpTestExpress = new System.Collections.ArrayList(5);
                       //try
                       //{
                       if (cmd.cmdType != CmdType.CmdReport)
                           cmd.CheckTestValue();
                       cmd.GenerateCmdDataSet();

                       //}
                       //catch (Exception ex)
                       //{
                       //    Console.WriteLine(ex.StackTrace);
                       //}
                       this.AddCmd(cmd);
                       break;

               }
               }
               catch (Exception ex)
               {
               Console.WriteLine(ex.StackTrace);
               throw ex;
               }

               return null;
        }
Exemplo n.º 3
0
        public void FillDsByTestValues(DataSet ds,int inx)
        {
            if (TestGroupValues.Count == 0) throw new Exception("無測試資料");
               System.Collections.IEnumerator ie = this.GetTestEnum(inx).GetEnumerator();
               TestValue tval;
               while (ie.MoveNext())
               {
               tval = (TestValue)ie.Current;
               if (ds.Tables["tblMain"].Columns[tval.itemName].ReadOnly) continue;
               //for (int i = tval.cmdItem.Bytes - 1; i >= 0; i--)
               //    ms.WriteByte((byte)(((tval.value >> (i * 8)) ;& 0x00ff)));
               ds.Tables["tblMain"].Rows[0][tval.itemName] = tval.value;

               if (tval.SubValueCnt > 0)
               {

                   TestValue[] t = new TestValue[tval.subValues.Count];
                   for (int j = 0; j < tval.subValues.Count; j++)
                   {
                       ie.MoveNext();

                       t[j] = (TestValue)ie.Current;

                   }
                   ds.Tables["tbl" + tval.itemName].Clear();
                   for (int k = 0; k < tval.value; k++)
                   {
                       System.Data.DataRow r = ds.Tables["tbl" + tval.itemName].NewRow();

                       for (int j = 0; j < tval.subValues.Count; j++)
                       {
                           r[t[j].itemName] = t[j].value;

                           //for (int i = t.cmdItem.Bytes - 1; i >= 0; i--)
                           //    ms.WriteByte((byte)(((t.value >> (i * 8)) & 0x00ff)));
                       }

                       ds.Tables["tbl" + tval.itemName].Rows.Add(r);

                   }
               }

               }
        }