Skip to content
Snippets Groups Projects
cmd151.h 2.75 KiB
Newer Older
Valerio Pastore's avatar
Valerio Pastore committed
/**
 * 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 CMD151 {
struct CMD151 {
Valerio Pastore's avatar
.  
Valerio Pastore committed
	int32_t telescopeID;
	int32_t type;
	int32_t subType;
	int32_t ssc;
	int32_t packetLength;
	int32_t spare;
	int32_t sync;
	CMD151() :
			telescopeID(int32_t()), type(int32_t()), subType(int32_t()), ssc(
					int32_t()), packetLength(int32_t()), spare(int32_t()), sync(
					int32_t()) {
	}
Valerio Pastore's avatar
Valerio Pastore committed
};

}
namespace avro {
template<> struct codec_traits<CMD151::CMD151> {
Valerio Pastore's avatar
.  
Valerio Pastore committed
	static void encode(Encoder &e, const CMD151::CMD151 &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.spare);
		avro::encode(e, v.sync);
	}
	static void decode(Decoder &d, CMD151::CMD151 &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.spare);
					break;
				case 6:
					avro::decode(d, v.sync);
					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.spare);
			avro::decode(d, v.sync);
		}
	}
Valerio Pastore's avatar
Valerio Pastore committed
};
void encodeCMD151(Encoder &avroencoder,
Valerio Pastore's avatar
.  
Valerio Pastore committed
		inaf::oasbo::Packets::BasePacket &packet) {
	// PACKET HEADER
	int offset;
	for (offset = 0; offset < 7; offset++)
		avro::encode(avroencoder, (int32_t) packet[offset].value());
}