IAutoTankGaugeController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using Wayne.FDCPOSLibrary;
  6. namespace Edge.Core.IndustryStandardInterface.ATG
  7. {
  8. /// <summary>
  9. /// Aka ATG.
  10. /// A Tank Level Gauge connects to one or more (maximum 31) Tank Probes.
  11. /// A Tank Probe is the item of forecourt equipment which is capable of
  12. /// measuring the level of product in a tank and hence volume can be calculated.
  13. /// Each Tank Probe (TP) represents a tank. The unique identifier is the Unit Number.
  14. /// There are real tank probes and virtual tank probes. A virtual tank probe describes a tank without a physical probe installed. Parent device of a TP device is a TLG.
  15. /// </summary>
  16. public interface IAutoTankGaugeController
  17. {
  18. /// <summary>
  19. /// Fired once ATG connection changed.
  20. /// <see cref="Tanks"/> may change.
  21. /// </summary>
  22. event EventHandler<AtgStateChangeEventArg> OnStateChange;
  23. event EventHandler<AtgAlarmEventArg> OnAlarm;
  24. /// <summary>
  25. /// Gets the name of this implementation of ATG, most used for descriptive purpose.
  26. /// </summary>
  27. string MetaConfigName { get; }
  28. /// <summary>
  29. /// Fc internal asigned id for identify this device.
  30. /// </summary>
  31. int DeviceId { get; }
  32. /// <summary>
  33. /// Gets the Tank readings of this implementation of ATG
  34. /// </summary>
  35. IEnumerable<Tank> Tanks { get; }
  36. /// <summary>
  37. /// Gets the state of the controller.
  38. /// </summary>
  39. AtgState State { get; }
  40. /// <summary>
  41. /// Read one reading for a tank.
  42. /// </summary>
  43. /// <param name="tankNumber"></param>
  44. /// <returns></returns>
  45. Task<TankReading> GetTankReadingAsync(int tankNumber);
  46. /// <summary>
  47. /// Read readings for all tanks.
  48. /// </summary>
  49. /// <returns>readings for all tanks</returns>
  50. Task<IEnumerable<TankReading>> GetTanksReadingAsync();
  51. /// <summary>
  52. /// read tank delivery info.
  53. /// </summary>
  54. /// <param name="tankNumber"></param>
  55. /// <param name="pageRowCount"></param>
  56. /// <param name="pageIndex"></param>
  57. /// <param name="filterTimestamp">only the records have the timestamp more recent will returned.</param>
  58. /// <returns></returns>
  59. Task<IEnumerable<Delivery>> GetTankDeliveryAsync(int tankNumber, int pageRowCount = 10, int pageIndex = 0, DateTime? filterTimestamp = null);
  60. /// <summary>
  61. /// read tank Inventory info.
  62. /// </summary>
  63. /// <param name="tankNumber"></param>
  64. /// <param name="pageRowCount"></param>
  65. /// <param name="pageIndex"></param>
  66. /// <param name="filterTimestamp">only the records have the timestamp more recent will returned.</param>
  67. /// <returns></returns>
  68. Task<IEnumerable<Inventory>> GetTankInventoryAsync(int tankNumber, int pageRowCount = 10, int pageIndex = 0, DateTime? filterTimestamp = null);
  69. /// <summary>
  70. /// read tank Alarm history info.
  71. /// </summary>
  72. /// <param name="tankNumber"></param>
  73. /// <param name="pageRowCount"></param>
  74. /// <param name="pageIndex"></param>
  75. /// <param name="filterTimestamp"></param>
  76. /// <returns></returns>
  77. Task<IEnumerable<Alarm>> GetTankAlarmAsync(int tankNumber, int pageRowCount = 10, int pageIndex = 0, DateTime? filterTimestamp = null);
  78. /// <summary>
  79. /// Gets the console's SystemUnit setting value.
  80. ///
  81. /// Length
  82. /// Metric US or Imperial
  83. /// 1 millimeter [mm] = 0.03937 inches [in]
  84. /// 1 centimeter [cm] = 0.3937 inches [in]
  85. /// 1 meter [m] = 1.0936 yard [yd]
  86. /// 1 kilometer [km] = 0.6214 mile
  87. ///
  88. /// 1 yard [yd] = 3 ft
  89. /// 1 mile = 1760 yd
  90. /// 2.54 cm = 1 inch [in]
  91. /// 0.3048 m = 1 foot [ft] = 12 in
  92. ///
  93. /// Volume/Capacity
  94. /// 1 cu cm [cm3] 0.0610 in3
  95. /// 1 cu decimeter [dm3] = 1,000 cm3 0.0353 ft3
  96. /// 1 cu meter [m3] 1,000 dm3 1.3080 yd3
  97. /// 1 liter [l] = 1 dm3 2.113 fluid pt = 1.7598 pt
  98. /// </summary>
  99. SystemUnit SystemUnit { get; }
  100. }
  101. public class Alarm
  102. {
  103. public Alarm() { }
  104. public Alarm(AlarmPriority priority, AlarmType type)
  105. {
  106. this.Priority = priority;
  107. this.Type = type;
  108. }
  109. public int Id { get; set; }
  110. public AlarmPriority Priority { get; set; }
  111. /// <summary>
  112. /// This Alarm is for which tank.
  113. /// </summary>
  114. public byte TankNumber { get; set; }
  115. public AlarmType Type { get; set; }
  116. public DateTime CreatedTimeStamp { get; set; }
  117. /// <summary>
  118. /// the fix time of this alarm.
  119. /// </summary>
  120. public DateTime? ClearedTimeStamp { get; set; }
  121. public string Description { get; set; }
  122. }
  123. public enum AlarmPriority
  124. {
  125. /// <summary>
  126. /// need take a look when available.
  127. /// </summary>
  128. Warning,
  129. /// <summary>
  130. /// need take a look right now.
  131. /// </summary>
  132. Alarm,
  133. }
  134. /// <summary>
  135. /// logical concept.
  136. /// </summary>
  137. public class Tank
  138. {
  139. /// <summary>
  140. /// Gets or sets the tank number which assigned in device internal
  141. /// </summary>
  142. public byte TankNumber { get; set; }
  143. /// <summary>
  144. /// descriptive info for this Tank.
  145. /// </summary>
  146. public string Label { get; set; }
  147. public Product Product { get; set; }
  148. public TankLimit Limit { get; set; }
  149. /// <summary>
  150. /// by mm.
  151. /// </summary>
  152. public double? Diameter { get; set; }
  153. /// <summary>
  154. /// </summary>
  155. public TankState State { get; set; }
  156. public Probe Probe { get; set; }
  157. public override string ToString()
  158. {
  159. return $"Tank with No.: {TankNumber} has Label: {Label ?? ""}, ProductCode: {Product?.ProductCode ?? ""}, ProductLabel: {Product?.ProductLabel ?? ""}";
  160. }
  161. }
  162. public class TankLimit
  163. {
  164. /// <summary>
  165. /// The max volume of this tank can safely save material, by Liter.
  166. /// by considering the material expansion along with temp rise, the Max volume must less than Full Volume.
  167. /// </summary>
  168. public double MaxVolume { get; set; }
  169. /// <summary>
  170. /// 100% volume of this tank, by Liter.
  171. /// </summary>
  172. public double FullVolume { get; set; }
  173. /// <summary>
  174. /// % of the Max Volume, typical value 0.9
  175. /// above this value will trigger high product alarm.
  176. /// </summary>
  177. public double HighProduct { get; set; }
  178. /// <summary>
  179. /// Liter of the low product threashold value, by Liter, typical value 30.
  180. /// lower thatn this value will trigger low product alarm.
  181. /// </summary>
  182. public double LowProduct { get; set; }
  183. /// <summary>
  184. /// mm of the high water warning threashold value, by mm, typical value 100.
  185. /// higher than this value will trigger high water warning.
  186. /// </summary>
  187. public double HighWaterWarning { get; set; }
  188. /// <summary>
  189. /// mm of the high water alarm threashold value, by mm, typical value 125.
  190. /// higher than this value will trigger high water alarm.
  191. /// </summary>
  192. public double HighWaterAlarm { get; set; }
  193. /// <summary>
  194. /// by centigrade(celsius), typical value -50
  195. /// </summary>
  196. public double FuelTemperatureLowLimit { get; set; }
  197. /// <summary>
  198. /// by centigrade(celsius), typical value 60
  199. /// </summary>
  200. public double FuelTemperatureHighLimit { get; set; }
  201. }
  202. public class Product
  203. {
  204. /// <summary>
  205. ///
  206. /// </summary>
  207. public string ProductCode { get; set; }
  208. /// <summary>
  209. /// descriptive info for the product.
  210. /// </summary>
  211. public string ProductLabel { get; set; }
  212. }
  213. /// <summary>
  214. /// represents a physical hardware of a probe, which used to measure liquid depth.
  215. /// </summary>
  216. public class Probe
  217. {
  218. /// <summary>
  219. /// unique in a ATG system.
  220. /// </summary>
  221. public int DeviceId { get; set; }
  222. /// <summary>
  223. /// hardware id, serial number? mac?
  224. /// </summary>
  225. public string HardwareIdentity { get; set; }
  226. /// <summary>
  227. /// phsycial length of the probe hardware, by mm.
  228. /// </summary>
  229. public double? ProbeLength { get; set; }
  230. /// <summary>
  231. /// the lowest point of the probe may not reached the bottom of the tank, this is the length of this distance.
  232. /// the fuel and water height readings will combine with this value before send out for ATG client applications.
  233. /// </summary>
  234. public double ProbeOffset { get; set; }
  235. /// <summary>
  236. /// user may want to 'hidden' some water in a tank, this is the value of the water height reading need to be substracted.
  237. /// </summary>
  238. public double WaterOffset { get; set; }
  239. /// <summary>
  240. /// may device manufactor dependency.
  241. /// </summary>
  242. public string State { get; set; }
  243. }
  244. public class ProbeReading
  245. {
  246. /// <summary>
  247. /// Fuel Height is the depth of all liquid in the tank in inches or millimeters.
  248. /// </summary>
  249. public double? Height { get; set; }
  250. /// <summary>
  251. /// Water Height is the depth of the water in the tank.
  252. /// Note: If you are using high alcohol probes that cannot detect water, Water Height will not appear on the display or the printed reports.
  253. /// </summary>
  254. public double? Water { get; set; }
  255. public IEnumerable<double> Temperature { get; set; }
  256. public double? Density { get; set; }
  257. }
  258. public class TankReading
  259. {
  260. public int? TankNumber { get; set; }
  261. /// <summary>
  262. /// Fuel Volume in tank, by Liter.
  263. /// </summary>
  264. public double? Volume { get; set; }
  265. /// <summary>
  266. /// Gets or sets the value of Temperature Compensated Volume.
  267. /// The product in the tank expands and contracts with temperature.
  268. /// The colder the temperature, the more the product will contract.
  269. /// The higher the temperature, the more the product will expand.
  270. /// Temperature Compensated Volume is at 60 degrees Fahrenheit, unless your system was programmed to use another temperature value.
  271. /// Note: If Temperature Compensated Volume was set to “Disable” using the System Setup function,
  272. /// you will not be able to print the Temperature Compensated Volume on the report.
  273. /// </summary>
  274. public double? TcVolume { get; set; }
  275. /// <summary>
  276. /// Ullage is the amount of room left in the tank. Normally,
  277. /// a tank is not totally full, this is done so that the product has some room to expand.
  278. /// you can't fill the tank with full product which may cause problem, like when temperature get warmer,
  279. /// the product will expand.
  280. /// </summary>
  281. public double? Ullage { get; set; }
  282. /// <summary>
  283. /// Water Volume is the amount of water in the tank in gallons or liters.
  284. /// Note: If you are using high alcohol probes, Water Volume will not appear in the display or the printed reports.
  285. /// </summary>
  286. public double? WaterVolume { get; set; }
  287. #region values read from real physical probe, all other business are actually rely on these hardware readings
  288. /// <summary>
  289. /// Fuel Height is the depth of all liquid in the tank in inches or millimeters.
  290. /// </summary>
  291. public double? Height { get; set; }
  292. /// <summary>
  293. /// Water Height is the depth of the water in the tank.
  294. /// Note: If you are using high alcohol probes that cannot detect water, Water Height will not appear on the display or the printed reports.
  295. /// </summary>
  296. public double? Water { get; set; }
  297. public double? Temperature { get; set; }
  298. public double? Density { get; set; }
  299. #endregion
  300. public override string ToString()
  301. {
  302. return "Product Height: " + (this?.Height ?? -1) +
  303. ", Product Volume: " + (this.Volume ?? -1) +
  304. ", Product TcVolume Volume: " + (this.TcVolume ?? -1) +
  305. ", Water Height: " + (this?.Water ?? -1) +
  306. ", Temperature: " + (this?.Temperature ?? -1) +
  307. ", Density: " + (this?.Density ?? -1);
  308. }
  309. }
  310. public enum SystemUnit
  311. {
  312. US = 1,
  313. Metric = 2,
  314. ImperialGallons = 3,
  315. }
  316. public enum SystemLanguage
  317. {
  318. English = 1,
  319. French = 2,
  320. Spanish = 3,
  321. German = 4,
  322. Portuguese = 5,
  323. Polish = 6,
  324. Swedish = 7,
  325. Janpanese = 8,
  326. Finnish = 9,
  327. }
  328. public enum AlarmType
  329. {
  330. #region VeederRoot defined
  331. TankSetupDataWarning = 1,
  332. TankLeakAlarm = 2,
  333. TankHighWaterAlarm = 3,
  334. TankOverfillAlarm = 4,
  335. TankLowProductAlarm = 5,
  336. TankSuddenLossAlarm = 6,
  337. TankHighProductAlarm = 7,
  338. TankInvalidFuelLevelAlarm = 8,
  339. TankProbeOutAlarm = 9,
  340. TankHighWaterWarning = 10,
  341. TankDeliveryNeededWarning = 11,
  342. TankMaximumProductAlarm = 12,
  343. TankGrossLeakTestFailAlarm = 13,
  344. TankPeriodicLeakTestFailAlarm = 14,
  345. TankAnnualLeakTestFailAlarm = 15,
  346. TankPeriodicTestNeededWarning = 16,
  347. TankAnnualTestNeedWarning = 17,
  348. TankPeriodicTestNeededAlarm = 18,
  349. TankAnnualTestNeededAlarm = 19,
  350. TankLeakTestActive = 20,
  351. TankNoCsldIdleTimeWarning = 21,
  352. TankSiphonBreakActiveWarning = 22,
  353. TankCsldRateIncreaseWarning = 23,
  354. TankAccuChartCalibrationWarning = 24,
  355. TankHrmReconciliationWarning = 25,
  356. TankHrmReconciliationAlarm = 26,
  357. TankColdTemperatureWarning = 27,
  358. TankMissingDeliveryTicketWarning = 28,
  359. TankLineGrossLeakAlarm = 29,
  360. //Shawn added
  361. TankHighTemperatureWarning = 5000,
  362. #endregion
  363. }
  364. public enum DeliveryReadingDataName
  365. {
  366. StartingVolume = 1,
  367. StartingTcVolume = 2,
  368. StartingWater = 3,
  369. StartingTemp = 4,
  370. EndingVolume = 5,
  371. EndingTcVolume = 6,
  372. EndingWater = 7,
  373. EndingTemp = 8,
  374. StartingHeight = 9,
  375. EndingHeight = 10,
  376. }
  377. public class Delivery
  378. {
  379. public byte TankNumber { get; set; }
  380. public DateTime StartingDateTime { get; set; }
  381. public double StartingFuelHeight { get; set; }
  382. public double StartingFuelVolume { get; set; }
  383. public double StartingFuelTCVolume { get; set; }
  384. public double StartingWaterHeight { get; set; }
  385. public double StartingTemperture { get; set; }
  386. public DateTime? EndingDateTime { get; set; }
  387. public double? EndingFuelHeight { get; set; }
  388. public double? EndingFuelVolume { get; set; }
  389. public double? EndingFuelTCVolume { get; set; }
  390. public double? EndingWaterHeight { get; set; }
  391. public double? EndingTemperture { get; set; }
  392. public string Description { get; set; }
  393. }
  394. public class Inventory
  395. {
  396. public int TankNumber { get; set; }
  397. public DateTime TimeStamp { get; set; }
  398. public double FuelHeight { get; set; }
  399. public double FuelVolume { get; set; }
  400. public double FuelTCVolume { get; set; }
  401. public double WaterHeight { get; set; }
  402. public double Temperture { get; set; }
  403. public string Description { get; set; }
  404. }
  405. }