VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtMyCommsModel

myCommsModel.h

/*******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//\file myCommsModel.h
//\brief An implementation of DtCommModel that models a simple radio model,
//\using signal interaction as the network transport type.
//\Will check the range between the sender and receiver. If the power of the sender's
//\radio is too weak for the range then the receiver will not get the message.
#pragma once
const char MyCommModelType[] = "my-comm-model";
{
private:
//Not implemented.
MyCommModel(const MyCommModel& orig);
protected:
//Use the create() method instead of calling the constructor.
//Virtual init() called from the create() method.
//Calls createTransporter() to set myTransporter.
virtual bool init();
public:
//Static creator function that can be registered with factories.
//Calls the constructor, and init() on the new instance before returning it.
//The params passed in are those read in from the commModelParams.mtl file for your simulation
//model set. If you'd like to add to these derive a new commModelDescriptor.
virtual ~MyCommModel();
//\return MyCommModelType.
//Type strings for default commModel subclasses are defined in
//commModelTypes.h. Returns MyCommModelType.This is the string that is added to the commModelParams.mtl
//configuration file for the simulation model set being used. Make sure the string returned here
//matches what is in that file.
virtual DtString type() const;
//Overridden from base to set the ReadyToSend status of the radio to
//true as soon as it registers.
virtual void registerRadio(DtVrfRadio* radio);
protected:
//Checks the connectivity of the radios for delivery of message.
//\return True if the message is allowed to be delivered, or false
//of the sender/receiver radios are not connected.
//Results will vary, depending on the current connection mode specified
//in the descriptor--default connection modes are "all"--you can send to any entity regardless of force,
//"force"--you can send to anyone in your force type, or "aggregate"--you can only send to those in your
//same echelon, same aggregate.
//For this example we will simply do a range check and see if the receiver is
//within the power range of the sender's radio.
virtual bool checkRadioConnectivity(DtSimObjectReference sender, DtSimObjectReference receiver) const override;
protected:
};

myCommsModel.cxx

/*******************************************************************************
** Copyright (c) 2011 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include "myCommsModel.h"
using namespace makVrf;
{
}
{
{
return false;
}
return true;
}
{
}
{
}
{
//Put in anything the radio needs to do to become ready to send if desired.
}
{
MyCommModel* val = new MyCommModel(params);
if (val->init())
{
return val;
}
delete val;
return 0;
}
{
//Call parent class first to check connection mode, ie "all", "force", or "aggregate"
//This will check if we are even allow to connect to the receiver at all.
bool bRet = DtSimpleRadioCommModel::checkRadioConnectivity(sender,receiver);
if ( bRet )
{
//Access the radios. If an entity has multiple radios you can lookup particular radios via their name
//in the communication interface via lookupRadio. We will use the default radio.
{
//Simple example check the sender's radio power. Check that the reciever's radio is within range of the sender's radio.
//the transmitterStateRepository is a class inside VR-Link. You'll find it has a lot of different parameters to be used
double senderPower = senderRad->power();
//The entities are configured by default with a power of 30. This value will make the radio effective
//for up to 1km away from each entity.
double minimumRecieverPower = 0.00003;
double power = 0.0;
DtVector senderAntennaPos = senderRad->worldAntennaLoc();
DtVector receiverAntennaPos = recRad->worldAntennaLoc();
double range = DtDistSqr(senderAntennaPos,receiverAntennaPos);
if ( range > 0.0 )
{
power = senderPower/range;
DtInfo("Range squared between receiver %s and sender %s is %f, %s radio power is %f\n", receiver->objectName().c_str(),sender->objectName().c_str(),range,sender->objectName().c_str(),power);
}
//If the calculated power at the reciever's location is greater than our minimum recieving power than we get the message.
if ( power < minimumRecieverPower )
{
DtInfo("%s too far away from %s to receive message\n", receiver->objectName().c_str(), sender->objectName().c_str());
bRet = false;
}
}
}
return bRet;
}

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)