DMGenericBluetoothTag.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Linq;
  2. namespace InABox.DigitalMatter
  3. {
  4. public class DMGenericBluetoothTag : DMBluetoothTag
  5. {
  6. public byte[] Data { get; set; }
  7. public ushort TagType { get; private set; }
  8. public byte[] MacAddress { get; private set; }
  9. public byte PayloadLength { get; private set; }
  10. public byte[] Payload { get; set; }
  11. protected override void DoDecode()
  12. {
  13. TagType = TakeUInt16();
  14. MacAddress = TakeBytes(6);
  15. PayloadLength = TakeByte();
  16. Payload = TakeBytes(DataLength);
  17. }
  18. protected override void DoEncode()
  19. {
  20. AddUInt16(TagType);
  21. AddBytes(MacAddress);
  22. AddByte(PayloadLength);
  23. AddBytes(Payload);
  24. }
  25. public override string ID()
  26. {
  27. return string.Join(":", MacAddress.Reverse().Select(x => x.ToString("X2")));
  28. //BitConverter.ToString(MacAddress);
  29. }
  30. public override string Type()
  31. {
  32. return string.Format("Type {0}", TagType);
  33. }
  34. }
  35. }