ZT/sources/ExtModules/Seaiolibinterface.cpp

78 lines
2.4 KiB
C++

/*******************************************************************************
* *
* Société de Transports de Montréal. *
* 2012 *
* *
* Projet Zones Tests *
* *
* *
* *
*******************************************************************************/
/*
Description:
Classe qui offre une interface avec la librairie de SeaLevel pour les modules
externes.
*/
/* ************************************************************************** */
/* Revision:
### 20121213 JFM
Verision d'origine.
### YYYYMMDD Description du besoin ou du bug
Description du changement.
*/
/* ************************************************************************** */
#include "Seaiolibinterface.h"
CSeaIOLibInterface::CSeaIOLibInterface():
mIsOpened(false)
{
}
CSeaIOLibInterface::~CSeaIOLibInterface()
{
mSeaMaxInterface.Close();
}
void CSeaIOLibInterface::CloseSeaMaxInterface()
{
mSeaMaxInterface.Close();
}
unsigned int CSeaIOLibInterface::OpenSeaMaxInterface(QString MasterModuleIP)
{
QString Address = "sealevel_tcp://";
Address += MasterModuleIP;
CEngLog::instance()->AddLogString(QString("Connexion aux modules externes : " + Address),1);
if(mSeaMaxInterface.Open(Address.toAscii().data()) < 0)
{
//Try to connect 2 times... sometimes the first connection is not successful
if(mSeaMaxInterface.Open(Address.toAscii().data()) < 0)
{
CEngLog::instance()->AddLogString(QString("").sprintf("Connexion aux modules externes impossible à l'adresse: %s",Address.toAscii().data()),1);
mIsOpened = false;
return RET_ERROR;
}
}
CEngLog::instance()->AddLogString("Connexion aux modules externes établie",3);
mIsOpened = true;
return RET_OK;
}
CSeaMaxLin *CSeaIOLibInterface::GetSeaMaxInterfacePtr()
{
if(mIsOpened == true)
return &mSeaMaxInterface;
else
return NULL;
}