Newer
Older
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <sstream>
#include "boost/any.hpp"
#include <Specific.hh>
#include <Encoder.hh>
#include <Decoder.hh>
#include <Base_Packet.h>
namespace VAR102 {
static const int VAR_PIXELS_SIZE = 64;
static const int NUM_PDM = 37;
bool pdmVal;
int32_t samplingPar;
int32_t pdmID;
std::vector<int32_t> var_pixels;
PDMBlock() :
pdmVal(bool()), samplingPar(int32_t()), pdmID(int32_t()), var_pixels(
std::vector<int32_t>()) {
}
int32_t telescopeID;
int32_t type;
int32_t subType;
int32_t ssc;
int32_t packetLength;
int32_t year;
int32_t month;
int32_t day;
int32_t hours;
int32_t minutes;
int32_t seconds;
bool validTime;
int32_t timeTagNanosec;
int32_t eventCounter;
bool lid;
bool fibSt;
bool fibCont;
bool fibPuls;
int32_t rgbCont;
int32_t rgbPuls;
int32_t spare_0;
std::vector<PDMBlock> PDMs;
VAR102() :
telescopeID(int32_t()), type(int32_t()), subType(int32_t()), ssc(
int32_t()), packetLength(int32_t()), year(int32_t()), month(
int32_t()), day(int32_t()), hours(int32_t()), minutes(
int32_t()), seconds(int32_t()), validTime(bool()), timeTagNanosec(
int32_t()), eventCounter(int32_t()), lid(bool()), fibSt(
bool()), fibCont(bool()), fibPuls(bool()), rgbCont(
int32_t()), rgbPuls(int32_t()), spare_0(int32_t()), PDMs(
std::vector<PDMBlock>()) {
}
};
}
namespace avro {
template<> struct codec_traits<VAR102::PDMBlock> {
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
static void encode(Encoder &e, const VAR102::PDMBlock &v) {
avro::encode(e, v.pdmVal);
avro::encode(e, v.samplingPar);
avro::encode(e, v.pdmID);
avro::encode(e, v.var_pixels);
}
static void decode(Decoder &d, VAR102::PDMBlock &v) {
if (avro::ResolvingDecoder *rd =
dynamic_cast<avro::ResolvingDecoder*>(&d)) {
const std::vector<size_t> fo = rd->fieldOrder();
for (std::vector<size_t>::const_iterator it = fo.begin();
it != fo.end(); ++it) {
switch (*it) {
case 0:
avro::decode(d, v.pdmVal);
break;
case 1:
avro::decode(d, v.samplingPar);
break;
case 2:
avro::decode(d, v.pdmID);
break;
case 3:
avro::decode(d, v.var_pixels);
break;
default:
break;
}
}
} else {
avro::decode(d, v.pdmVal);
avro::decode(d, v.samplingPar);
avro::decode(d, v.pdmID);
avro::decode(d, v.var_pixels);
}
}
};
template<> struct codec_traits<VAR102::VAR102> {
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
static void encode(Encoder &e, const VAR102::VAR102 &v) {
avro::encode(e, v.telescopeID);
avro::encode(e, v.type);
avro::encode(e, v.subType);
avro::encode(e, v.ssc);
avro::encode(e, v.packetLength);
avro::encode(e, v.year);
avro::encode(e, v.month);
avro::encode(e, v.day);
avro::encode(e, v.hours);
avro::encode(e, v.minutes);
avro::encode(e, v.seconds);
avro::encode(e, v.validTime);
avro::encode(e, v.timeTagNanosec);
avro::encode(e, v.eventCounter);
avro::encode(e, v.lid);
avro::encode(e, v.fibSt);
avro::encode(e, v.fibCont);
avro::encode(e, v.fibPuls);
avro::encode(e, v.rgbCont);
avro::encode(e, v.rgbPuls);
avro::encode(e, v.spare_0);
avro::encode(e, v.PDMs);
}
static void decode(Decoder &d, VAR102::VAR102 &v) {
if (avro::ResolvingDecoder *rd =
dynamic_cast<avro::ResolvingDecoder*>(&d)) {
const std::vector<size_t> fo = rd->fieldOrder();
for (std::vector<size_t>::const_iterator it = fo.begin();
it != fo.end(); ++it) {
switch (*it) {
case 0:
avro::decode(d, v.telescopeID);
break;
case 1:
avro::decode(d, v.type);
break;
case 2:
avro::decode(d, v.subType);
break;
case 3:
avro::decode(d, v.ssc);
break;
case 4:
avro::decode(d, v.packetLength);
break;
case 5:
avro::decode(d, v.year);
break;
case 6:
avro::decode(d, v.month);
break;
case 7:
avro::decode(d, v.day);
break;
case 8:
avro::decode(d, v.hours);
break;
case 9:
avro::decode(d, v.minutes);
break;
case 10:
avro::decode(d, v.seconds);
break;
case 11:
avro::decode(d, v.validTime);
break;
case 12:
avro::decode(d, v.timeTagNanosec);
break;
case 13:
avro::decode(d, v.eventCounter);
break;
case 14:
avro::decode(d, v.lid);
break;
case 15:
avro::decode(d, v.fibSt);
break;
case 16:
avro::decode(d, v.fibCont);
break;
case 17:
avro::decode(d, v.fibPuls);
break;
case 18:
avro::decode(d, v.rgbCont);
break;
case 19:
avro::decode(d, v.rgbPuls);
break;
case 20:
avro::decode(d, v.spare_0);
break;
case 21:
avro::decode(d, v.PDMs);
break;
default:
break;
}
}
} else {
avro::decode(d, v.telescopeID);
avro::decode(d, v.type);
avro::decode(d, v.subType);
avro::decode(d, v.ssc);
avro::decode(d, v.packetLength);
avro::decode(d, v.year);
avro::decode(d, v.month);
avro::decode(d, v.day);
avro::decode(d, v.hours);
avro::decode(d, v.minutes);
avro::decode(d, v.seconds);
avro::decode(d, v.validTime);
avro::decode(d, v.timeTagNanosec);
avro::decode(d, v.eventCounter);
avro::decode(d, v.lid);
avro::decode(d, v.fibSt);
avro::decode(d, v.fibCont);
avro::decode(d, v.fibPuls);
avro::decode(d, v.rgbCont);
avro::decode(d, v.rgbPuls);
avro::decode(d, v.spare_0);
avro::decode(d, v.PDMs);
}
}
// PACKET HEADER
int offset;
for (offset = 0; offset < 11; offset++)
avro::encode(avroencoder, (int32_t) packet[offset].value());
avro::encode(avroencoder, (bool) packet[11].value());
avro::encode(avroencoder, (int32_t) packet[12].value());
avro::encode(avroencoder, (int32_t) packet[13].value());
avro::encode(avroencoder, (bool) packet[14].value());
avro::encode(avroencoder, (bool) packet[15].value());
avro::encode(avroencoder, (bool) packet[16].value());
avro::encode(avroencoder, (bool) packet[17].value());
avro::encode(avroencoder, (int32_t) packet[18].value());
avro::encode(avroencoder, (int32_t) packet[19].value());
avro::encode(avroencoder, (int32_t) packet[20].value());
offset = 21;
// PACKET SOURCE DATA FIELD
avroencoder.arrayStart();
avroencoder.setItemCount(VAR102::NUM_PDM);
for (int i = 0; i < VAR102::NUM_PDM; i++) {
avroencoder.startItem();
avro::encode(avroencoder, (bool) packet[offset++].value());
avro::encode(avroencoder, (int32_t) packet[offset++].value());
avro::encode(avroencoder, (int32_t) packet[offset++].value());
avroencoder.arrayStart();
avroencoder.setItemCount(VAR102::VAR_PIXELS_SIZE);
}
offset += VAR102::VAR_PIXELS_SIZE;
avroencoder.arrayEnd();
}
avroencoder.arrayEnd();
}