Ieee80211SymbolDomainTest.cc 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Copyright (C) 2014 OpenSim Ltd.
  3. //
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public License
  6. // as published by the Free Software Foundation; either version 2
  7. // of the License, or (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. //
  17. #include "Ieee80211SymbolDomainTest.h"
  18. #include "inet/common/ModuleAccess.h"
  19. #include <fstream>
  20. namespace inet {
  21. Define_Module(Ieee80211SymbolDomainTest);
  22. void Ieee80211SymbolDomainTest::initialize(int stage)
  23. {
  24. if (stage == INITSTAGE_LOCAL)
  25. {
  26. ieee80211OFDMSignalEncoder = getModuleFromPar<Ieee80211OFDMEncoderModule>(par("ieee80211OFDMSignalEncoderModule"), this);
  27. ieee80211OFDMDataEncoder = getModuleFromPar<Ieee80211OFDMEncoderModule>(par("ieee80211OFDMDataEncoderModule"), this);
  28. ieee80211OFDMSignalModulator = getModuleFromPar<Ieee80211OFDMModulatorModule>(par("ieee80211OFDMSignalModulatorModule"), this);
  29. ieee80211OFDMDataModulator = getModuleFromPar<Ieee80211OFDMModulatorModule>(par("ieee80211OFDMDataModulatorModule"), this);
  30. ieee80211OFDMSignalDemodulator = getModuleFromPar<Ieee80211OFDMDemodulatorModule>(par("ieee80211OFDMSignalDemodulatorModule"), this);
  31. ieee80211OFDMDataDemodulator = getModuleFromPar<Ieee80211OFDMDemodulatorModule>(par("ieee80211OFDMDataDemodulatorModule"), this);
  32. ieee80211OFDMSignalDecoder = getModuleFromPar<Ieee80211OFDMDecoderModule>(par("ieee80211OFDMSignalDecoderModule"), this);
  33. ieee80211OFDMDataDecoder = getModuleFromPar<Ieee80211OFDMDecoderModule>(par("ieee80211OFDMDataDecoderModule"), this);
  34. parseInput(par("testFile").stringValue());
  35. }
  36. else if (stage == INITSTAGE_LAST)
  37. {
  38. test();
  39. }
  40. }
  41. void Ieee80211SymbolDomainTest::parseInput(const char* fileName)
  42. {
  43. std::ifstream file(fileName);
  44. std::string in;
  45. while (file >> in)
  46. {
  47. for (unsigned int i = 0; i < in.size(); i++)
  48. {
  49. if (in.at(i) == '0')
  50. input.appendBit(false);
  51. else if (in.at(i) == '1')
  52. input.appendBit(true);
  53. else
  54. throw cRuntimeError("Unexpected input format = %s", in.c_str());
  55. }
  56. }
  57. }
  58. void Ieee80211SymbolDomainTest::test() const
  59. {
  60. BitVector *signalField = new BitVector();
  61. BitVector *dataField = new BitVector();
  62. for (unsigned int i = 0; i < 24; i++)
  63. signalField->appendBit(input.getBit(i));
  64. for (unsigned int i = 24; i < input.getSize(); i++)
  65. dataField->appendBit(input.getBit(i));
  66. TransmissionPacketModel signalPacketModel(NULL, signalField, bps(NaN));
  67. TransmissionPacketModel dataPacketModel(NULL, dataField, bps(NaN));
  68. const ITransmissionBitModel *signalBitModel = ieee80211OFDMSignalEncoder->encode(&signalPacketModel);
  69. const ITransmissionBitModel *dataBitModel = ieee80211OFDMDataEncoder->encode(&dataPacketModel);
  70. const ITransmissionSymbolModel *transmissionSignalSymbolModel = ieee80211OFDMSignalModulator->modulate(signalBitModel);
  71. const ITransmissionSymbolModel *transmissionDataSymbolModel = ieee80211OFDMDataModulator->modulate(dataBitModel);
  72. ReceptionSymbolModel receptionSignalSymbolModel(0, 0, 0, 0, new std::vector<const ISymbol *>(*transmissionSignalSymbolModel->getSymbols()));
  73. const IReceptionBitModel *receptionSignalBitModel = ieee80211OFDMSignalDemodulator->demodulate(&receptionSignalSymbolModel);
  74. ReceptionSymbolModel receptionDataSymbolModel(0, 0, 0, 0, new std::vector<const ISymbol *>(*transmissionDataSymbolModel->getSymbols()));
  75. const IReceptionBitModel *receptionDataBitModel = ieee80211OFDMDataDemodulator->demodulate(&receptionDataSymbolModel);
  76. const IReceptionPacketModel *receptionSignalPacketModel = ieee80211OFDMSignalDecoder->decode(receptionSignalBitModel);
  77. const IReceptionPacketModel *receptionDataPacketModel = ieee80211OFDMDataDecoder->decode(receptionDataBitModel);
  78. delete dataBitModel;
  79. delete signalBitModel;
  80. delete transmissionDataSymbolModel;
  81. delete transmissionSignalSymbolModel;
  82. delete receptionDataBitModel;
  83. delete receptionSignalBitModel;
  84. delete receptionDataPacketModel;
  85. delete receptionSignalPacketModel;
  86. }
  87. } /* namespace inet */