DMGenericBluetoothTag.cs 1.2 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(IDMReadBuffer buffer)
  12. {
  13. TagType = buffer.TakeUInt16();
  14. MacAddress = buffer.TakeBytes(6);
  15. PayloadLength = buffer.TakeByte();
  16. Payload = buffer.TakeBytes(DataLength);
  17. }
  18. protected override void DoEncode(IDMWriteBuffer buffer)
  19. {
  20. buffer.AddUInt16(TagType);
  21. buffer.AddBytes(MacAddress);
  22. buffer.AddByte(PayloadLength);
  23. buffer.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. }