STeamRFMatch.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using MECF.Framework.Simulator.Core.Driver;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Timers;
  9. namespace MECF.Framework.Simulator.Core.RFMatchs.STeam
  10. {
  11. public class STeamRFMatch : SerialPortDeviceSimulator
  12. {
  13. public bool Failed { get; set; }
  14. public bool IsOn { get; set; }
  15. public bool IsHalo { get; set; }
  16. public bool IsContinueAck { get; set; }
  17. Stopwatch _timer = new Stopwatch();
  18. private System.Timers.Timer _tick;
  19. Random _rd = new Random();
  20. private object _locker = new object();
  21. public string ResultValue { get; set; }
  22. public STeamRFMatch(string port)
  23. : base(port, -1, "\r\n", ' ', false)
  24. {
  25. ResultValue = "";
  26. _tick = new System.Timers.Timer();
  27. _tick.Interval = 200;
  28. _tick.Elapsed += _tick_Elapsed;
  29. _tick.Start();
  30. }
  31. private void _tick_Elapsed(object sender, ElapsedEventArgs e)
  32. {
  33. lock (_locker)
  34. {
  35. if (_timer.IsRunning && _timer.Elapsed > TimeSpan.FromSeconds(10))
  36. {
  37. _timer.Stop();
  38. }
  39. }
  40. }
  41. List<byte> _cached = new List<byte>();
  42. //private int _mode1;
  43. //private int _mode2;
  44. //private bool _enablePreset;
  45. //private byte _presetNumber;
  46. //private int _load1;
  47. //private int _load2;
  48. //private int _tune1;
  49. //private int _tune2;
  50. protected override void ProcessUnsplitMessage(byte[] message1)
  51. {
  52. _cached.AddRange(message1);
  53. string command = "";
  54. if (_cached[0] == 0x80)
  55. {
  56. switch (_cached[1])
  57. {
  58. case 0x1C:
  59. if (_cached[_cached.Count - 1] == 0x39)
  60. {
  61. command = "80,1C,39,00,80,04";
  62. }
  63. if (_cached[_cached.Count - 1] == 0x38)
  64. {
  65. command = "80, 1C, 38,00,80,04";
  66. }
  67. if (_cached[_cached.Count - 1] == 0x07)
  68. {
  69. command = "80,1C,07,00,80,04";
  70. }
  71. if (_cached[_cached.Count - 1] == 0x4B)
  72. {
  73. command = "80,1C,4B,00,80,04";
  74. }
  75. if (_cached[_cached.Count - 1] == 0x06)
  76. {
  77. command = "80,1C,06,00,80,04";
  78. }
  79. if (_cached[_cached.Count - 1] == 0x35)
  80. {
  81. command = "80,1C,35,00,80,04";
  82. }
  83. if (_cached[_cached.Count - 1] == 0x46)
  84. {
  85. command = "80,1C,46,00,80,04";
  86. }
  87. if (_cached[_cached.Count - 1] == 0x47)
  88. {
  89. command = "80,1C,47,00,80,04";
  90. }
  91. if (_cached[_cached.Count - 1] == 0x48)
  92. {
  93. command = "80,1C,48,00,80,04";
  94. }
  95. if (_cached[_cached.Count - 1] == 0x49)
  96. {
  97. command = "80,1C,49,00,80,04";
  98. }
  99. if (_cached[_cached.Count - 1] == 0x4A)
  100. {
  101. command = "80,1C,4A,00,80,04";
  102. }
  103. if (_cached[_cached.Count - 1] == 0x56)
  104. {
  105. command = "80,1C,56,00,80,04";
  106. }
  107. if (_cached[_cached.Count - 1] == 0x5C)
  108. {
  109. command = "80,1C,5C,00,80,04";
  110. }
  111. if (_cached[_cached.Count - 1] == 0x60)
  112. {
  113. command = "80,1C,60,00,80,04";
  114. }
  115. break;
  116. case 0x11:
  117. command = "80,1C,11,00,80,04,80,1C,20,00,09,38,05,FE,00,D6,00,F8,04,B8,AC,A0,0E,7B,03,89,FF,17,0A,23,06,00,00,77,00,F0,80,10";
  118. break;
  119. case 0x39:
  120. command = "80,1C,38,00,80,04";
  121. break;
  122. case 0x45:
  123. command = "80,1C,45,00,80,04";
  124. break;
  125. case 0x4A:
  126. command = "80,1C,2D,00,00,01,02,A0,0E,79,00,59,80,10";
  127. break;
  128. case 0x55:
  129. command = "80,1C,34,00,09,26,05,FE,00,FF,D6,00,F8,04,B8,AC,A0,0C,7B,03,89,FF,00,00,01,02,A9,0F,77,00,81,80,10";
  130. break;
  131. case 0x57:
  132. command = "80,1C,34,00,09,2B,05,FE,00,FF,DF,00,F1,04,62,D8,9F,0E,7D,03,96,FF,AC,0D, 84,08,00,00,77,00,F7,80,10,80,1C,30,17,0A,23,08,00,00,77,80,80,73,80,10";
  133. break;
  134. }
  135. }
  136. _cached.Clear();
  137. OnWriteMessage(ToByteArray(command));
  138. }
  139. public static byte SetBits(byte _word, byte value, int offset)
  140. {
  141. byte mask_1 = (byte)(value << offset);
  142. byte mask_2 = (byte)(~mask_1 & _word);
  143. return (byte)(mask_1 | mask_2);
  144. }
  145. public void ResultData()
  146. {
  147. string msg = "Clk=50736732 HST=20 HER=16 MHz=915 Mag=0.928 Deg=34.127 Mgd=NONE Dgd=NONE Pi=7.376E3 Pr = 6.349E3 T = 25.1 M1 = 5000 M2 = 5000 M3 = 0 MS1 = 119 MS2 = 0 END\r\n";
  148. OnWriteMessage(msg);
  149. }
  150. protected static byte[] ToByteArray(string parameter)
  151. {
  152. if (parameter == null)
  153. return new byte[] { };
  154. return parameter.Split(',').Select(para => Convert.ToByte(para, 16)).ToArray();
  155. }
  156. }
  157. }