Esempio n. 1
0
        public void TransformToNameProtocolTest()
        {
            EriverProtocol ep = CreateTestProtocol(Command.Name);

            byte[] testData = EriverStreamReaderWriter.Transform(ep);
            Assert.AreEqual <EriverProtocol>(ep, EriverStreamReaderWriter.Transform(testData));
        }
Esempio n. 2
0
        public void TransformFromEmptyProtocolTest()
        {
            EriverProtocol ep = new EriverProtocol();

            byte[] ans = EriverStreamReaderWriter.Transform(ep);

            Assert.AreEqual <int>(1, ans.Length);
            CollectionAssert.AreEqual(new byte[] { 0 }, ans);
        }
Esempio n. 3
0
        public void TransformFromNameProtocolTest()
        {
            Command        underTest = Command.Name;
            EriverProtocol ep        = CreateTestProtocol(underTest);

            byte[] ans = EriverStreamReaderWriter.Transform(ep);

            Assert.AreEqual <int>(CommandConvert.ToLength(underTest) + 1, ans.Length);
            CollectionAssert.AreEqual(new byte[] { (byte)underTest, 0x21 }, ans);
        }
Esempio n. 4
0
        public void TransformFromStartCalProtocolTest()
        {
            Command        underTest = Command.StartCalibration;
            EriverProtocol ep        = CreateTestProtocol(underTest);

            byte[] ans = EriverStreamReaderWriter.Transform(ep);

            Assert.AreEqual <int>(CommandConvert.ToLength(underTest) + 1, ans.Length);
            CollectionAssert.AreEqual(new byte[] { (byte)underTest,
                                                   0x40, 0x2A, 0xBD, 0x70, 0xA3, 0xD7, 0x0A, 0x3D }, ans);
        }
Esempio n. 5
0
        public void TransformFromAddPointProtocolTest()
        {
            Command        underTest = Command.AddPoint;
            EriverProtocol ep        = CreateTestProtocol(Command.AddPoint);

            byte[] ans = EriverStreamReaderWriter.Transform(ep);

            Assert.AreEqual <int>(CommandConvert.ToLength(underTest) + 1, ans.Length);
            CollectionAssert.AreEqual(new byte[] { (byte)underTest,
                                                   0x3F, 0xDB, 0x95, 0x81, 0x06, 0x24, 0xDD, 0x2F,
                                                   0x3F, 0xD4, 0x18, 0x93, 0x74, 0xBC, 0x6A, 0x7F }, ans);
        }
Esempio n. 6
0
        /// <summary>
        /// Handler of connection to the ETServer
        /// Reads data from the stream, and answers accordingly.
        /// Deals with the tracker aswell using the ITracker interface.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="tracker_type"></param>
        /// <param name="clientId"></param>
        /// <param name="stream"></param>
        /// <param name="description"></param>
        public ConnectionHandler(byte name, string tracker_type, string clientId, NetworkStream stream, string description)
        {
            this.name = name;

            logger = LogManager.GetLogger(this.GetType());
            log4net.ThreadContext.Properties["id"] = "Id: " + clientId;

            this.stream  = stream;
            readerWriter = new EriverStreamReaderWriter(stream);
            this.stop    = new ManualResetEvent(false);
            tracker      = TrackerFactory.GetTracker(tracker_type, name);
            Description  = description;
        }
Esempio n. 7
0
        public ConnectionHandler(byte name, string clientId, Stream stream, ManualResetEvent shutdown)
        {
            // TODO: Complete member initialization
            this.name = name;

            logger = LogManager.GetLogger(this.GetType());
            log4net.ThreadContext.Properties["id"] = "Id: " + clientId;

            this.stream   = stream;
            readerWriter  = new EriverStreamReaderWriter(stream);
            this.shutdown = shutdown;
            this.stop     = new ManualResetEvent(false);
            tracker       = TrackerFactory.GetTracker(name);
        }
Esempio n. 8
0
 public void Send(EriverProtocol proto)
 {
     logger.Debug("Writing packet: " + proto);
     byte[] buf = EriverStreamReaderWriter.Transform(proto);
     try
     {
         stream.Write(buf, 0, buf.Length);
     }
     catch (IOException e)
     {
         logger.Error("IOException while writing to stream. Closing handler.");
         logger.Debug(e);
         stop.Set();
     }
 }
Esempio n. 9
0
        private void Connect_Button_Click(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("Event! Connect to " + Host.Text.ToString() + ":" + Port.Text.ToString());
            if (client != null)
            {
                esrw = null;
                client.Close();
                client = null;
            }

            try
            {
                client = new TcpClient(Host.Text.ToString(), Convert.ToInt32(Port.Text.ToString()));
            }
            catch (SocketException)
            {
                MessageBox.Show("Error connecting to host. Please check that the other side is listening for requests on the port number.");
                return;
            }
            esrw = new EriverStreamReaderWriter(client.GetStream());
        }
Esempio n. 10
0
 public void SetUp()
 {
     esrw = new EriverStreamReaderWriter(new MemoryStream(255));
 }