summaryrefslogtreecommitdiff
path: root/maximus/system/src/SystemSciMsg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'maximus/system/src/SystemSciMsg.cpp')
-rw-r--r--maximus/system/src/SystemSciMsg.cpp81
1 files changed, 50 insertions, 31 deletions
diff --git a/maximus/system/src/SystemSciMsg.cpp b/maximus/system/src/SystemSciMsg.cpp
index 1ab6a3dbd7..767e9d94e3 100644
--- a/maximus/system/src/SystemSciMsg.cpp
+++ b/maximus/system/src/SystemSciMsg.cpp
@@ -33,6 +33,7 @@ The original location of this file is /home/buret/eclipse/maximus/system/src/Sys
#include "Error.h"
#include <iomanip> // for 'std::setfill' and 'std::setw'
+#include <netinet/in.h> // for 'ntohl' and 'ntohs' functions
#include <iostream> // for 'cout', 'cerr' and 'clog'
using namespace std;
@@ -42,9 +43,9 @@ using namespace std;
SystemSciMsg::SystemSciMsg ( ):
-mpSystemManager(NULL),
mSpecializedSciMsgType(SYSTEM_TYPE_NONE),
-mpSpecializedSciMsgHeader(NULL)
+mpSpecializedSciMsgHeader(NULL),
+mpSystemManager(NULL)
{
clog << "SystemSciMsg()" << endl;
@@ -53,20 +54,21 @@ mpSpecializedSciMsgHeader(NULL)
SystemSciMsg::SystemSciMsg ( SystemManager * p_system_manager ):
-mpSystemManager(NULL),
mSpecializedSciMsgType(SYSTEM_TYPE_NONE),
-mpSpecializedSciMsgHeader(NULL)
+mpSpecializedSciMsgHeader(NULL),
+mpSystemManager(NULL)
{
clog << "SystemSciMsg(SystemManager*)" << endl;
initAttributes ();
+
if (NULL != p_system_manager)
{
mpSystemManager = p_system_manager;
}
else
{
- throw Error("SystemSciMsg(SystemManager*)", "Received SystemManager pointer is NULL");
+ throw Error("SystemSciMsg(SystemManager*)", "Received system manager pointer is NULL");
}
}
@@ -79,8 +81,8 @@ void SystemSciMsg::initAttributes ( )
if (NULL != mpSpecializedSciMsgHeader)
{
mpSpecializedSciMsgHeader->version = SYSTEM_VERSION;
- mpSpecializedSciMsgHeader->type = 0;
- mpSpecializedSciMsgHeader->flags = 0;
+ mpSpecializedSciMsgHeader->type = 0x00;
+ mpSpecializedSciMsgHeader->flags = 0x0000;
}
else
{
@@ -98,6 +100,7 @@ SystemSciMsg::~SystemSciMsg ( )
delete (mpSpecializedSciMsgHeader);
mpSpecializedSciMsgHeader = NULL;
}
+
if (NULL != mpSystemManager)
{
mpSystemManager = NULL;
@@ -133,14 +136,14 @@ bool SystemSciMsg::dispatchMsg ( )
if (NULL != mpSystemManager)
{
- if ( (NULL != getSpecializedSciMsgHeader()) && (SYSTEM_TYPE_IDLE == getSpecializedSciMsgType()) )
+ if ( SYSTEM_TYPE_IDLE == getSpecializedSciMsgType() )
{
- bDispatch = mpSystemManager->setStationToIdle(SciMsg::getSciMsgHeader()->station_id);
+ bDispatch = mpSystemManager->setStationToIdle(SciMsg::getSciMsgStationId());
}
}
else
{
- throw Error("SystemSciMsg::dispatchMsg", "SystemManager pointer is NULL");
+ throw Error("SystemSciMsg::dispatchMsg", "System manager pointer is NULL");
}
return bDispatch;
@@ -156,21 +159,22 @@ bool SystemSciMsg::identifySpecializedSciMsgHeader ( )
if (NULL != SciMsg::getSciMsgData())
{
+ // Set specialized SCI msg header size
+ //
+ SciMsg::setSpecializedSciMsgHeaderSize(static_cast<unsigned long>(sizeof(struct System_Header)));
+
// Get specialized SCI message header contents
//
- SciMsg::setSpecializedSciMsgHeaderSize((unsigned long)sizeof(struct System_Header));
if (SciMsg::getSciMsgDataLength() >= SciMsg::getSpecializedSciMsgHeaderSize()) // check that there are enough data to get the specialized SCI message header
{
if (NULL != mpSpecializedSciMsgHeader)
{
*mpSpecializedSciMsgHeader = *((System_Header*)SciMsg::getSciMsgData());
+ getSpecializedSciMsgHeader()->flags = ntohs(getSpecializedSciMsgHeader()->flags);
- mSpecializedSciMsgType = static_cast<System_Type>(mpSpecializedSciMsgHeader->type);
+ bIdentifyHeader = setSpecializedSciMsgType (static_cast<System_Type>(getSpecializedSciMsgHeader()->type));
displaySpecializedSciMsgHeader();
-
-
- bIdentifyHeader = true;
}
else
{
@@ -179,36 +183,50 @@ bool SystemSciMsg::identifySpecializedSciMsgHeader ( )
}
else
{
- Error e = Error("SystemSciMsg::identifySpecializedSciMsgHeader", "Not enough data to get the system header");
- throw (e);
+ throw Error("SystemSciMsg::identifySpecializedSciMsgHeader", "Not enough data to get the system header");
}
}
else
{
- Error e = Error("SystemSciMsg::identifySpecializedSciMsgHeader", "Received data pointer is NULL");
- throw (e);
+ throw Error("SystemSciMsg::identifySpecializedSciMsgHeader", "SCI msg data pointer is NULL");
}
return bIdentifyHeader;
}
-// private methods
-//
-
-
void SystemSciMsg::displaySpecializedSciMsgHeader ( ) const
{
- clog << "SystemSciMsg::displaySpecializedSciMsgHeader" << endl;
-
clog << "\tsystem SCI msg header = " << endl;
- clog << "\t\tversion = 0x" << setfill('0') << setw(2) << uppercase << hex << getSpecializedSciMsgHeader()->version << endl;
- clog << "\t\ttype = " << dec << getSpecializedSciMsgType() << endl;
+ clog << "\t\tversion = " << dec << static_cast<unsigned short int>(getSpecializedSciMsgHeader()->version) << endl;
+ clog << "\t\ttype = ";
+ displaySpecializedSciMsgType();
+ clog << endl;
clog << "\t\tflags = 0x" << setfill('0') << setw(4) << uppercase << hex << getSpecializedSciMsgHeader()->flags << endl;
- clog << dec;
}
+// private methods
+//
+
+
+void SystemSciMsg::displaySpecializedSciMsgType ( ) const
+{
+ switch (getSpecializedSciMsgType())
+ {
+ case 0:
+ clog << "SYSTEM_TYPE_NONE";
+ break;
+ case 1:
+ clog << "SYSTEM_TYPE_IDLE";
+ break;
+ default:
+ clog << "unknown";
+ break;
+ }
+}
+
+
// protected methods
//
@@ -236,7 +254,9 @@ bool SystemSciMsg::setSpecializedSciMsgType ( const System_Type type )
clog << "SystemSciMsg::setSpecializedSciMsgType" << endl;
mSpecializedSciMsgType = type;
- clog << "\tsystem sci msg type = " << mSpecializedSciMsgType << endl;
+ clog << "\tsystem SCI msg type = ";
+ displaySpecializedSciMsgType();
+ clog << endl;
return true;
}
@@ -261,8 +281,7 @@ bool SystemSciMsg::setSpecializedSciMsgHeader ( const System_Header * p_speciali
}
else
{
- Error e = Error("SystemSciMsg::setSpecializedSciMsgHeader", "System SCI msg header pointer is NULL");
- throw (e);
+ throw Error("SystemSciMsg::setSpecializedSciMsgHeader", "System SCI msg header pointer is NULL");
}
return bSetHeader;