Пример #1
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            outputBox.Clear();
            SimCore core   = SimCore.GetSimCore(codeBox.Text);
            var     result = core.Run();

            if (result != null)
            {
                byte[][] bytes = core.GetBytes();
                outputBox.Text += "Code: ";
                for (int i = 0; i < bytes.Length; i++)
                {
                    for (int j = 0; j < bytes[i].Length; j++)
                    {
                        outputBox.Text += (bytes[i][j].ToString("x2") + " ");
                    }
                }
                outputBox.Text += "\n";

                if ((int)ptr != -1)
                {
                    outputBox.Text += "Sending ...\n";

                    new Thread(new ThreadStart(() =>
                    {
                        Report report; int index = 0;
                        List <byte> buf          = new List <byte>();
                        while (index < bytes.Length)
                        {
                            if (buf.Count + bytes[index].Length < BUF_SIZE)
                            {
                                buf.AddRange(bytes[index]);
                                index += 1;
                                if (index >= bytes.Length)
                                {
                                    report = new Report(0x55, buf.ToArray());
                                    hid.Write(report);
                                    buf.Clear();
                                    break;
                                }
                            }
                            else
                            {
                                report = new Report(0x55, buf.ToArray());
                                hid.Write(report);
                                Thread.Sleep(500);
                                buf.Clear();
                            }
                        }
                    })).Start();
                }
            }
        }
Пример #2
0
        public void RunTest()
        {
            const int RUNS   = 10;
            int       _numIt = RUNS;
            var       _rnd   = new Random();
            int       _exec  = 0;
            SimCore   target = SimCore_Accessor.Instance; // TODO: Initialize to an appropriate value

            for (int i = 0; i < _numIt; i++)
            {
                Event _event = new Event("test", _rnd.NextDouble() * 1000d); // TODO: Initialize to an appropriate value
                _event.OnEventExecutionPreEdges += (o, e) =>
                {
                    _exec++;
                };
                //target.ScheduleEvent(_event);
                _event.Schedule();
            }

            // Test edges
            int _numEvtFrom = RUNS;
            int _numEvtTo   = RUNS;

            Event _eventTo   = new Event("testWithEdge");                            // TODO: Initialize to an appropriate value
            Event _eventFrom = new Event("testWithEdge", _rnd.NextDouble() * 1000d); // TODO: Initialize to an appropriate value
            Edge  _edge      = new Edge(_eventFrom, _eventTo);

            _edge.Distribution = new GenerateExponential();
            _eventFrom.OnEventExecutionPostEdges += (o, e) =>
            {
                _numEvtFrom++;
            };

            _eventTo.OnEventExecutionPostEdges += (o, e) =>
            {
                _numEvtTo++;
            };
            //target.ScheduleEvent(_eventFrom);
            _eventFrom.Schedule();

            target.Run();
            Assert.IsTrue(_exec == _numIt);
            Assert.IsTrue(_numEvtFrom == _numEvtTo);

            // Test self edges
            int _numSelf = 0;

            Event _eventFromTo = new Event("testWithEdge", 0); // TODO: Initialize to an appropriate value

            Edge _edgeSelf = new Edge(_eventFromTo, _eventFromTo);

            _edge.Distribution = new GenerateNormal(20, 0.1);
            _eventFromTo.OnEventExecutionPreEdges += (o, e) =>
            {
                _numSelf++;
                if (_numSelf > RUNS)
                {
                    ((Event)o).Edges.Clear();
                }
            };
            //target.ScheduleEvent(_eventFromTo);
            _eventFromTo.Schedule();
            target.Run();
            Assert.IsTrue(_numSelf == RUNS + 1);
        }