I'm receiving data from my sensor via TCP and the output looks like this: <-0.040000 , -0.005000 , 0,025000 , 0,990000 , -0,000500 , 0.033000 >
It's a 6 times double value. I need only first three. Forces in X,Y and Z direction to get their resultant force. I was told I'm reciving 'sensor streams string representation of double' and that I should use atof function which takes a string representing of a floating point number and returns a double.
So, the problem is. I'm using following code to receive data from sensor
char recvbuf[DEFAULT_BUFFER_LENGTH];
int iResult = recv(ConnectSocket, recvbuf, DEFAULT_BUFFER_LENGTH, 0);
double n;
n = atof (recvbuf);
Output is always wrong, either I get wrong data, 30000 instead of 0.1414, or I read 0.15 as 0. Any tips on how should I get all 3 data? I use BUFFER=50, cuz I don't need to read more and I don't even know how long in total, string from sensor is.
You need to break this down into smaller steps. For example:
recvbuf
) for a start-of-data marker '<'
.'>'
, go to step 4.atof
or fscanf
.