IcCardReaderMessageBase.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Parser.BinaryParser.Attributes;
  2. using Parser.BinaryParser.MessageEntity;
  3. using Parser.BinaryParser.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace WayneChina_IcCardReader_SinoChem.MessageEntity
  10. {
  11. public class IcCardReaderMessageBase : MessageTemplateBase
  12. {
  13. [Format(1, EncodingType.BIN, -9999)]
  14. public byte Prefix0xFA { get { return 0xFA; } set { } }
  15. [Format(1, EncodingType.BIN, -9980)]
  16. public byte RawMessageSeqNumberAndSourceAddress { get; set; }
  17. /// <summary>
  18. /// Gets or sets the message seq number, range must be in 0 to 15
  19. /// </summary>
  20. public byte MessageSeqNumber
  21. {
  22. get { return (byte)(this.RawMessageSeqNumberAndSourceAddress >> 4 & 0x0F); }
  23. set
  24. {
  25. if (value > 0x0F) throw new ArgumentOutOfRangeException("message Token max value is 0x0F");
  26. //E0 = 1110 0000
  27. this.RawMessageSeqNumberAndSourceAddress = RawMessageSeqNumberAndSourceAddress.SetBit(4, 7, value);
  28. }
  29. }
  30. /// <summary>
  31. /// Gets or sets the SourceAddress, range must be in 0 to 15
  32. /// </summary>
  33. public byte SourceAddress
  34. {
  35. get { return (byte)(this.RawMessageSeqNumberAndSourceAddress & 0x0F); }
  36. set
  37. {
  38. if (value > 0x0F) throw new ArgumentOutOfRangeException("message SourceAddress max value is 0x0F");
  39. //E0 = 1110 0000
  40. this.RawMessageSeqNumberAndSourceAddress = RawMessageSeqNumberAndSourceAddress.SetBit(0, 3, value);
  41. }
  42. }
  43. [Format(2, EncodingType.BCD, -9940)]
  44. public int MessageLength { get; set; }
  45. [EnumerableFormat("MessageLength", -9920)]
  46. public List<byte> RawData { get; set; }
  47. [EnumerableFormat(2, -9900)]
  48. public List<byte> CRC { get; set; }
  49. public override string ToLogString()
  50. {
  51. return this.GetType().Name + " " + base.ToLogString() + " MessageSeqNumber: " + this.MessageSeqNumber;
  52. }
  53. }
  54. }