comparison core/client.cpp @ 25:98aed580452a bbb_network

- Network now actually works.
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 08 May 2015 17:48:58 +0100
parents ad5cd8dd99b3
children 12ee9a61e81d
comparison
equal deleted inserted replaced
24:ad5cd8dd99b3 25:98aed580452a
78 struct timeval stTimeOut; 78 struct timeval stTimeOut;
79 fd_set stReadFDS; 79 fd_set stReadFDS;
80 FD_ZERO(&stReadFDS); 80 FD_ZERO(&stReadFDS);
81 // Timeout of one second 81 // Timeout of one second
82 stTimeOut.tv_sec = 0; 82 stTimeOut.tv_sec = 0;
83 stTimeOut.tv_usec = 1000; 83 stTimeOut.tv_usec = 0;
84 FD_SET(inSock, &stReadFDS); 84 FD_SET(inSock, &stReadFDS);
85 85
86 int t = select(inSock+1, &stReadFDS, NULL, NULL, &stTimeOut); 86 int t = select(inSock+1, &stReadFDS, NULL, NULL, &stTimeOut);
87 if (t == -1) { 87 if (t == -1) {
88 rt_fprintf(stderr, "Call to select() failed"); 88 rt_fprintf(stderr, "Call to select() failed");
99 printf("Received a datagram: "); 99 printf("Received a datagram: ");
100 printf(inBuffer); 100 printf(inBuffer);
101 //the worst parser ever 101 //the worst parser ever
102 int previousN=0; 102 int previousN=0;
103 int currentVariable=0; 103 int currentVariable=0;
104 for(int n=0; inBuffer[n]!=0 && currentVariable<message.numVariables && n-previousN<MAX_VAR_STRING;n++){ //scan the string 104 for(int n=0; inBuffer[n]!=0 && currentVariable<message.numVariables && n-previousN<MAX_VAR_STRING && n<BUFF_LEN; n++){ //scan the string
105 if(inBuffer[n]==';'||n==0){ // if you find a separator or you are at the end of the string, parse the variable 105 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
106 int j=0; 106 int j=0;
107 inBuffer[n]=0; //set the semicolon to 0 ... 107 inBuffer[n]=0; //set the semicolon to 0 ...
108 while( (variableString[j++]=inBuffer[previousN++]) ); // ... so that this will stop when it gets there 108 while( (variableString[j++]=inBuffer[previousN++]) );; // ... so that this will stop when it gets there
109 rt_printf("variable %d: %s\n", currentVariable, variableString); 109 rt_printf("variable %d: %s\n", currentVariable, variableString);
110 *(message.variables[currentVariable])=atof(variableString); 110 *(message.variables[currentVariable])=atof(variableString);
111 n++; //increment to step after the semicolon 111 n++; //increment to step after the semicolon
112 previousN=n; 112 previousN=n;
113 currentVariable++; 113 currentVariable++;