We can adjust the Tx power and Tx rate in Veins, the default data rate is 6Mbps which can be set in .ini, is it possible we adjust the data rate during the simulation? Thank you very much!
1 Answers
The function to set Tx power is public while the function to set bitrate is protected. It means that you cannot set the bitrate if you want to set it in a class that is not a subclass of Mac1609_4
, for example, if you want to set it in application layer (e.g., DemoBaseAppLayer
).
However, if you really want to force it to set bitrate at let's say application layer, here are the steps.
Go to Mac1609_4.h
file (veins/modules/mac/ieee80211p/Mac1609_4.h) and set the function void setParametersForBitrate(uint64_t bitrate);
to be public
instead of protected
.
Then here is the code for setting the Tx power and bitrate that I run and tested in DemoBaseAppLayer.cc
(veins/modules/application/ieee80211p/DemoBaseApplLayer.cc)
Header file to include:
#include "veins/modules/mac/ieee80211p/Mac1609_4.h"
Code for setting tx power and bitrate:
Mac1609_4* mac1609 = FindModule<Mac1609_4*>::findSubModule(getParentModule());
double powerToSet = 5; // 5mW
uint64_t bitrateToSet = 9000000; // 9Mbps
mac1609->setTxPower(powerToSet);
mac1609->setParametersForBitrate(bitrateToSet);
Note that valid bitrates are 3, 4.5, 6, 9, 12, 18, 24 and 27 Mbps.
In order to see more details about accepted bitrates, visit ConstsPhy.h
(in veins/modules/utility/ConstsPhy.h)

- 145
- 1
- 1
- 12
-
Thank you so much! yes, we found sometimes we have to change the protect to public to visit some functions in veins. – Xiaofeng Liu Nov 30 '20 at 16:01