00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef TRANSMISSION_MONITOR_HEADER
00029 #define TRANSMISSION_MONITOR_HEADER
00030
00031
00032 #include <iostream>
00033 #include <fstream>
00034 #include <string>
00035 #include <stdexcept>
00036 #include "misc.h"
00037 #include "phbib.h"
00038 #include "signals.h"
00039 #include "basicdevice.h"
00040
00041
00042
00043
00044 namespace simthlib
00045 {
00046
00047
00058 class TransmissionMonitor : public simth::Device
00059 {
00060 public:
00061
00062 enum InputTypes {BIT_BIT, BIT_LLR, LLR_LLR, LLR_BIT};
00063
00064 long int minBits_;
00065 long int maxBits_;
00066 long int minErrors_;
00067
00068 InputTypes inputCombination;
00069
00070
00071
00072 virtual void setXValue(double newXValue) = 0;
00073 virtual void setX2Value(double newX2Value) = 0;
00074
00075 protected:
00076
00077 long int minBits() const {return minBits_;}
00078 long int maxBits() const {return maxBits_;}
00079 long int minErrors() const {return minErrors_;}
00080
00081 virtual double xValue() const = 0;
00082 virtual double x2Value() const = 0;
00083
00087 virtual void record(const simth::BitSeq& bits,
00088 const simth::BitSeq& recBits) = 0;
00089
00090 void writeGnuplotFile(const std::string& gnuplotFilename,
00091 const std::string& dataFilename, bool append = false);
00092
00093 void writePositionGnuplotFile(const std::string& gnuplotFilename,
00094 const std::string& positionDataFilename,
00095 bool append = false) const;
00096
00097 public:
00098
00101 TransmissionMonitor(int ID, simth::DeviceSystemIntf *syst,
00102 const simth::PropertyList& pl);
00103
00104 virtual long int errors() const = 0;
00105
00106
00118 virtual void record(const simth::BitSeq& bits,
00119 const simth::BitSeq& recBits, double xValue) = 0;
00120
00121 virtual void process();
00122
00123 virtual void updateInputLengths();
00124 virtual void updateOutputLengths();
00125
00127 virtual void refresh();
00128
00129 virtual void print(std::ostream &os) const;
00130
00131 virtual void startOfSimulation();
00132
00133 static void init(const std::string& filename, simth::Device** dev,
00134 simth::DeviceSystemIntf* sysPtr, int ID,
00135 const std::string& regionQualifier = "");
00136 };
00137
00138
00141 class TransmissionMonitorFile : public TransmissionMonitor
00142 {
00143 const std::string errFilename_;
00144
00145
00146
00147 long int numBits;
00148
00149 long int numErrors;
00150
00151
00152
00153 long int currentNumBits_;
00154
00155
00156 long int currentNumErrors_;
00157
00158 long int packetErrors;
00159 long int numPackets;
00160
00161
00162 double currXValue;
00163
00164
00165 double currX2Value;
00166
00167 std::ofstream outStr;
00168
00169 bool isHeaderPrinted;
00170
00171
00172 bool refresh_statistics;
00173 unsigned nr_refresh;
00174 double cumul_ber;
00175 double cumul_ber_squared;
00176
00177 long int countErrors(const simth::BitSeq& bits, const simth::BitSeq& recBits);
00178 void printHeader();
00179
00180 protected:
00181 std::string errFilename() const {return errFilename_;}
00182
00183 virtual double xValue() const {return currXValue;}
00184 virtual double x2Value() const {return currX2Value;}
00185
00186
00187 void writeStoredErrorInfoToFile();
00188
00189 long int currentNumBits() const {return currentNumBits_;}
00190 long int currentNumErrors() const {return currentNumErrors_;}
00191 virtual bool stopSimulation();
00192 virtual void record(const simth::BitSeq& bits,const simth::BitSeq& recBits);
00193 public:
00196 TransmissionMonitorFile(int ID, simth::DeviceSystemIntf *syst, const simth::PropertyList& pl);
00197
00198 virtual ~TransmissionMonitorFile();
00199
00200 virtual long int errors() const {return numErrors;};
00201 virtual void record(const simth::BitSeq& bits,const simth::BitSeq& recBits, double xValue);
00202 virtual void endOfSimulation();
00203
00204 virtual void setXValue(double newXValue);
00205 virtual void setX2Value(double newX2Value);
00206 virtual void refresh();
00207 virtual void reset();
00208 };
00209
00210
00211
00214 class ErrorPositionMonitor : public TransmissionMonitorFile
00215 {
00216 const std::string posFilename;
00217 std::ofstream posStr;
00218 protected:
00219 simth::checkedVector<int> errorPositions;
00224 size_t accumulate_bits;
00225
00226 void writeErrorPositionInfoToFile();
00227 std::string getPosFilename() const {return posFilename;}
00228 public:
00231 ErrorPositionMonitor(int ID, simth::DeviceSystemIntf *syst,
00232 const simth::PropertyList& pl);
00233 virtual ~ErrorPositionMonitor();
00234 virtual void record(const simth::BitSeq& bits,const simth::BitSeq& recBits, double xValue);
00235 virtual void endOfSimulation();
00236 };
00237
00240 class ErrorPositionPipe : public ErrorPositionMonitor
00241 {
00242 public:
00243 ErrorPositionPipe(int ID, simth::DeviceSystemIntf *syst, const simth::PropertyList& pl);
00244 ~ErrorPositionPipe();
00245 void endOfSimulation();
00246
00247 void process();
00248
00249 void updateInputLengths();
00250 void updateOutputLengths();
00251
00252 };
00253
00254
00255
00258 class TransmissionMonitorGnuplot : public TransmissionMonitorFile
00259 {
00260 const std::string gnuplotFilename;
00261 void writeGnuplotFile();
00262 protected:
00263 std::string getGnuplotFilename() const {return gnuplotFilename;}
00264 public:
00265 TransmissionMonitorGnuplot(int ID, simth::DeviceSystemIntf *syst, const simth::PropertyList& pl);
00266
00270 virtual void display() const;
00271
00272 virtual void endOfSimulation();
00273 };
00274
00277 class ErrorPositionMonitorGnuplot : public ErrorPositionMonitor
00278 {
00279 const std::string gnuplotFilename;
00280 const std::string positionGnuplotFilename;
00281 void writeGnuplotFile();
00282 void writePositionGnuplotFile();
00283 protected:
00284 std::string getGnuplotFilename() const {return gnuplotFilename;}
00285 std::string getPositionGnuplotFilename() const {return positionGnuplotFilename;}
00286 public:
00287 ErrorPositionMonitorGnuplot(int ID, simth::DeviceSystemIntf *syst, const simth::PropertyList& pl);
00288
00294 virtual void display() const;
00295
00296 virtual void endOfSimulation();
00297 };
00298
00299
00300 }
00301
00302
00303
00304 #endif
00305
00306
00307
00308
00309
00310
00311