ClientData.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using OCPPServer.Protocol;
  2. using Packet.Cmd;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OCPPServer
  9. {
  10. public class ClientData
  11. {
  12. public byte[] _buffer = new byte[1024];
  13. public List<byte> bufferList = new List<byte>();
  14. public OCPPSession ClientSocket;
  15. public CmdHelper CmdHelper;
  16. public bool IsCheckIn { get; set; }
  17. public DateTime LastAccessDatetime { get; set; }
  18. /// <summary>
  19. /// 每個client有他自己的指令序號 2 byte
  20. /// </summary>
  21. private ushort _cmdSerNum = 0;
  22. /// <summary>
  23. /// 傳送的封包序號 1 byte
  24. /// </summary>
  25. private byte _serNum = 0;
  26. public string MachineId { get; set; }
  27. public Guid CustomerId { get; set; }
  28. public string CustomerName { get; set; }
  29. /// <summary>
  30. /// 客戶自訂的樁id
  31. /// </summary>
  32. public string MachineCustomId
  33. {
  34. get; set;
  35. }
  36. /// <summary>
  37. /// Accepted:0, Pending:1, Rejected:2
  38. /// </summary>
  39. public bool RegistrationStatus { get; set; }
  40. /// <summary>
  41. /// 0: 会员、1: 卡号、2:不识别
  42. /// </summary>
  43. public byte StartWith { get; set; }
  44. /// <summary>
  45. /// 充電/預約卡號、 36 bytes assic碼、不夠長度補'\0'
  46. /// </summary>
  47. public string ReservationCardNum { get; set; }
  48. /// <summary>
  49. /// Remote充電
  50. /// </summary>
  51. public bool RemoteCharging { get; set; }
  52. public ClientData()
  53. {
  54. MachineCustomId = Guid.NewGuid().ToString();
  55. IsCheckIn = false;
  56. RegistrationStatus = false;
  57. StartWith = 2; /// 0: 会员、1: 卡号、2:不识别
  58. ReservationCardNum = "";
  59. RemoteCharging = false; /// Remote充電
  60. LastAccessDatetime = DateTime.Now;
  61. }
  62. public ClientData(OCPPSession clientSocket)
  63. {
  64. this.ClientSocket = clientSocket;
  65. MachineCustomId = Guid.NewGuid().ToString();
  66. RemoteCharging = false; /// Remote充電
  67. LastAccessDatetime = DateTime.Now;
  68. }
  69. /// <summary>
  70. /// 取得指令序號 0-65535
  71. /// </summary>
  72. /// <returns></returns>
  73. public ushort GetCmdSerNum()
  74. {
  75. if (_cmdSerNum == ushort.MaxValue)
  76. _cmdSerNum = 0;
  77. return ++_cmdSerNum;
  78. }
  79. /// <summary>
  80. /// 取得封包序號 1-255
  81. /// </summary>
  82. /// <returns></returns>
  83. public byte GetSerNum()
  84. {
  85. if (_serNum == byte.MaxValue)
  86. {
  87. _serNum = 0;
  88. }
  89. return ++_serNum;
  90. }
  91. public bool CheckClient()
  92. {
  93. return false;
  94. }
  95. }
  96. }