예제 #1
0
 private void SendConfigButton_Click(object sender, EventArgs e)
 {
     foreach (ProtocolMessage msg in TemplateProvider.GetConfiguration(0x00, embeddedConfig, 0x01))
     {
         connector.SendMessage(MessageCodec.EncodeMessage(msg));
     }
 }
예제 #2
0
        public void DecodeMessage_MultipleEscapeCharactersEndingIn_f_x5()
        {
            byte    controllerID = 0x01;
            byte    msgID        = 0x90;
            Command cmd          = Command.DebugString;

            byte[] commandData = Encoding.UTF8.GetBytes("fffff");
            byte[] expectedMsg = new byte[] { 0x00, controllerID, msgID, (byte)cmd,
                                              0x66, 0x00, 0x66, 0x00, 0x66, 0x00, 0x66, 0x00, 0x66, 0x00,
                                              0x00, 0x00 };
            byte[] expectedMsgNotEscaped = new byte[] { 0x00, controllerID, msgID, (byte)cmd,
                                                        0x66, 0x66, 0x66, 0x66, 0x66,
                                                        0x00, 0x00 };
            expectedMsg[expectedMsg.Length - 2] = MessageCodec.CalculateCRC(expectedMsgNotEscaped);
            expectedMsg[expectedMsg.Length - 1] = ETX;
            expectedMsg[0] = STX;

            byte[] msg = MessageCodec.EncodeMessage(new ProtocolMessage(controllerID, msgID, cmd, commandData));
            MessageCodec.DecodeMessages(msg, out List <ProtocolMessage> msgs, out byte[] outputRemainder);
            ProtocolMessage myMessage = msgs.First();

            Assert.AreEqual(expectedMsg.Length, msg.Length);
            CollectionAssert.AreEqual(expectedMsg, msg);
            CollectionAssert.AreEqual(commandData, myMessage.CommandData);
        }
        public override void WriteConsole(CpuNode cpuNode, string message)
        {
            DebugStringMessage msg = new DebugStringMessage()
            {
                Message = message
            };

            // TODO add the msgID
            this.SendMessage(MessageCodec.EncodeMessage(msg.ToProtocolMessage(cpuNode.Id, 0x01)));
        }
예제 #4
0
        private void SendSine()
        {
            sendSine = true;
            long currentTime = stopwatch.ElapsedMilliseconds;

            while (stopwatch.ElapsedMilliseconds < currentTime + 600000 && sendSine)
            {
                double value = (((double)stopwatch.ElapsedMilliseconds / 100) % 6.28 - 3.14);
                connector.SendMessage(MessageCodec.EncodeMessage(TemplateProvider.GetChannelDataMessage((int)(100 * Math.Sin(value) + 128), stopwatch.ElapsedMilliseconds)));
                Thread.Sleep(1);
            }
        }
예제 #5
0
        public void EncodeMessage_CommandDataEscapeCharactersForSTXETX()
        {
            ProtocolMessage msg = new ProtocolMessage(STX, ETX, Command.ConfigChannel);

            byte[] output = MessageCodec.EncodeMessage(msg);
            byte   crc    = output[output.Length - 2];

            Assert.AreEqual(8, output.Length);
            Assert.AreEqual(ESC, output[1]);
            Assert.AreEqual(STX, (byte)(ESC ^ output[2]));
            Assert.AreEqual(ESC, output[3]);
            Assert.AreEqual(ETX, (byte)(ESC ^ output[4]));
        }
        public override void QueryValue(CpuNode cpuNode, Register register)
        {
            Version protocolVersion  = cpuNode.ProtocolVersion;
            byte    control          = MessageCodec.GetControlByte(protocolVersion, register.ReadWrite, register.Source, register.DerefDepth);
            QueryRegisterMessage msg = new QueryRegisterMessage()
            {
                Offset  = register.Offset,
                Control = control,
            };

            // TODO add the msgID
            this.SendMessage(MessageCodec.EncodeMessage(msg.ToProtocolMessage(cpuNode.Id, 0x01)));
        }
예제 #7
0
        public void DecodeMessage_DecodeEncodedMessageDataEscaped()
        {
            ProtocolMessage msg = new ProtocolMessage(STX, 0x02, Command.ConfigChannel, new byte[] { ESC, STX, ETX });

            byte[] encodedMsg = MessageCodec.EncodeMessage(msg);
            MessageCodec.DecodeMessages(encodedMsg, out List <ProtocolMessage> msgs, out byte[] remainder);

            Assert.IsTrue(msgs.Count == 1);
            Assert.IsTrue(remainder.Length == 0);
            Assert.AreEqual(msg.ControllerID, msgs.First().ControllerID);
            Assert.AreEqual(msg.MsgID, msgs.First().MsgID);
            Assert.AreEqual(msg.Command, msgs.First().Command);
            CollectionAssert.AreEqual(msg.CommandData, msgs.First().CommandData);
        }
예제 #8
0
        public void EncodeMessage_NoCommandDataValidFalse_ByteArray()
        {
            ProtocolMessage msg = new ProtocolMessage(0x01, 0x84, Command.QueryRegister);

            byte[] output = MessageCodec.EncodeMessage(msg);
            byte   crc    = output[output.Length - 2];

            Assert.AreEqual(output[0], STX);
            Assert.AreEqual(output[1], msg.ControllerID);
            Assert.AreEqual(output[2], msg.MsgID);
            Assert.AreEqual(output[3], (byte)msg.Command);
            Assert.AreEqual(output[output.Length - 1], ETX);
            Assert.IsTrue(string.IsNullOrEmpty(MessageCodec.ValidateMessageBytes(output)));

            output[0] = 0x00;
            output[output.Length - 2] = 0x00;
            output[output.Length - 1] = 0x00;
            Assert.AreEqual(crc, MessageCodec.CalculateCRC(output));
        }
예제 #9
0
        public void EncodeMessage_EncodeDecodedMessage_NormalData()
        {
            byte controllerID = 0x01;
            byte msgID        = 0x34;
            byte cmd          = (byte)Command.GetVersion;

            byte[]      commandData = new byte[] { 0x49, 0x05, 0x67, 0x96, 0x00 };
            byte[]      inputData   = new byte[] { 0x00, controllerID, msgID, cmd, 0x00, 0x00 };
            List <byte> dataList    = inputData.ToList();

            dataList.InsertRange(4, commandData);
            inputData = dataList.ToArray();
            inputData[inputData.Length - 2] = MessageCodec.CalculateCRC(inputData);
            inputData[0] = STX;
            inputData[inputData.Length - 1] = ETX;

            MessageCodec.DecodeMessages(inputData, out List <ProtocolMessage> msgs, out byte[] remainder);
            byte[] msg = MessageCodec.EncodeMessage(msgs.First());

            Assert.IsTrue(msgs.Count == 1);
            Assert.IsTrue(remainder.Length == 0);
            CollectionAssert.AreEqual(inputData, msg);
        }
예제 #10
0
 private void EmbeddedTerminal1_NewMessage(object sender, string e)
 {
     dp.Connector.SendMessage(MessageCodec.EncodeMessage(TemplateProvider.GetDebugStringMessage(e)));
 }
예제 #11
0
 private void SendInfoButton_Click(object sender, EventArgs e)
 {
     connector.SendMessage(MessageCodec.EncodeMessage(TemplateProvider.GetInfoMessage(0x00, 0x01)));
 }
예제 #12
0
 private void SendVersionButton_Click(object sender, EventArgs e)
 {
     connector.SendMessage(MessageCodec.EncodeMessage(TemplateProvider.GetVersionMessage(0x00, embeddedConfig, 0x01)));
 }
 public override void SearchForNodes()
 {
     // ControllerID 0xFF means broadcast
     this.SendMessage(MessageCodec.EncodeMessage(new ProtocolMessage(0xFF, 0x00, Command.GetVersion)));
 }
 public override void ResetTime(CpuNode cpuNode)
 {
     // TODO Add correct message id
     this.SendMessage(MessageCodec.EncodeMessage(new ProtocolMessage(cpuNode.Id, 0x02, Command.ResetTime)));
 }
 private void SendMessage(ProtocolMessage msg)
 {
     SendMessage(MessageCodec.EncodeMessage(msg));
 }