From: <sv...@ww...> - 2004-05-23 20:37:05
|
Author: wolverine Date: 2004-05-23 13:36:54 -0700 (Sun, 23 May 2004) New Revision: 957 Modified: trunk/CSP/CSPSim/CHANGES.current trunk/CSP/CSPSim/Data/CSPSim.ini trunk/CSP/CSPSim/Include/Networking.h trunk/CSP/CSPSim/Source/DynamicObject.cpp trunk/CSP/CSPSim/Source/ServerNode.cpp Log: changes to format of object update message Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2004-05-17 18:07:54 UTC (rev 956) +++ trunk/CSP/CSPSim/CHANGES.current 2004-05-23 20:36:54 UTC (rev 957) @@ -1,6 +1,15 @@ Version 0.4.0 (in progress) =========================== +2004-05-23: wolverine + * Changes to the format of the object update message. Now There + is a special class for the object update payload section that + contains fields for the payload data members. This should be + uptained by casting the payload ptr to a ObjectUpdateMessagePayload + pointer for both send and receive. Loading and Unloading can be + performed with object assignments instead of memcpys to make + the code a little clearer. + 2004-05-16: wolverine * changes to networking include configuration from CSPSim.ini which includes ports, server node, option to disable/enable Modified: trunk/CSP/CSPSim/Data/CSPSim.ini =================================================================== --- trunk/CSP/CSPSim/Data/CSPSim.ini 2004-05-17 18:07:54 UTC (rev 956) +++ trunk/CSP/CSPSim/Data/CSPSim.ini 2004-05-23 20:36:54 UTC (rev 957) @@ -38,7 +38,7 @@ [Networking] UseNetworking = true LocalMessagePort = 3150 -LocalMessageHost = 127.0.0.1 +LocalMessageHost = 127.0.0.1 RemoteMessagePort = 3160 RemoteMessageHost = 127.0.0.1 Modified: trunk/CSP/CSPSim/Include/Networking.h =================================================================== --- trunk/CSP/CSPSim/Include/Networking.h 2004-05-17 18:07:54 UTC (rev 956) +++ trunk/CSP/CSPSim/Include/Networking.h 2004-05-23 20:36:54 UTC (rev 957) @@ -37,6 +37,8 @@ #include <SimData/Vector3.h> #include <SimData/String.h> #include <SimData/Uniform.h> +#include <SimData/Quat.h> +#include <SimData/Date.h> typedef int SockFd; typedef simdata::uint16 Port; @@ -91,16 +93,24 @@ }; -//class ObjectUpdateMessage : public NetworkMessage -//{ -// -// public: -// ObjectUpdateMessage(simdata::uint16 id, simdata::Vector3 position, simdata::Vector3 velocity); -// -// -//}; +class ObjectUpdateMessagePayload +{ + private: + ObjectUpdateMessagePayload(); + public: + unsigned int id; + simdata::SimTime timeStamp; + simdata::Vector3 globalPosition; + simdata::Vector3 linearVelocity; + simdata::Vector3 angularVelocity; + simdata::Quat attitude; + + +}; + + class NetworkNode { private: Modified: trunk/CSP/CSPSim/Source/DynamicObject.cpp =================================================================== --- trunk/CSP/CSPSim/Source/DynamicObject.cpp 2004-05-17 18:07:54 UTC (rev 956) +++ trunk/CSP/CSPSim/Source/DynamicObject.cpp 2004-05-23 20:36:54 UTC (rev 957) @@ -372,7 +372,7 @@ if (InputInterface::onMapEvent(event)) { return true; } - if (m_SystemsModel.valid() && m_SystemsModel->onMapEvent(event)) { +if (m_SystemsModel.valid() && m_SystemsModel->onMapEvent(event)) { return true; } return false; @@ -401,33 +401,14 @@ NetworkMessage * message = CSPSim::theSim->getNetworkMessenger()->getMessageFromPool(messageType, payloadLen); - unsigned char * ptrBuf = (unsigned char*)message->getPayloadPtr(); - -// printf("Generating network update message for object id: %d\n", m_ID); - memcpy((void*)ptrBuf, (void*)&m_ID, sizeof(unsigned int)); ptrBuf += sizeof(unsigned int); - - simdata::SimTime timeStamp = CSPSim::theSim->getElapsedTime(); - memcpy((void*)ptrBuf, (void*)&timeStamp, sizeof(simdata::SimTime)); ptrBuf += sizeof(simdata::SimTime); - - int bytescopied; - bytescopied = b_GlobalPosition->value().writeBinary(ptrBuf, sizeof(simdata::Vector3)); - ptrBuf += bytescopied; - - bytescopied = b_LinearVelocity->value().writeBinary(ptrBuf, sizeof(simdata::Vector3)); - ptrBuf += bytescopied; - - bytescopied = b_AngularVelocity->value().writeBinary(ptrBuf, sizeof(simdata::Vector3)); - ptrBuf += bytescopied; - - bytescopied = b_Attitude->value().writeBinary(ptrBuf, sizeof(simdata::Quat)); - ptrBuf += bytescopied; - -// bytescopied = b_Inertia->value().writeBinary(ptrBuf, sizeof(simdata::Quat)); -// ptrBuf += bytescopied; + ObjectUpdateMessagePayload * ptrPayload = (ObjectUpdateMessagePayload*)message->getPayloadPtr(); + ptrPayload->id = m_ID; + ptrPayload->timeStamp = CSPSim::theSim->getElapsedTime(); + ptrPayload->globalPosition = b_GlobalPosition->value(); + ptrPayload->linearVelocity = b_LinearVelocity->value(); + ptrPayload->angularVelocity = b_AngularVelocity->value(); + ptrPayload->attitude = b_Attitude->value(); -// memcpy((void*)ptrBuf, (void*)&b_Mass->value(), sizeof(double)); -// ptrBuf += bytescopied; - CSP_LOG(APP, DEBUG, "DynamicObject::getUpdateMessage() - returning message"); @@ -438,15 +419,9 @@ { // read message - unsigned char * ptrBuf = (unsigned char*)message->getPayloadPtr(); - - // skip object id - unsigned int idValue; - memcpy((void*)&idValue, (void*)ptrBuf, sizeof(unsigned int)); - ptrBuf += sizeof(unsigned int); - + ObjectUpdateMessagePayload * ptrPayload = (ObjectUpdateMessagePayload*)message->getPayloadPtr(); // verify we have the correct id in the packet for this object. - if (m_ID == idValue) + if (m_ID == ptrPayload->id) { // printf("Loading update message of object %d\n", m_ID); } @@ -455,32 +430,17 @@ // printf("Error loading update message, object id (%d) does not match\n", idValue); } - // get timestamp - simdata::SimTime timeStamp; - memcpy((void*)&timeStamp, (void*)ptrBuf, sizeof(simdata::SimTime)); ptrBuf += sizeof(simdata::SimTime); - - int bytescopied; - bytescopied = b_GlobalPosition->value().readBinary(ptrBuf, sizeof(simdata::Vector3)); - ptrBuf += bytescopied; - bytescopied = b_LinearVelocity->value().readBinary(ptrBuf, sizeof(simdata::Vector3)); - ptrBuf += bytescopied; - bytescopied = b_AngularVelocity->value().readBinary(ptrBuf, sizeof(simdata::Vector3)); - ptrBuf += bytescopied; - bytescopied = b_Attitude->value().readBinary(ptrBuf, sizeof(simdata::Quat)); - ptrBuf += bytescopied; -// bytescopied = b_Inertia->value().readBinary(ptrBuf, sizeof(simdata::Matrix3)); -// ptrBuf += bytescopied; + // we can disregard this message if the timestamp is older then the most + // recent update. -// double *pValue = &b_Mass->value(); -// memcpy((void*)&pValue, (void*)ptrBuf, sizeof(double)); + //ptrPayload->timeStamp = CSPSim::theSim->getElapsedTime(); + // + //load the other values. + b_GlobalPosition->value() = ptrPayload->globalPosition; + b_LinearVelocity->value() = ptrPayload->linearVelocity; + b_AngularVelocity->value() = ptrPayload->angularVelocity; + b_Attitude->value() = ptrPayload->attitude; - //ptrBuf += sizeof(double); - - // return message to shared pool. - // NetworkMessagePool.putMessageObject(message); -// delete message; -// -// CSPSim::theSim->getNetworkMessenger()->returnMessageToPool(message); } Modified: trunk/CSP/CSPSim/Source/ServerNode.cpp =================================================================== --- trunk/CSP/CSPSim/Source/ServerNode.cpp 2004-05-17 18:07:54 UTC (rev 956) +++ trunk/CSP/CSPSim/Source/ServerNode.cpp 2004-05-23 20:36:54 UTC (rev 957) @@ -35,6 +35,11 @@ printf("Received Data From Client:\n"); printf("Client addr: %s\n", node->getHostname()); printf("Client port: %d\n", node->getPort()); + ObjectUpdateMessagePayload * ptrPayload = (ObjectUpdateMessagePayload*)message->getPayloadPtr(); + printf("PositionX: %f, PositionY: %f, PositionZ: %f\n", + ptrPayload->globalPosition.x(), + ptrPayload->globalPosition.y(), + ptrPayload->globalPosition.z()); } else { |