Example #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;
                }
            }
        }
Example #2
0
 public override ATValue FromByteArray(byte[] value)
 {
     var atValue = new ATStringValue(Encoding.UTF8.GetString(value, 0, value.Length));
     return atValue;
 }
 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"));
 }
 public void TestATStringValue()
 {
     var value = new ATStringValue();
     Assert.That(value, Is.AssignableTo<ATValue>());
     Assert.That(value, Is.TypeOf<ATStringValue>());
 }
 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 }));
 }
Example #6
0
        public override ATValue FromByteArray(byte[] value)
        {
            var atValue = new ATStringValue(Encoding.UTF8.GetString(value, 0, value.Length));

            return(atValue);
        }