RetCode ReadBuf(MSComm * msComm, char * buf)
{
int i = 0;
//int j = 0; // CHECK
int k = 0;
char *data = (char *)buffer; // CHECK
do {
// Read a character from the device
int tempChar = data[k++]; // CHECK
//int tempChar = msComm->readCharFunc(); // ADDED
if (tempChar > 0) {
// Store character into buffer
buf[i++] = tempChar;
if (tempChar == '\n') {
buf[i] = '\0'; // ADDED
if (buf[0] == REPLY_VERSION_RESPONSE) {
return CODE_VERSION_RESPONSE;
} else if ((buf[0] == REPLY_MEASURING) || (buf[0] == REPLY_NSCANS_START)) {
return CODE_MEASURING;
} else if (strcmp(buf, "e\n") == 0) {
return CODE_RESPONSE_BEGIN;
} else if ((strcmp(buf, "*\n") == 0 || strcmp(buf, "-\n") == 0)) {
return CODE_MEASUREMENT_DONE;
} else if (strcmp(buf, "\n") == 0) {
return CODE_RESPONSE_END;
} else if (buf[0] == REPLY_MEASURE_DP) {
return CODE_OK;
} else {
printf("Unexpected response from ES Pico: \"%s\"\n", buf);
return CODE_NOT_IMPLEMENTED;
}
}
}
} while (i < (READ_BUFFER_LENGTH - 1));
buf[i] = '\0';
return CODE_NULL;
}