# HG changeset patch # User Giulio Moro # Date 1438001571 -3600 # Node ID f944d0b60fa886f52a25241a6b931e2cb04dada6 # Parent 31ca45939a0ca4e69fd2188dc95ffdc16771c96a Removed old client.cpp and client.h files diff -r 31ca45939a0c -r f944d0b60fa8 core/RTAudio.cpp --- a/core/RTAudio.cpp Mon Jul 27 13:00:25 2015 +0100 +++ b/core/RTAudio.cpp Mon Jul 27 13:52:51 2015 +0100 @@ -31,7 +31,6 @@ #include "../include/PRU.h" #include "../include/I2c_Codec.h" #include "../include/GPIOcontrol.h" -#include "../include/client.h" // ARM interrupt number for PRU event EVTOUT7 #define PRU_RTAUDIO_IRQ 21 diff -r 31ca45939a0c -r f944d0b60fa8 core/client.cpp --- a/core/client.cpp Mon Jul 27 13:00:25 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +0,0 @@ -///* UDP client in the internet domain */ - -#include -#include -#include -#include "../include/client.h" -#include -#include - -#define MESSAGE_BUFF_LEN 1024 -#define MAX_VAR_STRING 20 - -struct sockaddr_in outServer, inServer; -int outSock, inSock, n, length; -socklen_t fromlen; -struct sockaddr_in from; -char inBuffer[1024]; -char variableString[MAX_VAR_STRING]; - -int setupSockets(int receivePort, int transmitPort, char const*serverName){ - //setup transmitter - printf("receivePort: %d; transmitPort: %d; serverName: %s\n",receivePort, transmitPort, serverName); - outSock= socket(AF_INET, SOCK_DGRAM, 0); - outServer.sin_port = htons(transmitPort); - if (outSock < 0){ - error("Opening out socket"); - return -1; - } - outServer.sin_family = AF_INET; - inet_pton(AF_INET,serverName,&outServer.sin_addr); - - //setup receiver - inSock=socket(AF_INET, SOCK_DGRAM, 0); - if (inSock < 0){ - return -1; - error("Opening in socket"); - } - length = sizeof(inServer); - inServer.sin_family=AF_INET; - inServer.sin_addr.s_addr=INADDR_ANY; - inServer.sin_port=htons(receivePort); - if (bind(inSock,(struct sockaddr *)&inServer,length)<0) - error("binding"); - fromlen = sizeof(struct sockaddr_in); - return 0; -} -int sendMessage(networkData message) -{ - unsigned int length; - char buffer[MESSAGE_BUFF_LEN]; - length=sizeof(struct sockaddr_in); - int k=0; - k=sprintf(buffer+k, "%8d;",*message.counter); - for(int j=0; jMESSAGE_BUFF_LEN - 20) //safety margin - continue; - } - sprintf(buffer+k,"\n"); - // printf(buffer); - n=sendto(outSock,buffer, - strlen(buffer),0,(const struct sockaddr *)&outServer,length); - if (n < 0) error("Sendto"); - return 0; -} - -int sendAudio(networkAudio *audio) -{ - unsigned int length; - length=sizeof(struct sockaddr_in); -// for(int k=0; kbuffers[!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; - fd_set stReadFDS; - FD_ZERO(&stReadFDS); - // Timeout of one second - stTimeOut.tv_sec = 0; - stTimeOut.tv_usec = 0; - FD_SET(inSock, &stReadFDS); - - int t = select(inSock+1, &stReadFDS, NULL, NULL, &stTimeOut); - if (t == -1) { - rt_fprintf(stderr, "Call to select() failed"); - return -1; - } - else if (t != 0) { - if (FD_ISSET(inSock, &stReadFDS)) { -// printf("There is data pending to be read..."); // Read data with recv() - int n = recvfrom(inSock,inBuffer,1024,0,(struct sockaddr *)&from,&fromlen); - if (n < 0){ - rt_fprintf(stderr,"Error while receiving"); - return -1; - } - printf("Received a datagram: "); - printf(inBuffer); - //the worst parser ever - int previousN=0; - int currentVariable=0; - for(int n=0; inBuffer[n]!=0 && currentVariable -#include -#include -#include -#include -#include -#include -#include -#include -#include "UdpClient.h" - -struct networkData{ - int *counter; - float *variables[16]; - int numVariables; -}; -#define NETWORK_AUDIO_BUFFER_SIZE 100 //1400/4 //maximum payload for a UDP datagram over ethernet is 1472 bytes, I leave some headroom and divide by 4 to get the number of floats -struct networkAudio{ - int timestamp; - int currentBuffer; - int index; - float buffers[2][NETWORK_AUDIO_BUFFER_SIZE]; - int doneOnTime; - bool toBeSent; - UdpClient udpClient; -}; - -void error(const char *); -int setupSockets(int receivePort, int transmitPort, char const*serverName); -int sendMessage(networkData message); -int sendAudio(networkAudio *audio); -int receiveMessage(networkData message); -void closeSockets();