Attached the class bluetooth
The function that checks data is
CommandStatus __FASTCALLCLASSFAST Chk_Answer(unsigned char command)
{
unsigned short buffer_len;
short n_car;
unsigned char car;
CommandStatus status;
unsigned char rx_bcc;
unsigned char n_bcc_car;
unsigned long tim;
unsigned char rx_status;
unsigned char buffer[280];
short rx_data_len;
short rx_buffer_ptr;
// Inizializzazione attesa risposta
SerialPort->StartTimer(RX_INTERCAR_TIMER, EXECUTE_CMD_MASTER_TIMEOUT);
rx_status = RX_WAITSTX;
do
{
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
buffer_len = SerialPort->ReadData(buffer, usLenBufferRX);
for(n_car=0; n_car<buffer_len; n_car++)
{
car = buffer[n_car];
switch(rx_status)
{
case RX_WAITSTX: if(car == STX)
rx_status = RX_WAITCMD;
break;
case RX_WAITCMD: rx_buffer_ptr = 0;
if(rx_buffer_ptr == usLenBufferRX)
rx_status = RX_WAITSTX;
else
{
ucBufferRX[rx_buffer_ptr++] = car;
rx_status = RX_WAITCMDSTATUS;
}
break;
case RX_WAITCMDSTATUS:
if(rx_buffer_ptr == usLenBufferRX)
rx_status = RX_WAITSTX;
else
{
ucBufferRX[rx_buffer_ptr++] = car;
rx_status = RX_WAITLEN;
status = (CommandStatus)car;
if(status!=StatusCMD_DONE)
{
rx_status = RX_WAITBCC;
rx_data_len = 1;
}
}
break;
case RX_WAITLEN: if(rx_buffer_ptr == usLenBufferRX)
rx_status = RX_WAITSTX;
else
{
ucBufferRX[rx_buffer_ptr++] = car;
rx_data_len = car;
if(rx_data_len)
rx_status = RX_DATA;
else
rx_status = RX_WAITBCC;
}
break;
case RX_DATA: if(rx_buffer_ptr == usLenBufferRX)
rx_status = RX_WAITSTX;
else
{
ucBufferRX[rx_buffer_ptr++] = car;
rx_data_len--;
if(!rx_data_len)
rx_status = RX_WAITBCC;
}
break;
case RX_WAITBCC: rx_bcc = 0;
for(n_bcc_car=0; n_bcc_car<rx_buffer_ptr; n_bcc_car++)
rx_bcc += ucBufferRX[n_bcc_car];
if(car == rx_bcc)
rx_status = RX_WAITETX;
else
rx_status = RX_WAITSTX;
break;
case RX_WAITETX: if(car == ETX)
rx_status = RX_END;
else
rx_status = RX_WAITSTX;
break;
}
}
if(buffer_len)
SerialPort->StartTimer(RX_INTERCAR_TIMER, RX_INTERCAR_TIMEOUT);
if(rx_status!=RX_END)
tim=SerialPort->CheckTimer(RX_INTERCAR_TIMER);
else
tim = 1;
}while(tim && rx_status!=RX_END);
// time out
if(rx_status!=RX_END)
status = StatusCMD_ERROR;
gEndAnswer = status;
return (status);
}
[attachment deleted by admin]