INET Framework for OMNeT++/OMNEST
inet::serializer::Ieee80211PhySerializer Class Reference

#include <Ieee80211PhySerializer.h>

Public Member Functions

bool serialize (const inet::physicallayer::Ieee80211PLCPFrame *plcpHeader, BitVector *serializedPacket) const
 
inet::physicallayer::Ieee80211PLCPFramedeserialize (BitVector *serializedPacket) const
 

Protected Member Functions

void writeToBitVector (unsigned char *buf, unsigned int bufSize, BitVector *bitVector) const
 

Member Function Documentation

Ieee80211PLCPFrame * inet::serializer::Ieee80211PhySerializer::deserialize ( BitVector serializedPacket) const

Referenced by inet::physicallayer::Ieee80211LayeredOFDMReceiver::createCompletePacketModel().

70 {
71  // TODO: Revise this code snippet and optimize
72  // FIXME: We only have OFDM deserializer
73  unsigned char *hdrBuf = new unsigned char[OFDM_PLCP_HEADER_LENGTH];
74  const std::vector<uint8>& bitFields = serializedPacket->getBytes();
75  for (int i = 0; i < OFDM_PLCP_HEADER_LENGTH; i++)
76  hdrBuf[i] = bitFields[i];
77  Ieee80211OFDMPLCPHeader *hdr = (Ieee80211OFDMPLCPHeader *) hdrBuf;
78  Ieee80211OFDMPLCPFrame *plcpFrame = new Ieee80211OFDMPLCPFrame();
79  plcpFrame->setRate(hdr->rate);
80  plcpFrame->setLength(hdr->length);
81  plcpFrame->setType(OFDM);
82  unsigned char *buf = new unsigned char[hdr->length + OFDM_PLCP_HEADER_LENGTH];
83  for (int i = 0; i < hdr->length + OFDM_PLCP_HEADER_LENGTH; i++)
84  buf[i] = bitFields[i];
85  Ieee80211Serializer serializer;
86  Buffer subBuffer(buf + OFDM_PLCP_HEADER_LENGTH, hdr->length);
87  Context c;
88  cPacket *payload = serializer.deserializePacket(subBuffer, c);
89  plcpFrame->setBitLength(OFDM_PLCP_HEADER_LENGTH);
90  plcpFrame->encapsulate(payload);
91 // ASSERT(plcpFrame->getBitLength() == OFDM_PLCP_HEADER_LENGTH + 8 * hdr->length);
92  delete[] buf;
93  delete[] hdrBuf;
94  return plcpFrame;
95 }
Definition: Ieee80211PLCPHeaders.h:28
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
#define OFDM_PLCP_HEADER_LENGTH
Definition: Ieee80211PLCPHeaders.h:24
bool inet::serializer::Ieee80211PhySerializer::serialize ( const inet::physicallayer::Ieee80211PLCPFrame plcpHeader,
BitVector serializedPacket 
) const

Referenced by inet::physicallayer::Ieee80211LayeredOFDMTransmitter::serialize().

30 {
31  if (plcpHeader->getType() == OFDM)
32  {
33  const Ieee80211OFDMPLCPFrame *ofdmPhyFrame = check_and_cast<const Ieee80211OFDMPLCPFrame *>(plcpHeader);
34  unsigned int byteLength = ofdmPhyFrame->getByteLength(); // Byte length of the complete frame
35  unsigned char *buf = new unsigned char[byteLength];
36  for (unsigned int i = 0; i < byteLength; i++)
37  buf[i] = 0;
38  Buffer b(buf, byteLength);
39  Ieee80211OFDMPLCPHeader *hdr = (Ieee80211OFDMPLCPHeader *) b.accessNBytes(OFDM_PLCP_HEADER_LENGTH);
40  ASSERT(hdr);
41  hdr->length = ofdmPhyFrame->getLength(); // Byte length of the payload
42  hdr->rate = ofdmPhyFrame->getRate();
43  hdr->parity = 0; // TODO What is the correct value for this? Check the reference.
44  hdr->reserved = 0;
45  hdr->service = 0;
46  hdr->tail = 0;
47  Ieee80211Frame *encapsulatedPacket = check_and_cast<Ieee80211Frame*>(ofdmPhyFrame->getEncapsulatedPacket());
48  Ieee80211Serializer ieee80211Serializer;
49  // Here we just write the header which is exactly 5 bytes in length.
50  Buffer subBuffer(b, b.getRemainingSize());
51  Context c;
52  ieee80211Serializer.serializePacket(encapsulatedPacket, subBuffer, c);
53  b.accessNBytes(subBuffer.getPos());
54  unsigned int numOfWrittenBytes = b.getPos();
55  // TODO: This assertion must hold!
56 // ASSERT(numOfWrittenBytes == byteLength);
57  writeToBitVector(buf, numOfWrittenBytes, serializedPacket);
58  // KLUDGE: if numOfWrittenBytes != byteLength it causes runtime error at the physical layer
59  int pad = byteLength - numOfWrittenBytes;
60  if (pad > 0)
61  serializedPacket->appendBit(false, pad * 8);
62  serializedPacket->appendBit(0, 6); // tail bits
63  delete[] buf;
64  return true;
65  }
66  return false;
67 }
Definition: Ieee80211PLCPHeaders.h:28
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
void writeToBitVector(unsigned char *buf, unsigned int bufSize, BitVector *bitVector) const
Definition: Ieee80211PhySerializer.cc:98
#define OFDM_PLCP_HEADER_LENGTH
Definition: Ieee80211PLCPHeaders.h:24
value< double, units::m > b
Definition: Units.h:1054
void inet::serializer::Ieee80211PhySerializer::writeToBitVector ( unsigned char *  buf,
unsigned int  bufSize,
BitVector bitVector 
) const
protected
99 {
100  for (unsigned int i = 0; i < bufSize; i++)
101  {
102  unsigned int currentByte = buf[i];
103  for (unsigned int j = 0; j < 8; j++)
104  {
105  bool currentBit = currentByte & (1 << j);
106  bitVector->appendBit(currentBit);
107  }
108  }
109 }

The documentation for this class was generated from the following files: