-
Notifications
You must be signed in to change notification settings - Fork 8
/
settings.cpp
196 lines (162 loc) · 3.76 KB
/
settings.cpp
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// settings.cpp
#include "settings.h"
#include <stdio.h>
void CSettings::Init()
{
dtbId = -1;
scriptPath = "script";
proberPort = -1;
rocType = 1;
sensor = false;
// cable length:
deser160_clkDelay = 4;
deser160_tinDelay = 4;
adc_tinDelay = 14;
adc_toutDelay = 10;
adc_clkDelay = 16;
cableLength = 50;
errorRep = 1;
waferList.clear();
waferMask.clear();
waferExclude.clear();
}
void CSettings::SkipWhitespace()
{
while (IsWhitespace(f.Get())) f.GetNext();
}
void CSettings::SkipComment()
{
char ch = f.GetNext();
if (ch == '*')
{ // skip to string end
do { while (f.GetNext() != '*'); } while(f.GetNext() != '/');
f.GetNext();
}
else if (ch == '/')
{ // skip to line end
f.GetNext();
while (f.Get() != '\n' && f.Get() != '\r') f.GetNext();
}
}
void CSettings::SkipToTag()
{
while (f.Get() != '[')
{
if (f.Get() == '/') SkipComment();
else f.GetNext();
}
f.GetNext();
}
void CSettings::ReadTag(std::string &tag)
{
tag.clear();
SkipToTag();
for (int i=0; i<64; i++)
{
if (IsAlphaNum(f.Get())) tag.push_back(f.Get());
else if (f.Get() == ']') { f.GetNext(); return; }
else throw int(101);
f.GetNext();
}
tag.clear();
throw int(102);
}
bool CSettings::ReadBool()
{
std::string s;
ReadString(s);
if (s == "true") return true;
if (s == "false") return false;
throw int(103);
return false;
}
int CSettings::ReadInt(int min, int max)
{
int x;
bool negative = false;
SkipWhitespace();
if (f.Get() == '+') f.GetNext();
else if (f.Get() == '-') { negative = true; f.GetNext(); }
if (IsNumber(f.Get())) { x = f.Get() - '0'; f.GetNext(); }
else throw int(104);
while (IsNumber(f.Get())) { x = x*10 + f.Get() - '0'; f.GetNext(); }
if (negative) x = -x;
if (x < min || x > max) throw int(105);
return x;
}
void CSettings::ReadString(std::string &s)
{
s.clear();
int i = 0;
SkipWhitespace();
while (IsAlphaNum(f.Get()))
{
s.push_back(f.Get());
i++;
if (i > 256) throw int(106);
f.GetNext();
}
}
void CSettings::ReadWaferMask()
{
std::string mask;
ReadString(mask);
for (unsigned int i=0; i<mask.length(); i++)
{
char ch;
switch (mask[i])
{
case 'a': case 'A': ch = 'A'; break;
case 'b': case 'B': ch = 'B'; break;
case 'c': case 'C': ch = 'C'; break;
case 'd': case 'D': ch = 'D'; break;
default: throw int(107);
}
if (waferMask.find(ch) == std::string::npos) waferMask.push_back(ch);
}
}
void CSettings::ReadWaferExclude()
{
std::string s;
ReadString(s);
while (s.length() != 0)
{
CChipPos map;
map.ReadString(s);
waferExclude.push_back(map);
ReadString(s);
}
}
bool CSettings::Read(const char filename[])
{
bool ok = true;
try
{
f.Open(filename);
while (true)
{
std::string s;
ReadTag(s);
if (s == "DTB_ID") dtbId = ReadInt(-1, 1000);
else if (s == "SCRIPT_PATH") ReadString(scriptPath);
else if (s == "PROBER_PORT") proberPort = ReadInt(-1, 99);
else if (s == "ROC_TYPE") rocType = ReadInt(0, 2);
else if (s == "SENSOR") sensor = ReadBool();
else if (s == "TESTREP") errorRep = ReadInt(0, 10);
else if (s == "CABLE_LENGTH") cableLength = ReadInt(0, 10000);
else if (s == "DESER160_CLK_DELAY") deser160_clkDelay = ReadInt(0, 63);
else if (s == "DESER160_TIN_DELAY") deser160_tinDelay = ReadInt(0, 63);
else if (s == "ADC_TIN_DELAY") adc_tinDelay = ReadInt(0, 63);
else if (s == "ADC_TOUT_DELAY") adc_toutDelay = ReadInt(0, 63);
else if (s == "ADC_CLK_DELAY") adc_clkDelay = ReadInt(0, 320);
else if (s == "WAFERLIST") ReadString(waferList);
else if (s == "WAFERMASK") ReadWaferMask();
else if (s == "WAFEREXCLUDE") ReadWaferExclude();
}
}
catch (int e)
{
if (e != ERROR_FILE_END_OF_FILE) ok = false;
}
return ok;
}