-
Notifications
You must be signed in to change notification settings - Fork 0
/
PMS2D.cc
240 lines (176 loc) · 6.52 KB
/
PMS2D.cc
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
/*
-------------------------------------------------------------------------
OBJECT NAME: PMS2D.cc
FULL NAME: PMS2D Probe Class
DESCRIPTION:
COPYRIGHT: University Corporation for Atmospheric Research, 1997-2018
-------------------------------------------------------------------------
*/
#include "PMS2D.h"
#include "OAPUserConfig.h"
#include "portable.h"
using namespace OAP;
const uint32_t PMS2D::StandardSyncWord = 0x55000000;
const uint32_t PMS2D::SyncWordMask = 0xff000000;
/* -------------------------------------------------------------------- */
PMS2D::PMS2D(UserConfig *cfg, const char xml_entry[], int recSize) : Probe(PMS2D_T, cfg, xml_entry, recSize, 32)
{
_lrLen = recSize;
std::string id = ::XMLgetAttributeValue(xml_entry, "id");
strcpy(_code, id.c_str());
_name = ::XMLgetAttributeValue(xml_entry, "type");
_name += ::XMLgetAttributeValue(xml_entry, "suffix");
_resolution = atoi(::XMLgetAttributeValue(xml_entry, "resolution").c_str());
pms2d_init();
printf("PMS2D::OAP id=%s, name=%s, resolution=%zu, armWidth=%f, eaw=%f\n", _code, _name.c_str(), _resolution, _armWidth, _eaw);
}
/* -------------------------------------------------------------------- */
PMS2D::PMS2D(UserConfig *cfg, const char name[]) : Probe(PMS2D_T, cfg, name, 32)
{
pms2d_init();
printf("PMS2D::NoHdr id=%s, name=%s, resolution=%zu, armWidth=%f, eaw=%f\n", _code, _name.c_str(), _resolution, _armWidth, _eaw);
}
/* -------------------------------------------------------------------- */
PMS2D::PMS2D(UserConfig *cfg, Header * hdr, const Pms2 * p, int cnt) : Probe(PMS2D_T, cfg, hdr, p, cnt, 32)
{
pms2d_init();
printf("PMS2D::ADS2 id=%s, name=%s, resolution=%zu, armWidth=%f, eaw=%f\n", _code, _name.c_str(), _resolution, _armWidth, _eaw);
}
void PMS2D::pms2d_init()
{
if (_code[0] == 'C') // 2DC
_armWidth = 61.0;
if (_code[0] == 'P') // 2DP
_armWidth = 261.0;
SetSampleArea();
}
/* -------------------------------------------------------------------- */
bool PMS2D::isSyncWord(const unsigned char *p)
{
return *p == 0x55;
}
/* -------------------------------------------------------------------- */
struct recStats PMS2D::ProcessRecord(const P2d_rec *record, float version)
{
int startTime, overload;
uint32_t *p, pSlice, syncWord, startMilliSec;
bool overloadAdded = false;
double sampleVolume[(nDiodes()<<1)+1], totalLiveTime;
ClearStats(record);
stats.DASelapsedTime = stats.thisTime - _prevTime;
// ADS2 recorded tas encoded, decode here.
if (version < 5.09)
{
stats.tas = stats.tas * 125 / 255;
stats.frequency = Resolution() / stats.tas;
}
stats.SampleVolume = SampleArea() * stats.tas *
(stats.DASelapsedTime - record->overld) * 0.001;
if (version == -1) // This means set time stamp only
{
_prevTime = stats.thisTime;
memcpy((char *)&_prevHdr, (char *)record, sizeof(P2d_hdr));
return(stats);
}
if (version < 3.35)
syncWord = SyncWordMask;
else
syncWord = StandardSyncWord;
#ifdef DEBUG
printf("%02d:%02d:%02d.%d - ", record->hour, record->minute, record->second, record->msec);
#endif
overload = _prevHdr.overld;
totalLiveTime = 0.0;
switch (_userConfig->GetConcentration()) {
case CENTER_IN:
case RECONSTRUCTION: _numBins = 64; break;
default: _numBins = nDiodes();
}
// Compute frequency, which is used to convert timing words from TAS clock
// pulses to milliseconds. Most of sample volume is here, time comes in
// later.
for (size_t i = 0; i < NumberBins(); ++i)
sampleVolume[i] = stats.tas * sampleArea[i] * 0.001;
// Scan record, compute tBarElapsedtime and stats.
p = (uint32_t *)record->data;
pSlice = _prevSlice;
startTime = _prevTime / 1000;
startMilliSec = _prevHdr.msec * 1000;
// Loop through all slices in record.
for (size_t i = 0; i < nSlices(); )
{
if (i > 515 && overloadAdded == false)
{
startMilliSec += overload * 1000;
overloadAdded = true;
}
/* Have particle, will travel.
*/
#ifdef DEBUG
printf("%08x %08x %08x\n", pSlice, p[i], p[i+1]);
#endif
if (pSlice == 0xffffffff && (p[i] & 0x55) == 0x55 && ntohl(p[i+1]) == syncWord)
{
cp->time = startTime;
cp->msec = startMilliSec;
cp->w = 1; // first slice of particle is in sync word
cp->h = 1;
cp->area = 1; // assume at list 1 pixel hidden in sync-word.
cp->timeWord = 0;
if ((ntohl(p[i]) & 0x00ffffff) != 0x00ffffff)
cp->timeWord = ntohl(p[i]) & 0x00ffffff;
cp->deltaTime = (uint32_t)((float)cp->timeWord * stats.frequency);
stats.minBar = std::min(stats.minBar, cp->deltaTime);
stats.maxBar = std::max(stats.maxBar, cp->deltaTime);
if (!cp->timeReject)
stats.tBarElapsedtime += cp->deltaTime;
++stats.nTimeBars;
/* Determine height of particle.
*/
i += 2; // skip time & sync word.
for (; i < nSlices() && p[i] != 0xffffffff && p[i] != 0x55; ++i)
{
++cp->w;
checkEdgeDiodes(cp, (const unsigned char *)&p[i]);
cp->area += area((const unsigned char *)&p[i]);
cp->h = std::max(height((const unsigned char *)&p[i]), cp->h);
}
/* If the particle becomes rejected later, we need to now much time the
* particle consumed, so we can add it to the deadTime, so sampleVolume
* can be reduced accordingly.
*/
cp->liveTime = (uint32_t)((float)(cp->w + 3) * stats.frequency);
cp->msec /= 1000;
// This will not get caught in checkRejectionCriteria(), so do it here.
if (_userConfig->RejectZeroAreaImage() && cp->w == 1 && cp->h == 1)
cp->reject = true;
totalLiveTime += checkRejectionCriteria(cp, stats);
startMilliSec += (cp->deltaTime + cp->liveTime);
stats.particles.push_back(cp);
cp = new Particle();
if (startMilliSec >= 1000000)
{
startMilliSec -= 1000000;
++startTime;
}
}
else
++i;
pSlice = p[i-1];
}
stats.tBarElapsedtime += (uint32_t)(nSlices() * stats.frequency);
if (stats.nTimeBars > 0)
stats.meanBar = stats.tBarElapsedtime / stats.nTimeBars;
stats.tBarElapsedtime /= 1000; // convert to milliseconds
stats.frequency /= 1000;
// Compute "science" data.
totalLiveTime /= 1000000; // convert to seconds
computeDerived(sampleVolume, totalLiveTime);
// Save time for next round.
_prevTime = stats.thisTime;
memcpy((char *)&_prevHdr, (char *)record, sizeof(P2d_hdr));
p = (uint32_t *)record->data;
_prevSlice = p[1023];
return(stats);
} // END PROCESSPMS2D
// END PMS2D.CC