123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- function check = ParseCheck(check_in, case_in, connections)
- %PARSE_CASE 此处显示有关此函数的摘要
- % 此处显示详细说明
- check.id = check_in.id;
- check.tag = check_in.tag;
- check.condition_str = check_in.condition;
- check.condition.Name = '';
- check.condition.Test = @() 0;
- check.ref_name = '';
- check.ref = timeseries(0, 0);
- check.refIntp = 1; %默认使能插值
- check.fdb_name = '';
- check.fdb = timeseries(0, 0);
- check.fdbIntp = 1; %默认使能插值
- tmp.ref.time = 0;
- tmp.ref.value = 0;
- tmp.fdb.time = 0;
- tmp.fdb.value = 0;
- if isa(check_in.time, 'struct')
- check.preprocess = 1;
- check.time = check_in.time.duration;
- check.adv = check_in.time.adv;
- else
- check.preprocess = 0;
- check.time = check_in.time;
- check.adv = 'None';
- end
- check.tolerance = check_in.tolerance;
- if check.tolerance == 0
- check.tolerance = 1e-10;
- end
- check.test = @() 0;
- if isa(check_in.ref, 'char')
- check.ref_name = check_in.ref;
- [tmp.ref.time, tmp.ref.value, check.refIntp] = GetSignal(check_in.ref, case_in, connections);
- elseif isa(check_in.ref, 'double')
- tmp.ref.time = check.time;
- if (check.preprocess == 1)
- tmp.ref.value = [check_in.ref; check_in.ref];
- else
- tmp.ref.value = check_in.ref;
- end
- end
- if isa(check_in.fdb, 'char')
- check.fdb_name = check_in.fdb;
- [tmp.fdb.time, tmp.fdb.value, check.fdbIntp] = GetSignal(check_in.fdb, case_in, connections);
- elseif isa(check_in.fdb, 'double')
- tmp.fdb.time = check.time;
- if (check.preprocess == 1)
- tmp.fdb.value = [check_in.fdb; check_in.fdb];
- else
- tmp.fdb.value = check_in.fdb;
- end
- end
- check.ref = timeseries(tmp.ref.value, tmp.ref.time);
- check.fdb = timeseries(tmp.fdb.value, tmp.fdb.time);
- switch(check_in.condition)
- case 'eq'
- check.condition.Name = 'Equal';
- check.condition.Test = @(ref, fdb, tor) and(fdb <= ref + tor, fdb >= ref - tor);
- case 'ne'
- check.condition.Name = 'NotEqual';
- check.condition.Test = @(ref, fdb, tor) or(fdb > ref + tor, fdb < ref - tor);
- case 'gt'
- check.condition.Name = 'GreaterThan';
- check.condition.Test = @(ref, fdb, tor) (fdb > ref);
- case 'ge'
- check.condition.Name = 'GreaterOrEqual';
- check.condition.Test = @(ref, fdb, tor) (fdb >= ref);
- case 'lt'
- check.condition.Name = 'LessThan';
- check.condition.Test = @(ref, fdb, tor) (fdb >= ref);
- case 'le'
- check.condition.Name = 'LessOrEqual';
- check.condition.Test = @(ref, fdb, tor) (fdb >= ref);
- case 'EqAngle'
- check.condition.Name = 'EqualAngle';
- check.condition.Test = @(ref, fdb, tor) ((mod(fdb - ref, 2*pi) < tor) || (mod(fdb - ref, 2*pi) > (2*pi - tor)));
- case 'In'
- check.condition.Name = 'In';
- check.condition.Test = @(ref, fdb, tor) and(fdb <= ref + tor, fdb >= ref - tor);
- case 'NotIn'
- check.condition.Name = 'NotIn';
- check.condition.Test = @(ref, fdb, tor) or(fdb > ref + tor, fdb < ref - tor);
- end
- check.test = @ConditionCheck;
- end
- function [time, value, intp] = GetSignal(tag, test, connections)
- time = 0;
- value = 0;
- intp = 0;
- for i = 1:length(test.Initializations)
- if strcmp(tag, test.Initializations(i).tag)
- time = 0;
- value = test.Initializations(i).value;
- return;
- end
- end
- for i = 1:length(test.Injections)
- if strcmp(tag, test.Injections(i).tag)
- time = test.Injections(i).time;
- value = test.Injections(i).value;
- if isfield(test.Injections(i), 'option')
- if isfield(test.Injections(i).option, 'interpolation')
- if test.Injections(i).option.interpolation
- intp = 1;
- end
- end
- end
- return;
- end
- end
- for i = 1:length(test.Feedbacks)
- if strcmp(tag, test.Feedbacks(i).tag)
- [t, n, c] = SelectConnection(test.Feedbacks(i).tag, connections);
- if t == 'v' || t == 'a'
- time = evalin('base', n).Time;
- value = evalin('base', n).Data(:,c + 1);
- return;
- end
- end
- end
- end
|