Mercurial > hg > beaglert
diff core/client.cpp @ 70:f3251851c718
Brought UdpClient files over from ultra-staging branch (with include fix), and updated Makefile accordingly
author | andrewm |
---|---|
date | Fri, 17 Jul 2015 17:50:54 +0100 |
parents | 579c86316008 |
children |
line wrap: on
line diff
--- a/core/client.cpp Fri Jul 17 17:41:35 2015 +0100 +++ b/core/client.cpp Fri Jul 17 17:50:54 2015 +0100 @@ -7,7 +7,7 @@ #include <unistd.h> #include <rtdk.h> -#define BUFF_LEN 1024 +#define MESSAGE_BUFF_LEN 1024 #define MAX_VAR_STRING 20 struct sockaddr_in outServer, inServer; @@ -47,13 +47,13 @@ int sendMessage(networkData message) { unsigned int length; - char buffer[BUFF_LEN]; + char buffer[MESSAGE_BUFF_LEN]; length=sizeof(struct sockaddr_in); int k=0; k=sprintf(buffer+k, "%8d;",*message.counter); for(int j=0; j<message.numVariables; j++){ k+=sprintf(buffer+k, "%.3f;",*message.variables[j]); - if(k>BUFF_LEN - 20) //safety margin + if(k>MESSAGE_BUFF_LEN - 20) //safety margin continue; } sprintf(buffer+k,"\n"); @@ -63,16 +63,18 @@ if (n < 0) error("Sendto"); return 0; } -/* -int receiveMessage() + +int sendAudio(networkAudio *audio) { - int n = recvfrom(inSock,inBuffer,1024,0,(struct sockaddr *)&from,&fromlen); - if (n < 0) error("recvfrom"); - printf("Received a datagram: "); - printf(inBuffer); - } -*/ - + unsigned int length; + length=sizeof(struct sockaddr_in); +// for(int k=0; k<NETWORK_AU DIO_BUFFER_SIZE; k++) +// printf("%f\n",audio.buffers[!audio.currentBuffer][k]); + n=sendto(outSock,audio->buffers[!audio->currentBuffer],NETWORK_AUDIO_BUFFER_SIZE*sizeof(float),0,(const struct sockaddr *)&outServer,length); + if (n < 0) error("Sendto"); + audio->doneOnTime=1; + return 0; +} int receiveMessage(networkData message){ struct timeval stTimeOut; @@ -97,11 +99,11 @@ return -1; } printf("Received a datagram: "); - printf("%s", inBuffer); + printf(inBuffer); //the worst parser ever int previousN=0; int currentVariable=0; - for(int n=0; inBuffer[n]!=0 && currentVariable<message.numVariables && n-previousN<MAX_VAR_STRING && n<BUFF_LEN; n++){ //scan the string + for(int n=0; inBuffer[n]!=0 && currentVariable<message.numVariables && n-previousN<MAX_VAR_STRING && n<MESSAGE_BUFF_LEN; n++){ //scan the string if(inBuffer[n]==';'||inBuffer[n]==0||inBuffer[n]=='\n'){ // if you find a separator or you are at the end of the string, parse the variable int j=0; inBuffer[n]=0; //set the semicolon to 0 ...