change signature of parseData to use unsigned char*, include packet header always

This commit is contained in:
Stephen Birarda 2013-04-16 11:51:36 -07:00
parent 288a259ac1
commit 5c091a51a6
16 changed files with 40 additions and 41 deletions

View file

@ -309,7 +309,7 @@ int main(int argc, const char * argv[])
agentList->increaseAgentId();
}
agentList->updateAgentWithData(agentAddress, (void *)packetData, receivedBytes);
agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);
} else {
memcpy(loopbackAudioPacket, packetData + 1 + (sizeof(float) * 4), 1024);
agentList->getAgentSocket().send(agentAddress, loopbackAudioPacket, 1024);

View file

@ -77,7 +77,7 @@ int main(int argc, char* argv[])
switch (packetData[0]) {
case PACKET_HEADER_HEAD_DATA:
// this is positional data from an agent
agentList->updateAgentWithData(agentAddress, (void *)(packetData + 1), receivedBytes);
agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);
currentBufferPosition = broadcastPacket + 1;
agentIndex = 0;

View file

@ -1174,7 +1174,7 @@ void Head::SetNewHeadTarget(float pitch, float yaw) {
YawTarget = yaw;
}
void Head::processTransmitterData(char *packetData, int numBytes) {
void Head::processTransmitterData(unsigned char *packetData, int numBytes) {
// Read a packet from a transmitter app, process the data
float accX, accY, accZ,
graX, graY, graZ,

View file

@ -139,7 +139,7 @@ class Head : public AvatarData {
void renderBody();
void renderHead( int faceToFace, int isMine );
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );
void renderOrientataionDirections( glm::vec3 position, Orientation orientation, float size );
void simulate(float);
@ -166,7 +166,7 @@ class Head : public AvatarData {
// Related to getting transmitter UDP data used to animate the avatar hand
//
void processTransmitterData(char * packetData, int numBytes);
void processTransmitterData(unsigned char * packetData, int numBytes);
float getTransmitterHz() { return transmitterHz; };
private:

View file

@ -112,33 +112,33 @@ long int VoxelSystem::getVoxelsBytesReadRunningAverage() {
}
void VoxelSystem::parseData(void *data, int size) {
void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
unsigned char command = *(unsigned char*)data;
unsigned char *voxelData = (unsigned char *) data + 1;
unsigned char command = *sourceBuffer;
unsigned char *voxelData = sourceBuffer + 1;
switch(command) {
case PACKET_HEADER_VOXEL_DATA:
// ask the VoxelTree to read the bitstream into the tree
tree->readBitstreamToTree(voxelData, size - 1);
tree->readBitstreamToTree(voxelData, numBytes - 1);
break;
case PACKET_HEADER_ERASE_VOXEL:
// ask the tree to read the "remove" bitstream
tree->processRemoveVoxelBitstream((unsigned char*)data,size);
tree->processRemoveVoxelBitstream(sourceBuffer, numBytes);
break;
case PACKET_HEADER_Z_COMMAND:
// the Z command is a special command that allows the sender to send high level semantic
// requests, like erase all, or add sphere scene, different receivers may handle these
// messages differently
char* packetData =(char*)data;
char* packetData = (char *)sourceBuffer;
char* command = &packetData[1]; // start of the command
int commandLength = strlen(command); // commands are null terminated strings
int totalLength = 1+commandLength+1;
printf("got Z message len(%d)= %s\n",size,command);
printf("got Z message len(%d)= %s\n", numBytes, command);
while (totalLength <= size) {
while (totalLength <= numBytes) {
if (0==strcmp(command,(char*)"erase all")) {
printf("got Z message == erase all\n");
tree->eraseAllVoxels();

View file

@ -26,7 +26,7 @@ public:
VoxelSystem();
~VoxelSystem();
void parseData(void *data, int size);
void parseData(unsigned char* sourceBuffer, int numBytes);
VoxelSystem* clone() const;
void init();

View file

@ -1260,7 +1260,7 @@ void *networkReceive(void *args)
{
sockaddr senderAddress;
ssize_t bytesReceived;
char *incomingPacket = new char[MAX_PACKET_SIZE];
unsigned char *incomingPacket = new unsigned char[MAX_PACKET_SIZE];
while (!stopNetworkReceiveThread) {
if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {

View file

@ -60,16 +60,17 @@ int AvatarData::getBroadcastData(char* destinationBuffer) {
}
// called on the other agents - assigns it to my views of the others
void AvatarData::parseData(void *sourceBuffer, int numBytes) {
void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
char* bufferPointer = (char*) sourceBuffer ;
// increment to push past the packet header
sourceBuffer++;
memcpy(&_bodyPosition, bufferPointer, sizeof(float) * 3);
bufferPointer += sizeof(float) * 3;
memcpy(&_bodyPosition, sourceBuffer, sizeof(float) * 3);
sourceBuffer += sizeof(float) * 3;
bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyYaw);
bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyPitch);
bufferPointer += unpackFloatAngleFromTwoByte((uint16_t*)bufferPointer, &_bodyRoll);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll);
}
glm::vec3 AvatarData::getBodyPosition() {

View file

@ -26,7 +26,7 @@ public:
void setBodyPosition(glm::vec3 bodyPosition);
int getBroadcastData(char* destinationBuffer);
void parseData(void *sourceBuffer, int numBytes);
void parseData(unsigned char* sourceBuffer, int numBytes);
float getBodyYaw();
void setBodyYaw(float bodyYaw);

View file

@ -12,7 +12,7 @@
class AgentData {
public:
virtual ~AgentData() = 0;
virtual void parseData(void * data, int size) = 0;
virtual void parseData(unsigned char* sourceBuffer, int numBytes) = 0;
virtual AgentData* clone() const = 0;
};

View file

@ -98,7 +98,7 @@ void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size
}
}
void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData, int numTotalBytes, int numBytesPerAgent) {
void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent) {
// find the avatar mixer in our agent list and update the lastRecvTime from it
int bulkSendAgentIndex = indexOfMatchingAgent(senderAddress);
@ -131,7 +131,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, void *packetData,
delete[] packetHolder;
}
void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes) {
void AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
// find the agent by the sockaddr
int agentIndex = indexOfMatchingAgent(senderAddress);
@ -140,7 +140,7 @@ void AgentList::updateAgentWithData(sockaddr *senderAddress, void *packetData, s
}
}
void AgentList::updateAgentWithData(Agent *agent, void *packetData, int dataBytes) {
void AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) {
agent->setLastRecvTimeUsecs(usecTimestampNow());
if (agent->getLinkedData() == NULL) {

View file

@ -49,11 +49,11 @@ public:
bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId);
void processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
void processBulkAgentData(sockaddr *senderAddress, void *packetData, int numTotalBytes, int numBytesPerAgent);
void processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
void processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent);
void updateAgentWithData(sockaddr *senderAddress, void *packetData, size_t dataBytes);
void updateAgentWithData(Agent *agent, void *packetData, int dataBytes);
void updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
void updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes);
void broadcastToAgents(char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes);
char getOwnerType();

View file

@ -105,12 +105,10 @@ void AudioRingBuffer::setBearing(float newBearing) {
bearing = newBearing;
}
void AudioRingBuffer::parseData(void *data, int size) {
unsigned char *audioDataStart = (unsigned char *) data;
if (size > (bufferLengthSamples * sizeof(int16_t))) {
void AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
if (numBytes > (bufferLengthSamples * sizeof(int16_t))) {
unsigned char *dataPtr = audioDataStart + 1;
unsigned char *dataPtr = sourceBuffer + 1;
for (int p = 0; p < 3; p ++) {
memcpy(&position[p], dataPtr, sizeof(float));
@ -123,7 +121,7 @@ void AudioRingBuffer::parseData(void *data, int size) {
memcpy(&bearing, dataPtr, sizeof(float));
dataPtr += sizeof(float);
audioDataStart = dataPtr;
sourceBuffer = dataPtr;
}
if (endOfLastWrite == NULL) {
@ -134,7 +132,7 @@ void AudioRingBuffer::parseData(void *data, int size) {
started = false;
}
memcpy(endOfLastWrite, audioDataStart, bufferLengthSamples * sizeof(int16_t));
memcpy(endOfLastWrite, sourceBuffer, bufferLengthSamples * sizeof(int16_t));
endOfLastWrite += bufferLengthSamples;

View file

@ -19,7 +19,7 @@ class AudioRingBuffer : public AgentData {
~AudioRingBuffer();
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
void parseData(void *data, int size);
void parseData(unsigned char* sourceBuffer, int numBytes);
AudioRingBuffer* clone() const;
int16_t* getNextOutput();

View file

@ -22,7 +22,7 @@ public:
~VoxelAgentData();
VoxelAgentData(const VoxelAgentData &otherAgentData);
void parseData(void *data, int size);
void parseData(unsigned char* sourceBuffer, int numBytes);
VoxelAgentData* clone() const;
};

View file

@ -385,7 +385,7 @@ int main(int argc, const char * argv[])
agentList->increaseAgentId();
}
agentList->updateAgentWithData(&agentPublicAddress, (void *)packetData, receivedBytes);
agentList->updateAgentWithData(&agentPublicAddress, packetData, receivedBytes);
}
}
}