page13
C++ Code
- implement RT actions
- build class library
void GenerateRandomNumber::execute(fesa::RTEvent* pEvt)
{
std::vector<Device*>::iterator device;
for(device=deviceCol_.begin();device!=deviceCol_.end();++device)
{
// get upper limit for random-numbers from internal field
int32_t rand_max = (*device)->randomNumberMax.get(pEvt->getMultiplexingContext());
// generate random-number between 0 and rand_max
int32_t rand_number = rand() % ( rand_max + 1 );
// produce some output
std::ostringstream message;
message << " Produced random number: " << rand_number << " for device: " << (*device)->getName();
LOG_TRACE_IF(logger, message.str());
std::cout << message.str() << std::endl;
// save produced random-number in internal field
(*device)->randomNumber.set(rand_number,pEvt->getMultiplexingContext());
}
}
As next step we will add some C++ code in order to generate the random-numbers itself. To do so, open the file “HandsOnClass/src/HandsOnClass/RealTime/GenerateRandomNumber.cpp” from the Eclipse-Project-Explorer and modify it, according to the source-code below.
After you finished the implementation you can compile your FESA class library. Go to the project folder and execute the make target „all x86_64“. This can be done in Eclipse using the „Make Targets“ view in the FESA or C++ perspective.
By executing the target „clean“ you can remove all object files and libraries from previous builds.
You may want to copy + paste this source code!