You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.2 KiB
C++

/***************************************************************************
* Copyright (C) 2012 by gempa GmbH *
* *
* All Rights Reserved. *
* *
* NOTICE: All information contained herein is, and remains *
* the property of gempa GmbH and its suppliers, if any. The intellectual *
* and technical concepts contained herein are proprietary to gempa GmbH *
* and its suppliers. *
* Dissemination of this information or reproduction of this material *
* is strictly forbidden unless prior written permission is obtained *
* from gempa GmbH. *
***************************************************************************/
#ifndef GEMPA_CAPS_CUSTOMPACKET_H
#define GEMPA_CAPS_CUSTOMPACKET_H
#include <gempa/caps/packet.h>
#include <gempa/caps/endianess.h>
#include <vector>
namespace Gempa {
namespace CAPS {
class AnyDataRecord : public DataRecord {
public:
typedef std::vector<char> Buffer;
struct AnyHeader {
char type[5];
Header dataHeader;
TimeStamp endTime;
bool get(std::streambuf &buf) {
Endianess::Reader get(buf);
get(type, sizeof(type)-1);
type[sizeof(type)-1] = '\0';
dataHeader.get(buf);
get(endTime.year);
get(endTime.yday);
get(endTime.hour);
get(endTime.minute);
get(endTime.second);
get(endTime.usec);
return get.good;
}
bool put(std::streambuf &buf) const;
// 4 additional bytes (type) with respect to the original
// data header
int dataSize() const {
return sizeof(type)-1 +
dataHeader.dataSize() +
sizeof(endTime.year) +
sizeof(endTime.yday) +
sizeof(endTime.hour) +
sizeof(endTime.minute) +
sizeof(endTime.second) +
sizeof(endTime.usec);
}
};
AnyDataRecord();
//! Sets the format of the any record. The format can be
//! anything that fits into 4 characters. If more than
//! 4 characters are given, false is returned.
bool setType(const char *type);
const char *type() const;
virtual const char *formatName() const;
virtual bool readMetaData(std::streambuf &buf, int size,
Header &header,
Time &startTime,
Time &endTime);
virtual const Header *header() const;
virtual Time startTime() const;
virtual Time endTime() const;
virtual bool canTrim() const;
virtual bool canMerge() const;
virtual bool trim(const Time &start,
const Time &end) const;
virtual size_t dataSize(bool withHeader) const;
virtual ReadStatus get(std::streambuf &buf, int size,
const Time &start = Time(),
const Time &end = Time(),
int maxSize = -1);
virtual bool put(std::streambuf &buf, bool withHeader) const;
/**
* @brief Returns the packet type
* @return The packet type
*/
PacketType packetType() const { return ANYPacket; }
/**
* @brief Sets the start time of the record
* @param The start time
*/
void setStartTime(const Time &time);
/**
* @brief Sets the end time of the record
* @param The end time
*/
void setEndTime(const Time &time);
/**
* @brief Sets the sampling frequency of the record
* @param numerator The numerator
* @param denominator The denomintor
*/
void setSamplingFrequency(uint16_t numerator, uint16_t denominator);
/**
* @brief Returns the data vector to be filled by the caller
* @return The pointer to the internal buffer
*/
Buffer *data() { return &_data; }
/**
* @brief Initializes the internal data vector from the given buffer
* @param The buffer to read the data from
* @param The buffer size
*/
virtual void setData(char *data, size_t size);
protected:
AnyHeader _header;
Buffer _data;
Time _startTime;
Time _endTime;
};
}
}
#endif