📄 dt_utility.c
字号:
* character after delimiter, i.e. the next field in the
* command line
*/
source_string_ptr->index++;
}
/* If some thing is present and check for the valid range as
* specified by the calling function
*/
else
{
ret_val = value;
/* Increment the string sliding index to point to the next
* character after delimiter, i.e. the next field in the
* command line
*/
source_string_ptr->index++;
}
return ret_val;
}
/*****************************************************************************
* FUNCTION
* dt_string_validator_ext
* DESCRIPTION
* this function extends dt_string_validator_ext().
* addtionally it passes the error_cause back, and here <CR> acts as delimiter as well
* PARAMETERS
*
* RETURNS
* if string is correctly parsed: ret_val = RMMI_DEF_VALUE.
* otherwise : ret_val = RMMI_VALIDATOR ERROR. there are 3 possible cases:
* 1. no string is found by delimiter or <CR> ==> error_cause = RMMI_PARSE_NOT_FOUND
* 2. string is invalid syntax or too long ==> error_cause = RMMI_PARSE_ERROR
* 3. string is a null string (the case "" ) ==> error_cause = RMMI_PARSE_OK
* GLOBALS AFFECTED
* source_string_ptr->index will be increased
*****************************************************************************/
kal_uint8 dt_string_validator_ext (kal_uint8 * error_cause,
dt_string_struct *source_string_ptr,
kal_uint8 delimiter,
kal_uint16 max_length,
kal_uint8 *str)
{
kal_uint8 ret_val = DT_VALIDATOR_ERROR;
kal_uint16 index = 0;
kal_uint8 error_flag = 0;
kal_bool some_char_found = KAL_FALSE;
kal_uint16 length;
kal_trace(TRACE_FUNC, FUNC_DT_STRING_VALIDATOR_ENTRY);
ASSERT ((str != NULL) && (source_string_ptr != NULL) && (error_cause!= NULL) );
*error_cause = DT_PARSE_OK;
length = strlen ((char *)source_string_ptr->string_ptr);
if (source_string_ptr->index >= length)
{
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
*error_cause = DT_PARSE_NOT_FOUND;
return ret_val;
}
/* check the first char (but skip space first ) */
while (1)
{
/* If there are some leading white spaces, ignore them */
dt_skip_spaces( source_string_ptr );
/* if double_quote found: string begins */
if (source_string_ptr->string_ptr[source_string_ptr->index]
== DT_DOUBLE_QUOTE)
{
source_string_ptr->index++;
break;
}
/* if delimiter found: error cause = RMMI_PARSE_NOT_FOUND */
else if ((source_string_ptr->string_ptr[source_string_ptr->index]
== delimiter) ||
(source_string_ptr->string_ptr[source_string_ptr->index]
== DT_PTR->s_reg.s3))
{
source_string_ptr->index++; /* point to the next char after delimiter */
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
*error_cause = DT_PARSE_NOT_FOUND;
return ret_val;
}
/* else : error cause = RMMI_PARSE_ERROR, not string type */
else{
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
*error_cause = DT_PARSE_ERROR;
return ret_val;
}
}
while (source_string_ptr->string_ptr[source_string_ptr->index]
!= DT_DOUBLE_QUOTE)
{
/* It means we found something after " */
some_char_found = KAL_TRUE;
if (index >= (max_length-1)) /* length is too long , break */
{
error_flag = DT_ERR_TEXT_ERRSTRING_TOO_LONG_ERR;
break;
}
/*append the char to str except backslash '\' */
if(source_string_ptr->string_ptr[source_string_ptr->index]!='\\')
{
*((kal_uint8 *)str+index) =
source_string_ptr->string_ptr[source_string_ptr->index];
index ++;
source_string_ptr->index++;
}
else //according to v.25ter sec 5.4.2.2
{
kal_uint8 temp;
kal_uint8 ch;
source_string_ptr->index++;
ch = source_string_ptr->string_ptr[source_string_ptr->index];
if (DT_IS_NUMBER(ch))
temp = ch - DT_CHAR_0;
else if((ch>= DT_CHAR_A) && (ch<= DT_CHAR_F))
temp = ch - DT_CHAR_A + 10;
else if((ch>= dt_char_a) && (ch<= dt_char_f))
temp = ch - dt_char_a+ 10;
else //not hex format
{
error_flag = DT_ERR_INVALID_CHARACTERS_IN_TEXT_ERRSTRING_ERR;
break;
}
source_string_ptr->index++;
ch = source_string_ptr->string_ptr[source_string_ptr->index];
if (DT_IS_NUMBER(ch))
temp = (temp<<4) + (ch - DT_CHAR_0);
else if((ch>= DT_CHAR_A) && (ch<= DT_CHAR_F))
temp = (temp<<4) + ((ch - DT_CHAR_A) + 10);
else if((ch>= dt_char_a) && (ch<= dt_char_f))
temp = (temp<<4) + ((ch - dt_char_a) + 10);
else //not hex format
{
error_flag = DT_ERR_INVALID_CHARACTERS_IN_TEXT_ERRSTRING_ERR;
break;
}
*((kal_uint8 *)str+index)= temp;
index ++;
source_string_ptr->index++;
}
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
} /* end of the while loop */
if (error_flag != 0)
{
if(error_flag==DT_ERR_TEXT_ERRSTRING_TOO_LONG_ERR)
*error_cause = DT_PARSE_TEXT_TOO_LONG;
else
*error_cause = DT_PARSE_ERROR; /* Value is not in the valid range. */
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
ret_val = DT_VALIDATOR_ERROR;
return ret_val;
}
else if ( some_char_found == KAL_FALSE )
{
/* Null string: "" : set error_cause = RMMI_PARSE_OK (ret_val= RMMI_VALIDATOR_ERROR) */
*error_cause = DT_PARSE_OK;
ret_val = DT_VALIDATOR_ERROR;
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
/* Increment the string sliding index to point to the next
* character after DOUBLE_QUOTE */
source_string_ptr->index++;
}
else
{
/* If some thing is present between 2 double quotes: "xxx" */
ret_val = DT_DEF_VALUE;
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
/* Increment the string sliding index to point to the next
* character after DOUBLE_QUOTE */
source_string_ptr->index++;
}
/* final check the delimiter and increase index to skip it */
while (1)
{
/* If there are some leading white spaces, ignore them */
dt_skip_spaces( source_string_ptr );
/* if delimiter found: increase index and break(thus return)*/
if ((source_string_ptr->string_ptr[source_string_ptr->index]
== delimiter) ||
(source_string_ptr->string_ptr[source_string_ptr->index]
== DT_PTR->s_reg.s3))
{
source_string_ptr->index++;
break;
}
/* no delimiter nor <CR> : ret_val = RMMI_VALIDATOR_ERROR */
else
{
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
*error_cause = DT_PARSE_ERROR;
ret_val = DT_VALIDATOR_ERROR;
return ret_val;
}
}
return ret_val;
}
kal_uint8 dt_string_validator (dt_string_struct *source_string_ptr,
kal_uint8 delimiter,
kal_uint16 max_length,
kal_uint8 *str)
{
kal_uint8 ret_val = DT_VALIDATOR_ERROR;
kal_uint16 index = 0;
kal_uint8 error_flag = 0;
kal_bool some_char_found = KAL_FALSE;
kal_trace(TRACE_FUNC, FUNC_DT_STRING_VALIDATOR_ENTRY);
ASSERT ((str != NULL) && (source_string_ptr != NULL));
/* Start checking for the integer, till the delimiter which may
* be a comma, a dot etc.
*/
while (1)
{
/* If there are some leading white spaces, ignore them */
dt_skip_spaces( source_string_ptr );
if (source_string_ptr->string_ptr[source_string_ptr->index]
== DT_DOUBLE_QUOTE)
{
source_string_ptr->index++;
break;
}
else
{
if (source_string_ptr->string_ptr[source_string_ptr->index]
== delimiter)
{
source_string_ptr->index++;
}
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
return ret_val;
}
}
while (source_string_ptr->string_ptr[source_string_ptr->index]
!= DT_DOUBLE_QUOTE )
{
/* It means we found something between two commas(,) */
some_char_found = KAL_TRUE;
//rmmi_skip_spaces( source_string_ptr );
/* check whether the character is in 0 - 9 range. If so,
* store corresponding integer value for that character
*/
if (DT_IS_NUMBER(
source_string_ptr->string_ptr[source_string_ptr->index]) ||
DT_IS_ALPHA (
source_string_ptr->string_ptr[source_string_ptr->index]) ||
DT_IS_SYMBOL (
source_string_ptr->string_ptr[source_string_ptr->index])
)
{
if (index >= (max_length-1))
{
error_flag = DT_ERR_TEXT_ERRSTRING_TOO_LONG_ERR;
break;
}
*((kal_uint8 *)str+index) =
source_string_ptr->string_ptr[source_string_ptr->index];
index ++;
}
else /* out of range, return immediately */
{
error_flag = DT_ERR_INVALID_CHARACTERS_IN_TEXT_ERRSTRING_ERR;
break;
}
/*If the character is a valid part of integer, then continue*/
source_string_ptr->index++;
} /* end of the while loop */
if (error_flag != 0)
{
/* Value is not in the valid range. It can also be due to
* white space in between two digits, because such white
* spaces are not allowed
*/
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
// rmmi_result_code_fmttr ( RMMI_RCODE_ERROR, error_flag );
ret_val = DT_VALIDATOR_ERROR;
}
else if ( some_char_found == KAL_FALSE )
{
/* Nothing is present before the delimiter */
ret_val = DT_VALIDATOR_ERROR;
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
/* Increment the string sliding index to point to the next
* character after delimiter, i.e. the next field in the
* command line
*/
source_string_ptr->index++;
}
/* If some thing is present and check for the valid range as
* specified by the calling function
*/
else
{
ret_val = DT_DEF_VALUE;
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
/* Increment the string sliding index to point to the next
* character after delimiter, i.e. the next field in the
* command line
*/
source_string_ptr->index++;
}
while (1)
{
/* If there are some leading white spaces, ignore them */
dt_skip_spaces( source_string_ptr );
if (source_string_ptr->string_ptr[source_string_ptr->index]
== delimiter)
{
source_string_ptr->index++;
break;
}
else
{
*((kal_uint8 *)str+index) = DT_END_OF_STRING_CHAR;
ret_val = DT_VALIDATOR_ERROR;
return ret_val;
}
}
return ret_val;
}
kal_uint8 dt_find_cmd_mode (dt_string_struct *source_string_ptr)
{
kal_uint8 ret_val = DT_WRONG_MODE;
kal_trace(TRACE_FUNC, FUNC_DT_FIND_CMD_MODE_ENTRY);
ASSERT (source_string_ptr != NULL);
/* Skip all leading white spaces */
dt_skip_spaces( source_string_ptr );
/* First check for the READ command format
* Eg:"AT+CGATT?\r" Here we first search for '?' character */
if ( source_string_ptr->string_ptr[source_string_ptr->index]
== DT_QUESTION_MARK )
{
source_string_ptr->index++;
dt_skip_spaces ( source_string_ptr );
/* Check for the end of line character ('\r'). there may be
* spaces between the question mark and the command line
* termination character.
*/
if ( source_string_ptr-> string_ptr[source_string_ptr->index]
== DT_PTR->s_reg.s3 )
{
/* If the above two conditions are passed then return
* READ_MODE */
ret_val = DT_READ_MODE;
}
/* else, return RMMI_WRONG_MODE */
return ret_val;
}
/* If not read mode, then check for the TEST/SET/EXECUTE mode.
* Symbol '=' is common for both SET/EXECUTE and TEST command;
* so first check for the '=' symbol.
*/
if ( source_string_ptr->string_ptr[source_string_ptr->index]
== DT_EQUAL )
{
/* If we find '?' after the '=' symbol, then we decide that
* given command is TEST command. Else it is assumed to be
* either a SET or an EXECUTE command
*/
source_string_ptr->index++;
/* Skip white spaces after the '=' symbol */
dt_skip_spaces(source_string_ptr);
if (source_string_ptr->string_ptr[source_string_ptr->index]
== DT_QUESTION_MARK )
{
/* Since question mark is also found, check whether the
* string is terminated properly by a termination character.
* White spaces may be present between the question mark and
* the termination character.
*/
source_string_ptr->index++;
dt_skip_spaces(source_string_ptr);
if ( source_string_ptr->string_ptr[source_string_ptr->index]
== DT_PTR->s_reg.s3 )
{
ret_val = DT_TEST_MODE;
}
}
/* If didn't find '?' after the '=' symbol then we decide that
* given command is SET/EXECUTE command */
else
{
ret_val = DT_SET_OR_EXECUTE_MODE;
}
}/* mtk00468 add for some extend command has no parameter */
else if((source_string_ptr->string_ptr[source_string_ptr->index] == DT_PTR->s_reg.s3)||
( source_string_ptr->string_ptr[source_string_ptr->index] == DT_PTR->s_reg.s4 ))
{
ret_val = DT_ACTIVE_MODE;
}
return ret_val;
}
void dt_reset_state()
{
DT_PTR->transfer_type = DT_NO_TRANSFER_TYPE;
DT_PTR->app_type = DT_NO_APP_TYPE;
DT_PTR->transfered_port = 0xff;
DT_PTR->transfer_state = DT_IDLE_STATE;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -