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
|
#ifndef RSPREADER_H
#define RSPREADER_H
#include <fstream>
#include "../util/logger.h"
#include "../structures/timefrequencydata.h"
#include "../structures/timefrequencymetadata.h"
class RSPReader {
public:
explicit RSPReader(const std::string& rawFile)
: _rawFile(rawFile), _clockSpeed(200000000) {}
~RSPReader() {}
std::pair<TimeFrequencyData, TimeFrequencyMetaDataPtr> ReadChannelBeamlet(
unsigned long timestepStart, unsigned long timestepEnd,
unsigned beamletCount, unsigned beamletIndex);
std::pair<TimeFrequencyData, TimeFrequencyMetaDataPtr> ReadSingleBeamlet(
unsigned long timestepStart, unsigned long timestepEnd,
unsigned beamletCount, unsigned beamletIndex);
std::pair<TimeFrequencyData, TimeFrequencyMetaDataPtr> ReadAllBeamlets(
unsigned long timestepStart, unsigned long timestepEnd,
unsigned beamletCount);
void ReadForStatistics(unsigned beamletCount);
const std::string& File() const { return _rawFile; }
unsigned long TimeStepCount(size_t beamletCount) const;
private:
static const unsigned char BitReverseTable256[256];
static signed short toShort(unsigned char c1, unsigned char c2) {
return (c2 << 8) | c1;
}
static unsigned short toUShort(unsigned char c1, unsigned char c2) {
return (c1 << 8) | c2;
}
static unsigned int toUInt(unsigned char c1, unsigned char c2,
unsigned char c3, unsigned char c4) {
return (c1 << 24) | (c2 << 16) | (c3 << 8) | c4;
}
const std::string _rawFile;
const unsigned long _clockSpeed;
static const unsigned long STATION_INTEGRATION_STEPS;
struct RCPTransportHeader {
unsigned char versionAndHeaderLength : 8;
unsigned char typeOfService : 8;
unsigned short totalLength : 16;
unsigned short identification : 16;
unsigned int flagsAndFragmentOffset : 8;
unsigned int ttl : 8;
unsigned int protocol : 8;
unsigned int headerCrc : 16;
unsigned int sourceIP : 32;
unsigned int destinationIP : 32;
unsigned int udpSourcePort : 16;
unsigned int udpDestPort : 16;
unsigned int udpLength : 16;
unsigned int udpChecksum : 16;
void Print() const {
Logger::Debug << "versionAndHeaderLength=" << versionAndHeaderLength
<< "\n"
<< "typeOfService=" << typeOfService << "\n"
<< "totalLength=" << totalLength << "\n"
<< "identification=" << identification << "\n"
<< "flagsAndFragmentOffset=" << flagsAndFragmentOffset
<< "\n"
<< "ttl=" << ttl << "\n"
<< "protocol=" << protocol << "\n"
<< "headerCrc=" << headerCrc << "\n"
<< "sourceIP=" << sourceIP << "\n"
<< "destinationIP=" << destinationIP << "\n"
<< "udpSourcePort=" << udpSourcePort << "\n"
<< "udpDestPort=" << udpDestPort << "\n"
<< "udpLength=" << udpLength << "\n"
<< "udpChecksum=" << udpChecksum << "\n";
}
};
struct RCPApplicationHeader {
unsigned char versionId;
unsigned char sourceInfo;
unsigned short configurationId;
unsigned short stationId;
unsigned char nofBeamlets;
unsigned char nofBlocks;
unsigned int timestamp;
unsigned int blockSequenceNumber;
static const unsigned int SIZE;
void Read(std::ifstream& stream) {
unsigned char buffer[16];
stream.read(reinterpret_cast<char*>(buffer), 16);
versionId = buffer[0];
sourceInfo = buffer[1];
configurationId = toUShort(buffer[3], buffer[2]);
stationId = toUShort(buffer[5], buffer[4]);
nofBeamlets = buffer[6];
nofBlocks = buffer[7];
timestamp = toUInt(buffer[11], buffer[10], buffer[9], buffer[8]);
blockSequenceNumber =
toUInt(buffer[15], buffer[14], buffer[13], buffer[12]);
}
void Print() const {
Logger::Debug << "versionId=" << (unsigned int)versionId << "\n"
<< "sourceInfo=" << (unsigned int)sourceInfo << "\n"
<< "configurationId=" << (unsigned int)configurationId
<< "\n"
<< "stationId=" << (unsigned int)stationId << "\n"
<< "nofBeamlets=" << (unsigned int)nofBeamlets << "\n"
<< "nofBlocks=" << (unsigned int)nofBlocks << "\n"
<< "timestamp=" << (unsigned int)timestamp << "\n"
<< "blockSequenceNumber="
<< (unsigned int)blockSequenceNumber << "\n";
}
};
struct RCPBeamletData {
signed short xr, xi;
signed short yr, yi;
static const unsigned int SIZE;
void Read(std::ifstream& stream) {
unsigned char buffer[8];
stream.read(reinterpret_cast<char*>(buffer), 8);
xr = toShort(buffer[6], buffer[7]);
xi = toShort(buffer[4], buffer[5]);
yr = toShort(buffer[2], buffer[3]);
yi = toShort(buffer[0], buffer[1]);
}
void Print() {
Logger::Debug << "x=" << xr;
if (xi > 0)
Logger::Debug << "+" << xi << "i";
else
Logger::Debug << "-" << (-xi) << "i";
Logger::Debug << ",y=" << yr;
if (yi > 0)
Logger::Debug << "+" << yi << "i\n";
else
Logger::Debug << "-" << (-yi) << "i\n";
}
};
struct BeamletStatistics {
BeamletStatistics() : totalCount(0) {
for (unsigned i = 0; i < 16; ++i) bitUseCount[i] = 0;
}
void Print() {
for (unsigned bit = 0; bit < 16; ++bit) {
Logger::Info << "Bit " << bit << " times required: " << bitUseCount[bit]
<< " ("
<< (100.0 * (double)bitUseCount[bit] / (double)totalCount)
<< "%)" << '\n';
}
}
unsigned long totalCount;
unsigned long bitUseCount[16];
};
};
#endif // RSPREADER_H
|