VR-Forces 4.0.4 Class Documentation
DtMyCommsModel

myCommsModel.h

/*******************************************************************************
** Copyright (c) 2011 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: myCommsModel.h,v $ $Revision: 1.1 $ $State: Exp $
** Created: 9/16/11 MEM
*******************************************************************************/

//\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

#include "vrfobjcore/simpleRadioCommModel.h"

const char MyCommModelType[] = "my-comm-model";

class  MyCommModel : public DtSimpleRadioCommModel
{
private:
   //Not implemented.
   MyCommModel();
   MyCommModel(const MyCommModel& orig);
   MyCommModel& operator=(const MyCommModel& orig);

protected:
   //Use the create() method instead of calling the constructor.
   MyCommModel(DtCommModelCreationParams& params);
   //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.
   static DtCommModel* create(DtCommModelCreationParams& params);

   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(DtVrfObject* sender, DtVrfObject* receiver);

protected:

};

myCommsModel.cxx

/*******************************************************************************
** Copyright (c) 2011 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: myCommsModel.cxx,v $ $Revision: 1.1 $ $State: Exp $
** Created: 9/29/11 MEM
*******************************************************************************/

#include "myCommsModel.h"

#include "vrfobjcore/vrfRadio.h"
#include "vrfobjcore/vrfObject.h"
#include "vrfcore/simMgr.h"
#include "vrfobjcore/baseRadio.h"
#include "vrfobjcore/vrfObjMgr.h"
#include "vrfobjcore/vrfObjSR.h"
#include "vrfobjcore/vrfRadioTransmitter.h"
#include "vrfobjcore/vrfObjectCommunicationInterface.h"
#include <vl/radioXmitSR.h>

MyCommModel::MyCommModel(DtCommModelCreationParams& params) :
   DtSimpleRadioCommModel(params)
{
}

bool MyCommModel::init()
{
   if (!DtSimpleRadioCommModel::init())
   {
      return false;
   }

   return true;
}

MyCommModel::~MyCommModel()
{
}

DtString MyCommModel::type() const
{
   return MyCommModelType;
}

void MyCommModel::registerRadio(DtVrfRadio* radio)
{
   DtSimpleRadioCommModel::registerRadio(radio);
   //Put in anything the radio needs to do to become ready to send if desired.
}

DtCommModel* MyCommModel::create(DtCommModelCreationParams& params)
{
   MyCommModel* val = new MyCommModel(params);
   if (val->init())
   {
      return val;
   }
   delete val;
   return 0;
}

bool MyCommModel::checkRadioConnectivity(DtVrfObject* sender, DtVrfObject* receiver)
{
   //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.
      DtVrfRadio * senderRad = dynamic_cast<DtVrfRadio*>(sender->communicationInterface()->defaultRadio());
      DtVrfRadio * recRad = dynamic_cast<DtVrfRadio*>(receiver->communicationInterface()->defaultRadio());

      if ( senderRad && recRad && senderRad->radioTransmitter() && senderRad->radioTransmitter()->transmitterStateRepository() )
      {
         //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->radioTransmitter()->transmitterStateRepository()->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->radioTransmitter()->transmitterStateRepository()->worldAntennaLoc();
         DtVector receiverAntennaPos = recRad->radioTransmitter()->transmitterStateRepository()->worldAntennaLoc();
         double range = DtDistSqr(senderAntennaPos,receiverAntennaPos);
         if ( range > 0.0 )
         {             
            power = senderPower/range;
            DtInfo("Range squared between radios is %f, sender radio power is %f\n", range,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("Receiver too far away to receive message\n");
            bRet = false;
         }
      }
   }
   return bRet;
}



Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)