RevtechMatchMockPMB.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Threading;
  3. using MECF.Framework.Simulator.Core.Driver;
  4. namespace VirgoSimulator.Devices
  5. {
  6. class RevtechMatchMockPMB : SocketDeviceSimulator
  7. {
  8. private const string EOF = "\n";
  9. private const char MSG_DELIMITER = '\n';
  10. private const int MOCKUP_PORT = 6001;
  11. string info = "FAUTO,0,0,0,0,0,0,11,22,0,0,0,33,44,0,0,0,0";
  12. public RevtechMatchMockPMB() : base(MOCKUP_PORT, -1, EOF, MSG_DELIMITER)
  13. {
  14. }
  15. protected override void ProcessUnsplitMessage(string message)
  16. {
  17. if (string.IsNullOrEmpty(message))
  18. throw new ArgumentException("Hardware command message is invalid");
  19. //string sRes = string.Empty;
  20. if (message.Contains(EOF))
  21. {
  22. message = message.Remove(message.Length - 1);
  23. }
  24. string[] msgs = message.Split('\n');
  25. foreach (string msg in msgs)
  26. {
  27. if (msg.Contains("MATCH:POS:C1"))
  28. {
  29. string newInfo = "";
  30. var c1 = msg.Split(' ')[1];
  31. string[] splits = info.Split(',');
  32. for (int i = 0; i < splits.Length; i++)
  33. {
  34. if (i == 8)
  35. {
  36. newInfo += c1;
  37. newInfo += ",";
  38. }
  39. else if (i == splits.Length - 1)
  40. {
  41. newInfo += splits[i];
  42. //newInfo += ",";
  43. }
  44. else
  45. {
  46. newInfo += splits[i];
  47. newInfo += ",";
  48. }
  49. }
  50. info = newInfo;
  51. }
  52. else if (msg.Contains("MATCH:POS:C2"))
  53. {
  54. string newInfo = "";
  55. var c2 = msg.Split(' ')[1];
  56. string[] splits = info.Split(',');
  57. for (int i = 0; i < splits.Length; i++)
  58. {
  59. if (i == 7)
  60. {
  61. newInfo += c2;
  62. newInfo += ",";
  63. }
  64. else if (i == splits.Length - 1)
  65. {
  66. newInfo += splits[i];
  67. //newInfo += ",";
  68. }
  69. else
  70. {
  71. newInfo += splits[i];
  72. newInfo += ",";
  73. }
  74. }
  75. info = newInfo;
  76. }
  77. else if (msg.Contains("MATCH:MODE"))
  78. {
  79. string newInfo = "";
  80. var mode = msg.Split(' ')[1];
  81. string[] splits = info.Split(',');
  82. for (int i = 0; i < splits.Length; i++)
  83. {
  84. if (i == 0)
  85. {
  86. newInfo += mode;
  87. newInfo += ",";
  88. }
  89. else if (i == splits.Length - 1)
  90. {
  91. newInfo += splits[i];
  92. //newInfo += ",";
  93. }
  94. else
  95. {
  96. newInfo += splits[i];
  97. newInfo += ",";
  98. }
  99. }
  100. info = newInfo;
  101. }
  102. if (msg.Contains("MATCH:FETCH?"))
  103. {
  104. //if (!info.Contains("\n"))
  105. //{
  106. // info += "\n";
  107. //}
  108. OnWriteMessage(info);
  109. }
  110. }
  111. }
  112. }
  113. }