#include "block.h" class BitErrCounter : public Block { private: InPort < bool > * in0; InPort < bool > * in1; Result < double > * ber; Result < long > * bits; Result < long > * errors; Parameter < long > * dropbitsPar; Parameter < long > * maxbitsPar; Parameter < long > * maxerrorPar; long maxbits; long maxerror; long bitcounter; long errcounter; public: BitErrCounter(const Blockopt & blockopt) : Block(blockopt) {} void makeParameters() { dropbitsPar = new Parameter < long > (this, "dropbits", 0); maxbitsPar = new Parameter < long > (this, "maxbits", 1000000); maxerrorPar = new Parameter < long > (this, "maxerror", 10000); } void makeIOPorts() { in0 = new InPort < bool > (this, "in0", 1); in1 = new InPort < bool > (this, "in1", 1); } void makeResults() { ber = new Result < double > (this, "ber"); bits = new Result < long > (this, "bits"); errors = new Result < long > (this, "errors"); } void initialize() { maxbits = maxbitsPar->value(); maxerror = maxerrorPar->value(); bitcounter = -dropbitsPar->value(); errcounter = 0; } void progressInfo(std::ostream & os) { os << "bitcounter=" << bitcounter << std::endl; os << "errcounter=" << errcounter << std::endl; os << "ber (so far)=" << double(errcounter) / double(bitcounter) << std::endl; } void go() { bitcounter++; if (in0->read() != in1->read()) { if (bitcounter > 0) { errcounter++; if (errcounter >= maxerror) simend("BitErrCounter max no.of errors reached"); } } if (bitcounter >= maxbits) simend("BitErrCounter max no. of bits reached"); } void finalize() { ber->append(double(errcounter) / double(bitcounter)); bits->append(bitcounter); errors->append(errcounter); } }; PUBLISH(BitErrCounter);