📄 dt_utility.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*******************************************************************************
*
* Filename:
* ---------
* dt_utility.c
*
* Project:
* --------
* MAUI
*
* Description:
* ------------
* This file is intends for ....
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
*****************************************************************************/
#define DT_UTILITY_C
#include <stdio.h>
#include <string.h>
#include "kal_release.h"
#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h" /* Task message communiction */
#include "stacklib.h" /* Basic type for dll, evshed, stacktimer */
#include "app_buff_alloc.h"
#include "stack_timer.h"
#include "event_shed.h"
#include "stack_config.h"
#include "stack_buff_pool.h"
#include "ctrl_buff_pool.h"
#include "tst_buff_pool.h"
#include "sysconf_statistics.h"
#include "divider_public.h"
#include "dt_trc.h"
#include "uart_sw.h"
#include "dt_common_enum.h"
#include "dt_context.h"
#include "dt_utility.h"
#include "dt_rspfmttr.h"
#include "dt_aux_msg_hdlr.h"
extern kal_wchar *l4c_get_download_path(void);
extern void l4c_set_download_path(kal_wchar *downlaod_path);
extern kal_wchar* custom_get_at_audio_download_folder(void);
extern kal_wchar* custom_get_at_image_download_folder(void);
kal_bool dt_eq_fs_read_req(void)
{
#if !(defined(__SLIM_AT__) || defined( __EM_AT_ONLY__))
#ifdef __FS_ON__
kal_uint8 eof_flag=0;
kal_uint8 * download_ptr;
kal_uint32 rlen;
kal_int32 ret_v=0;
kal_uint16 i;
kal_uint8 j=0;
kal_trace(TRACE_FUNC, FUNC_DT_FS_READ_ENTRY);
#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 !*/
#endif
download_ptr = get_ctrl_buffer(DT_DOWNLOAD_SIZE);//cage_read
dt_clear_download_timer();
for (i = 0; i< 100; i++)//cage_read
//while(eof_flag==0)
{
DT_PTR->printingDownloadData_loopCount ++;
ret_v = FS_Read(DT_PTR->fd[0], (kal_uint8 *)download_ptr, DT_DOWNLOAD_SIZE, &rlen);//cage_read
if( ret_v != FS_NO_ERROR ) //Error occurs!!
{
ret_v = FS_Close(DT_PTR->fd[0]);
kal_trace (TRACE_GROUP_4, DT_FS_ACCESS, DT_FS_CLOSE, ret_v);
/* clear the stored infomation */
DT_PTR->fd[0] = 0;
DT_PTR->data_folder= 0;
DT_PTR->printingDownloadData_flag = KAL_FALSE;
DT_PTR->printingDownloadData_loopCount = 0;
if(download_ptr!=NULL) free_ctrl_buffer(download_ptr);
DT_PTR->cmee_err = DT_ERR_READ_FILE_FAILURE;
return KAL_FALSE;
}
if( rlen<DT_DOWNLOAD_SIZE ) //cage_read
{
j++;
eof_flag=1; //EOF
}
/* read file and print it out */
dt_eq_fs_read_rrsp( download_ptr,
DT_PTR->data_folder,
rlen,
eof_flag,
DT_PTR->printingDownloadData_loopCount );
if(DT_PTR->abort_download == KAL_TRUE)
{/*mtk00924_060320: user abort file download during wait for uart rtw_ind,
so after finishing the last run of +EFSR, senfing download_cnf to L4C*/
if(DT_PTR->fd[0] !=0)
{
/* close the file handle and clear the stored infomation*/
FS_Close(DT_PTR->fd[0]);
DT_PTR->fd[0] = 0;
DT_PTR->data_folder= 0;
DT_PTR->printingDownloadData_flag = KAL_FALSE;
DT_PTR->printingDownloadData_loopCount = 0;
}
if (DT_PTR->download_filename!= NULL)
{
free_ctrl_buffer(DT_PTR->download_filename);//filename is allocated in l4c and free here
DT_PTR->download_filename = NULL;
}
dt_send_l4c_download_cnf(DT_ERR_USER_ABORT);
dt_reset_state();
DT_PTR->abort_download = KAL_FALSE;
return KAL_TRUE;
}
if(eof_flag==1) // reach End of File, we can close filehandler and clear stored info
{
ret_v = FS_Close(DT_PTR->fd[0]);
kal_trace (TRACE_GROUP_4, DT_FS_ACCESS, DT_FS_CLOSE, ret_v);
/* clear the stored infomation */
DT_PTR->fd[0] = 0;
DT_PTR->data_folder= 0;
DT_PTR->printingDownloadData_flag = KAL_FALSE;
DT_PTR->printingDownloadData_loopCount = 0;
if(download_ptr!=NULL) free_ctrl_buffer(download_ptr);
if (DT_PTR->download_filename!= NULL)
{
free_ctrl_buffer(DT_PTR->download_filename);//filename is allocated in l4c and free here
DT_PTR->download_filename = NULL;
}
if(DT_PTR->uart_stop_send_flag == KAL_FALSE)
{
dt_send_l4c_download_cnf(DT_NO_ERR);
dt_reset_state();
}
else
{/*mtk00924_060416: if UART is full, do not send download_cnf but set download_complete as TRUE,
and have to wait for ready_to_write_ind from UART to put all data to UART buffer and then send download_cnf*/
kal_trace(TRACE_WARNING, WARNING_DT_DOWNLOAD_COMPLETE_WHEN_UART_FULL);
DT_PTR->download_complete = KAL_TRUE;
}
return KAL_TRUE;
}
else // if(eof_flag=0)
{
/* check if UART is busy or not, if busy, set printingDownloadData_flag = TRUE,
and wait till UART ReadyToWrite Indication(rmmi_uart_rtw_ind_hdlr) */
//if(DT_PTR->uart_stop_send_flag & (0x01 << 0))
if(DT_PTR->uart_stop_send_flag == KAL_TRUE)
{
DT_PTR->printingDownloadData_flag = KAL_TRUE;
if(download_ptr!=NULL) free_ctrl_buffer(download_ptr);
return KAL_TRUE;
}
}
}
/* the file is not finished yet, but we stop for a while, so L4 task can process its external queue first.
use timer to trigger the resuming action */
DT_PTR->printingDownloadData_flag = KAL_TRUE;
//l4c_pause_download(); //Maui_sw 9922, 20050221 mark: do not use timer,
//instead, resume download in layer4_task_main()
DT_PTR->event_id[1] = evshed_set_event (DT_PTR->event_scheduler_ptr,
(kal_timer_func_ptr)dt_resume_download,
NULL, DT_DOWNLOAD_SLEEP_TIMER * KAL_TICKS_100_MSEC);
if(download_ptr!=NULL) free_ctrl_buffer(download_ptr);
return KAL_TRUE;
#endif/*__FS_ON__*/
#endif/*(defined(__SLIM_AT__) || defined( __EM_AT_ONLY__))*/
}
//#ifdef DATA_DOWNLOAD
/*****************************************************************************
* FUNCTION
* dt_eq_general_fs_access_req
*
* DESCRIPTION
* directly access file system.
* for +EIMG,+EMDY: WHEN "FILE MANAGER" is enabled in MMI
* for +EFSR, +EFSW, +EFSD.
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
* none.
*****************************************************************************/
kal_bool dt_eq_general_fs_access_req(
dt_fs_opcode_enum action,
dt_app_type_enum app_type,
kal_wchar *file_name,
kal_uint8 *data,
kal_uint16 data_len)
{
#if !(defined(__SLIM_AT__) || defined( __EM_AT_ONLY__))
#ifdef __FS_ON__
FS_HANDLE file_handle;
kal_wchar full_name[(FS_MAX_PATH)];
kal_int8 ret_drv;
kal_uint8 buf[30];
kal_wchar UCS2_buf[30];
kal_int32 ret_v;
kal_uint16 file_path_len;
kal_wchar *custom_audio_floder_name, *custom_image_floder_name;
custom_audio_floder_name = custom_get_at_audio_download_folder();
custom_image_floder_name = custom_get_at_image_download_folder();
kal_trace(TRACE_FUNC, FUNC_DT_EQ_GENERAL_FS_ACCESS_REQ_ENTRY);
//if(src_id != RMMI_SRC)
//{
// RMMI_PTR->cmee_err = RMMI_ERR_UNKNOWN;
// return KAL_FALSE;
//}
if(file_name!=NULL)
{
switch(app_type)
{
case DT_APP_UNKNOWN:
/*+EFSR,+EFSW, +EFSD: PC suite give full-path*/
{
/* append file_name to the previous set current dir if any*/
dt_get_downloadFullpath((kal_wchar *)file_name);
file_path_len = kal_wstrlen((WCHAR*)file_name);
kal_trace(TRACE_INFO,INFO_DT_U, file_path_len);
if(file_path_len > (FS_MAX_PATH/2))
{
DT_PTR->cmee_err = DT_ERR_FILE_PATH_EXCEEDED;
return KAL_FALSE;
}
else
kal_wsprintf((WCHAR*)full_name, "%w", (kal_wchar *)file_name);
break;
}
default:
/* +EIMG, +EMDY: PC suite only give filename, we need to store it to default folder */
{
FS_DOSDirEntry fileinfo;
kal_wchar filename[30];
/* get default Drive */
ret_drv = FS_GetDrive(FS_DRIVE_V_NORMAL, 2, FS_ONLY_ALT_SERIAL);
if(!((ret_drv>='A')&&(ret_drv<='Z')))
{
ret_drv = FS_GetDrive(FS_DRIVE_V_REMOVABLE, 1, FS_NO_ALT_DRIVE);
if(!((ret_drv>='A')&&(ret_drv<='Z')))
{
DT_PTR->cmee_err = DT_ERR_GET_DRIVE_FAILURE;
return KAL_FALSE;
}
}
if(action==DT_FS_OPEN) //OPEN might need to create default folder.
{
/*
// check if folder \USER exists, if not create it
kal_sprintf((char*)buf, "%c:\\USER", ret_drv);
ascii_to_ucs2( buf, UCS2_buf );
file_handle = FS_FindFirst(UCS2_buf, FS_ATTR_DIR, 0, &fileinfo, filename, 30);
if(file_handle<0)
{ FS_CreateDir(UCS2_buf); }
FS_FindClose(file_handle);
*/
/* set default folder */
if(app_type==DT_IMELODY||app_type==DT_SOUND_OTHER)
{
kal_sprintf((char*)buf, "%c:\\", ret_drv);
dt_ascii_to_ucs2( buf, UCS2_buf );
kal_wstrcat(UCS2_buf, custom_audio_floder_name);
}
else
{
kal_sprintf((char*)buf, "%c:\\", ret_drv);
dt_ascii_to_ucs2( buf, UCS2_buf );
kal_wstrcat(UCS2_buf, custom_image_floder_name);
}
//dt_ascii_to_ucs2( buf, UCS2_buf );
/* check if default folder \xxx exists, if not create it */
file_handle = FS_FindFirst(UCS2_buf, FS_ATTR_DIR, 0, &fileinfo, filename, 30);
if(file_handle<0)
{ FS_CreateDir(UCS2_buf); }
FS_FindClose(file_handle);
}
else
{
/* set default folder */
if(app_type==DT_IMELODY||app_type==DT_SOUND_OTHER)
{
kal_sprintf((char*)buf, "%c:\\", ret_drv);
dt_ascii_to_ucs2( buf, UCS2_buf );
kal_wstrcat(UCS2_buf, custom_audio_floder_name);
}
else
{
kal_sprintf((char*)buf, "%c:\\", ret_drv);
dt_ascii_to_ucs2( buf, UCS2_buf );
kal_wstrcat(UCS2_buf, custom_image_floder_name);
}
//dt_ascii_to_ucs2( buf, UCS2_buf );
}
/* combine foldername & file_name to "full_name" */
kal_wsprintf((WCHAR*)full_name, "%w\\%w", UCS2_buf, (kal_wchar *)file_name);
break;
}
}
}
switch(action)
{
/****************OPEN FILE *****************/
case DT_FS_OPEN:
{
/* check if RMMI already still hold a open file*/
if(DT_PTR->fd[0]!= 0)
{
DT_PTR->cmee_err = DT_ERR_OPERATION_NOT_ALLOWED_ERR;
return KAL_FALSE;
}
/* check if the file exist: we only allow to open a new file */
file_handle = FS_Open(full_name, FS_OPEN_DIR | FS_READ_ONLY );
if (file_handle >0)
{
FS_Close(file_handle);
DT_PTR->cmee_err = DT_ERR_OPERATION_NOT_ALLOWED_ERR;
return KAL_FALSE;
}
FS_Close(file_handle);
/* create a file */
file_handle = FS_Open(full_name, FS_CREATE|FS_READ_WRITE);
if (file_handle < 0)
{
kal_trace (TRACE_GROUP_4, DT_FS_ACCESS, DT_FS_OPEN, file_handle);
DT_PTR->cmee_err = DT_ERR_UNSPECIFIED;
return KAL_FALSE;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -