ReadFuelDataResponse.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Edge.Core.Parser.BinaryParser.Util;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace LanTian_Pump_664_Or_886.MessageEntity.Incoming
  9. {
  10. public class ReadFuelDataResponse : MessageBase
  11. {
  12. /*only used for unit test purpose*/
  13. public void SetAmountAndVolume(int amount, int volume)
  14. {
  15. base.BodyAndXRL = volume.GetBCDBytes(3).Concat(amount.GetBCDBytes(3))
  16. .Concat(new byte[] { 0x00, 0x00 }).ToList();
  17. }
  18. /// <summary>
  19. /// Without decimal points
  20. /// </summary>
  21. public int Volume
  22. {
  23. get
  24. {
  25. if (base.BodyAndXRL.Count - 2 == 6)
  26. {
  27. /*Model 664*/
  28. return base.BodyAndXRL.Take(3).GetBCD();
  29. }
  30. else if (base.BodyAndXRL.Count - 2 == 8)
  31. {
  32. /*Model 886*/
  33. return base.BodyAndXRL.Take(4).GetBCD();
  34. }
  35. throw new InvalidDataException("data body length should either 6 or 8, but now is: " + (base.BodyAndXRL.Count - 1));
  36. }
  37. }
  38. /// <summary>
  39. /// Without decimal points
  40. /// </summary>
  41. public int Amount
  42. {
  43. get
  44. {
  45. if (base.BodyAndXRL.Count - 2 == 6)
  46. {
  47. /*Model 664*/
  48. return base.BodyAndXRL.Skip(3).Take(3).GetBCD();
  49. }
  50. else if (base.BodyAndXRL.Count - 2 == 8)
  51. {
  52. /*Model 886*/
  53. return base.BodyAndXRL.Skip(4).Take(4).GetBCD();
  54. }
  55. throw new InvalidDataException("data body length should either 6 or 8, but now is: " + (base.BodyAndXRL.Count - 1));
  56. }
  57. }
  58. }
  59. }