ConfigModel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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<EquipmentModel> Equipments { get; set; }
  25. public List<SwitchInstance> SwitchInstances { get; set; }
  26. public CalibrationSettings Calibration { get; set; }
  27. public RiskLevelSettings RiskLevelSettings { get; set; }
  28. public double DamageExtent { get; set; }
  29. public int AlarmValidCount { get; set; }
  30. public string GenerateNewSerialNo()
  31. {
  32. string prefix = DateTime.Now.ToString("yyMM");
  33. // 获取当前月份最大序号
  34. int max = Equipments.Select(e => e.SerialNo)?
  35. .Where(s => s != null && s.StartsWith(prefix))
  36. .Select(s => int.Parse(s.Substring(4)))
  37. .DefaultIfEmpty(0)
  38. .Max() ?? 0;
  39. // 生成新序号(最大+1,格式化为3位数)
  40. return $"{prefix}{(max + 1):D3}";
  41. }
  42. }
  43. public class CalibrationSettings
  44. {
  45. public ModuleType ModuleType { get; set; }
  46. public List<LimitData> Limits { get; set; }
  47. public TcpSettings Tcp { get; set; }
  48. public SerialSettings Serial { get; set; }
  49. }
  50. public class TcpSettings
  51. {
  52. public string IpAddress { get; set; }
  53. public int Port { get; set; }
  54. public byte Station { get; set; } = 1;
  55. }
  56. public class SerialSettings
  57. {
  58. public string PortName { get; set; }
  59. public int BaudRate { get; set; }
  60. public int DataBits { get; set; }
  61. [JsonConverter(typeof(StringEnumConverter))]
  62. public Parity Parity { get; set; }
  63. public StopBits StopBits { get; set; }
  64. public byte Station { get; set; } = 1;
  65. }
  66. public class RiskLevelSettings
  67. {
  68. public List<RiskLevelConfig> Levels { get; set; }
  69. }
  70. public class RiskLevelConfig
  71. {
  72. public RiskLevel Level { get; set; }
  73. public Range MaxDamageRange { get; set; }
  74. public Range AvgDamageRange { get; set; }
  75. }
  76. public class Range
  77. {
  78. public int Min { get; set; }
  79. public int Max { get; set; }
  80. }
  81. public class LimitData
  82. {
  83. public string Name { get; set; }
  84. public string Address { get; set; }
  85. public double Position { get; set; }
  86. public bool IsReverse { get; set; }
  87. public LimitState State { get; set; }
  88. public bool IsEnable { get; set; }
  89. public List<int> RelatedRopes { get; set; } = new List<int>();
  90. }
  91. public class SwitchInstance
  92. {
  93. public string InstanceName { get; set; }
  94. public string ProgressName { get; set; }
  95. public string ImageSource { get; set; }
  96. }
  97. }