예제 #1
0
        public override void Parse()
        {
            FrameId       = (byte)parser.ReadByte();
            Command       = parser.ReadATCommand();
            CommandStatus = (byte)parser.ReadByte();

            if (Command == AT.NodeDiscover)
            {
                ParseNetworkDiscovery();
            }

            var type = ((ATAttribute)Command.GetAttr()).ValueType;

            if ((type != ATValueType.None) && parser.HasMoreData())
            {
                switch (type)
                {
                case ATValueType.Number:
                    var vData = parser.ReadData();
                    Value = new ATLongValue().FromByteArray(vData);
                    break;

                case ATValueType.HexString:
                    var hexData = parser.ReadData();
                    Value = new ATStringValue(ByteUtils.ToBase16(hexData));
                    break;

                case ATValueType.String:
                    var str = parser.ReadData();
                    Value = new ATStringValue(Encoding.UTF8.GetString(str));
                    break;
                }
            }
        }
예제 #2
0
 public override ATValue FromByteArray(byte[] value)
 {
     var atValue = new ATStringValue(Encoding.UTF8.GetString(value, 0, value.Length));
     return atValue;
 }
예제 #3
0
 public void TestATStringValueFromByteArray()
 {
     var data = new byte[] { 0x4D, 0x65, 0x54, 0x65, 0x73, 0x74, 0x69, 0x6E, 0x67, 0x31, 0x32, 0x33 };
     var value = new ATStringValue().FromByteArray(data);
     Assert.That(value, Is.TypeOf<ATStringValue>());
     Assert.That(((ATStringValue)value).Value, Is.EqualTo("MeTesting123"));
 }
예제 #4
0
 public void TestATStringValue()
 {
     var value = new ATStringValue();
     Assert.That(value, Is.AssignableTo<ATValue>());
     Assert.That(value, Is.TypeOf<ATStringValue>());
 }
예제 #5
0
 public void TestATStringValueToByteArray()
 {
     var value = new ATStringValue("MeTesting123");
     Assert.That(value.ToByteArray(), Is.TypeOf<byte[]>());
     Assert.That(value.ToByteArray(), Is.EqualTo(new byte[] { 0x4D, 0x65, 0x54, 0x65, 0x73, 0x74, 0x69, 0x6E, 0x67, 0x31, 0x32, 0x33 }));
 }
예제 #6
0
파일: ATValue.cs 프로젝트: gagmax981/XBee
        public override ATValue FromByteArray(byte[] value)
        {
            var atValue = new ATStringValue(Encoding.UTF8.GetString(value, 0, value.Length));

            return(atValue);
        }