/** * Writes (AT) command to device and reads reply. * * \todo This makes no reply parsing or error detection. */ static void FBUS2_WriteDLR3(GSM_StateMachine *s, const char *command, int length, int timeout) { unsigned char buff[300]={0}; int w = 0,recvlen=0; gboolean wassomething = FALSE; GSM_DumpMessageLevel2(s, command, length, 0xff); s->Device.Functions->WriteDevice(s, command, length); for (w = 0; w < timeout; w++) { recvlen = s->Device.Functions->ReadDevice(s, buff, sizeof(buff)); if (wassomething && recvlen == 0) { return; } else if (recvlen > 0) { GSM_DumpMessageLevel2Recv(s, buff, recvlen, 0xff); wassomething = TRUE; } usleep(50000); } }
GSM_Error GSM_DispatchMessage(GSM_StateMachine *s) { GSM_Error error = ERR_UNKNOWNFRAME; GSM_Protocol_Message *msg = s->Phone.Data.RequestMsg; GSM_Phone_Data *Phone = &s->Phone.Data; gboolean disp = FALSE; GSM_Reply_Function *Reply; int reply; GSM_DumpMessageLevel2Recv(s, msg->Buffer, msg->Length, msg->Type); GSM_DumpMessageLevel3Recv(s, msg->Buffer, msg->Length, msg->Type); Reply = s->User.UserReplyFunctions; if (Reply != NULL) { error = CheckReplyFunctions(s,Reply,&reply); } if (error == ERR_UNKNOWNFRAME) { Reply = s->Phone.Functions->ReplyFunctions; error = CheckReplyFunctions(s,Reply,&reply); } if (error==ERR_NONE) { error=Reply[reply].Function(msg, s); if (Reply[reply].requestID==Phone->RequestID) { if (error == ERR_NEEDANOTHERANSWER) { error = ERR_NONE; } else { Phone->RequestID=ID_None; } } } if (strcmp(s->Phone.Functions->models,"NAUTO")) { disp = TRUE; switch (error) { case ERR_UNKNOWNRESPONSE: smprintf_level(s, D_ERROR, "\nUNKNOWN response"); break; case ERR_UNKNOWNFRAME: smprintf_level(s, D_ERROR, "\nUNKNOWN frame"); break; case ERR_FRAMENOTREQUESTED: smprintf_level(s, D_ERROR, "\nFrame not request now"); break; default: disp = FALSE; } if (error == ERR_UNKNOWNFRAME || error == ERR_FRAMENOTREQUESTED) { error = ERR_TIMEOUT; } } if (disp) { smprintf(s,". Please report the error, see <http://wammu.eu/support/bugs/>. Thank you\n"); if (Phone->SentMsg != NULL) { smprintf(s,"LAST SENT frame "); smprintf(s, "type 0x%02X/length %ld", Phone->SentMsg->Type, (long)Phone->SentMsg->Length); DumpMessage(GSM_GetDI(s), Phone->SentMsg->Buffer, Phone->SentMsg->Length); } smprintf(s, "RECEIVED frame "); smprintf(s, "type 0x%02X/length 0x%lx/%ld", msg->Type, (long)msg->Length, (long)msg->Length); DumpMessage(GSM_GetDI(s), msg->Buffer, msg->Length); smprintf(s, "\n"); } return error; }