byte GSM::WaitResp(uint16_t start_comm_tmout, uint16_t max_interchar_tmout, char const *expected_resp_string) { byte status; byte ret_val; RxInit(start_comm_tmout, max_interchar_tmout); // wait until response is not finished do { status = IsRxFinished(); } while (status == RX_NOT_FINISHED); if (status == RX_FINISHED) { // something was received but what was received? // --------------------------------------------- if(IsStringReceived(expected_resp_string)) { // expected string was received // ---------------------------- ret_val = RX_FINISHED_STR_RECV; } else { ret_val = RX_FINISHED_STR_NOT_RECV; } } else { // nothing was received // -------------------- ret_val = RX_TMOUT_ERR; } return (ret_val); }
/********************************************************** Methods receives data from the serial port return: number of received bytes an example of usage: GSM gsm; byte num_of_bytes; num_of_bytes = gsm.RcvData(5000, 100); if (num_of_bytes) { // some data were received } **********************************************************/ uint16_t GSM::RcvData(uint16_t start_comm_tmout, uint16_t max_interchar_tmout, byte** ptr_to_rcv_data) { byte status; RxInit(start_comm_tmout, max_interchar_tmout, 0, 0); // wait until response is not finished do { status = IsRxFinished(); } while (status == RX_NOT_FINISHED); if (comm_buf_len) *ptr_to_rcv_data = comm_buf; else *ptr_to_rcv_data = NULL; // check <CR><LF>NO CARRIER<CR><LF> // in case this string was received => socked is closed if (comm_buf_len) { if (StrInBin(comm_buf, "\r\nNO CARRIER\r\n", comm_buf_len) != -1) { // NO CARRIER was received => socket was closed from the host side // we can set the communication line to the FREE state SetCommLineStatus(CLS_FREE); } } return (comm_buf_len); }
byte GSM::WaitResp(uint16_t start_comm_tmout, uint16_t max_interchar_tmout) { byte status; RxInit(start_comm_tmout, max_interchar_tmout); // wait until response is not finished do { status = IsRxFinished(); } while (status == RX_NOT_FINISHED); return (status); }
//------------------------------------------------------------------------------ unsigned char WaitResp(unsigned int start_comm_tmout, unsigned int max_interchar_tmout) { unsigned char status; RxInit(start_comm_tmout, max_interchar_tmout); // wait until response is not finished do { status = IsRxFinished(); }while(status == RX_NOT_FINISHED); return(status); }
GSM::RXstateRes GSM::WaitResp(unsigned long int start_comm_tmout, unsigned long int max_interchar_tmout) { RXstateRes status; RxInit(start_comm_tmout, max_interchar_tmout); DATA(F("wait until response is not finished")); // wait until response is not finished do { status = IsRxFinished(); } while (status == RX_NOT_FINISHED); DATA(F("status != RX_NOT_FINISHED")); return (status); }
/** * @function RxIsr * @brief RX interrupt handler * @param uint8_t byte: received byte * @return none */ static void RxIsr(uint8_t byte) { switch(rxFsm) { case MSG_STOPPED: if(byte == TOKEN_START) rxFsm = MSG_STARTING; break; case MSG_STARTING: if(byte == TOKEN_START) rxFsm = MSG_STARTED; else rxFsm = MSG_STOPPED; break; case MSG_STARTED: if(byte == TOKEN_STOP) rxFsm = MSG_STOPPING; else RxAdd(byte); break; case MSG_STOPPING: if(byte == TOKEN_STOP) { UartMaskRxInterrupt(); pRxBuf = &rxBuf[0]; rxFsm = MSG_STOPPED; } else { RxAdd(TOKEN_STOP); RxAdd(byte); rxFsm = MSG_STARTED; } break; default: RxInit(); break; } }
/********************************************************** Method checks status of call(incoming or active) and makes authorization with specified SIM positions range phone_number: a pointer where the tel. number string of current call will be placed so the space for the phone number string must be reserved - see example first_authorized_pos: initial SIM phonebook position where the authorization process starts last_authorized_pos: last SIM phonebook position where the authorization process finishes Note(important): ================ In case first_authorized_pos=0 and also last_authorized_pos=0 the received incoming phone number is NOT authorized at all, so every incoming is considered as authorized (CALL_INCOM_VOICE_NOT_AUTH is returned) return: CALL_NONE - no call activity CALL_INCOM_VOICE_AUTH - incoming voice - authorized CALL_INCOM_VOICE_NOT_AUTH - incoming voice - not authorized CALL_ACTIVE_VOICE - active voice CALL_INCOM_DATA_AUTH - incoming data call - authorized CALL_INCOM_DATA_NOT_AUTH - incoming data call - not authorized CALL_ACTIVE_DATA - active data call CALL_NO_RESPONSE - no response to the AT command CALL_COMM_LINE_BUSY - comm line is not free **********************************************************/ byte GSM::CallStatusWithAuth(char *phone_number, byte first_authorized_pos, byte last_authorized_pos) { byte ret_val = CALL_NONE; byte search_phone_num = 0; byte i; byte status; char *p_char; char *p_char1; phone_number[0] = 0x00; // no phonr number so far if (CLS_FREE != GetCommLineStatus()) return (CALL_COMM_LINE_BUSY); SetCommLineStatus(CLS_ATCMD); Serial.println(F("AT+CLCC")); // 5 sec. for initial comm tmout // and max. 1500 msec. for inter character timeout RxInit(5000, 1500, 1, 1); // wait response is finished do { if (IsStringReceived("OK\r\n")) { // perfect - we have some response, but what: // there is either NO call: // <CR><LF>OK<CR><LF> // or there is at least 1 call // +CLCC: 1,1,4,0,0,"+420XXXXXXXXX",145<CR><LF> // <CR><LF>OK<CR><LF> status = RX_FINISHED; break; // so finish receiving immediately and let's go to // to check response } status = IsRxFinished(); } while (status == RX_NOT_FINISHED); // generate tmout 30msec. before next AT command delay(30); if (status == RX_FINISHED) { // something was received but what was received? // example: //+CLCC: 1,1,4,0,0,"+420XXXXXXXXX",145 // --------------------------------------------- if(IsStringReceived("+CLCC: 1,1,4,0,0")) { // incoming VOICE call - not authorized so far // ------------------------------------------- search_phone_num = 1; ret_val = CALL_INCOM_VOICE_NOT_AUTH; } else if(IsStringReceived("+CLCC: 1,1,4,1,0")) { // incoming DATA call - not authorized so far // ------------------------------------------ search_phone_num = 1; ret_val = CALL_INCOM_DATA_NOT_AUTH; } else if(IsStringReceived("+CLCC: 1,0,0,0,0")) { // active VOICE call - GSM is caller // ---------------------------------- search_phone_num = 1; ret_val = CALL_ACTIVE_VOICE; } else if(IsStringReceived("+CLCC: 1,1,0,0,0")) { // active VOICE call - GSM is listener // ----------------------------------- search_phone_num = 1; ret_val = CALL_ACTIVE_VOICE; } else if(IsStringReceived("+CLCC: 1,1,0,1,0")) { // active DATA call - GSM is listener // ---------------------------------- search_phone_num = 1; ret_val = CALL_ACTIVE_DATA; } else if(IsStringReceived("+CLCC:")){ // other string is not important for us - e.g. GSM module activate call // etc. // IMPORTANT - each +CLCC:xx response has also at the end // string <CR><LF>OK<CR><LF> ret_val = CALL_OTHERS; } else if(IsStringReceived("OK")){ // only "OK" => there is NO call activity // -------------------------------------- ret_val = CALL_NONE; } // now we will search phone num string if (search_phone_num) { // extract phone number string // --------------------------- p_char = strchr((char *)(comm_buf),'"'); p_char1 = p_char+1; // we are on the first phone number character p_char = strchr((char *)(p_char1),'"'); if (p_char != NULL) { *p_char = 0; // end of string strcpy(phone_number, (char *)(p_char1)); } if ( (ret_val == CALL_INCOM_VOICE_NOT_AUTH) || (ret_val == CALL_INCOM_DATA_NOT_AUTH)) { if ((first_authorized_pos == 0) && (last_authorized_pos == 0)) { // authorization is not required => it means authorization is OK // ------------------------------------------------------------- if (ret_val == CALL_INCOM_VOICE_NOT_AUTH) ret_val = CALL_INCOM_VOICE_AUTH; else ret_val = CALL_INCOM_DATA_AUTH; } else { // make authorization // ------------------ SetCommLineStatus(CLS_FREE); for (i = first_authorized_pos; i <= last_authorized_pos; i++) { if (ComparePhoneNumber(i, phone_number)) { // phone numbers are identical // authorization is OK // --------------------------- if (ret_val == CALL_INCOM_VOICE_NOT_AUTH) ret_val = CALL_INCOM_VOICE_AUTH; else ret_val = CALL_INCOM_DATA_AUTH; break; // and finish authorization } } } } } } else { // nothing was received (RX_TMOUT_ERR) // ----------------------------------- ret_val = CALL_NO_RESPONSE; } SetCommLineStatus(CLS_FREE); return (ret_val); }