-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathScouseTom_ard_parseinput.m
159 lines (112 loc) · 3.04 KB
/
ScouseTom_ard_parseinput.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
function [ CMD,DataOut,StringOut ] = ScouseTom_ard_parseinput( StringIn )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%% Possible inputs
%this must be the same as the Errors.h
%expected stuff:
Error_prefix='!';
Message_prefix='+';
Repeat_prefix='R';
Prt_prefix='P';
Freqord_prefix='O';
Phaseord_prefix='D';
Compliance_prefix='C';
CScommerrmsg='!E';
CSsettingserrmsg='!S';
CSpmarkerrmsg = '!P';
SwitchPWRerrmsg = '!Wp';
SwitchOpenerrmsg = '!Ws';
CScomplianceerrmsg = '!C';
CSTimeouterrmsg='!To';
CScommOKmsg='+OK';
CSfinishmsg='+Fin';
SwitchOKmsg = '+SW';
ComplianceOKmsg = '+C';
%% Process Input
%characters srrounding number
startchar='<';
endchar='>';
start_idx=strfind(StringIn,startchar);
end_idx=strfind(StringIn,endchar);
StringOut=StringIn(start_idx+1:end_idx-1);
cmdstr=StringIn(start_idx+1); %get the first "command" character
%the rest is the data, either a sring for the errors and ok flags, or a
%single number for repeat and protocol, or comma separated array for freq
%order and phase order
datastr=StringIn(start_idx+2:end_idx-1);
% disp(['cmd is ' cmd]);
% disp(['datastr is ' datastr]);
%% Do stuff based on the CMD
switch cmdstr
case Error_prefix % error!
[CMD,DataOut]=ParseError(datastr);
case Message_prefix % ok message
[CMD,DataOut]=ParseMessage(datastr);
case Repeat_prefix % new repeat num
CMD=2;
DataOut=sscanf(datastr,'%d');
case Prt_prefix % new prot line num
CMD=3;
DataOut=sscanf(datastr,'%d');
case Freqord_prefix % new freq order array
CMD=4;
tmp=textscan(datastr,'%d','delimiter',',');
DataOut=double(tmp{1}');
case Phaseord_prefix % new phase order array
CMD=5;
tmp=textscan(datastr,'%d','delimiter',',');
DataOut=double(tmp{1}');
case Compliance_prefix
CMD=6;
tmp=textscan(datastr,'%d','delimiter',',');
DataOut=double(tmp{1}');
otherwise
CMD=-99;
DataOut=-99;
end
end
function [CMD,DataOut]=ParseMessage(datastr)
CScommOKmsg='OK';
CSfinishmsg='Fin';
SwitchOKmsg = 'SW';
ComplianceOKmsg = 'C';
switch datastr
case CScommOKmsg
%comm ok
CMD=0;
DataOut=0;
case CSfinishmsg %finished inj
CMD=1;
DataOut=1;
case SwitchOKmsg
CMD = 10;
DataOut=1;
case ComplianceOKmsg
CMD=7;
DataOut=1;
end
end
function [CMD,DataOut]=ParseError(datastr)
CScommerrmsg='E';
CSsettingserrmsg='S';
CSpmarkerrmsg = 'P';
SwitchPWRerrmsg = 'Wp';
SwitchOpenerrmsg = 'Ws';
CScomplianceerrmsg = 'C';
CSTimeouterrmsg= 'To';
CMD=-1; %all error have same code
%certain error codes mean we should stop injection, others we can carry on
switch datastr
case CScommerrmsg
%CS comm bad, this is
DataOut=1;
case SwitchPWRerrmsg
%CS comm bad, this is
DataOut=1;
case SwitchOpenerrmsg
%CS comm bad, this is
DataOut=1;
otherwise
DataOut=0;
end
end