ParseCheck.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. function check = ParseCheck(check_in, case_in, connections)
  2. %PARSE_CASE 此处显示有关此函数的摘要
  3. % 此处显示详细说明
  4. check.id = check_in.id;
  5. check.tag = check_in.tag;
  6. check.condition_str = check_in.condition;
  7. check.condition.Name = '';
  8. check.condition.Test = @() 0;
  9. check.ref_name = '';
  10. check.ref = timeseries(0, 0);
  11. check.refIntp = 1; %默认使能插值
  12. check.fdb_name = '';
  13. check.fdb = timeseries(0, 0);
  14. check.fdbIntp = 1; %默认使能插值
  15. tmp.ref.time = 0;
  16. tmp.ref.value = 0;
  17. tmp.fdb.time = 0;
  18. tmp.fdb.value = 0;
  19. if isa(check_in.time, 'struct')
  20. check.preprocess = 1;
  21. check.time = check_in.time.duration;
  22. check.adv = check_in.time.adv;
  23. else
  24. check.preprocess = 0;
  25. check.time = check_in.time;
  26. check.adv = 'None';
  27. end
  28. check.tolerance = check_in.tolerance;
  29. if check.tolerance == 0
  30. check.tolerance = 1e-10;
  31. end
  32. check.test = @() 0;
  33. if isa(check_in.ref, 'char')
  34. check.ref_name = check_in.ref;
  35. [tmp.ref.time, tmp.ref.value, check.refIntp] = GetSignal(check_in.ref, case_in, connections);
  36. elseif isa(check_in.ref, 'double')
  37. tmp.ref.time = check.time;
  38. if (check.preprocess == 1)
  39. tmp.ref.value = [check_in.ref; check_in.ref];
  40. else
  41. tmp.ref.value = check_in.ref;
  42. end
  43. end
  44. if isa(check_in.fdb, 'char')
  45. check.fdb_name = check_in.fdb;
  46. [tmp.fdb.time, tmp.fdb.value, check.fdbIntp] = GetSignal(check_in.fdb, case_in, connections);
  47. elseif isa(check_in.fdb, 'double')
  48. tmp.fdb.time = check.time;
  49. if (check.preprocess == 1)
  50. tmp.fdb.value = [check_in.fdb; check_in.fdb];
  51. else
  52. tmp.fdb.value = check_in.fdb;
  53. end
  54. end
  55. check.ref = timeseries(tmp.ref.value, tmp.ref.time);
  56. check.fdb = timeseries(tmp.fdb.value, tmp.fdb.time);
  57. switch(check_in.condition)
  58. case 'eq'
  59. check.condition.Name = 'Equal';
  60. check.condition.Test = @(ref, fdb, tor) and(fdb <= ref + tor, fdb >= ref - tor);
  61. case 'ne'
  62. check.condition.Name = 'NotEqual';
  63. check.condition.Test = @(ref, fdb, tor) or(fdb > ref + tor, fdb < ref - tor);
  64. case 'gt'
  65. check.condition.Name = 'GreaterThan';
  66. check.condition.Test = @(ref, fdb, tor) (fdb > ref);
  67. case 'ge'
  68. check.condition.Name = 'GreaterOrEqual';
  69. check.condition.Test = @(ref, fdb, tor) (fdb >= ref);
  70. case 'lt'
  71. check.condition.Name = 'LessThan';
  72. check.condition.Test = @(ref, fdb, tor) (fdb >= ref);
  73. case 'le'
  74. check.condition.Name = 'LessOrEqual';
  75. check.condition.Test = @(ref, fdb, tor) (fdb >= ref);
  76. case 'EqAngle'
  77. check.condition.Name = 'EqualAngle';
  78. check.condition.Test = @(ref, fdb, tor) ((mod(fdb - ref, 2*pi) < tor) || (mod(fdb - ref, 2*pi) > (2*pi - tor)));
  79. case 'In'
  80. check.condition.Name = 'In';
  81. check.condition.Test = @(ref, fdb, tor) and(fdb <= ref + tor, fdb >= ref - tor);
  82. case 'NotIn'
  83. check.condition.Name = 'NotIn';
  84. check.condition.Test = @(ref, fdb, tor) or(fdb > ref + tor, fdb < ref - tor);
  85. end
  86. check.test = @ConditionCheck;
  87. end
  88. function [time, value, intp] = GetSignal(tag, test, connections)
  89. time = 0;
  90. value = 0;
  91. intp = 0;
  92. for i = 1:length(test.Initializations)
  93. if strcmp(tag, test.Initializations(i).tag)
  94. time = 0;
  95. value = test.Initializations(i).value;
  96. return;
  97. end
  98. end
  99. for i = 1:length(test.Injections)
  100. if strcmp(tag, test.Injections(i).tag)
  101. time = test.Injections(i).time;
  102. value = test.Injections(i).value;
  103. if isfield(test.Injections(i), 'option')
  104. if isfield(test.Injections(i).option, 'interpolation')
  105. if test.Injections(i).option.interpolation
  106. intp = 1;
  107. end
  108. end
  109. end
  110. return;
  111. end
  112. end
  113. for i = 1:length(test.Feedbacks)
  114. if strcmp(tag, test.Feedbacks(i).tag)
  115. [t, n, c] = SelectConnection(test.Feedbacks(i).tag, connections);
  116. if t == 'v' || t == 'a'
  117. time = evalin('base', n).Time;
  118. value = evalin('base', n).Data(:,c + 1);
  119. return;
  120. end
  121. end
  122. end
  123. end