📄 dt_utility.c
字号:
{
ASSERT(file_name!=NULL);
//mtk00924_051021: downloadFullpath in DT should get from L4C
DT_PTR->downloadFullpath = l4c_get_download_path();
if(DT_PTR->downloadFullpath!=NULL)
{
/* append foldername to the previous set current dir */
kal_wstrcat(DT_PTR->downloadFullpath, file_name);
kal_wstrcpy(file_name, DT_PTR->downloadFullpath);
/* clear stored L4C_PTR->downloadFullpath and release buffer which is allocated in L4C when doing FS_DIR*/
free_ctrl_buffer(DT_PTR->downloadFullpath);
DT_PTR->downloadFullpath=NULL;
l4c_set_download_path(DT_PTR->downloadFullpath);
/* clear data download timer*/
//dt_clear_download_timer();
}
else
{
kal_prompt_trace(MOD_DT, "download path is NULL");
}
}
#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 !*/
#endif
//#endif /*(defined(__SLIM_AT__) || defined( __EM_AT_ONLY__))*/
//#endif /* DATA_DOWNLOAD */
/*****************************************************************************
* FUNCTION
* dt_unicode_to_string()
*
* DESCRIPTION
* check hex value
* 0x1234 => "1234"
* 0x6600 => "6600"
*
* PARAMETERS
* val IN hex value.
* str OUT string
* RETURNS
* none.
*
* GLOBALS AFFECTED
* none.
*****************************************************************************/
void dt_unicode_to_string (kal_uint8 *val, kal_uint8 *str)
{
kal_uint16 i=0, j=0;
ASSERT ((str != NULL) && (val != NULL));
while (!((val[j] == 0)&&(val[j+1] == 0)))
{
i += kal_sprintf((char *)str+i, "%02X%02X", val[j+1], val[j]);
j+=2;
}
str[i] = '\0';
}
/*****************************************************************************
* FUNCTION
* dt_ascii_to_ucs2()
*
* DESCRIPTION
* this function is using to convert ascii code to ucs2 format
*
* PARAMETERS
* src IN ascii string
* dest OUT ucs2 value
* RETURNS
*
* GLOBALS AFFECTED
* none.
*****************************************************************************/
void dt_ascii_to_ucs2(kal_uint8* src, kal_wchar* dest)
{
kal_uint8 index = 0;
while(src[index] != DT_END_OF_STRING_CHAR)
{
dest[index] = src[index];
index++;
}
dest[index]=0 ;
return;
}
/*****************************************************************************
* FUNCTION
* dt_ucs2_to_ascii()
*
* DESCRIPTION
* this function is using to convert ucs2 code to ascii format
* If there's a non-convertable ucs2 char, such as chinese word,
* KAL_FALSE will be returned.
* Otherwise, KAL_TRUE will be returned if successful.
* PARAMETERS
* src IN ucs2 wchar
* dest OUT ascii string
* RETURNS
* kal_bool
* GLOBALS AFFECTED
* none.
*****************************************************************************/
kal_bool dt_ucs2_to_ascii(kal_wchar* ucs2_src, kal_uint8* ascii_dest)
{
kal_uint8 i= 0;
while (!(ucs2_src[i] == 0)) //while not end of UCS2 string
{
if((ucs2_src[i] >> 8) != 0) // the first byte is not 0x00, cannot convert to ASCII
{
ascii_dest[i] = '\0';
return KAL_FALSE;
}
else //0x00YZ, so convert dest to
{
ascii_dest[i]= (kal_uint8)ucs2_src[i] ;
}
i++;
}
ascii_dest[i] = '\0';
return KAL_TRUE;
}
/*****************************************************************************
* FUNCTION
* dt_print_hex_value()
*
* DESCRIPTION
* This function print the hex value to ascii.
* Note that UCS2 should use rmmi_print_ucs2(). not this function!!
* check hex value
* 0x1234 => "1234"
*
* PARAMETERS
* val IN hex value.
* str OUT string
* RETURNS
* none.
*
* GLOBALS AFFECTED
* none.
*****************************************************************************/
void dt_print_hex_value (kal_uint8 *val, kal_uint8 *str)
{
kal_uint16 i=0, j=0;
ASSERT ((str != NULL) && (val != NULL));
while (!((val[j] == 0)&&(val[j+1] == 0)))
{
i += kal_sprintf((char *)str+i, "%02X", val[j]);
j++;
}
str[i] = '\0';
}
void dt_toUpper (kal_uint8 *str)
{
kal_uint8 *ptr;
kal_trace(TRACE_FUNC, FUNC_DT_TOUPPER_ENTRY);
ASSERT (str != NULL);
ptr = str;
while (*ptr != 0)
{
if (DT_IS_LOWER(*ptr))
{
*ptr += DT_CHAR_A-dt_char_a;
}
ptr++;
}
}
/*****************************************************************************
* FUNCTION
* check_hex_value()
*
* DESCRIPTION
* check hex value
*
* PARAMETERS
* str IN string
* val OUT hex value.
* RETURNS
* none.
*
* GLOBALS AFFECTED
* none.
*****************************************************************************/
void dt_check_hex_value (kal_uint8 *str, kal_uint8 *val)
{
kal_uint16 i=0, j=0;
kal_uint16 temp;
kal_trace(TRACE_FUNC, FUNC_DT_CHECK_HEX_VALUE_ENTRY);
ASSERT ((str != NULL) && (val != NULL));
dt_toUpper (str);
while (str[i] != DT_END_OF_STRING_CHAR)
{
if (DT_IS_NUMBER(str[i]))
temp = str[i] - DT_CHAR_0;
else
temp = (str[i] - DT_CHAR_A) + 10;
if (DT_IS_NUMBER(str[i+1]))
temp = (temp<<4) + (str[i+1] - DT_CHAR_0);
else
temp = (temp<<4) + ((str[i+1] - DT_CHAR_A) + 10);
val[j] = temp;
i+= 2;
j++;
}
}
void dt_int_to_ascii_converter (
kal_uint32 digit,
kal_uint8 *buff_ptr
)
{
kal_uint8 divisor = 10;
kal_uint8 tmp;
kal_uint8 index1;
kal_uint8 index2;
kal_trace(TRACE_FUNC, FUNC_DT_INT_TO_ASCII_CONVERTER_ENTRY);
for ( index1 = 0; digit >= 10; index1++ )
{
/* Get last digit of given integer number*/
*( buff_ptr + index1) = MODULO (digit, divisor);
/* remove the last digit from the given number & restore the
* remaining number into the same variable */
digit = DIVIDE ((digit - (*(buff_ptr + index1))), divisor);
/* convert the last digit into ASCII Equivalent value */
*( buff_ptr + index1 ) += DT_CHAR_0;
}
/* Incorporate last digit */
*( buff_ptr + index1 ) = DT_CHAR_0 + digit;
/* Now invert the string.Because digits are extracted from the
* number from right to left direction */
for ( index2 = 0; index2 <= (index1>>1); index2++ )
{
tmp = *( buff_ptr + index2 );
*( buff_ptr + index2 ) = *( buff_ptr+index1 - index2 );
*( buff_ptr + index1 - index2 ) = tmp;
}
/* Finish the string */
*( buff_ptr + index1 + 1 ) = DT_END_OF_STRING_CHAR;
/*
l4_fn_exit(
MOD_ATCI,
FUNC_ATCI_INT_TO_ASCII_CONVERTER_SUBOP
);
*/
return;
}
kal_uint32 dt_int_validator_ext(kal_uint8 *error_cause, dt_string_struct *source_string_ptr,
kal_uint8 delimiter)
{
kal_uint32 ret_val = DT_VALIDATOR_ERROR;
kal_int32 value = 0;
kal_uint16 length;
kal_bool error_flag = KAL_FALSE;
kal_bool some_char_found = KAL_FALSE;
kal_trace(TRACE_FUNC, FUNC_DT_INT_VALIDATOR_EXT_ENTRY);
ASSERT (source_string_ptr != NULL);
length = strlen ((char *)source_string_ptr->string_ptr);
/* If there are some leading white spaces, ignore them */
dt_skip_spaces( source_string_ptr );
/* we have to initial the error so that we can using again and
again even if any error occur. so we dont have to init before
enter this function
*/
*error_cause = DT_PARSE_OK;
/* Start checking for the integer, till the delimiter which may
* be a comma, a dot etc.
*/
while ((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 < length))
{
/* It means we found something between two commas(,) */
some_char_found = KAL_TRUE;
/* check whether the character is in 0 - 9 range. If so,
* store corresponding integer value for that character
*/
if ( ( source_string_ptr->string_ptr[source_string_ptr->index]
>= DT_CHAR_0 ) &&
( source_string_ptr->string_ptr[source_string_ptr->index]
<= DT_CHAR_9 )
)
{
value = value * 10 +
(source_string_ptr->string_ptr[source_string_ptr->index]
- DT_CHAR_0);
}
else /* out of range, return immediately */
{
error_flag = KAL_TRUE;
break;
}
/*If the character is a valid part of integer, then continue*/
source_string_ptr->index++;
} /* end of the while loop */
if (error_flag == KAL_TRUE)
{
/* 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
*/
/* mark for solve correct input but incorrect end for 1,2,2, */
/* rmmi_result_code_fmttr ( RMMI_RCODE_ERROR,
INVALID_CHARACTERS_IN_TEXT_ERRSTRING_ERR );*/
ret_val = DT_VALIDATOR_ERROR;
*error_cause = (kal_uint8)DT_PARSE_ERROR;
}
else if ( some_char_found == KAL_FALSE )
{
/* Nothing is present before the delimiter */
ret_val = DT_VALIDATOR_ERROR;
*error_cause = (kal_uint8)DT_PARSE_NOT_FOUND;
/* 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 = value;
/* Increment the string sliding index to point to the next
* character after delimiter, i.e. the next field in the
* command line
*/
if (source_string_ptr->string_ptr[source_string_ptr->index] == delimiter)
{
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_VALIDATOR_ERROR;
*error_cause = (kal_uint8)DT_PARSE_ERROR;
}
}
else
source_string_ptr->index++;
}
return ret_val;
}
kal_uint32 dt_int_validator(
dt_string_struct *source_string_ptr,
kal_uint8 delimiter
)
{
kal_uint32 ret_val = DT_VALIDATOR_ERROR;
kal_int32 value = 0;
kal_uint16 length;
kal_bool error_flag = KAL_FALSE;
kal_bool some_char_found = KAL_FALSE;
kal_trace(TRACE_FUNC, FUNC_DT_INT_VALIDATOR_ENTRY);
ASSERT (source_string_ptr != NULL);
length = strlen ((char *)source_string_ptr->string_ptr);
/* If there are some leading white spaces, ignore them */
dt_skip_spaces( source_string_ptr );
/* Start checking for the integer, till the delimiter which may
* be a comma, a dot etc.
*/
while ((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 < length))
{
/* It means we found something between two commas(,) */
some_char_found = KAL_TRUE;
/* check whether the character is in 0 - 9 range. If so,
* store corresponding integer value for that character
*/
if ( ( source_string_ptr->string_ptr[source_string_ptr->index]
>= DT_CHAR_0 ) &&
( source_string_ptr->string_ptr[source_string_ptr->index]
<= DT_CHAR_9 )
)
{
value = value * 10 +
(source_string_ptr->string_ptr[source_string_ptr->index]
- DT_CHAR_0);
}
else /* out of range, return immediately */
{
error_flag = KAL_TRUE;
break;
}
/*If the character is a valid part of integer, then continue*/
source_string_ptr->index++;
} /* end of the while loop */
if (error_flag == KAL_TRUE)
{
/* 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
*/
/* mark for solve correct input but incorrect end for 1,2,2, */
/* rmmi_result_code_fmttr ( RMMI_RCODE_ERROR,
INVALID_CHARACTERS_IN_TEXT_ERRSTRING_ERR );*/
ret_val = DT_VALIDATOR_ERROR;
}
else if ( some_char_found == KAL_FALSE )
{
/* Nothing is present before the delimiter */
ret_val = DT_VALIDATOR_ERROR;
/* Increment the string sliding index to point to the next
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -