StdPJ/Core/Src/APP/BSP/ug96/ug96.c
/**
  * @brief  Get current Network Operator (by string descriptor).
  * @param  Obj: pointer to module handle
  * @param  Operator: pointer to a string
  * @param  bufsize: max string buffer length
  * @retval Operation Status.
  */
@brief  Get current Network Operator (by string descriptor).
@param  Obj: pointer to module handle
@param  Operator: pointer to a string
@param  bufsize: max string buffer length
@retval Operation Status.
@brief Get current Network Operator ( by string descriptor ) . @param Obj : pointer to module handle @param Operator : pointer to a string @param bufsize : max string buffer length @retval Operation Status .
UG96_Return_t  UG96_GetCurrentOperator(Ug96Object_t *Obj, char *Operator, uint8_t Bufsize)
{
  UG96_Return_t ret = UG96_RETURN_ERROR;
  char *align_ptr;
  const char s[2] = ",";
  char *token;
  int i;
  ret = (UG96_Return_t) AT_ExecuteCommand(Obj, UG96_TOUT_180000, (uint8_t *)"AT+COPS?\r\n", RET_OK | RET_ERROR | RET_CME_ERROR);
  if (RET_OK == ret)
  {
    align_ptr = strstr((char *) Obj->CmdResp,"+COPS:") + sizeof("+COPS:");
    strncpy((char *)Operator,  align_ptr, Bufsize);
    token = strtok(Operator, s);
    i = 0;
    while( token != NULL && i < 2) {   
      token = strtok(NULL, s);
      i++;
    }
    if (token != NULL)
    {
      strncpy((char *)(Operator), token, Bufsize);
    }
    else
    {
      ret = UG96_RETURN_ERROR;
    }
  }
  return ret;
}
UG96_Return_t UG96_GetCurrentOperator ( Ug96Object_t * Obj , char * Operator , uint8_t Bufsize ) { UG96_Return_t ret = UG96_RETURN_ERROR ; char * align_ptr ; const char s [ 2 ] = " " ; char * token ; int i ; ret = ( UG96_Return_t ) AT_ExecuteCommand ( Obj , UG96_TOUT_180000 , ( uint8_t * ) " \r \n " , RET_OK | RET_ERROR | RET_CME_ERROR ) ; if ( RET_OK == ret ) { align_ptr = strstr ( ( char * ) Obj -> CmdResp , " " ) + sizeof ( " " ) ; strncpy ( ( char * ) Operator , align_ptr , Bufsize ) ; token = strtok ( Operator , s ) ; i = 0 ; while ( token != NULL && i < 2 ) { token = strtok ( NULL , s ) ; i ++ ; } if ( token != NULL ) { strncpy ( ( char * ) ( Operator ) , token , Bufsize ) ; } else { ret = UG96_RETURN_ERROR ; } } return ret ; }
@brief  Get current Network Operator (by string descriptor).
@brief Get current Network Operator ( by string descriptor ) .
/* get the first token */ /* walk through tokens until operator info */