summaryrefslogtreecommitdiff
path: root/maximus
diff options
context:
space:
mode:
Diffstat (limited to 'maximus')
-rw-r--r--maximus/common/interfaces/IFunctionCall.h2
-rw-r--r--maximus/common/types/sci_types.h2
-rw-r--r--maximus/coreengine/inc/CoreEngine.h4
-rw-r--r--maximus/coreengine/src/CoreEngine.cpp55
-rw-r--r--maximus/coreengine/src/main.cpp1
-rw-r--r--maximus/functioncall/inc/FunctionCallManager.h23
-rw-r--r--maximus/functioncall/inc/FunctionSciMsg.h20
-rw-r--r--maximus/functioncall/src/FunctionCallManager.cpp85
-rw-r--r--maximus/functioncall/src/FunctionCallParameter.cpp38
-rw-r--r--maximus/functioncall/src/FunctionSciMsg.cpp159
-rw-r--r--maximus/functioncall/src/FunctionSciMsgTest.cpp2
-rw-r--r--maximus/functioncall/src/IFunctionCallTest.cpp4
-rw-r--r--maximus/networkclock/inc/ClockSciMsg.h6
-rw-r--r--maximus/networkclock/inc/NetworkClockProcessor.h2
-rw-r--r--maximus/networkclock/src/ClockSciMsg.cpp8
-rw-r--r--maximus/networkclock/src/NetworkClockProcessor.cpp95
-rw-r--r--maximus/phy/inc/PhyProcessor.h12
-rw-r--r--maximus/phy/inc/PhySciMsg.h6
-rw-r--r--maximus/phy/src/PhyProcessor.cpp15
-rw-r--r--maximus/phy/src/PhySciMsg.cpp6
-rw-r--r--maximus/sci/inc/SciMsg.h6
-rw-r--r--maximus/sci/inc/SciServer.h15
-rw-r--r--maximus/sci/src/SciMsg.cpp7
-rw-r--r--maximus/sci/src/SciServer.cpp117
-rw-r--r--maximus/system/inc/SystemSciMsg.h6
-rw-r--r--maximus/system/src/Station.cpp4
-rw-r--r--maximus/system/src/SystemSciMsg.cpp6
27 files changed, 368 insertions, 338 deletions
diff --git a/maximus/common/interfaces/IFunctionCall.h b/maximus/common/interfaces/IFunctionCall.h
index 7309e0af10..cd875701f6 100644
--- a/maximus/common/interfaces/IFunctionCall.h
+++ b/maximus/common/interfaces/IFunctionCall.h
@@ -74,7 +74,7 @@ public:
* @param function_sci_msg
* @param callback_address
*/
- virtual bool registerCallback ( const char * callback_name, callbackFunction callback_address ) = 0;
+ virtual bool registerCallback ( std::string callback_name, callbackFunction callback_address ) = 0;
/**
* @return bool
diff --git a/maximus/common/types/sci_types.h b/maximus/common/types/sci_types.h
index 45fbace4b1..f778e9e5ae 100644
--- a/maximus/common/types/sci_types.h
+++ b/maximus/common/types/sci_types.h
@@ -44,7 +44,7 @@ struct Sci_Msg_Header
uint16_t station_id; /* 5th field is station id (16 bits): source or destination station id; in general, the process id of the simulated station */
uint16_t msg_id; /* 6th field is msg id (16 bits): unique message id for each station – simulator transaction
0x0001-0x7fff: request created by simulator
- 0x8000-0xfffe: request created by a station */
+ 0x8000-0xffff: request created by a station */
uint32_t netclock_high; /* 7th field is netclock high: high part of 64 bits NetClock value */
uint32_t netclock_low; /* 8th field is netclock low: low part of 64 bits NetClock value */
uint16_t flags; /* 9th and last field is flags (16 bits): Sci_Msg_Flag */
diff --git a/maximus/coreengine/inc/CoreEngine.h b/maximus/coreengine/inc/CoreEngine.h
index 928238fbfd..611e7d0319 100644
--- a/maximus/coreengine/inc/CoreEngine.h
+++ b/maximus/coreengine/inc/CoreEngine.h
@@ -38,6 +38,10 @@ class FunctionCallManager;
class NetworkClockProcessor;
class SystemManager;
class SciServer;
+class FunctionSciMsg;
+
+
+void maximus_print ( FunctionSciMsg & function_sci_msg );
/**
diff --git a/maximus/coreengine/src/CoreEngine.cpp b/maximus/coreengine/src/CoreEngine.cpp
index 9497ae11fe..6046bac436 100644
--- a/maximus/coreengine/src/CoreEngine.cpp
+++ b/maximus/coreengine/src/CoreEngine.cpp
@@ -35,12 +35,19 @@ The original location of this file is /home/buret/eclipse/maximus/coreengine/src
#include "SystemManager.h"
#include "SciServer.h"
#include "Error.h"
-#include "Station.h"
+#include "FunctionCallParameter.h"
+#include "FunctionSciMsg.h"
#include <iostream> // for 'cout', 'cerr' and 'clog'
using namespace std;
+void maximus_function_call_test ( FunctionSciMsg & function_sci_msg )
+{
+ clog << "=> maximus_function_call_test" << endl;
+}
+
+
// Constructors/Destructors
//
@@ -146,17 +153,61 @@ void CoreEngine::run ( )
{
clog << "CoreEngine::run" << endl;
+ // FOR TESTS PURPOSE ONLY, TO REMOVE
+ //
try
{
Sci_Msg_Station_Id stationId = mpSystemManager->createStation(); // FOR TESTS PURPOSE ONLY, TO REMOVE
if (0 != stationId)
{
+ // Test function call
+ //
+ FunctionSciMsg * functionSciMsg = mpFunctionCallManager->createMsg();
+ mpFunctionCallManager->registerCallback("function_call_test", &maximus_function_call_test);
+ functionSciMsg->setFunctionName("function_call_test");
+ FunctionCallParameter parameter ("function_call_parameter", 28, (unsigned char *)"Maximus function call test\0");
+ functionSciMsg->addParameter(parameter);
+ functionSciMsg->setSciMsgStationId(stationId);
+ mpFunctionCallManager->sendMsg(functionSciMsg);
+
+ // Test probe
+ //
+ FunctionSciMsg * probeSciMsg = mpFunctionCallManager->createMsg();
+ probeSciMsg->setFunctionName("probe");
+ FunctionCallParameter probeParameter ("probe_call_parameter", 0, NULL);
+ probeSciMsg->addParameter(probeParameter);
+ probeSciMsg->setSciMsgStationId(stationId);
+ mpFunctionCallManager->sendMsg(probeSciMsg);
+
+ // Test exception
+ //
+ /*
+ int toto = 15;
+ int titi = 0;
+ toto = toto/titi;
+ */
bool b = true;
while (b)
{
b = mpNetworkClockProcessor->processNextEvt();
}
- mpSystemManager->removeStation(stationId); // FOR TESTS PURPOSE ONLY, TO REMOVE
+
+ // Free allocated memory
+ //
+ if (NULL != probeSciMsg)
+ {
+ delete(probeSciMsg);
+ probeSciMsg = NULL;
+ }
+ if (NULL != functionSciMsg)
+ {
+ delete (functionSciMsg);
+ functionSciMsg = NULL;
+ }
+
+ // Kill station
+ //
+ mpSystemManager->removeStation(stationId);
}
}
catch ( Error &e )
diff --git a/maximus/coreengine/src/main.cpp b/maximus/coreengine/src/main.cpp
index bb204e332c..2166a39872 100644
--- a/maximus/coreengine/src/main.cpp
+++ b/maximus/coreengine/src/main.cpp
@@ -12,6 +12,7 @@ int main ( int argc, const char * argv[] )
{
// Create a file for logging
//
+ //ofstream logFile ("/dev/null");
ofstream logFile ("maximuslog.txt");
if (logFile)
{
diff --git a/maximus/functioncall/inc/FunctionCallManager.h b/maximus/functioncall/inc/FunctionCallManager.h
index d815403055..99d73b4247 100644
--- a/maximus/functioncall/inc/FunctionCallManager.h
+++ b/maximus/functioncall/inc/FunctionCallManager.h
@@ -42,12 +42,12 @@ class SciServer;
#define callFunction(pFunction) (*(pFunction))
struct ltstr
{
- bool operator( ) ( const char * s1, const char * s2 ) const
+ bool operator( ) ( std::string s1, std::string s2 ) const
{
- return strcmp(s1, s2) < 0;
+ return s1.compare(s2) < 0;
}
};
-typedef std::map<const char *, callbackFunction, ltstr> Map;
+typedef std::map<std::string, callbackFunction, ltstr> Map;
/**
@@ -66,8 +66,6 @@ private:
// private attributes
//
-
- Network_Clock_Tick mNetworkClockTick;
Map * mpListOfCallbacks;
SciServer * mpSciServer;
@@ -109,7 +107,7 @@ public:
* @param function_sci_msg
* @param callback_address
*/
- bool registerCallback ( const char * callback_name, callbackFunction callback_address );
+ bool registerCallback ( std::string callback_name, callbackFunction callback_address );
/**
* @return bool
@@ -128,18 +126,7 @@ public:
// private attribute accessor methods
//
-
- /**
- * @return bool
- * @param current_tick_value
- */
- bool updateTickValue ( const Network_Clock_Tick current_tick_value );
-
- /**
- * @return Network_Clock_Tick
- */
- Network_Clock_Tick getNetworkClockTick ( ) const;
-
+
// protected attribute accessor methods
//
diff --git a/maximus/functioncall/inc/FunctionSciMsg.h b/maximus/functioncall/inc/FunctionSciMsg.h
index 5f822ae444..fe8c5fb245 100644
--- a/maximus/functioncall/inc/FunctionSciMsg.h
+++ b/maximus/functioncall/inc/FunctionSciMsg.h
@@ -73,7 +73,7 @@ private:
// Unique string identifier for function call
//
- char * mpFunctionName;
+ std::string mFunctionName;
// Function parameters
//
@@ -198,6 +198,12 @@ public:
* @param number_of_parameters the new value of mSpecializedSciMsgParametersNumber
*/
bool setSpecializedSciMsgParametersNumber ( const Function_Call_Parameters_Number number_of_parameters );
+
+ /**
+ * Get the value of mpSpecializedSciMsgHeader
+ * @return the value of mpSpecializedSciMsgHeader into a void pointer
+ */
+ void * returnSpecializedSciMsgHeader ( ) const;
/**
* @return mpSpecializedSciMsgHeader
@@ -211,17 +217,17 @@ public:
bool setSpecializedSciMsgHeader ( const Function_Call_Header * p_specialized_sci_msg_header );
/**
- * Get the value of mpFunctionName
- * @return the value of mpFunctionName
+ * Get the value of mFunctionName
+ * @return the value of mFunctionName
*/
- char * getFunctionName ( ) const;
+ std::string getFunctionName ( ) const;
/**
- * Set the value of mpFunctionName
+ * Set the value of mFunctionName
* @return bool
- * @param name the new value of mpFunctionName
+ * @param name the new value of mFunctionName
*/
- bool setFunctionName ( const char * name );
+ bool setFunctionName ( const std::string name );
/**
* Get the value of mListOfParameters
diff --git a/maximus/functioncall/src/FunctionCallManager.cpp b/maximus/functioncall/src/FunctionCallManager.cpp
index f8a91211cf..2f625beb0c 100644
--- a/maximus/functioncall/src/FunctionCallManager.cpp
+++ b/maximus/functioncall/src/FunctionCallManager.cpp
@@ -44,7 +44,6 @@ using namespace std;
FunctionCallManager::FunctionCallManager ( ):
-mNetworkClockTick(0),
mpSciServer(NULL)
{
clog << "FunctionCallManager()" << endl;
@@ -54,7 +53,6 @@ mpSciServer(NULL)
FunctionCallManager::FunctionCallManager ( SciServer * sci_server ):
-mNetworkClockTick(0),
mpSciServer(NULL)
{
clog << "FunctionCallManager(SciServer*)" << endl;
@@ -86,13 +84,6 @@ FunctionCallManager::~FunctionCallManager ( )
if (mpListOfCallbacks->empty())
{
- for (Map::const_iterator it = mpListOfCallbacks->begin(); it != mpListOfCallbacks->end(); ++it)
- {
- if (NULL != it->first)
- {
- delete [] (it->first);
- }
- }
mpListOfCallbacks->clear();
}
delete (mpListOfCallbacks);
@@ -131,12 +122,12 @@ FunctionSciMsg * FunctionCallManager::createMsg ( )
// Called by user before a message is sent
//
-bool FunctionCallManager::registerCallback ( const char * callback_name, callbackFunction callback_address )
+bool FunctionCallManager::registerCallback ( string callback_name, callbackFunction callback_address )
{
clog << "FunctionCallManager::registerCallback" << endl;
bool bRegister = false;
- if ( (NULL != callback_name) && (NULL != callback_address) )
+ if ( (!callback_name.empty()) && (NULL != callback_address) )
{
if ( (NULL != mpListOfCallbacks) && (FUNCTION_CALL_FUNCTION_MAX_NB > mpListOfCallbacks->size()) ) /* max number of registred functions */
{
@@ -180,62 +171,15 @@ bool FunctionCallManager::sendMsg ( FunctionSciMsg * function_sci_msg_to_send )
0x00 }; // flags
bSend &= function_sci_msg_to_send->setSpecializedSciMsgHeader(&functionSciMsgHeader);
- // Fill specialized SCI msg header size
+ // Fill specialized SCI msg attributes:
+ // - header size
//
bSend &= function_sci_msg_to_send->setSpecializedSciMsgHeaderSize(sizeof(struct Function_Call_Header));
- // Fill SCI msg data length
- // When sending a SCI msg, SCI msg data contain:
- // - SCI msg header,
- // - specialized SCI msg header,
- // - and specialized SCI msg data
- //
- bSend &= function_sci_msg_to_send->setSciMsgDataLength(static_cast<unsigned long>(sizeof(struct Sci_Msg_Header)) + function_sci_msg_to_send->getSpecializedSciMsgHeaderSize() + function_sci_msg_to_send->getSpecializedSciMsgDataLength());
-
- // Decompose current tick value into two uint32_t values
- //
- uint32_t netclockHigh=0, netclockLow=0;
- netclockLow = (uint32_t)(getNetworkClockTick());
- netclockHigh = (uint32_t)(((uint64_t)(getNetworkClockTick()) >> 32));
-
- // Fill SCI msg header
- // As SCI msg header will be sent on an output pipe, 'hton' functions have to be called
- //
- bSend &= function_sci_msg_to_send->incrementSciMsgId(); // to have an updated msg id
- struct Sci_Msg_Header sciMsgHeader = { htonl(function_sci_msg_to_send->getDefinedSciMsgMagicId()),
- function_sci_msg_to_send->getDefinedSciMsgVersion(),
- static_cast<uint8_t>(SCI_MSG_TYPE_FUNCTION_CALL),
- htons(static_cast<uint16_t>(function_sci_msg_to_send->getSciMsgDataLength())),
- htons(function_sci_msg_to_send->getSciMsgStationId()),
- htons(function_sci_msg_to_send->getSciMsgId()),
- htonl(netclockHigh),
- htonl(netclockLow),
- htons(0x0000), // flags
- htons(0x0000) }; // reserved
- bSend &= function_sci_msg_to_send->setSciMsgHeader(&sciMsgHeader);
-
- // Fill SCI msg data
- // When sending a SCI msg, since only SCI msg data will be sent on an output pipe,
- // SCI msg header and specialized SCI msg header have to be copied into SCI msg data
- // Then, specialized SCI msg data have to be copied into SCI msg data
- //
- unsigned char * pTempData = new unsigned char [function_sci_msg_to_send->getSciMsgDataLength()];
- if (NULL != pTempData)
- {
- memcpy(pTempData, (unsigned char *)&sciMsgHeader, sizeof(struct Sci_Msg_Header));
- memcpy(pTempData+sizeof(Sci_Msg_Header), (unsigned char *)&functionSciMsgHeader, sizeof(struct Function_Call_Header));
- memcpy(pTempData+sizeof(Sci_Msg_Header)+sizeof(struct Function_Call_Header), function_sci_msg_to_send->getSpecializedSciMsgData(), function_sci_msg_to_send->getSpecializedSciMsgDataLength());
- }
- bSend &= function_sci_msg_to_send->setSciMsgData(pTempData);
+ // Fill SCI msg attributes:
+ // - type
+ bSend &= function_sci_msg_to_send->setSciMsgType(SCI_MSG_TYPE_FUNCTION_CALL);
- // Free temporary allocated memory
- //
- if (NULL != pTempData)
- {
- delete [] pTempData;
- pTempData = NULL;
- }
-
if (bSend)
{
if (NULL != mpSciServer)
@@ -274,7 +218,7 @@ bool FunctionCallManager::receiveMsg ( FunctionSciMsg & function_sci_msg )
{
for (Map::const_iterator it = mpListOfCallbacks->begin(); it != mpListOfCallbacks->end(); ++it)
{
- if (!strcmp(it->first, function_sci_msg.getFunctionName()))
+ if (!function_sci_msg.getFunctionName().compare(it->first))
{
clog << "\t=> callback" << endl;
callFunction ((*mpListOfCallbacks)[function_sci_msg.getFunctionName()]) (function_sci_msg);
@@ -350,19 +294,6 @@ void FunctionCallManager::displayListOfCallbacks ( ) const
//
-Network_Clock_Tick FunctionCallManager::getNetworkClockTick ( ) const
-{
- return mNetworkClockTick;
-}
-
-
-bool FunctionCallManager::updateTickValue ( const Network_Clock_Tick current_tick_value )
-{
- mNetworkClockTick = current_tick_value;
- return true;
-}
-
-
// protected attribute accessor methods
//
diff --git a/maximus/functioncall/src/FunctionCallParameter.cpp b/maximus/functioncall/src/FunctionCallParameter.cpp
index 5e79c269f5..2ff7de7ae9 100644
--- a/maximus/functioncall/src/FunctionCallParameter.cpp
+++ b/maximus/functioncall/src/FunctionCallParameter.cpp
@@ -30,6 +30,7 @@ The original location of this file is /home/buret/eclipse/maximus/functioncall/s
#include "FunctionCallParameter.h"
+#include <iomanip> // for 'std::setfill' and 'std::setw'
#include <iostream> // for 'clog'
using namespace std;
@@ -212,10 +213,10 @@ unsigned long FunctionCallParameter::getValueLength ( ) const
bool FunctionCallParameter::setValueLength ( const unsigned long value_length )
{
- //clog << "FunctionCallParameter::setValueLength" << endl;
+ clog << "FunctionCallParameter::setValueLength" << endl;
mValueLength = value_length;
- //clog << "\tvalue length = " << getValueLength() << endl;
+ clog << "\tvalue length = " << getValueLength() << endl;
return true;
}
@@ -229,24 +230,11 @@ unsigned char * FunctionCallParameter::getValue ( ) const
bool FunctionCallParameter::setValue ( const unsigned char * p_value )
{
- //clog << "FunctionCallParameter::setValue" << endl;
+ clog << "FunctionCallParameter::setValue" << endl;
bool bSetValue = false;
if (NULL != p_value)
{
- // Check value length
- //
- unsigned int length = 0;
- if ( getValueLength()<=strlen((char*)p_value) )
- {
- length = static_cast<unsigned int>(getValueLength());
- }
- else
- {
- setValueLength (static_cast<unsigned long>(strlen((char*)p_value)));
- length = static_cast<unsigned int>(strlen((char*)p_value));
- }
-
// Allocate (and free) memory
//
if (NULL != mpValue)
@@ -254,20 +242,30 @@ bool FunctionCallParameter::setValue ( const unsigned char * p_value )
delete(mpValue);
mpValue = NULL;
}
- mpValue = new unsigned char [length+1];
+ mpValue = new unsigned char [getValueLength()];
// Copy value
//
- for (unsigned int i=0; i<length; i++)
+ memcpy(mpValue, p_value, getValueLength());
+
+ // Display set value
+ clog << "\tvalue = ";
+ for (unsigned int i=0; i<getValueLength(); i++)
{
- *(mpValue+i) = *(p_value+i);
+ clog << setfill('0') << setw(2) << uppercase << hex << (unsigned short int)*(mpValue+i) << "-";
}
- mpValue[length] = '\0';
+ clog << endl;
bSetValue = true;
}
else
{
+ // Set value
+ //
mpValue = NULL;
+
+ // Display value
+ //
+ clog << "\tvalue = NULL" << endl;
}
return bSetValue;
diff --git a/maximus/functioncall/src/FunctionSciMsg.cpp b/maximus/functioncall/src/FunctionSciMsg.cpp
index 1cb4d84661..b1b6dda4ad 100644
--- a/maximus/functioncall/src/FunctionSciMsg.cpp
+++ b/maximus/functioncall/src/FunctionSciMsg.cpp
@@ -51,7 +51,6 @@ FunctionSciMsg::FunctionSciMsg ( ):
mSpecializedSciMsgType(FUNCTION_CALL_TYPE_NONE),
mSpecializedSciMsgParametersNumber(0),
mpSpecializedSciMsgHeader(NULL),
-mpFunctionName(NULL),
mpFunctionCallManager(NULL)
{
//clog << "FunctionSciMsg()" << endl;
@@ -64,7 +63,6 @@ FunctionSciMsg::FunctionSciMsg ( FunctionCallManager * p_function_call_manager )
mSpecializedSciMsgType(FUNCTION_CALL_TYPE_NONE),
mSpecializedSciMsgParametersNumber(0),
mpSpecializedSciMsgHeader(NULL),
-mpFunctionName(NULL),
mpFunctionCallManager(NULL)
{
//clog << "FunctionSciMsg(FunctionCallManager*)" << endl;
@@ -150,11 +148,6 @@ FunctionSciMsg::~FunctionSciMsg ( )
mpSpecializedSciMsgHeader = NULL;
}
- if (NULL != mpFunctionName)
- {
- delete [] mpFunctionName;
- mpFunctionName = NULL;
- }
if (!mListOfParameters.empty())
{
mListOfParameters.clear();
@@ -183,7 +176,7 @@ FunctionSciMsg::~FunctionSciMsg ( )
ostream & operator<< ( ostream & os, const FunctionSciMsg & function_sci_msg )
{
os << "\tfunction SCI msg = [function name = ";
- if (NULL != function_sci_msg.getFunctionName())
+ if (!function_sci_msg.getFunctionName().empty())
{
os << function_sci_msg.getFunctionName();
}
@@ -297,8 +290,7 @@ bool FunctionSciMsg::addParameter ( const FunctionCallParameter & function_argum
if ( FUNCTION_CALL_PARAM_MAX_SIZE >= function_argument_to_add.getValueLength())
{
- FunctionCallParameter parameterToAdd = function_argument_to_add;
- mListOfParameters.push_back(parameterToAdd);
+ mListOfParameters.push_back(function_argument_to_add);
displayListOfParameters();
bAddParameter = true;
}
@@ -352,7 +344,7 @@ bool FunctionSciMsg::bindParameter ( const string name_of_parameter_to_get, unsi
//
bool FunctionSciMsg::identifyCallbackName ( )
{
- //clog << "FunctionSciMsg::identifyCallbackName" << endl;
+ clog << "FunctionSciMsg::identifyCallbackName" << endl;
bool bIdentifyName = false;
if (NULL != getSpecializedSciMsgData())
@@ -376,35 +368,24 @@ bool FunctionSciMsg::identifyCallbackName ( )
// Copy function name from specialized SCI msg data to function name attribute
//
- mpFunctionName = new char [functionNameLength+1];
- if (NULL != mpFunctionName)
- {
- for (unsigned int i=0; i<functionNameLength+1; i++)
- {
- *(mpFunctionName+i) = static_cast<char>(*(getSpecializedSciMsgData()+i));
- }
- //clog << "\tcallback name = " << mpFunctionName << endl;
+ mFunctionName.assign((char*)getSpecializedSciMsgData(), functionNameLength);
+ clog << "\tcallback name = " << mFunctionName << endl;
- // Remove function name from specialized SCI msg data
- //
- unsigned long tempDataLength = getSpecializedSciMsgDataLength();
- unsigned char * pTempData = getSpecializedSciMsgData();
- bIdentifyName = SciMsg::removeData (functionNameLength+1, tempDataLength, &pTempData);
- if (0 != bIdentifyName)
- {
- bIdentifyName &= setSpecializedSciMsgDataLength(tempDataLength);
- bIdentifyName &= setSpecializedSciMsgData(pTempData);
- }
- pTempData = NULL; // free pointer
- }
- else
+ // Remove function name from specialized SCI msg data
+ //
+ unsigned long tempDataLength = getSpecializedSciMsgDataLength();
+ unsigned char * pTempData = getSpecializedSciMsgData();
+ bIdentifyName = SciMsg::removeData (functionNameLength+1, tempDataLength, &pTempData);
+ if (0 != bIdentifyName)
{
- throw Error("FunctionSciMsg::identifyCallbackName", "Initialized function call name pointer is NULL");
+ bIdentifyName &= setSpecializedSciMsgDataLength(tempDataLength);
+ bIdentifyName &= setSpecializedSciMsgData(pTempData);
}
+ pTempData = NULL; // free pointer
}
else
{
- if (NULL != getFunctionName()) // function name has already been set
+ if (!getFunctionName().empty()) // function name has already been set
{
bIdentifyName = true;
}
@@ -422,7 +403,7 @@ bool FunctionSciMsg::identifyCallbackName ( )
//
bool FunctionSciMsg::identifyCallbackParameters ( )
{
- //clog << "FunctionSciMsg::identifyCallbackParameters" << endl;
+ clog << "FunctionSciMsg::identifyCallbackParameters" << endl;
bool bIdentifyParameters = false;
if ( NULL != getSpecializedSciMsgData() )
@@ -434,27 +415,20 @@ bool FunctionSciMsg::identifyCallbackParameters ( )
// Find parameter name length
//
unsigned long parameterNameLength = 0;
- char * pTempParameterName = new char [getSpecializedSciMsgDataLength()+1];
while ( (getSpecializedSciMsgDataLength() >= parameterNameLength)
&& ('\0' != *(getSpecializedSciMsgData()+parameterNameLength)) )
{
- *(pTempParameterName+parameterNameLength) = *(getSpecializedSciMsgData()+parameterNameLength);
parameterNameLength++;
}
- *(pTempParameterName+parameterNameLength) = '\0';
- //clog << dec << "\tparameter " << n+1 << " name length = " << parameterNameLength+1 << endl;
+ clog << dec << "\tparameter " << n+1 << " name length = " << parameterNameLength+1 << endl;
// Copy parameter name from specialized SCI msg data to parameter name attribute
//
+ string tempParameterName;
+ tempParameterName.assign((char*)getSpecializedSciMsgData(), parameterNameLength);
FunctionCallParameter parameterToFill;
- parameterToFill.setName (pTempParameterName);
- //clog << "\tparameter " << dec << n+1 << " name = " << parameterToFill.getName() << endl;
-
- if (NULL != pTempParameterName)
- {
- delete [] pTempParameterName;
- pTempParameterName = NULL;
- }
+ parameterToFill.setName (tempParameterName);
+ clog << "\tparameter " << dec << n+1 << " name = " << parameterToFill.getName() << endl;
// Remove parameter name from specialized SCI msg data
//
@@ -473,7 +447,7 @@ bool FunctionSciMsg::identifyCallbackParameters ( )
if ( FUNCTION_CALL_PARAM_MAX_SIZE >= tempLength )
{
parameterToFill.setValueLength (static_cast<unsigned long>(tempLength));
- //clog << dec << "\tparameter " << n+1 << " value length = " << parameterToFill.getValueLength ()<< endl;
+ clog << dec << "\tparameter " << n+1 << " value length = " << parameterToFill.getValueLength ()<< endl;
}
else
{
@@ -483,14 +457,17 @@ bool FunctionSciMsg::identifyCallbackParameters ( )
// Find parameter value
//
unsigned char * pTempParameterValue = new unsigned char [parameterToFill.getValueLength()];
- //clog << "\tparameter " << dec << n+1 << " value = ";
- for (unsigned int i=0; i<static_cast<unsigned int>(parameterToFill.getValueLength()); i++)
+ memcpy(pTempParameterValue, getSpecializedSciMsgData()+2, parameterToFill.getValueLength()); // +2 because parameter value length is coded on 2 bytes
+ parameterToFill.setValue (pTempParameterValue);
+ clog << "\tparameter " << dec << n+1 << " value = ";
+ if (NULL != parameterToFill.getValue())
{
- *(pTempParameterValue+i) = *(getSpecializedSciMsgData()+2+i); // +2 because parameter value length is coded on 2 bytes
- //clog << *(pTempParameterValue+i);
+ clog << parameterToFill.getValue() << endl;
+ }
+ else
+ {
+ clog << "NULL" << endl;
}
- //clog << endl;
- parameterToFill.setValue (pTempParameterValue);
// Remove parameter value length and parameter value from specialized SCI msg data
//
@@ -539,17 +516,17 @@ bool FunctionSciMsg::fillSpecializedSciMsgToSend ( )
// Function name is sent into the SCI msg data, before parameters
//
- if (NULL != getFunctionName())
+ if (!getFunctionName().empty())
{
- pData = (unsigned char *)(malloc(strlen(getFunctionName())+1)); // memory allocation for function name
- strcpy ((char*)(pData), getFunctionName()); // copy function name into data
- pData[strlen(getFunctionName())] = '\0';
+ pData = (unsigned char *)(malloc(getFunctionName().size()+1)); // memory allocation for function name
+ getFunctionName().copy ((char*)(pData), getFunctionName().size()); // copy function name into data
+ pData[getFunctionName().size()] = '\0';
clog << "\tfunction name = " << pData << endl; // display function name
- dataLength += static_cast<unsigned long>(strlen((char*)(pData))+1); // update data length
+ dataLength += static_cast<unsigned long>(getFunctionName().size()+1); // update data length
- // Parameters are defined as 'struct Function_Call_Parameter'
+ // Parameters are defined as 'FunctionCallParameter'
// They will be sent into the function SCI msg into specialized SCI msg data
- // 'Function_Call_Parameter' fields are sent according to the following format:
+ // 'FunctionCallParameter' fields are sent according to the following format:
// name\0lengthp_value etc. with length coded on 2 bytes
// Number of parameters is sent into the 'Function_Call_Header.param_nb' field
//
@@ -561,15 +538,15 @@ bool FunctionSciMsg::fillSpecializedSciMsgToSend ( )
// Parameter name
//
- mListOfParameters[i].getName().copy ((char*)(pData+dataLength), mListOfParameters[i].getName().length()); // copy parameter name into data
- pData[mListOfParameters[i].getName().length()]='\0';
+ mListOfParameters[i].getName().copy ((char*)(pData+dataLength), mListOfParameters[i].getName().size()); // copy parameter name into data
+ *(pData+dataLength+mListOfParameters[i].getName().size()) = '\0';
clog << "\tparameter " << dec << i+1 << " name = ";
- for (unsigned int j=dataLength; j<dataLength+mListOfParameters[i].getName().length(); j++)
+ for (unsigned int j=dataLength; j<dataLength+mListOfParameters[i].getName().size(); j++)
{
clog << *(pData+j); // display parameter name
}
clog << endl;
- dataLength += static_cast<unsigned long>(strlen((char*)(pData))+1); // update data length
+ dataLength += static_cast<unsigned long>(mListOfParameters[i].getName().size()+1); // update data length
// Parameter value length
//
@@ -585,13 +562,21 @@ bool FunctionSciMsg::fillSpecializedSciMsgToSend ( )
// Parameter value
//
+ clog << "\tparameter " << dec << i+1 << " value length = " << mListOfParameters[i].getValueLength() << endl;
clog << "\tparameter " << dec << i+1 << " value = ";
- for (unsigned int j=0; j<mListOfParameters[i].getValueLength(); j++)
+ if (0 != (mListOfParameters[i].getValueLength()))
{
- *(pData+dataLength+j) = *(mListOfParameters[i].getValue()+j);
- clog << *(pData+dataLength+j); // display parameter value
+ for (unsigned int j=0; j<mListOfParameters[i].getValueLength(); j++)
+ {
+ *(pData+dataLength+j) = *(mListOfParameters[i].getValue()+j);
+ clog << *(pData+dataLength+j); // display parameter value
+ }
+ clog << endl;
+ }
+ else
+ {
+ clog << "NULL" << endl;
}
- clog << endl;
dataLength += mListOfParameters[i].getValueLength(); // update data length
// Increment number of parameters that have been copied into data
@@ -755,6 +740,12 @@ bool FunctionSciMsg::setSpecializedSciMsgParametersNumber ( const Function_Call
}
+void * FunctionSciMsg::returnSpecializedSciMsgHeader ( ) const
+{
+ return (void*)mpSpecializedSciMsgHeader;
+}
+
+
Function_Call_Header * FunctionSciMsg::getSpecializedSciMsgHeader ( ) const
{
return mpSpecializedSciMsgHeader;
@@ -786,40 +777,24 @@ bool FunctionSciMsg::setSpecializedSciMsgHeader ( const Function_Call_Header * p
}
-char * FunctionSciMsg::getFunctionName ( ) const
+string FunctionSciMsg::getFunctionName ( ) const
{
- return mpFunctionName;
+ return mFunctionName;
}
// Called by user to configure a SCI message to send
//
-bool FunctionSciMsg::setFunctionName ( const char * name )
+bool FunctionSciMsg::setFunctionName ( const string name )
{
//clog << "FunctionSciMsg::setFunctionCallName" << endl;
bool bSetName = false;
- if ( (NULL != name) && (FUNCTION_CALL_ID_MAX_SIZE > strlen(name)) ) /* max length of a function id */
- {
- mpFunctionName = new char [strlen(name)];
- strcpy (mpFunctionName, name);
-
- if (!strcmp(mpFunctionName, name))
- {
- if (NULL != mpFunctionName)
- {
- //clog << "\tfunction call name = " << mpFunctionName << endl;
- }
- else
- {
- //clog << "\tfunction call name = NULL" << endl;
- }
- bSetName = true;
- }
- }
- else
+ if ( FUNCTION_CALL_ID_MAX_SIZE > name.size() ) /* max length of a function id */
{
- throw Error("FunctionSciMsg::setFunctionName", "Length of function call name exceeds max size");
+ mFunctionName = name;
+ clog << "\tfunction call name = " << mFunctionName << endl;
+ bSetName = true;
}
return bSetName;
diff --git a/maximus/functioncall/src/FunctionSciMsgTest.cpp b/maximus/functioncall/src/FunctionSciMsgTest.cpp
index 7588e7539d..6148cced3f 100644
--- a/maximus/functioncall/src/FunctionSciMsgTest.cpp
+++ b/maximus/functioncall/src/FunctionSciMsgTest.cpp
@@ -179,7 +179,7 @@ void FunctionSciMsgTest::fillSpecializedSciMsgToSendTest (void)
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::setFunctionCallName" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("setFunctionName failed"),
- mpFunctionSciMsg->setFunctionName ("function_to_call\0") );
+ mpFunctionSciMsg->setFunctionName ("function_to_call") );
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("fillSpecializedSciMsgToSend failed"),
mpFunctionSciMsg->fillSpecializedSciMsgToSend() );
}
diff --git a/maximus/functioncall/src/IFunctionCallTest.cpp b/maximus/functioncall/src/IFunctionCallTest.cpp
index dbc08db64e..ac105468ec 100644
--- a/maximus/functioncall/src/IFunctionCallTest.cpp
+++ b/maximus/functioncall/src/IFunctionCallTest.cpp
@@ -47,9 +47,9 @@ void IFunctionCallTest::userTest (void)
clog << "IFunctionCallTest -> FunctionCallManager::setFunctionName" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("setFunctionName failed"),
- functionSciMsg->setFunctionName("function_to_call\0") );
+ functionSciMsg->setFunctionName("function_to_call") );
- FunctionCallParameter parameter ("parameter\0", 25, (unsigned char *)"1234567890123456789012345");
+ FunctionCallParameter parameter ("parameter", 25, (unsigned char *)"1234567890123456789012345");
clog << "IFunctionCallTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
functionSciMsg->addParameter (parameter) );
diff --git a/maximus/networkclock/inc/ClockSciMsg.h b/maximus/networkclock/inc/ClockSciMsg.h
index f7630a66c5..72004133b1 100644
--- a/maximus/networkclock/inc/ClockSciMsg.h
+++ b/maximus/networkclock/inc/ClockSciMsg.h
@@ -156,6 +156,12 @@ public:
bool setSpecializedSciMsgTick ( const Network_Clock_Tick tick );
/**
+ * Get the value of mpSpecializedSciMsgHeader
+ * @return the value of mpSpecializedSciMsgHeader into a void pointer
+ */
+ void * returnSpecializedSciMsgHeader ( ) const;
+
+ /**
* @return mpSpecializedSciMsgHeader
*/
Network_Clock_Header * getSpecializedSciMsgHeader ( ) const;
diff --git a/maximus/networkclock/inc/NetworkClockProcessor.h b/maximus/networkclock/inc/NetworkClockProcessor.h
index d5f2619a82..da16895205 100644
--- a/maximus/networkclock/inc/NetworkClockProcessor.h
+++ b/maximus/networkclock/inc/NetworkClockProcessor.h
@@ -193,8 +193,6 @@ private:
* @param clock_sci_msg_to_send
*/
bool sendEvtMsg ( ClockSciMsg & clock_sci_msg_to_send );
-
- bool incrementCurrentTickValue ( );
void initAttributes ( ) ;
diff --git a/maximus/networkclock/src/ClockSciMsg.cpp b/maximus/networkclock/src/ClockSciMsg.cpp
index 5d483cd082..af79e32ca6 100644
--- a/maximus/networkclock/src/ClockSciMsg.cpp
+++ b/maximus/networkclock/src/ClockSciMsg.cpp
@@ -313,7 +313,7 @@ Network_Clock_Type ClockSciMsg::getSpecializedSciMsgType ( ) const
bool ClockSciMsg::setSpecializedSciMsgType ( const Network_Clock_Type type )
{
- //clog << "ClockSciMsg::setSpecializedSciMsgType" << endl;
+ clog << "ClockSciMsg::setSpecializedSciMsgType" << endl;
bool bSetType = true;
mSpecializedSciMsgType = type;
@@ -361,6 +361,12 @@ bool ClockSciMsg::setSpecializedSciMsgTick ( const Network_Clock_Tick tick )
}
+void * ClockSciMsg::returnSpecializedSciMsgHeader ( ) const
+{
+ return (void*)mpSpecializedSciMsgHeader;
+}
+
+
Network_Clock_Header * ClockSciMsg::getSpecializedSciMsgHeader ( ) const
{
return mpSpecializedSciMsgHeader;
diff --git a/maximus/networkclock/src/NetworkClockProcessor.cpp b/maximus/networkclock/src/NetworkClockProcessor.cpp
index 25e192193b..f6f09efdea 100644
--- a/maximus/networkclock/src/NetworkClockProcessor.cpp
+++ b/maximus/networkclock/src/NetworkClockProcessor.cpp
@@ -237,8 +237,10 @@ bool NetworkClockProcessor::processNextEvt ( )
{
// FOR TESTS PURPOSE ONLY, TO REMOVE
//
+
sleep (10);
- bProcess = false;
+ bProcess = false;
+
}
}
}
@@ -289,20 +291,31 @@ bool NetworkClockProcessor::processEvtStation ( NetworkClockEvt & evt_to_process
netclockHigh = (uint32_t)(((uint64_t)(getCurrentTickValue()) >> 32));
// Fill specialized SCI msg header
- // As specialized SCI msg header will be sent on an output pipe, 'hton' functions have to be called
//
struct Network_Clock_Header clockSciMsgHeader = { NETWORK_CLOCK_VERSION,
static_cast<uint8_t>(evt_to_process.getNetworkClockType()),
- htons(evt_to_process.getNetworkClockId()),
- htons(0x0000), // flags
- htons(0x0000), // reserved
- htonl(netclockHigh),
- htonl(netclockLow) };
+ evt_to_process.getNetworkClockId(),
+ 0x0000, // flags
+ 0x0000, // reserved
+ netclockHigh,
+ netclockLow };
bProcessStation = clockSciMsgToSend.setSpecializedSciMsgHeader(&clockSciMsgHeader);
+
+ // As specialized SCI msg header will be sent on an output pipe, 'hton' functions have to be called
+ //
+ clockSciMsgHeader.id = htons(clockSciMsgHeader.id);
+ clockSciMsgHeader.tick_high = htonl(clockSciMsgHeader.tick_high);
+ clockSciMsgHeader.tick_low = htonl(clockSciMsgHeader.tick_low);
- // Fill specialized SCI msg header size
+ // Fill specialized SCI msg attributes:
+ // - header size
//
- bProcessStation &= clockSciMsgToSend.setSpecializedSciMsgHeaderSize(static_cast<unsigned long>(sizeof(Network_Clock_Header)));
+ bProcessStation &= clockSciMsgToSend.setSpecializedSciMsgHeaderSize(static_cast<unsigned long>(sizeof(Network_Clock_Header)));
+
+ // Fill SCI msg attributes:
+ // - type
+ //
+ bProcessStation &= clockSciMsgToSend.setSciMsgType(SCI_MSG_TYPE_NETWORK_CLOCK);
// Fill specialized SCI msg data length and specialized SCI msg data
// When sending a clock SCI msg, there is no clock SCI msg data
@@ -310,51 +323,10 @@ bool NetworkClockProcessor::processEvtStation ( NetworkClockEvt & evt_to_process
bProcessStation &= clockSciMsgToSend.setSpecializedSciMsgDataLength(0);
bProcessStation &= clockSciMsgToSend.setSpecializedSciMsgData(NULL);
- // Fill SCI msg data length
- // When sending a SCI msg, SCI msg data contain:
- // - SCI msg header,
- // - specialized SCI msg header,
- // - and specialized SCI msg data
+ // Fill SCI msg attributes:
+ // - station id
//
- bProcessStation &= clockSciMsgToSend.setSciMsgDataLength(static_cast<unsigned long>(sizeof(struct Sci_Msg_Header)) + clockSciMsgToSend.getSpecializedSciMsgHeaderSize() + clockSciMsgToSend.getSpecializedSciMsgDataLength());
-
- // Fill SCI msg header
- // As SCI msg header will be sent on an output pipe, 'hton' functions have to be called
- //
- bProcessStation &= clockSciMsgToSend.incrementSciMsgId(); // to have an updated msg id
- struct Sci_Msg_Header sciMsgHeader = { htonl(clockSciMsgToSend.getDefinedSciMsgMagicId()),
- clockSciMsgToSend.getDefinedSciMsgVersion(),
- SCI_MSG_TYPE_NETWORK_CLOCK,
- htons(static_cast<uint16_t>(clockSciMsgToSend.getSciMsgDataLength())),
- htons(evt_to_process.getStationId()),
- htons(clockSciMsgToSend.getSciMsgId()),
- htonl(netclockHigh),
- htonl(netclockLow),
- htons(0), // flags
- htons(0) }; // reserved
- bProcessStation &= clockSciMsgToSend.setSciMsgHeader(&sciMsgHeader);
-
- // Fill SCI msg data
- // When sending a SCI msg, since only SCI msg data will be sent on an output pipe,
- // SCI msg header and specialized SCI msg header have to be copied into SCI msg data
- // Then, specialized SCI msg data have to be copied into SCI msg data
- //
- unsigned char * pTempData = new unsigned char [clockSciMsgToSend.getSciMsgDataLength()];
- if (NULL != pTempData)
- {
- memcpy(pTempData, (unsigned char *)&sciMsgHeader, sizeof(struct Sci_Msg_Header));
- memcpy(pTempData+sizeof(Sci_Msg_Header), (unsigned char *)&clockSciMsgHeader, sizeof(struct Network_Clock_Header));
- memcpy(pTempData+sizeof(Sci_Msg_Header)+sizeof(struct Network_Clock_Header), clockSciMsgToSend.getSpecializedSciMsgData(), clockSciMsgToSend.getSpecializedSciMsgDataLength());
- }
- bProcessStation &= clockSciMsgToSend.setSciMsgData(pTempData);
-
- // Free temporary allocated memory
- //
- if (NULL != pTempData)
- {
- delete [] pTempData;
- pTempData = NULL;
- }
+ bProcessStation &= clockSciMsgToSend.setSciMsgStationId(evt_to_process.getStationId());
if (0 != bProcessStation)
{
@@ -407,18 +379,6 @@ bool NetworkClockProcessor::processEvtSystem ( NetworkClockEvt & evt_to_process
// private methods
//
-
-bool NetworkClockProcessor::incrementCurrentTickValue ( )
-{
- bool bTick = false;
-
- mCurrentTickValue++;
- bTick = mpFunctionCallManager->updateTickValue(mCurrentTickValue);
- bTick &= mpPhyProcessor->updateTickValue(mCurrentTickValue);
-
- return bTick;
-}
-
bool NetworkClockProcessor::sendEvtMsg ( ClockSciMsg & clock_sci_msg_to_send )
{
@@ -477,9 +437,12 @@ Network_Clock_Tick NetworkClockProcessor::getCurrentTickValue ( ) const
bool NetworkClockProcessor::setCurrentTickValue ( const Network_Clock_Tick tick_value )
{
+ bool bTick = false;
+
mCurrentTickValue = tick_value;
+ bTick = mpSciServer->updateTickValue(mCurrentTickValue);
- return true;
+ return bTick;
}
diff --git a/maximus/phy/inc/PhyProcessor.h b/maximus/phy/inc/PhyProcessor.h
index 85cb56ca7d..5bce23ea31 100644
--- a/maximus/phy/inc/PhyProcessor.h
+++ b/maximus/phy/inc/PhyProcessor.h
@@ -55,7 +55,6 @@ private:
// private attributes
//
- Network_Clock_Tick mNetworkClockTick;
Phy_Link_Quality mLinkQuality; // list
SciServer * mpSciServer;
@@ -135,17 +134,6 @@ public:
// private attribute accessor methods
//
- /**
- * @return bool
- * @param current_tick_value
- */
- bool updateTickValue ( const Network_Clock_Tick current_tick_value );
-
- /**
- * @return Network_Clock_Tick
- */
- Network_Clock_Tick getNetworkClockTick ( ) const;
-
// protected attribute accessor methods
//
diff --git a/maximus/phy/inc/PhySciMsg.h b/maximus/phy/inc/PhySciMsg.h
index 23a69911c7..a17a2baa26 100644
--- a/maximus/phy/inc/PhySciMsg.h
+++ b/maximus/phy/inc/PhySciMsg.h
@@ -128,6 +128,12 @@ public:
//
/**
+ * Get the value of mpSpecializedSciMsgHeader
+ * @return the value of mpSpecializedSciMsgHeader into a void pointer
+ */
+ void * returnSpecializedSciMsgHeader ( ) const;
+
+ /**
* @return mpSpecializedSciMsgHeader
*/
Phy_Header * getSpecializedSciMsgHeader ( ) const;
diff --git a/maximus/phy/src/PhyProcessor.cpp b/maximus/phy/src/PhyProcessor.cpp
index 745d897fbd..aeaf69b537 100644
--- a/maximus/phy/src/PhyProcessor.cpp
+++ b/maximus/phy/src/PhyProcessor.cpp
@@ -43,7 +43,6 @@ using namespace std;
PhyProcessor::PhyProcessor ( ):
-mNetworkClockTick(0),
mpSciServer(NULL)
{
clog << "PhyProcessor()" << endl;
@@ -53,7 +52,6 @@ mpSciServer(NULL)
PhyProcessor::PhyProcessor ( SciServer * sci_server ):
-mNetworkClockTick(0),
mpSciServer(NULL)
{
clog << "PhyProcessor(SciServer*)" << endl;
@@ -175,19 +173,6 @@ void PhyProcessor::registerPhySciMsg ( )
//
-Network_Clock_Tick PhyProcessor::getNetworkClockTick ( ) const
-{
- return mNetworkClockTick;
-}
-
-
-bool PhyProcessor::updateTickValue ( const Network_Clock_Tick current_tick_value )
-{
- mNetworkClockTick = current_tick_value;
- return true;
-}
-
-
// protected attribute accessor methods
//
diff --git a/maximus/phy/src/PhySciMsg.cpp b/maximus/phy/src/PhySciMsg.cpp
index f97ef58ba1..44a42e91ab 100644
--- a/maximus/phy/src/PhySciMsg.cpp
+++ b/maximus/phy/src/PhySciMsg.cpp
@@ -248,6 +248,12 @@ void PhySciMsg::displaySpecializedSciMsgHeader ( ) const
//
+void * PhySciMsg::returnSpecializedSciMsgHeader ( ) const
+{
+ return (void*)mpSpecializedSciMsgHeader;
+}
+
+
Phy_Header * PhySciMsg::getSpecializedSciMsgHeader ( ) const
{
return mpSpecializedSciMsgHeader;
diff --git a/maximus/sci/inc/SciMsg.h b/maximus/sci/inc/SciMsg.h
index 8837bb33f6..62dcb09097 100644
--- a/maximus/sci/inc/SciMsg.h
+++ b/maximus/sci/inc/SciMsg.h
@@ -267,6 +267,12 @@ public:
virtual bool setSpecializedSciMsgHeaderSize ( const unsigned long header_size );
/**
+ * Get the value of mpSpecializedSciMsgHeader
+ * @return the value of mpSpecializedSciMsgHeader into a void pointer
+ */
+ virtual void * returnSpecializedSciMsgHeader ( ) const = 0;
+
+ /**
* Get the value of mSpecializedSciMsgDataLength
* @return the value of mSpecializedSciMsgDataLength
*/
diff --git a/maximus/sci/inc/SciServer.h b/maximus/sci/inc/SciServer.h
index dccce36bff..5f6fc73b7e 100644
--- a/maximus/sci/inc/SciServer.h
+++ b/maximus/sci/inc/SciServer.h
@@ -35,6 +35,7 @@ The original location of this file is /home/buret/eclipse/maximus/sci/inc/SciSer
#include <pthread.h>
#include <list>
+#include "networkclock_types.h"
#include "system_types.h"
#include "sci_types.h"
#include "Error.h"
@@ -67,6 +68,7 @@ private:
SciMsg ** mpSpecializedSciMsgArray;
unsigned int mArraySize;
StationsList * mpListOfStations;
+ Network_Clock_Tick mNetworkClockTick;
protected:
@@ -100,7 +102,7 @@ public:
* @return bool
* @param sci_msg_to_send
*/
- bool sendSciMsg ( const SciMsg * sci_msg_to_send ) const;
+ bool sendSciMsg ( SciMsg * sci_msg_to_send ) const;
/**
* Set a value into mpSpecializedSciMsgArray
@@ -167,6 +169,17 @@ public:
*/
SciMsg ** getSpecializedSciMsgArray ( ) const;
+ /**
+ * @return bool
+ * @param current_tick_value
+ */
+ bool updateTickValue ( const Network_Clock_Tick current_tick_value );
+
+ /**
+ * @return Network_Clock_Tick
+ */
+ Network_Clock_Tick getNetworkClockTick ( ) const;
+
// protected attribute accessor methods
//
diff --git a/maximus/sci/src/SciMsg.cpp b/maximus/sci/src/SciMsg.cpp
index 2e5bcd6b86..b9ff3891a7 100644
--- a/maximus/sci/src/SciMsg.cpp
+++ b/maximus/sci/src/SciMsg.cpp
@@ -193,8 +193,7 @@ bool SciMsg::checkValidity ( ) const
bool bCheck = false;
if ( (getDefinedSciMsgMagicId() == getSciMsgHeader()->magic_id)
- && (SCI_MSG_ID_STATION <= getSciMsgHeader()->msg_id)
- && (0xFFFF > getSciMsgHeader()->msg_id) )
+ && (SCI_MSG_ID_STATION <= getSciMsgHeader()->msg_id) )
{
bCheck = true;
}
@@ -267,8 +266,8 @@ void SciMsg::displaySciMsgHeader ( ) const
clog << "\t\ttype = ";
displaySciMsgType();
clog << endl;
- clog << "\t\tlength = " << dec << getSciMsgHeader()->length << endl;
- clog << "\t\tstation_id = 0x" << setfill('0') << setw(4) << uppercase << hex << getSciMsgHeader()->station_id << endl;
+ clog << "\t\tlength = 0x" << setfill('0') << setw(4) << uppercase << hex << getSciMsgHeader()->length << " (" << dec << getSciMsgHeader()->length << " bytes)" << endl;
+ clog << "\t\tstation_id = 0x" << setfill('0') << setw(4) << uppercase << hex << getSciMsgHeader()->station_id << " (" << dec << getSciMsgHeader()->station_id << ")" << endl;
clog << "\t\tmsg_id = 0x" << setfill('0') << setw(4) << uppercase << hex << getSciMsgHeader()->msg_id << endl;
clog << "\t\tnetclock = 0x" << setfill('0') << setw(8) << uppercase << hex << getSciMsgHeader()->netclock_high;
clog << setfill('0') << setw(8) << uppercase << hex << getSciMsgHeader()->netclock_low << endl;
diff --git a/maximus/sci/src/SciServer.cpp b/maximus/sci/src/SciServer.cpp
index 819de45976..68d82f7699 100644
--- a/maximus/sci/src/SciServer.cpp
+++ b/maximus/sci/src/SciServer.cpp
@@ -53,7 +53,8 @@ SciServer::SciServer ( ) :
mStatus(MAXIMUS_SCI_SERVER_STATUS_NONE),
mpSpecializedSciMsgArray(NULL),
mArraySize(0),
-mpListOfStations(NULL)
+mpListOfStations(NULL),
+mNetworkClockTick(0)
{
clog << "SciServer()" << endl;
@@ -143,24 +144,77 @@ SciServer::~SciServer ( )
//
-bool SciServer::sendSciMsg ( const SciMsg * sci_msg_to_send ) const
+bool SciServer::sendSciMsg ( SciMsg * sci_msg_to_send ) const
{
- clog << "SciServer::sendSciMsg" << endl;
+ clog << "<- SciServer::sendSciMsg" << endl;
bool bSend = false;
if (NULL != sci_msg_to_send)
{
- // Display SCI msg to send
+ // Fill SCI msg data length
//
- //sci_msg_to_send->displaySciMsgHeader();
- //clog << "\tSCI msg data = ";
- //sci_msg_to_send->displaySciMsgData();
- //clog << endl;
- //sci_msg_to_send->displaySpecializedSciMsgHeader();
- //clog << "\tspecialized SCI msg data = ";
- //sci_msg_to_send->displaySpecializedSciMsgData();
- //clog << endl;
-
+ bSend = sci_msg_to_send->setSciMsgDataLength(sci_msg_to_send->getSpecializedSciMsgHeaderSize() + sci_msg_to_send->getSpecializedSciMsgDataLength());
+
+ // Decompose current tick value into two uint32_t values
+ //
+ uint32_t netclockHigh=0, netclockLow=0;
+ netclockLow = (uint32_t)(getNetworkClockTick());
+ netclockHigh = (uint32_t)(((uint64_t)(getNetworkClockTick()) >> 32));
+
+ // Fill SCI msg header
+ //
+ bSend &= sci_msg_to_send->incrementSciMsgId(); // to have an updated msg id
+ struct Sci_Msg_Header sciMsgHeader = { sci_msg_to_send->getDefinedSciMsgMagicId(),
+ sci_msg_to_send->getDefinedSciMsgVersion(),
+ static_cast<uint8_t>(sci_msg_to_send->getSciMsgType()),
+ static_cast<uint16_t>(sci_msg_to_send->getSciMsgDataLength()),
+ sci_msg_to_send->getSciMsgStationId(),
+ sci_msg_to_send->getSciMsgId(),
+ netclockHigh,
+ netclockLow,
+ 0, // flags
+ 0 }; // reserved
+ bSend &= sci_msg_to_send->setSciMsgHeader(&sciMsgHeader);
+
+ // As SCI msg header will be sent on an output pipe, 'hton' functions have to be called
+ //
+ sciMsgHeader.magic_id = htonl(sciMsgHeader.magic_id);
+ sciMsgHeader.length = htons(sciMsgHeader.length);
+ sciMsgHeader.station_id = htons(sciMsgHeader.station_id);
+ sciMsgHeader.msg_id = htons(sciMsgHeader.msg_id);
+ sciMsgHeader.netclock_high = htonl(sciMsgHeader.netclock_high);
+ sciMsgHeader.netclock_low = htonl(sciMsgHeader.netclock_low);
+
+ // Fill SCI msg data length
+ // When sending a SCI msg, SCI msg data contain:
+ // - SCI msg header,
+ // - specialized SCI msg header,
+ // - and specialized SCI msg data
+ //
+ bSend = sci_msg_to_send->setSciMsgDataLength(static_cast<unsigned long>(sizeof(struct Sci_Msg_Header)) + sci_msg_to_send->getSpecializedSciMsgHeaderSize() + sci_msg_to_send->getSpecializedSciMsgDataLength());
+
+ // Fill SCI msg data
+ // When sending a SCI msg, since only SCI msg data will be sent on an output pipe,
+ // SCI msg header and specialized SCI msg header have to be copied into SCI msg data
+ // Then, specialized SCI msg data have to be copied into SCI msg data
+ //
+ unsigned char * pTempData = new unsigned char [sci_msg_to_send->getSciMsgDataLength()];
+ if (NULL != pTempData)
+ {
+ memcpy(pTempData, (unsigned char *)&sciMsgHeader, sizeof(struct Sci_Msg_Header));
+ memcpy(pTempData+sizeof(Sci_Msg_Header), (unsigned char *)sci_msg_to_send->returnSpecializedSciMsgHeader(), sci_msg_to_send->getSpecializedSciMsgHeaderSize());
+ memcpy(pTempData+sizeof(Sci_Msg_Header)+sci_msg_to_send->getSpecializedSciMsgHeaderSize(), sci_msg_to_send->getSpecializedSciMsgData(), sci_msg_to_send->getSpecializedSciMsgDataLength());
+ }
+ bSend &= sci_msg_to_send->setSciMsgData(pTempData);
+
+ // Free temporary allocated memory
+ //
+ if (NULL != pTempData)
+ {
+ delete [] pTempData;
+ pTempData = NULL;
+ }
+
// Retrieve destination station
//
Station * destination = NULL;
@@ -170,7 +224,7 @@ bool SciServer::sendSciMsg ( const SciMsg * sci_msg_to_send ) const
{
if (NULL != *it)
{
- if ( ((*it)->getStationId()) == ntohs(sci_msg_to_send->getSciMsgHeader()->station_id) )
+ if ( ((*it)->getStationId()) == sci_msg_to_send->getSciMsgStationId() )
{
destination = (*it);
@@ -256,7 +310,7 @@ bool SciServer::receiveMsg ( const Sci_Msg_Header * header,
const unsigned long data_length,
const unsigned char * received_data ) const
{
- clog << "SciServer::receiveMsg" << endl;
+ clog << "-> SciServer::receiveMsg" << endl;
bool bReceiveMsg = false;
// Log the SCI message header
@@ -300,6 +354,26 @@ bool SciServer::receiveMsg ( const Sci_Msg_Header * header,
}
else
{
+ // Display SCI msg header
+ //
+ cerr << "\tSCI msg header = " << endl;
+ cerr << "\t\tmagic_id = 0x" << setfill('0') << setw(8) << uppercase << hex << sciMsg->getSciMsgHeader()->magic_id << endl;
+ cerr << "\t\tversion = 0x" << setfill('0') << setw(2) << uppercase << hex << static_cast<unsigned short int>(sciMsg->getSciMsgHeader()->version) << endl;
+ cerr << "\t\ttype = 0x" << setfill('0') << setw(2) << uppercase << hex << static_cast<unsigned short int>(sciMsg->getSciMsgHeader()->type) << endl;
+ cerr << "\t\tlength = " << dec << sciMsg->getSciMsgHeader()->length << endl;
+ cerr << "\t\tstation_id = 0x" << setfill('0') << setw(4) << uppercase << hex << sciMsg->getSciMsgHeader()->station_id << endl;
+ cerr << "\t\tmsg_id = 0x" << setfill('0') << setw(4) << uppercase << hex << sciMsg->getSciMsgHeader()->msg_id << endl;
+ cerr << "\t\tnetclock = 0x" << setfill('0') << setw(8) << uppercase << hex << sciMsg->getSciMsgHeader()->netclock_high;
+ cerr << setfill('0') << setw(8) << uppercase << hex << sciMsg->getSciMsgHeader()->netclock_low << endl;
+ cerr << "\t\tflags = " << dec << sciMsg->getSciMsgHeader()->flags << endl;
+ cerr << "\t\treserved = 0x" << setfill('0') << setw(4) << uppercase << hex << sciMsg->getSciMsgHeader()->reserved << endl;
+
+ // Display SCI msg data
+ for (unsigned int i=0; i<data_length; i++)
+ {
+ cerr << hex << *(received_data+i);
+ }
+
throw Error(__FUNCTION__, "SCI msg not valid");
}
@@ -673,6 +747,19 @@ unsigned int SciServer::getArraySize ( ) const
}
+Network_Clock_Tick SciServer::getNetworkClockTick ( ) const
+{
+ return mNetworkClockTick;
+}
+
+
+bool SciServer::updateTickValue ( const Network_Clock_Tick current_tick_value )
+{
+ mNetworkClockTick = current_tick_value;
+ return true;
+}
+
+
// protected attribute accessor methods
//
diff --git a/maximus/system/inc/SystemSciMsg.h b/maximus/system/inc/SystemSciMsg.h
index 63711f77c2..baba65875d 100644
--- a/maximus/system/inc/SystemSciMsg.h
+++ b/maximus/system/inc/SystemSciMsg.h
@@ -133,6 +133,12 @@ public:
bool setSpecializedSciMsgType ( const System_Type type );
/**
+ * Get the value of mpSpecializedSciMsgHeader
+ * @return the value of mpSpecializedSciMsgHeader into a void pointer
+ */
+ void * returnSpecializedSciMsgHeader ( ) const;
+
+ /**
* @return mpSpecializedSciMsgHeader
*/
System_Header * getSpecializedSciMsgHeader ( ) const;
diff --git a/maximus/system/src/Station.cpp b/maximus/system/src/Station.cpp
index 2c1276c765..316432c558 100644
--- a/maximus/system/src/Station.cpp
+++ b/maximus/system/src/Station.cpp
@@ -32,6 +32,7 @@ The original location of this file is /home/buret/eclipse/maximus/system/src/Sta
#include <unistd.h> // for 'exec'
#include <sys/signal.h>
#include <errno.h>
+#include <iomanip> // for 'std::setfill' and 'std::setw'
#include "Station.h"
#include "StationConfiguration.h"
@@ -140,7 +141,8 @@ Station & Station::operator= ( const Station & station )
void Station::displayStation ( ) const
{
- clog << dec << "\t[input file descriptor = " << getInputFileDescriptor() << ", output file descriptor = " << getOutputFileDescriptor() << ", log file descriptor = " << getLogFileDescriptor() << ", process id = " << getStationId() << "]" << endl;
+ clog << dec << "\t[input file descriptor = " << getInputFileDescriptor() << ", output file descriptor = " << getOutputFileDescriptor() << ", log file descriptor = " << getLogFileDescriptor();
+ clog << ", process id = 0x" << setfill('0') << setw(4) << uppercase << hex << getStationId() << " (" << dec << getStationId() << ")]" << endl;
}
diff --git a/maximus/system/src/SystemSciMsg.cpp b/maximus/system/src/SystemSciMsg.cpp
index fd05f55e9d..f0897ea8af 100644
--- a/maximus/system/src/SystemSciMsg.cpp
+++ b/maximus/system/src/SystemSciMsg.cpp
@@ -282,6 +282,12 @@ bool SystemSciMsg::setSpecializedSciMsgType ( const System_Type type )
}
+void * SystemSciMsg::returnSpecializedSciMsgHeader ( ) const
+{
+ return (void*)mpSpecializedSciMsgHeader;
+}
+
+
System_Header * SystemSciMsg::getSpecializedSciMsgHeader ( ) const
{
return mpSpecializedSciMsgHeader;