-
Notifications
You must be signed in to change notification settings - Fork 0
/
jSeisCalModel.java
372 lines (316 loc) · 10.9 KB
/
jSeisCalModel.java
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Properties;
import calc.*;
import jlib330.*;
public class jSeisCalModel {
//... Constants
private static final String INITIAL_Q330SERIAL = "0100000123456789";
private static final String INITIAL_Q330ADDRESS = "192.168.1.10";
private static final String INITIAL_Q330DATAPORT = "3";
private static final String INITIAL_Q330AUTHCODE = "0000000000000000";
private static final int Q330BASEPORT = 5330;
private static final String INITIAL_TABLEDISPLACEMENT = "0.893";
private static final String INITIAL_TABLEFREEPERIOD = "360";
private static final String INITIAL_TABLEDAMPING = "0.707";
private static final String INITIAL_TABLEBITS = "26";
private static final String INITIAL_TABLEVOLTS = "40";
private static final String INITIAL_TABLECHANNEL = "HHZ";
private static final String INITIAL_METROZETADDRESS = "192.168.1.30";
private String q330serial;
private String q330address;
private String q330dataport;
private String q330authcode;
private String tableDisplacement;
private String tableFreePeriod;
private String tableDamping;
private String tableBits;
private String tableVolts;
private String tableChannel;
public boolean tableMode = false;
public ModBus tableMB;
private String metrozetAddress;
public UDPClient q330controlsocket = null;;
public UDPClient q330datasocket = null;
private InetAddress q330inetaaddress = null;
UdpServer q330UdpServer = null;
private int calcdatastartindex;
private int calcdatastopindex;
private int calcdatalenght;
public CalcDataset dataset = null;
public Data buffers = null;
public q330 q330 = null;
public MetrozetClient metrozetClient;
//============================================================== constructor
/** Constructor */
jSeisCalModel() {
reset();
}
//==================================================================== reset
/** Reset to initial value. */
public void reset() {
if (new File("jSeisCal.ini").exists()) {
try {
Properties p = new Properties();
p.loadFromXML(new FileInputStream("jSeisCal.ini"));
p.list(System.out);
q330address = p.getProperty("q330address");
q330serial = p.getProperty("q330serial");
q330dataport = p.getProperty("q330dataport");
q330authcode = p.getProperty("q330authcode");
tableDisplacement = p.getProperty("tableDisplacement");
tableFreePeriod = p.getProperty("tableFreePeriod");
tableDamping = p.getProperty("tableDamping");
tableBits = p.getProperty("tableBits");
tableVolts = p.getProperty("tableVolts");
tableChannel = p.getProperty("tableChannel");
metrozetAddress = p.getProperty("metrozetAddress");
} catch (Exception e) {
System.out.println(e);
}
} else {
System.out.println ("jSeisCal.ini not found - using defaults");
q330serial = INITIAL_Q330SERIAL;
q330address = INITIAL_Q330ADDRESS;
q330dataport = INITIAL_Q330DATAPORT;
q330authcode = INITIAL_Q330AUTHCODE;
tableDisplacement = INITIAL_TABLEDISPLACEMENT;
tableFreePeriod = INITIAL_TABLEFREEPERIOD;
tableDamping = INITIAL_TABLEDAMPING;
tableBits = INITIAL_TABLEBITS;
tableVolts = INITIAL_TABLEVOLTS;
tableChannel = INITIAL_TABLECHANNEL;
metrozetAddress = INITIAL_METROZETADDRESS;
WriteProperties();
}
dataset = new CalcDataset();
buffers = new Data();
q330 = new q330(buffers);
tableMB = new ModBus();
}
public void WriteProperties() {
Properties p = new Properties();
p.setProperty("q330address", q330address);
p.setProperty("q330serial", q330serial);
p.setProperty("q330authcode", q330authcode);
p.setProperty("q330dataport", q330dataport);
p.setProperty("tableDisplacement", tableDisplacement);
p.setProperty("tableFreePeriod", tableFreePeriod);
p.setProperty("tableDamping", tableDamping);
p.setProperty("tableBits", tableBits);
p.setProperty("tableVolts", tableVolts);
p.setProperty("tableChannel", tableChannel);
p.setProperty("metrozetAddress", metrozetAddress);
try {
FileOutputStream out = new FileOutputStream("jSeisCal.ini");
p.storeToXML(out, "jSeisCal Configuration File");
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//================================================================= set
public void setQ330Serial(String serial) {
q330serial = serial;
}
public void setQ330Address(String address) {
q330address = address;
}
public void setQ330DataPort(String dp) {
q330dataport = dp;
}
public void setQ330AuthCode(String code) {
q330authcode = code;
}
public void setDataStartIndex(){
if (dataset.axis == "HHZ") {
calcdatastartindex = buffers.hhz.index;
}else if (dataset.axis == "HHN") {
calcdatastartindex = buffers.hhn.index;
}else if (dataset.axis == "HHE") {
calcdatastartindex = buffers.hhe.index;
} else if (dataset.axis == "BHZ") {
calcdatastartindex = buffers.bhz.index;
}else if (dataset.axis == "BHN") {
calcdatastartindex = buffers.bhn.index;
}else if (dataset.axis == "BHE") {
calcdatastartindex = buffers.bhe.index;
}
}
public void setDataStopIndex(){
if (dataset.axis == "HHZ") {
calcdatastopindex = buffers.hhz.index;
}else if (dataset.axis == "HHN") {
calcdatastopindex = buffers.hhn.index;
}else if (dataset.axis == "HHE") {
calcdatastopindex = buffers.hhe.index;
}
if (dataset.axis == "BHZ") {
calcdatastopindex = buffers.bhz.index;
}else if (dataset.axis == "BHN") {
calcdatastopindex = buffers.bhn.index;
}else if (dataset.axis == "BHE") {
calcdatastopindex = buffers.bhe.index;
}
}
public void setTableDisplacement(String dis) {
tableDisplacement = dis;
dataset.displacement = Double.valueOf(dis);
}
public void setTableFreePeriod(String s) {
tableFreePeriod = s;
dataset.freeperiod = Double.valueOf(s);
}
public void setTableDamping(String s) {
tableDamping = s;
dataset.damping = Double.valueOf(s);
}
public void setTableBits(String s) {
tableBits = s;
dataset.bits = Double.valueOf(s);
}
public void setTableVolts(String s) {
tableVolts = s;
dataset.volts = Double.valueOf(s);
}
public void setTableChannel(String s) {
tableChannel = s;
dataset.axis = s;
}
public void setMetrozetAddress(String address) {
metrozetAddress = address;
}
//================================================================= get
public String getQ330Serial() {
return q330serial;
}
public String getQ330Address() {
return q330address;
}
public String getQ330DataPort() {
return q330dataport;
}
public String getQ330AuthCode() {
return q330authcode;
}
public int getDataStartIndex(){
return calcdatastartindex;
}
public int getDataStopIndex(){
return calcdatastopindex;
}
public String getTableDisplacement() {
return tableDisplacement;
}
public String getTableFreePeriod() {
return tableFreePeriod;
}
public String getTableDamping() {
return tableDamping;
}
public String getTableBits() {
return tableBits;
}
public String getTableVolts() {
return tableVolts;
}
public String getTableChannel() {
return tableChannel;
}
public String getMetrozetAddress() {
return metrozetAddress;
}
public UDPClient newQ330ControlSocket() {
int port = Integer.valueOf(getQ330DataPort()) * 2 + Q330BASEPORT;
System.out.println(port);
try {
q330inetaaddress = InetAddress.getByName(getQ330Address());
q330controlsocket = new UDPClient(q330inetaaddress, port, 5500);
q330controlsocket.setTimeOut(5000);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
}
return q330controlsocket;
}
public UDPClient newQ330DataSocket() {
int port = Integer.valueOf(getQ330DataPort()) * 2 + Q330BASEPORT + 1;
System.out.println(port);
try {
q330inetaaddress = InetAddress.getByName(getQ330Address());
q330datasocket = new UDPClient(q330inetaaddress, port, 5501);
q330datasocket.setTimeOut(5000);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
}
return q330datasocket;
}
public UDPClient getQ330DataSocket() {
return q330datasocket;
}
public UDPClient getQ330ControlSocket() {
return q330controlsocket;
}
public void setQ330DataSocket(UDPClient socket) {
q330datasocket = socket;
}
public void setQ330ControlSocket(UDPClient socket) {
q330controlsocket = socket;
}
public void setCalcDataset() {
System.out.println("calcdatastartindex = " + calcdatastartindex);
System.out.println("calcdatastopindex = " + calcdatastopindex);
calcdatalenght = calcdatastopindex - calcdatastartindex;
System.out.println("calcdatalenght = " + calcdatalenght);
dataset.bits = Double.valueOf(tableBits);
dataset.volts = Double.valueOf(tableVolts);
dataset.freeperiod = Double.valueOf(tableFreePeriod);
dataset.damping = Double.valueOf(tableDamping);
dataset.displacement = Double.valueOf(tableDisplacement);
if (dataset.axis == "HHZ") {
dataset.samplerate = 200; // temporaire
dataset.Init(calcdatalenght);
System.arraycopy(buffers.hhz.samples, calcdatastartindex, dataset.samples, 0, calcdatalenght);
System.arraycopy(buffers.hhz.times, calcdatastartindex, dataset.times, 0, calcdatalenght);
}else if (dataset.axis == "HHN") {
dataset.samplerate = 200; // temporaire
dataset.Init(calcdatalenght);
System.arraycopy(buffers.hhn.samples, calcdatastartindex, dataset.samples, 0, calcdatalenght);
System.arraycopy(buffers.hhn.times, calcdatastartindex, dataset.times, 0, calcdatalenght);
}else if (dataset.axis == "HHE") {
dataset.samplerate = 200; // temporaire
dataset.Init(calcdatalenght);
System.arraycopy(buffers.hhe.samples, calcdatastartindex, dataset.samples, 0, calcdatalenght);
System.arraycopy(buffers.hhe.times, calcdatastartindex, dataset.times, 0, calcdatalenght);
}else if (dataset.axis == "BHZ") {
dataset.samplerate = 20; // temporaire
dataset.Init(calcdatalenght);
System.arraycopy(buffers.bhz.samples, calcdatastartindex, dataset.samples, 0, calcdatalenght);
System.arraycopy(buffers.bhz.times, calcdatastartindex, dataset.times, 0, calcdatalenght);
}else if (dataset.axis == "BHN") {
dataset.samplerate = 20; // temporaire
dataset.Init(calcdatalenght);
System.arraycopy(buffers.bhn.samples, calcdatastartindex, dataset.samples, 0, calcdatalenght);
System.arraycopy(buffers.bhn.times, calcdatastartindex, dataset.times, 0, calcdatalenght);
}else if (dataset.axis == "BHE") {
dataset.samplerate = 20; // temporaire
dataset.Init(calcdatalenght);
System.arraycopy(buffers.bhe.samples, calcdatastartindex, dataset.samples, 0, calcdatalenght);
System.arraycopy(buffers.bhe.times, calcdatastartindex, dataset.times, 0, calcdatalenght);
}
}
public static void main(String[] args) {
jSeisCalModel test = new jSeisCalModel();
}
}