ConfigModel.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Converters;
  3. using SWRIS.Enums;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO.Ports;
  7. using System.Linq;
  8. namespace SWRIS.Models
  9. {
  10. public class ConfigModel
  11. {
  12. public string AppName { get; set; }
  13. public string Version { get; set; }
  14. public string Copyright { get; set; }
  15. public string IpAddress { get; set; }
  16. public int Port { get; set; }
  17. public int DataSaveDays { get; set; } = 120;
  18. public TimeSpan CleanScheduledTime { get; set; }
  19. public int DamageNearPointCount { get; set; } = 20;
  20. public bool ShowDebugMessage { get; set; } = false;
  21. public RiskLevel SoundRiskLevel { get; set; } = RiskLevel.Moderate;
  22. public double SpeedVariationThreshold { get; set; } = 0.25;
  23. public string Crane { get; set; }
  24. public List<TrolleyData> Trolleys { get; set; }
  25. public List<EquipmentModel> Equipments { get; set; }
  26. public List<SwitchInstance> SwitchInstances { get; set; }
  27. public CalibrationSettings Calibration { get; set; }
  28. public RiskLevelSettings RiskLevelSettings { get; set; }
  29. public double DamageExtent { get; set; }
  30. public int AlarmValidCount { get; set; }
  31. public string GenerateNewSerialNo()
  32. {
  33. string prefix = DateTime.Now.ToString("yyMM");
  34. // 获取当前月份最大序号
  35. int max = Equipments.Select(e => e.SerialNo)?
  36. .Where(s => s != null && s.StartsWith(prefix))
  37. .Select(s => int.Parse(s.Substring(4)))
  38. .DefaultIfEmpty(0)
  39. .Max() ?? 0;
  40. // 生成新序号(最大+1,格式化为3位数)
  41. return $"{prefix}{(max + 1):D3}";
  42. }
  43. }
  44. public class CalibrationSettings
  45. {
  46. public ModuleType ModuleType { get; set; }
  47. public List<LimitData> Limits { get; set; }
  48. public TcpSettings Tcp { get; set; }
  49. public SerialSettings Serial { get; set; }
  50. }
  51. public class TcpSettings
  52. {
  53. public string IpAddress { get; set; }
  54. public int Port { get; set; }
  55. public byte Station { get; set; } = 1;
  56. }
  57. public class SerialSettings
  58. {
  59. public string PortName { get; set; }
  60. public int BaudRate { get; set; }
  61. public int DataBits { get; set; }
  62. [JsonConverter(typeof(StringEnumConverter))]
  63. public Parity Parity { get; set; }
  64. public StopBits StopBits { get; set; }
  65. public byte Station { get; set; } = 1;
  66. }
  67. public class RiskLevelSettings
  68. {
  69. public List<RiskLevelConfig> Levels { get; set; }
  70. }
  71. public class RiskLevelConfig
  72. {
  73. public RiskLevel Level { get; set; }
  74. public Range MaxDamageRange { get; set; }
  75. public Range AvgDamageRange { get; set; }
  76. }
  77. public class Range
  78. {
  79. public int Min { get; set; }
  80. public int Max { get; set; }
  81. }
  82. public class TrolleyData
  83. {
  84. public int Id { get; set; }
  85. public string Name { get; set; }
  86. }
  87. public class LimitData
  88. {
  89. public int TrolleyId { get; set; }
  90. public string Name { get; set; }
  91. public string Address { get; set; }
  92. public double Position { get; set; }
  93. public bool IsReverse { get; set; }
  94. public LimitState State { get; set; }
  95. public bool IsEnable { get; set; }
  96. public List<int> RelatedRopes { get; set; } = new List<int>();
  97. public int SwitchIndex { get; set; }
  98. }
  99. public class SwitchInstance
  100. {
  101. public string InstanceName { get; set; }
  102. public string ProgressName { get; set; }
  103. public string ImageSource { get; set; }
  104. }
  105. }