summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburet2007-06-07 17:09:59 +0000
committerburet2007-06-07 17:09:59 +0000
commitc3df772233e886963a5382af8579b30ca4863454 (patch)
tree675fd0575b2d175c5a7c7a8ecfd73756492352b6
parent37e7f2572aee43c33e335ab4a711a7c2a7e9664a (diff)
- Development of send sci msg
- Update tests git-svn-id: svn+ssh://pessac/svn/cesar/trunk@252 017c9cb6-072f-447c-8318-d5b54f68fe89
-rw-r--r--maximus/common/types/networkclock_types.h12
-rw-r--r--maximus/functioncall/src/FunctionCallManager.cpp19
-rw-r--r--maximus/functioncall/src/IFunctionCallTest.cpp1
-rw-r--r--maximus/networkclock/src/NetworkClockProcessor.cpp22
-rw-r--r--maximus/networkclock/src/NetworkClockProcessorTest.cpp12
-rw-r--r--maximus/sci/inc/SciServerTest.h8
-rw-r--r--maximus/sci/src/SciServer.cpp47
-rw-r--r--maximus/sci/src/SciServerTest.cpp143
-rw-r--r--maximus/system/src/SystemManager.cpp2
9 files changed, 201 insertions, 65 deletions
diff --git a/maximus/common/types/networkclock_types.h b/maximus/common/types/networkclock_types.h
index 7ef1832776..453ca5aef9 100644
--- a/maximus/common/types/networkclock_types.h
+++ b/maximus/common/types/networkclock_types.h
@@ -8,12 +8,12 @@
enum Network_Clock_Type
{
- NETWORK_CLOCK_TYPE_NONE = 0,
- NETWORK_CLOCK_TYPE_REMOVE,
- NETWORK_CLOCK_TYPE_STATION,
- NETWORK_CLOCK_TYPE_FUNCTION_CALL,
- NETWORK_CLOCK_TYPE_PHY,
- NETWORK_CLOCK_TYPE_SYSTEM,
+ NETWORK_CLOCK_TYPE_NONE = 0x00,
+ NETWORK_CLOCK_TYPE_REMOVE = 0x01,
+ NETWORK_CLOCK_TYPE_STATION = 0x02,
+ NETWORK_CLOCK_TYPE_FUNCTION_CALL = 0x03,
+ NETWORK_CLOCK_TYPE_PHY = 0x04,
+ NETWORK_CLOCK_TYPE_SYSTEM = 0x05,
NETWORK_CLOCK_TYPE_NB
};
diff --git a/maximus/functioncall/src/FunctionCallManager.cpp b/maximus/functioncall/src/FunctionCallManager.cpp
index e37283ccc2..a4d5bbf192 100644
--- a/maximus/functioncall/src/FunctionCallManager.cpp
+++ b/maximus/functioncall/src/FunctionCallManager.cpp
@@ -176,10 +176,12 @@ bool FunctionCallManager::sendMsg ( FunctionSciMsg * function_sci_msg_to_send )
0 }; // flags
bSend &= function_sci_msg_to_send->setSpecializedSciMsgHeader(&functionSciMsgHeader);
+ bSend &= function_sci_msg_to_send->setSciMsgDataLength(sizeof(struct Function_Call_Header) + function_sci_msg_to_send->getSpecializedSciMsgDataLength());
+ //bSend &= function_sci_msg_to_send->setSciMsgData();
struct Sci_Msg_Header sciMsgHeader = { (uint32_t)SCI_MSG_MAGIC,
SCI_MSG_VERSION,
SCI_MSG_TYPE_FUNCTION_CALL,
- sizeof(struct Function_Call_Header) + function_sci_msg_to_send->getSpecializedSciMsgDataLength(),
+ (uint16_t)function_sci_msg_to_send->getSciMsgDataLength(),
function_sci_msg_to_send->getStationId(),
0, // msg_id
netclockHigh,
@@ -190,13 +192,20 @@ bool FunctionCallManager::sendMsg ( FunctionSciMsg * function_sci_msg_to_send )
clog << "\tsends event to station" << endl;
- if (NULL != mpSciServer)
- {
- bSend &= mpSciServer->sendSciMsg(function_sci_msg_to_send);
+ if (bSend)
+ {
+ if (NULL != mpSciServer)
+ {
+ bSend = mpSciServer->sendSciMsg(function_sci_msg_to_send);
+ }
+ else
+ {
+ throw Error("FunctionCallManager::sendMsg", "SciServer pointer is NULL");
+ }
}
else
{
- throw Error("FunctionCallManager::sendMsg", "SciServer pointer is NULL");
+ throw Error("FunctionCallManager::sendMsg", "Event cannot be sent because it is not correctly filled in");
}
}
else
diff --git a/maximus/functioncall/src/IFunctionCallTest.cpp b/maximus/functioncall/src/IFunctionCallTest.cpp
index 6de3312506..e1e3c63cf1 100644
--- a/maximus/functioncall/src/IFunctionCallTest.cpp
+++ b/maximus/functioncall/src/IFunctionCallTest.cpp
@@ -65,7 +65,6 @@ void IFunctionCallTest::userTest (void)
{
clog << "\tIFunctionCallTest -> Error::display" << endl;
e.display();
- CPPUNIT_FAIL ( "Catch exception" );
}
clog << "-------------------------------------------------------------------------------------" << endl;
diff --git a/maximus/networkclock/src/NetworkClockProcessor.cpp b/maximus/networkclock/src/NetworkClockProcessor.cpp
index 708a5eacec..f850700ff9 100644
--- a/maximus/networkclock/src/NetworkClockProcessor.cpp
+++ b/maximus/networkclock/src/NetworkClockProcessor.cpp
@@ -293,23 +293,33 @@ bool NetworkClockProcessor::processEvtStation ( NetworkClockEvt & evt_to_process
0, // reserved
netclockHigh,
netclockLow };
- clockSciMsgToSend.setSpecializedSciMsgHeader(&clockSciMsgHeader);
- clockSciMsgToSend.setSpecializedSciMsgData(NULL);
+ bProcessStation = clockSciMsgToSend.setSpecializedSciMsgHeader(&clockSciMsgHeader);
+ bProcessStation &= clockSciMsgToSend.setSpecializedSciMsgDataLength(0);
+ bProcessStation &= clockSciMsgToSend.setSpecializedSciMsgData(NULL);
+ bProcessStation &= clockSciMsgToSend.setSciMsgDataLength(sizeof(struct Network_Clock_Header) + clockSciMsgToSend.getSpecializedSciMsgDataLength());
+ //bProcessStation &= clockSciMsgToSend.setSciMsgData();
struct Sci_Msg_Header sciMsgHeader = { (uint32_t)SCI_MSG_MAGIC,
SCI_MSG_VERSION,
SCI_MSG_TYPE_NETWORK_CLOCK,
- sizeof(struct Network_Clock_Header),
+ (uint16_t)clockSciMsgToSend.getSciMsgDataLength(),
evt_to_process.getStationId(),
0, // msg_id
netclockHigh,
netclockLow,
0, // flags
0 }; // reserved
- clockSciMsgToSend.setSciMsgHeader(&sciMsgHeader);
+ bProcessStation &= clockSciMsgToSend.setSciMsgHeader(&sciMsgHeader);
- clog << "\tsends event to station" << endl;
- bProcessStation = sendEvtMsg (clockSciMsgToSend);
+ if (bProcessStation)
+ {
+ clog << "\tsends event to station" << endl;
+ bProcessStation = sendEvtMsg (clockSciMsgToSend);
+ }
+ else
+ {
+ throw Error("NetworkClockProcessor::processEvtStation", "Event cannot be sent because it is not correctly filled in");
+ }
return bProcessStation;
}
diff --git a/maximus/networkclock/src/NetworkClockProcessorTest.cpp b/maximus/networkclock/src/NetworkClockProcessorTest.cpp
index 10a91a64d2..7d117de5db 100644
--- a/maximus/networkclock/src/NetworkClockProcessorTest.cpp
+++ b/maximus/networkclock/src/NetworkClockProcessorTest.cpp
@@ -1,6 +1,7 @@
#include "NetworkClockProcessorTest.h"
#include "Error.h"
+#include "Station.h"
#include <iostream>
using namespace std;
@@ -163,8 +164,15 @@ void NetworkClockProcessorTest::processNextEvtTest (void)
{
try
{
+ Sci_Station_Id stationId = 0;
+ Station * station = mpSystemManager->createStation(); // will be deleted by SystemManager
+ if (NULL != station)
+ {
+ stationId = station->getStationId();
+ }
+
clog << "\tNetworkClockProcessorTest -> NetworkClockEvt(...)" << endl;
- NetworkClockEvt evt (1415, 1718, NETWORK_CLOCK_TYPE_STATION);
+ NetworkClockEvt evt (stationId, 0, NETWORK_CLOCK_TYPE_STATION);
clog << "\tNetworkClockProcessorTest -> NetworkClockProcessor::insertEvt" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("insertEvt failed"),
@@ -190,7 +198,6 @@ void NetworkClockProcessorTest::processNextEvtTest (void)
{
clog << "\tNetworkClockProcessorTest -> Error::display" << endl;
e.display();
- CPPUNIT_FAIL ( "Catch exception" );
}
}
else
@@ -224,7 +231,6 @@ void NetworkClockProcessorTest::processEvtStationTest (void)
{
clog << "\tNetworkClockProcessorTest -> Error::display" << endl;
e.display();
- CPPUNIT_FAIL ( "Catch exception" );
}
}
else
diff --git a/maximus/sci/inc/SciServerTest.h b/maximus/sci/inc/SciServerTest.h
index 77ffed61b2..1667fe7d6b 100644
--- a/maximus/sci/inc/SciServerTest.h
+++ b/maximus/sci/inc/SciServerTest.h
@@ -47,10 +47,10 @@ private:
void registerPhySciMsgTest (void);
void registerSystemSciMsgTest (void);
void registerFunctionSciMsgTest (void);
- void receiveClockSciMsgTest ( Sci_Msg_Header & msg_header, unsigned long data_length, unsigned char * p_data );
- void receivePhySciMsgTest ( Sci_Msg_Header & msg_header, unsigned long data_length, unsigned char * p_data );
- void receiveSystemSciMsgTest ( Sci_Msg_Header & msg_header, unsigned long data_length, unsigned char * p_data );
- void receiveFunctionSciMsgTest ( Sci_Msg_Header & msg_header, unsigned long data_length, unsigned char * p_data );
+ void receiveClockSciMsgTest ( Sci_Msg_Header & msg_header );
+ void receivePhySciMsgTest ( Sci_Msg_Header & msg_header );
+ void receiveSystemSciMsgTest ( Sci_Msg_Header & msg_header );
+ void receiveFunctionSciMsgTest ( Sci_Msg_Header & msg_header );
};
diff --git a/maximus/sci/src/SciServer.cpp b/maximus/sci/src/SciServer.cpp
index 25a9d877d6..9279646bf4 100644
--- a/maximus/sci/src/SciServer.cpp
+++ b/maximus/sci/src/SciServer.cpp
@@ -148,9 +148,50 @@ bool SciServer::sendSciMsg ( const SciMsg * sci_msg_to_send ) const
if (NULL != sci_msg_to_send)
{
- // ...
+ // Retrieve destination station
+ //
+ Station * destination = NULL;
+ if (!mpListOfStations->empty())
+ {
+ for (StationsList::const_iterator it = mpListOfStations->begin(); it != mpListOfStations->end(); ++it)
+ {
+ if (NULL != *it)
+ {
+ if ( ((*it)->getStationId()) == sci_msg_to_send->getSciMsgHeader()->station_id )
+ {
+ destination = (*it);
+ it = mpListOfStations->end();
+ --it;
+ }
+ }
+ else
+ {
+ throw Error("SciServer::sendSciMsg", "Station pointer is NULL");
+ }
+ }
+ }
- bSend = true;
+ // Write data into output pipe
+ //
+ if (NULL != destination)
+ {
+ int length=0, totalLength=0;
+
+ while(totalLength < (int)sci_msg_to_send->getSciMsgDataLength())
+ {
+ length = write(destination->getOutputFileDescriptor(), sci_msg_to_send->getSciMsgData() + totalLength, sci_msg_to_send->getSciMsgDataLength());
+ if(length < 0)
+ {
+ throw Error("SciServer::sendSciMsg", "Write failed");
+ }
+ totalLength += length;
+ bSend = true;
+ }
+ }
+ else
+ {
+ throw Error("SciServer::sendSciMsg", "Destination station not found");
+ }
}
else
{
@@ -201,6 +242,8 @@ bool SciServer::receiveMsg ( const Sci_Msg_Header * header,
//
if (NULL != header)
{
+ displayMsgHeader(header);
+
// Create a specialized SCI message according to the message header type
//
SciMsg * sciMsg = NULL;
diff --git a/maximus/sci/src/SciServerTest.cpp b/maximus/sci/src/SciServerTest.cpp
index b94324f576..d95d590e53 100644
--- a/maximus/sci/src/SciServerTest.cpp
+++ b/maximus/sci/src/SciServerTest.cpp
@@ -9,6 +9,9 @@
#include <string>
#include <iostream>
+#include <iomanip>
+#include <stdio.h>
+#include <stdlib.h>
using namespace std;
CPPUNIT_TEST_SUITE_REGISTRATION (SciServerTest);
@@ -125,36 +128,31 @@ void SciServerTest::receiveMsgTest (void)
mpSciServer->displaySpecializedSciMsgArray();
- unsigned long dataLength = 60;
-
// Convert const char * to uint32_t
- uint32_t magicId = 0;
- stringstream ioss;
- ioss << SCI_MSG_MAGIC;
- ioss >> magicId;
+ //
+ uint32_t magicId = 0x00000000;
Sci_Msg_Header msgHeader = { magicId, // uint32_t magic_id
- SCI_MSG_VERSION, // uint8_t version
- SCI_MSG_TYPE_NONE, // uint8_t type
- (uint16_t)dataLength, // uint16_t length
+ 0x01,//SCI_MSG_VERSION, // uint8_t version = 0x01
+ 0x00,//SCI_MSG_TYPE_NONE, // uint8_t type = 0x00
+ 0x0000, // uint16_t length
0x0000, // uint16_t station_id
0x0000, // uint16_t msg_id
0x01234567, // uint32_t netclock_high
0x89101112, // uint32_t netclock_low
- 0x0000, //uint16_t flags
- 0xFFFF }; // uint16_t reserved
+ 0xFFFF, //uint16_t flags
+ 0xFFFF }; // uint16_t reserved
try
{
- receiveClockSciMsgTest (msgHeader, dataLength, (unsigned char *)"123456789011223344556677889900111222333444555666777888999000");
- receivePhySciMsgTest (msgHeader, dataLength, (unsigned char *)"123456789011223344556677889900111222333444555666777888999000");
- receiveSystemSciMsgTest (msgHeader, dataLength, (unsigned char *)"113456789011223344556677889900111222333444555666777888999000");
- receiveFunctionSciMsgTest (msgHeader, dataLength, (unsigned char *)"0020functionSciMsgCallback\0parameter1\0 012parameter2\0 061234");
+ receiveClockSciMsgTest (msgHeader);
+ receivePhySciMsgTest (msgHeader);
+ receiveSystemSciMsgTest (msgHeader);
+ receiveFunctionSciMsgTest (msgHeader);
}
catch ( Error &e )
{
e.display();
- CPPUNIT_FAIL ("Catch exception");
}
}
else
@@ -234,53 +232,116 @@ void SciServerTest::registerSystemSciMsgTest (void)
}
-void SciServerTest::receiveClockSciMsgTest ( Sci_Msg_Header & msg_header, unsigned long data_length, unsigned char * p_data )
+void SciServerTest::receiveClockSciMsgTest ( Sci_Msg_Header & msg_header )
{
- // Message header type has to be set to the corresponding specialized SCI message
- //
- msg_header.type = SCI_MSG_TYPE_NETWORK_CLOCK;
+ clog << "\tSciServerTest::receiveClockSciMsgTest" << endl;
+ // Message header type and length have to be set to the corresponding specialized SCI message
+ //
+ msg_header.type = 0x01;//SCI_MSG_TYPE_NETWORK_CLOCK; // uint8_t type = 0x01
+ msg_header.length = (uint16_t)(sizeof(struct Network_Clock_Header)); // uint16_t length = 0x0010
+
+ unsigned long dataLength = 28;//(unsigned long)msg_header.length; // 16
+
+ stringstream ioss;
+ ioss << hex << setfill('0') << setw(2) << uppercase << NETWORK_CLOCK_VERSION; // uint8_t version = 0x01
+ ioss << hex << setfill('0') << setw(2) << uppercase << NETWORK_CLOCK_TYPE_STATION; // uint8_t type = 0x02
+ ioss << hex << setfill('0') << setw(4) << uppercase << 0x0000; // uint16_t id
+ ioss << hex << setfill('0') << setw(4) << uppercase << 0xFFFF; // uint16_t flags
+ ioss << hex << setfill('0') << setw(4) << uppercase << 0xFFFF; // uint16_t reserved
+ ioss << hex << setfill('0') << setw(8) << uppercase << 0x01234567; // uint32_t tick_high
+ ioss << hex << setfill('0') << setw(8) << uppercase << 0x89101113; // uint32_t tick_low
+ unsigned char * pData = new unsigned char [ioss.str().length()];
+ if (NULL != pData)
+ {
+ ioss >> (unsigned char *)pData;
+ clog << "\tdata = 0x" << hex << pData << endl;
+ }
+
// Test the receiveMsg method
//
clog << "\tSciServerTest -> SciServer::receiveMsg" << endl;
- CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("receiveMsg failed"),
- mpSciServer->receiveMsg (&msg_header, data_length, p_data) );
+ CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("receiveMsg ClockSciMsg failed"),
+ mpSciServer->receiveMsg (&msg_header, dataLength, pData) );
+
+ // Free allocated memory
+ //
+ if (NULL != pData)
+ {
+ delete [] pData;
+ pData = NULL;
+ }
}
-void SciServerTest::receiveSystemSciMsgTest ( Sci_Msg_Header & msg_header, unsigned long data_length, unsigned char * p_data )
+void SciServerTest::receiveSystemSciMsgTest ( Sci_Msg_Header & msg_header )
{
- // Message header type has to be set to the corresponding specialized SCI message
+ clog << "\tSciServerTest::receiveSystemSciMsgTest" << endl;
+
+ // Message header type and length have to be set to the corresponding specialized SCI message
//
msg_header.type = SCI_MSG_TYPE_SYSTEM;
-
+ msg_header.length = (uint16_t)sizeof(struct System_Header);
+
+ unsigned long dataLength = (unsigned long)msg_header.length;
+ unsigned char * pData = new unsigned char [dataLength]; // TO FILL
+
// Test the receiveMsg method
//
clog << "\tSciServerTest -> SciServer::receiveMsg" << endl;
- CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("receiveMsg failed"),
- !mpSciServer->receiveMsg (&msg_header, data_length, p_data) );
+ CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("receiveMsg SystemSciMsg failed"),
+ !mpSciServer->receiveMsg (&msg_header, dataLength, pData) );
+
+ // Free allocated memory
+ //
+ if (NULL != pData)
+ {
+ delete [] pData;
+ pData = NULL;
+ }
}
-void SciServerTest::receivePhySciMsgTest ( Sci_Msg_Header & msg_header, unsigned long data_length, unsigned char * p_data )
+void SciServerTest::receivePhySciMsgTest ( Sci_Msg_Header & msg_header )
{
- // Message header type has to be set to the corresponding specialized SCI message
+ clog << "\tSciServerTest::receivePhySciMsgTest" << endl;
+
+ // Message header type and length have to be set to the corresponding specialized SCI message
//
msg_header.type = SCI_MSG_TYPE_PHY;
-
- // Test the receiveMsg method
+ msg_header.length = (uint16_t)sizeof(struct Phy_Header);
+
+ unsigned long dataLength = (unsigned long)msg_header.length;
+ unsigned char * pData = new unsigned char [dataLength]; // TO FILL
+
+ //Test the receiveMsg method
//
clog << "\tSciServerTest -> SciServer::receiveMsg" << endl;
- CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("receiveMsg failed"),
- mpSciServer->receiveMsg (&msg_header, data_length, p_data) );
+ CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("receiveMsg PhySciMsg failed"),
+ mpSciServer->receiveMsg (&msg_header, dataLength, pData) );
+
+ // Free allocated memory
+ //
+ if (NULL != pData)
+ {
+ delete [] pData;
+ pData = NULL;
+ }
}
-void SciServerTest::receiveFunctionSciMsgTest ( Sci_Msg_Header & msg_header, unsigned long data_length, unsigned char * p_data )
+void SciServerTest::receiveFunctionSciMsgTest ( Sci_Msg_Header & msg_header )
{
- // Message header type has to be set to the corresponding specialized SCI message
+ clog << "\tSciServerTest::receiveFunctionSciMsgTest" << endl;
+
+ // Message header type and length have to be set to the corresponding specialized SCI message
//
msg_header.type = SCI_MSG_TYPE_FUNCTION_CALL;
+ msg_header.length = 60;
+
+ unsigned long dataLength = (unsigned long)msg_header.length;
+ unsigned char * pData = new unsigned char [dataLength]; // TO FILL
+ //"0020functionSciMsgCallback\0parameter1\0 012parameter2\0 03123\0"
// Register callback
//
@@ -298,8 +359,16 @@ void SciServerTest::receiveFunctionSciMsgTest ( Sci_Msg_Header & msg_header, uns
// Test the receiveMsg method
//
clog << "\tSciServerTest -> SciServer::receiveMsg" << endl;
- CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("receiveMsg failed"),
- mpSciServer->receiveMsg (&msg_header, data_length, p_data) );
+ CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("receiveMsg FunctionSciMsg failed"),
+ !mpSciServer->receiveMsg (&msg_header, dataLength, pData) );
+
+ // Free allocated memory
+ //
+ if (NULL != pData)
+ {
+ delete [] pData;
+ pData = NULL;
+ }
}
diff --git a/maximus/system/src/SystemManager.cpp b/maximus/system/src/SystemManager.cpp
index fa22d320e8..ccf64ab730 100644
--- a/maximus/system/src/SystemManager.cpp
+++ b/maximus/system/src/SystemManager.cpp
@@ -212,7 +212,7 @@ bool SystemManager::setStationToIdle ( Sci_Station_Id station_id )
{
if (NULL != *it)
{
- if ( (Sci_Station_Id)((*it)->getStationId()) == station_id )
+ if ( ((*it)->getStationId()) == station_id )
{
(*it)->updateStationStatus(MAXIMUS_STATION_STATUS_IDLE);
it = mListOfStations.end();