-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-collection.cpp
More file actions
299 lines (270 loc) · 8.89 KB
/
Copy pathdata-collection.cpp
File metadata and controls
299 lines (270 loc) · 8.89 KB
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
/***********************************************************************//**
* @file data-collection.cpp
* @date Feb 3, 2014
* @author Ocean Optics, Inc
*
* This is a command-line utility to perform bulk data-collection via SeaBreeze.
*
* Invocation and arguments: see usage()
*
* To-Do:
*
* - more complex "step" syntax, including support for EDC, NLC, etc:
*
* --step 'cnt=10,integ=100ms,avg=3,delay=50ms,edc=on,nlc=on,boxcar=5'
*
* - or, move to an external file specifying steps (possibly read at STDIN):
*
* <steps>
* <step label="laser" count="1" integ="10ms" averaging="1" delay="0ms" edc="on" nlc="on" boxcar="0" />
* <step label="raman" count="10" integ="100ms" averaging="3" delay="50ms" edc="on" nlc="on" boxcar="5" />
* </steps>
*
* LICENSE:
*
* SeaBreeze Copyright (C) 2014, Ocean Optics Inc
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "globals.h"
#include "api/SeaBreezeWrapper.h"
#include "api/seabreezeapi/SeaBreezeAPIConstants.h"
#include "common/Log.h"
#include "util.h"
#include <string>
#include <vector>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <getopt.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include "tinyxml.h"
#include "tinystr.h"
#include "tinyxml.cpp"
#include "tinystr.cpp"
#include "tinyxmlparser.cpp"
#include "tinyxmlerror.cpp"
#include "cconfig.h"
#include "cconfig.cpp"
#include "gpsparser.cpp"
#include "toolbox.cpp"
#include "cspectrometer.cpp"
#include "radiomanager.cpp"
//#include "BBBiolib.h"
#include "leds.cpp"
#include "crc32.cpp"
#ifdef _WIN32
#include <windows.h>
#endif
using namespace std;
using std::string;
using std::vector;
#define MAX_EEPROM_LENGTH 15
#define MAX_DEVICES 32
#define MAX_PIXELS 2048
////////////////////////////////////////////////////////////////////////////////
// globals
////////////////////////////////////////////////////////////////////////////////
int main()
{
cout << "\n\n\n********************************" << endl;
cout << "********************************" << endl;
cout << "********** microDOAS *********" << endl;
cout << "********************************" << endl;
cout << "********************************" << endl;
cout << "version 2.0 from September 2015" << endl;
cout << "Christoph Kern (ckern@usgs.gov)\n" << endl;
// read the config file
cfg.ReadXML();
// start the GPS or System Timer
if (pthread_mutex_init(&gpslock, NULL) != 0)
{
printf("Error initializing gps/system timer mutex.\n");
return 1;
}
if (cfg.GPS.UseGPS == 1)
{
printf("Booting GPS...\n");
threaderr = pthread_create(&gpsthread, NULL, &start_gps, NULL);
if (threaderr != 0)
{
printf("Error initializing gps thread : %s\n", strerror(threaderr));
return 1;
}
}
else
{
printf("NOT USING A GPS, as per config file. Are you sure?\n");
printf("Using the system time for data acquisition.\n");
threaderr = pthread_create(&gpsthread, NULL, &PopulateSystemTime, NULL);
if (threaderr != 0)
{
printf("Error initializing system timer thread : %s\n", strerror(threaderr));
return 1;
}
sleep(2);
}
if (cfg.GPS.UseGPS == 1)
{
// start GPSLED thread
threaderr = pthread_create(&gpsledthread, NULL, &start_gpsled, NULL);
if (threaderr != 0)
{
printf("Error initializing gps led thread : %s\n", strerror(threaderr));
return 1;
}
// start GPSLOCKLED thread
threaderr = pthread_create(&gpslockledthread, NULL, &start_gpslockled, NULL);
if (threaderr != 0)
{
printf("Error initializing gps lock led thread : %s\n", strerror(threaderr));
return 1;
}
}
// start SHUTDOWNSWITCH thread
threaderr = pthread_create(&shutdownswitchthread, NULL, &start_CheckShutdownSwitch, NULL);
if (threaderr != 0)
{
printf("Error initializing shutdown switch thread : %s\n", strerror(threaderr));
return 1;
}
if (cfg.General.ZipSpectra == 1)
{
// start ZIP thread
threaderr = pthread_create(&zipthread, NULL, &start_zip, NULL);
if (threaderr != 0)
{
printf("Error initializing zip thread : %s\n", strerror(threaderr));
return 1;
}
}
if (cfg.GPS.WaitForLockOnStartup == 0)
{
sleep(5);
}
else
{
printf("Waiting for GPS lock...");
while (1)
{
if (WarnCode == 'A')
{
printf("Got GPS lock!\n");
break;
}
sleep(2);
}
}
if (Date != 0)
{
while (1)
{
printf("Waiting for good date and time info...\n");
if ((Year > 2014) & (Year < 2050))
{
char datestrbfr[15];
string datestrstr;
sprintf(datestrbfr, "%02d%02d%02d%02d%04d.%02d", Month, Day, Hour, Minute, Year, int(round(Second)));
datestrstr = "echo doas | sudo -S date ";
datestrstr += datestrbfr;
//datestrstr += "\"";
printf("Updating system time from GPS: %s\n", datestrstr.c_str());
system(datestrstr.c_str());
break;
}
else
{
sleep(2);
}
}
}
CreateOutputDir();
// set up the radio
int serialErrorCode = radio.open_serial();
string error = "Radio/serial error: ";
switch(serialErrorCode){
case OPEN_SUCCESS:
cout << "Radio/serial: open success\n";
break;
case OPEN_FAIL:
cout << error << serialErrorCode << "failed to open port\n";
break;
case NOT_A_TTY:
cout << error << serialErrorCode << "not a tty port\n";
break;
case GET_CONFIG_FAIL:
cout << error << serialErrorCode << "failed to copy previous config settings\n";
break;
case BAUD_FAILED:
cout << error << serialErrorCode << "failed to apply baud rate\n";
break;
case CONFIG_APPLY_FAIL:
cout << error << serialErrorCode << " failed to apply config settings\n";
break;
default:
cout << error << serialErrorCode << "unknown error\n";
}
// start acquiring spectra
printf("Starting spectral acquisition...\n");
if (pthread_mutex_init(&speclock, NULL) != 0)
{
printf("Error initializing spec mutex.\n");
return 1;
}
threaderr = pthread_create(&specthread, NULL, &start_spec, NULL);
if (threaderr != 0)
{
printf("Error initializing spec thread : %s\n", strerror(threaderr));
return 1;
}
// start SPECLED thread
threaderr = pthread_create(&specledthread, NULL, &start_specled, NULL);
if (threaderr != 0)
{
printf("Error initializing spectrometer led thread : %s\n", strerror(threaderr));
return 1;
}
int userin = fileno(stdin);
//int charcount;
char userinbuf[10];
char quitbuf[10];
int charsread;
set_non_blocking(userin);
while (strcmp(quitbuf, "quit") != 0)
{
charsread = read(userin, userinbuf, sizeof userinbuf);
if (charsread > 0)
{
strncpy(quitbuf, userinbuf, 10);
quitbuf[4] = '\0';
printf("USER INPUT: %s\n", userinbuf);
}
sleep(1);
//printf("Time:[%f]\nDate:[%lu]\nLatitude:[%f]\nLongitude:[%f]\nAltitude:[%f]\nCourse:[%f]\nSpeed:[%f]\nQuality:[%d]\nWarningCode:[%c]\n", Time, Date, Latitude, Longitude, Altitude, Course, Speed, Quality, WarnCode);
}
printf("Exiting microDOAS. Have a nice day.\n");
return 0;
}