-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.cr1
453 lines (410 loc) · 15.4 KB
/
default.cr1
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
' BioFiltro Study GHG Logger
' Patrick O'Keeffe <pokeeffe@wsu.edu>
' https://github.com/patricktokeeffe/2022-biofiltro-logger
'
'Copyright 2022 - Patrick O'Keeffe for Washington State University
'
'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.
ConstTable(Constants) 'HINT named so can modify via LoggerNet
Const UTC_OFFSET = -8 'hrs, logger offset relative to UTC time
Const PAR_MULT As Float = -197.63 'unique sensor calibration, umol/(mV s m^2) - NEGATIVE for LI-190SA wiring convention
EndConstTable
Const CH4_COM = Com2
Const CH4_BAUD = 115200
Const CH4_FMT = 3 '8/n/1
Const CH4_BUFF = 800
Const N2O_COM = Com3
Const N2O_BAUD = 115200
Const N2O_FMT = 3 '8/n/1
Const N2O_BUFF = 800
Const WXT_COM = 7 'C7
Const WXT_SDI = 0 'SDI address
Public WXT_AZIMUTH As Float = 0 'orientation w.r.t. True North, degrees
Units WXT_AZIMUTH = degrees
Const PAR_DF = 1
Const AC_TYPEK_DF = 4
Const GPS_COM = Com1
Const MAX_DRIFT = 500 'ms
Const DAYS_DATA = 14 'how long to store data ON THE CARD? (Ring fill)
Const RTMR = 1
Dim run_state As Boolean 'For triggering data reduction at end of run
Public run_flag As Boolean 'For toggling GHG averaging off/on
Public run_duration As Long
Units run_duration = seconds
Dim disable_ugga As Boolean
Dim ch4_record As String * 400
Dim ugga(25) 'HINT use biofiltro_1Hz table instead of Public to monitor data
'1: date (only year captured) '2: time (only hour captured)
Alias ugga(3) = ugga_CH4 '4: CH4 s.d.
Alias ugga(5) = ugga_H2O '6: H2O s.d.
Alias ugga(7) = ugga_CO2 '8: CO2 s.d.
Alias ugga(9) = ugga_CH4_dry '10: CH4 dry s.d.
Alias ugga(11) = ugga_CO2_dry '12: CO2 dry s.d.
Alias ugga(13) = ugga_cell_P '14: gas P s.d.
Alias ugga(15) = ugga_cell_T '16: gas T s.d.
Alias ugga(17) = ugga_self_T '18: self T s.d.
'19: ringdown #0 '20: ringdown #0 s.d.
'21: ringdown #1 '22: ringdown #1 s.d.
'23: Fit flag '24: MIU valve
'25: MIU description
Units ugga_CH4 = ppm
Units ugga_H2O = ppm
Units ugga_CO2 = ppm
Units ugga_CH4_dry = ppm (dry)
Units ugga_CO2_dry = ppm (dry)
Units ugga_cell_P = Torr
Units ugga_cell_T = degC
Units ugga_self_T = degC
Dim disable_n2o As Boolean
Dim n2o_record As String * 400
Dim n2oco(25) 'HINT use biofiltro_1Hz table instead of Public to monitor data
'1: time (year), '2: time (hour)
Alias n2oco(3) = lgr_CO '4: CO se
Alias n2oco(5) = lgr_N2O '6: N2O se
Alias n2oco(7) = lgr_H2O '8: H2O se
Alias n2oco(9) = lgr_CO_dry '10: CO dry se
Alias n2oco(11) = lgr_N2O_dry '12: N2O dry se
Alias n2oco(13) = lgr_cell_P '14: GasP se
Alias n2oco(15) = lgr_cell_T '16: GasT se
Alias n2oco(17) = lgr_self_T '18: AmbT se
'19: LTC0 (volts) '20: LTCO (volts) se
'21: AIN5 '22: AIN5 se
'23: DetOff '24: DetOff se
'25: Fit_Flag
Units lgr_CO = ppb
Units lgr_N2O = ppb
Units lgr_H2O = ppm
Units lgr_CO_dry = ppb (dry)
Units lgr_N2O_dry = ppb (dry)
Units lgr_cell_P = Torr
Units lgr_cell_T = degC
Units lgr_self_T = degC
Const WXT_NVARS = 9
Dim WXT(WXT_NVARS)
'HINT order of variables in data messages dictates array alias order, see
'Vaisala WXT510 User's Guide, Chap 7 for details on data messages
Alias WXT(1) = WindDir 'aR1, Dm (Wind)
Alias WXT(2) = WindSpeed ' " , Sm
Alias WXT(3) = Tmpr 'aR2, Ta (PTU)
Alias WXT(4) = RH ' " , Ua
Alias WXT(5) = Press ' " , Pa
Alias WXT(6) = Rain_amt 'aR3, Rc (Precip)
Alias WXT(7) = Hail_amt ' " , Hc
Alias WXT(8) = HeaterTmpr 'aR5, Th (Supervisor)
Alias WXT(9) = HeaterVolts ' " , Vh
Units WindDir = degrees
Units WindSpeed = m/s
Units Tmpr = degC
Units RH = percent
Units Press = hPa
Units Rain_amt = mm
Units Hail_amt = hits/cm^2
Units HeaterTmpr = degC
Units HeaterVolts = Vdc
Dim PAR_density
Units PAR_density = umol/(s m^2)
Public LoggerTmpr
Dim PowerIn
Units LoggerTmpr = degC
Units PowerIn = Vdc
Public AC_Tmpr
Units AC_Tmpr = degC
Dim nmea_sentence(2) As String * 110
Dim gps_data(15)
Alias gps_data(1) = latitude_a 'Degrees latitude (+ = North; - = South)
Alias gps_data(2) = latitude_b 'Minutes latitude
Alias gps_data(3) = longitude_a 'Degress longitude (+ = East; - = West)
Alias gps_data(4) = longitude_b 'Minutes longitude
Alias gps_data(5) = speed 'Speed
Alias gps_data(6) = course 'Course over ground
Alias gps_data(7) = magnetic_variation 'Magnetic variation from true north (+ = East; - = West)
Alias gps_data(8) = fix_quality 'GPS fix quality: 0 = invalid, 1 = GPS, 2 = differential GPS, 6 = estimated
Alias gps_data(9) = nmbr_satellites 'Number of satellites used for fix
Alias gps_data(10) = altitude 'Antenna altitude
Alias gps_data(11) = pps 'usec into sec of system clock when PPS rising edge occurs, typically 990,000 once synced
Alias gps_data(12) = dt_since_gprmc 'Time since last GPRMC string, normally less than 1 second
Alias gps_data(13) = gps_ready 'Counts from 0 to 10, 10 = ready
Alias gps_data(14) = max_clock_change 'Maximum value the clock was changed in msec
Alias gps_data(15) = nmbr_clock_change 'Number of times the clock was changed
Units latitude_a = degrees
Units latitude_b = minutes
Units longitude_a = degrees
Units longitude_b = minutes
Units speed = m/s
Units course = degrees
Units magnetic_variation = degrees
Units fix_quality = arb
Units nmbr_satellites = count
Units altitude = m
Units pps = ms
Units dt_since_gprmc = s
Units gps_ready = arb
Units max_clock_change = ms
Units nmbr_clock_change = samples
DataTable(biofiltro_runs,(run_flag <> run_state),-1)
CardOut(0,100)
OpenInterval
Average(1,UTC_OFFSET,IEEE4,UTC_OFFSET=NAN)
FieldNames("UTC_OFFSET")
Units UTC_OFFSET = hours
Sample(1,run_duration,IEEE4)
Average(1,lgr_CO,IEEE4,disable_n2o)
StdDev(1,lgr_CO,IEEE4,disable_n2o)
Average(1,lgr_N2O,IEEE4,disable_n2o)
StdDev(1,lgr_N2O,IEEE4,disable_n2o)
Average(1,lgr_H2O,IEEE4,disable_n2o)
StdDev(1,lgr_H2O,IEEE4,disable_n2o)
Average(1,lgr_CO_dry,IEEE4,disable_n2o)
StdDev(1,lgr_CO_dry,IEEE4,disable_n2o)
Average(1,lgr_N2O_dry,IEEE4,disable_n2o)
StdDev(1,lgr_N2O_dry,IEEE4,disable_n2o)
Average(1,lgr_cell_P,IEEE4,disable_n2o)
StdDev(1,lgr_cell_P,IEEE4,disable_n2o)
Average(1,lgr_cell_T,IEEE4,disable_n2o)
StdDev(1,lgr_cell_T,IEEE4,disable_n2o)
Average(1,lgr_self_T,IEEE4,disable_n2o)
StdDev(1,lgr_self_T,IEEE4,disable_n2o)
Average(1,ugga_CH4,IEEE4,disable_ugga)
StdDev(1,ugga_CH4,IEEE4,disable_ugga)
Average(1,ugga_CO2,IEEE4,disable_ugga)
StdDev(1,ugga_CO2,IEEE4,disable_ugga)
Average(1,ugga_H2O,IEEE4,disable_ugga)
StdDev(1,ugga_H2O,IEEE4,disable_ugga)
Average(1,ugga_CH4_dry,IEEE4,disable_ugga)
StdDev(1,ugga_CH4_dry,IEEE4,disable_ugga)
Average(1,ugga_CO2_dry,IEEE4,disable_ugga)
StdDev(1,ugga_CO2_dry,IEEE4,disable_ugga)
Average(1,ugga_cell_P,IEEE4,disable_ugga)
StdDev(1,ugga_cell_P,IEEE4,disable_ugga)
Average(1,ugga_cell_T,IEEE4,disable_ugga)
StdDev(1,ugga_cell_T,IEEE4,disable_ugga)
Average(1,ugga_self_T,IEEE4,disable_ugga)
StdDev(1,ugga_self_T,IEEE4,disable_ugga)
WindVector(1,WindSpeed,WindDir,IEEE4,(WindDir=NAN OR WindSpeed=NAN),0,0,0)
FieldNames("WindSpeed_Avg,WindDir_vector_Avg,WindDir_Std")
Units WindSpeed_Avg = m/s
Units WindDir_vector_Avg = degrees
Units WindDir_Std = degrees
Average(1,WXT_AZIMUTH,IEEE4,WXT_AZIMUTH=NAN)
Average(1,Tmpr,IEEE4,Tmpr=NAN)
Average(1,RH,IEEE4,RH=NAN)
Average(1,Press,IEEE4,Press=NAN)
StdDev(1,Press,IEEE4,Press=NAN)
'XXXX HINT halved to compensate for calling table twice/update
Totalize(1,Rain_amt/2,IEEE4,Rain_amt=NAN)
FieldNames("Rain_amt_Tot")
Units Rain_amt_Tot = mm
Totalize(1,Hail_amt/2,IEEE4,Hail_amt=NAN)
FieldNames("Hail_amt_Tot")
Units Hail_amt_Tot = hits/cm^2
Average(1,HeaterTmpr,IEEE4,HeaterTmpr=NAN)
Average(1,HeaterVolts,IEEE4,HeaterVolts=NAN)
Average(1,PAR_density,IEEE4,PAR_density=NAN)
StdDev(1,PAR_density,IEEE4,PAR_density=NAN)
Average(1,PAR_MULT,IEEE4,PAR_MULT=NAN)
'HINT constants are anonymous in tables so apply fieldnames & units
FieldNames("PAR_MULT_Avg")
Units PAR_MULT_Avg = umol/(mV s m^2)
Average(1,LoggerTmpr,IEEE4,LoggerTmpr=NAN)
Average(1,AC_Tmpr,IEEE4,AC_Tmpr=NAN)
EndTable
DataTable(biofiltro_1hz,True,-1)
CardOut(0,DAYS_DATA*86400)
DataInterval(0,1,Sec,10)
Sample(1,lgr_CO,IEEE4)
Sample(1,lgr_N2O,IEEE4)
Sample(1,lgr_H2O,IEEE4)
Sample(1,lgr_CO_dry,IEEE4)
Sample(1,lgr_N2O_dry,IEEE4)
Sample(1,lgr_cell_P,IEEE4)
Sample(1,lgr_cell_T,IEEE4)
Sample(1,lgr_self_T,IEEE4)
Sample(1,ugga_CH4,IEEE4)
Sample(1,ugga_CO2,IEEE4)
Sample(1,ugga_H2O,IEEE4)
Sample(1,ugga_CH4_dry,IEEE4)
Sample(1,ugga_CO2_dry,IEEE4)
Sample(1,ugga_cell_P,IEEE4)
Sample(1,ugga_cell_T,IEEE4)
Sample(1,ugga_self_T,IEEE4)
EndTable
'HINT omit Units on previously defined FieldNames() to avoid compiler crash
DataTable(biofiltro_1min,True,-1)
CardOut(0,DAYS_DATA*1440)
DataInterval(0,60,Sec,10)
WindVector(1,WindSpeed,WindDir,IEEE4,(WindDir=NAN OR WindSpeed=NAN),0,0,0)
FieldNames("WindSpeed_Avg,WindDir_vector_Avg,WindDir_Std")
Average(1,WXT_AZIMUTH,IEEE4,WXT_AZIMUTH=NAN)
Average(1,Tmpr,IEEE4,Tmpr=NAN)
Average(1,RH,IEEE4,RH=NAN)
Average(1,Press,IEEE4,Press=NAN)
Totalize(1,Rain_amt,IEEE4,Rain_amt=NAN)
Totalize(1,Hail_amt,IEEE4,Hail_amt=NAN)
Average(1,HeaterTmpr,IEEE4,HeaterTmpr=NAN)
Average(1,HeaterVolts,IEEE4,HeaterVolts=NAN)
Average(1,PAR_density,IEEE4,PAR_density=NAN)
Average(1,PAR_MULT,IEEE4,PAR_MULT=NAN)
'HINT constants are anonymous in tables so apply fieldnames
FieldNames("PAR_MULT_Avg")
Average(1,LoggerTmpr,IEEE4,LoggerTmpr=NAN)
Average(1,AC_Tmpr,IEEE4,AC_Tmpr=NAN)
Average(1,lgr_cell_T,IEEE4,disable_n2o)
Average(1,lgr_self_T,IEEE4,disable_n2o)
Average(1,ugga_cell_T,IEEE4,disable_ugga)
Average(1,ugga_self_T,IEEE4,disable_ugga)
EndTable
DataTable(biofiltro_gps,True,-1)
CardOut(0,DAYS_DATA*1440)
DataInterval(0,60,Sec,10)
Average(1,UTC_OFFSET,IEEE4,UTC_OFFSET=NAN)
FieldNames("UTC_OFFSET")
Sample(15,gps_data(1),IEEE4)
EndTable
DataTable(biofiltro_wxt,True,-1)
CardOut(0,DAYS_DATA*1440*12)
Sample(1,WXT_AZIMUTH,IEEE4)
Sample(1,WindSpeed,IEEE4)
Sample(1,WindDir,IEEE4)
Sample(1,Tmpr,IEEE4)
Sample(1,RH,IEEE4)
Sample(1,Press,IEEE4)
Sample(1,Rain_amt,IEEE4)
Sample(1,Hail_amt,IEEE4)
Sample(1,HeaterTmpr,IEEE4)
Sample(1,HeaterVolts,IEEE4)
EndTable
DisplayMenu("Trailer WA-25012E",-1)
MenuItem("Run flag", run_flag)
SubMenu("Temperature (*C)")
DisplayValue("Ambient", Tmpr)
DisplayValue("AC", AC_Tmpr)
DisplayValue("Logger", LoggerTmpr)
DisplayValue("N2O/CO cell", lgr_cell_T)
DisplayValue("N2O/CO amb", lgr_self_T)
DisplayValue("CH4/CO2 cell", ugga_cell_T)
DisplayValue("CH4/CO2 amb", ugga_self_T)
EndSubMenu
SubMenu("N2O/CO")
DisplayValue("N2O, ppb", lgr_N2O)
DisplayValue("N2O (dry)", lgr_N2O_dry)
DisplayValue("CO, ppb", lgr_CO)
DisplayValue("CO (dry)", lgr_CO_dry)
DisplayValue("H2O, ppm", lgr_H2O)
DisplayValue("Cell P", lgr_cell_P)
DisplayValue("Cell T", lgr_cell_T)
DisplayValue("Amb T", lgr_self_T)
DisplayValue("Fit flag", n2oco(25))
EndSubMenu
SubMenu("CH4/CO2")
DisplayValue("CH4, ppm", ugga_CH4)
DisplayValue("CH4 (dry)", ugga_CH4_dry)
DisplayValue("CO2, ppm", ugga_CO2)
DisplayValue("CO2 (dry)", ugga_CO2_dry)
DisplayValue("H2O, ppm", ugga_H2O)
DisplayValue("Cell P", ugga_cell_P)
DisplayValue("Cell T", ugga_cell_T)
DisplayValue("Self T", ugga_self_T)
DisplayValue("rd0, usec", ugga(19))
DisplayValue("rd1, usec", ugga(21))
DisplayValue("Fit flag", ugga(23))
EndSubMenu
SubMenu("WXT510")
MenuItem("Azimuth", WXT_AZIMUTH)
DisplayValue("WD, deg", WindDir)
DisplayValue("WS, m/s", WindSpeed)
DisplayValue("T, *C", Tmpr)
DisplayValue("RH, %", RH)
DisplayValue("P, hPa", Press)
DisplayValue("Rain, mm", Rain_amt)
DisplayValue("Hail, hits/cm^2", Hail_amt)
DisplayValue("Heater, *C", HeaterTmpr)
DisplayValue("Heater, Vdc", HeaterVolts)
EndSubMenu
SubMenu("GPS")
DisplayValue("Lat deg", latitude_a)
DisplayValue("Lat min", latitude_b)
DisplayValue("Long deg", longitude_a)
DisplayValue("Long min", longitude_b)
DisplayValue("Mag decl.", magnetic_variation)
DisplayValue("Altitude", altitude)
DisplayValue("GPS Ready", gps_ready)
EndSubMenu
DisplayValue("PAR (approx)", PAR_density)
DisplayValue("PowerIn, Vdc", PowerIn)
EndMenu
PipeLineMode
BeginProg
SerialOpen(N2O_COM,N2O_BAUD,N2O_FMT,0,N2O_BUFF)
SerialOpen(CH4_COM,CH4_BAUD,CH4_FMT,0,CH4_BUFF)
Scan (500,mSec,0,0)
SerialIn(n2o_record,N2O_COM,5,&h0A,N2O_BUFF)
If (Len(n2o_record)) Then
SplitStr(n2oco(1),n2o_record,", ",25,6)
disable_n2o = NOT(n2oco(25) = 3) 'HACK - assume Fit_Flag always 3
n2o_record = ""
If (NOT disable_n2o) Then
lgr_CO *= 1000 'ppm --> ppb
lgr_N2O *= 1000
lgr_CO_dry *= 1000
lgr_N2O_dry *= 1000
EndIf
EndIf
SerialIn(ch4_record,CH4_COM,5,&h0A,CH4_BUFF)
If (Len(ch4_record)) Then
SplitStr(ugga(1),ch4_record,", ",25,6)
disable_ugga = NOT(ugga(23) = 3) 'HACK - assume Fit_Flag always 3
ch4_record = ""
EndIf
CallTable(biofiltro_1hz)
If (run_flag) 'During a sampling run...
run_state = run_flag 'ensure data table trigger is false...
run_duration = Timer(RTMR,Sec,0) 'and start/update timer
CallTable(biofiltro_runs) 'and include data in final output.
'When run is ended, wait for next whole second...
ElseIf (run_state AND NOT run_flag) AND TimeIntoInterval(0,1,Sec)
'then with table trigger active (run_state != run_flag)...
CallTable(biofiltro_runs) 'call final data storage...
run_state = run_flag 'then reset flags...
Timer(RTMR,Sec,3) 'and timer for next run.
EndIf
NextScan
SlowSequence
Scan (5,Sec,0,0)
PanelTemp(LoggerTmpr,250)
Battery(PowerIn)
SW12(PowerIn > 12.6)
TCDiff(AC_Tmpr,1,mV2_5,AC_TYPEK_DF,TypeK,LoggerTmpr,True,0,_60Hz,1,0)
SDI12Recorder(WXT(1),WXT_COM,WXT_SDI,"RC!",1,0,-1)
If (WindDir <> NAN) Then
WindDir = (WindDir + WXT_AZIMUTH) MOD 360
EndIf
VoltDiff(PAR_density,1,mV25,PAR_DF,True,0,_60Hz,PAR_MULT,0)
If (PAR_density < 0) Then
PAR_density = 0
EndIf
CallTable(biofiltro_1min)
CallTable(biofiltro_wxt)
NextScan
SlowSequence
Scan(1,Min,1,0)
GPS(gps_data(1),GPS_COM,UTC_OFFSET*3600,MAX_DRIFT,nmea_sentence(1))
CallTable(biofiltro_gps)
NetworkTimeProtocol("",UTC_OFFSET,MAX_DRIFT)
NextScan
EndProg