📄 l1tm_cust_add.c
字号:
timStart(tim);
return CMD_RET_OK;
}
/*******************************************************************************
$Function: read_sim_sms_cb
$Description: This function invokes the operation for creat the simphb file.
$Returns:
$Arguments:
*******************************************************************************/
static int read_sim_sms_cb(void)
{
char simpath[20];
int j=0;//all phb data index
T_MFW mfwret=MFW_SMS_FAIL;
UBYTE idx=0;
char test[20];
MmiTrace("read_sim_sms_cb");
//防止sim正忙时,又有命令进来。
if(PcCmdStatus.isPcCmdRun)
return CMD_BUSY;
PcCmdStatus.isPcCmdRun=1;
//check if the sim cark ok
if (!smsidle_get_ready_state())
return return_info(SIM_NOT_REDAY,psmsidx,memory.total*sizeof(T_MFW_SMS_IDX),pWriteSmsdata,1024);
//读结束时,写入文件
if(unreadsms==0){
write_sms_file();
// dspl_TextOut(6, 6, 0, "pos 1");//chenjun 0409
totallen=0;
// if(command ==READ_NEW_SMS_CMD)
// PcCmdStatus.nNewsms=0;//hxl&chj 0409 del for PCSync
return return_info(CMD_COMPLETE_OK,psmsidx,memory.total*sizeof(T_MFW_SMS_IDX),pWriteSmsdata,1024);
}
while(mfwret==MFW_SMS_FAIL)
{
//psmsidx++;
idx=(&psmsidx[i])->index;//psmsidx->index;
mfwret=sms_read(MFW_SMS_MESSAGE,idx);
MmiTrace("readsms");
MmiTraceInt( i);
MmiTraceInt(idx);
MmiTraceInt(mfwret);
unreadsms--;
i++;
if((unreadsms==0)&&(mfwret==MFW_SMS_FAIL)){
write_sms_file();
totallen=0;
// if(command ==READ_NEW_SMS_CMD)
// PcCmdStatus.nNewsms=0;//chenjun 0409 del for PCSync
return return_info(CMD_COMPLETE_OK,psmsidx,memory.total*sizeof(T_MFW_SMS_IDX),pWriteSmsdata,1024);
}
}
return CMD_RET_OK;
}
void Get_sms_info(const char *info,void *adr, void * t,void *scaddr,int errStatus)
{
UINT16 year,month,day,hour,minute,second;
char date[18];
char other[5];
int len=0;
char readdata[600];
char *preaddata=&readdata[0];
int m=0;
T_MFW_SMS_ADDR *addr=(T_MFW_SMS_ADDR *)adr;
T_MFW_SMS_SCTP *time=(T_MFW_SMS_SCTP *)t;
char test[80];
MmiTrace("Get_sms_info");
if(errStatus){
read_sim_sms_cb();
return;
}
//将数值转换为ASII
year=time->year[0]%13*10+time->year[1]%13;
month=time->month[0]*10+time->month[1]%13;
day=time->day[0]*10+time->day[1]%32;
hour=time->hour[0]*10+time->hour[1]%24;
minute=time->minute[0]%60*10+time->minute[1]%60;
second=time->second[0]%60*10+time->second[1]%60;
memset(date,0,18);
sprintf(date,"%2d-%2d-%2d %2d:%2d:%2d",
year,month,day,hour,minute,second);
sprintf(other,"%d%d%d%d"
,(&psmsidx[i-1])->stat
,addr->ton
,addr->npi
,(&psmsidx[i-1])->index);
MmiTrace("index");
MmiTraceInt((&psmsidx[i-1])->index);
//将内容整合入readdata中,长度为len
memset(readdata,0,600);
len+=hstrcpy(preaddata+len,date);
len+=hstrcpy(preaddata+len,addr->number);
len+=hstrcpy(preaddata+len,info);
len+=hstrcpy(preaddata+len,scaddr);
len+=hstrcpy(preaddata+len,other);
//若原先的数据已构成一个文件长度,则写文件
if((totallen+len)>1024){
write_sms_file();
memset(pWriteSmsdata,0,1024);
totallen=0;
}
memcpy(pWriteSmsdata+totallen,readdata,len);
totallen+=len;
if((&psmsidx[i-1])->stat ==MFW_SMS_UNREAD)
sms_change_read_status( (&psmsidx[i-1])->index);
read_sim_sms_cb();//读下一个
}
static void write_sms_file(void)
{
char path[20];
MmiTrace("write_sms_file");
k++;
//creat simphb file in the phone
sprintf(path,"/mmi/PhonMf%d",k);
if(ffs_fwrite(path,pWriteSmsdata,1024 )>=0)
PcCmdStatus.nSimSmsFile+=1;
k=PcCmdStatus.nSimSmsFile;
MmiTraceInt(k);
}
/*******************************************************************************
$Function: del_sim_sms
$Description: This function creat the timer and start to excute.
$Returns:
$Arguments:
*******************************************************************************/
int del_sim_sms(UWORD16 value)
{
//check if the sim cark ok
if (!smsidle_get_ready_state())
return SIM_NOT_REDAY;
InitPcCmdStatus();
PcCmdStatus.isPcCmdRun=1;
sms_msg_delete((UWORD8)value);
return return_info(CMD_RET_OK,NULL,0,NULL,0);
}
/*******************************************************************************
$Function: change_sim_sms
$Description: This function creat the timer and start to excute.
$Returns:
$Arguments:
*******************************************************************************/
int change_sim_sms(UWORD16 value)
{
//check if the sim cark ok
if (!smsidle_get_ready_state())
return SIM_NOT_REDAY;
InitPcCmdStatus();
PcCmdStatus.isPcCmdRun=1;
sms_change_read_status((UWORD8)value);
return return_info(CMD_RET_OK,NULL,0,NULL,0);
}
void tell_smsFile_num(UWORD16 value)
{
MmiTrace("tell_smsFile_num");
PcCmdStatus.nSimSmsFile=(UWORD8)value;
MmiTraceInt(PcCmdStatus.nSimSmsFile);
}
/*******************************************************************************
$Function: send_sms
$Description: This function creat the timer and start to excute.
$Returns:
$Arguments:
*******************************************************************************/
int send_sms(void)
{
//check if the sim cark ok
if (!smsidle_get_ready_state())
return SIM_NOT_REDAY;
if ( ( pReadSmsdata = (char *) ALLOC_MEMORY( 1024) ) == NULL )
return return_info( ALLOC_MEM_FAIL,NULL,0,NULL,0);
if((psenddata=(T_MFW_SMS_MO *)ALLOC_MEMORY( sizeof(T_MFW_SMS_MO)))==NULL)
return return_info( ALLOC_MEM_FAIL,pReadSmsdata,1024,NULL,0);
InitPcCmdStatus();
totallen=0;
tim = timCreate(win, 100, (MfwCb)excute_tim_cb);
command =SEND_SMS_CMD;
timStart(tim);
return CMD_RET_OK;
}
/*******************************************************************************
$Function: send_sms_cb
$Description: This function invokes the operation for creat the simphb file.
$Returns:
$Arguments:
*******************************************************************************/
int send_sms_cb(void)
{
char simpath[20];
char test[80];
MmiTrace("send_sms_cb");
//防止sim正忙时,又有命令进来。
if(PcCmdStatus.isPcCmdRun)
return CMD_BUSY;
PcCmdStatus.isPcCmdRun=1;
//check if the sim cark ok
if (!smsidle_get_ready_state())
return return_info(SIM_NOT_REDAY,pReadSmsdata,1024,psenddata,sizeof(T_MFW_SMS_MO));
//为第一次读文件作准备
if(k==0)
memset(pReadSmsdata,0,1024);
if(get_data_and_send()<0){
MmiTrace("getdata<0");
if(k==PcCmdStatus.nSimSmsFile){
MmiTrace("k=nsimsmsfile");
if(k>0){
sprintf(simpath,"/mmi/PhonMf%d",k);
ffs_remove(simpath);
}
return return_info(CMD_COMPLETE_OK,pReadSmsdata,1024,psenddata,sizeof(T_MFW_SMS_MO));
}
//打开新文件,读出数据
if(totallen==0){
memset(pReadSmsdata,0,1024);
//删除老的文件
if(k>0){
sprintf(simpath,"/mmi/PhonMf%d",k);
ffs_remove(simpath);
}
k++;
sprintf(simpath,"/mmi/PhonMf%d",k);
if(ffs_fread(simpath,pReadSmsdata, 1024)<0)
return return_info(FREAD_FAIL,pReadSmsdata,1024,psenddata,sizeof(T_MFW_SMS_MO));
MmiTrace("freadfile");
MmiTraceInt(k);
}
if(get_data_and_send()<0){
MmiTrace("getda<0");
if(k>0){
sprintf(simpath,"/mmi/PhonMf%d",k);
ffs_remove(simpath);
}
return return_info(NO_SIM_SMS,pReadSmsdata,1024,psenddata,sizeof(T_MFW_SMS_MO));
}
}
else{
MmiTrace("getdata>=0");
}
return CMD_RET_OK;
}
static int get_data_and_send(void)
{
TPhoneSmsItem readdata;
T_MFW_SMS_INFO sms_parameter;
USHORT outLen;
char other[5] ;
UBYTE* pstrinfo;
MmiTrace("get_data_and_send");
memset(&readdata,0,sizeof(TPhoneSmsItem));
//取出一个记录
totallen+=hstrcpy(readdata.date,pReadSmsdata+totallen);
MmiTraceInt(totallen);
totallen+=hstrcpy(readdata.Number,pReadSmsdata+totallen);
totallen+=hstrcpy(readdata.info,pReadSmsdata+totallen);
totallen+=hstrcpy(readdata.sc_addr,pReadSmsdata+totallen);
totallen+=hstrcpy(other,pReadSmsdata+totallen);
readdata.type=other[0];
readdata.ton=other[1];
readdata.npi=other[2];
readdata.index=other[3];
//判断是否结束
if((readdata.info[0]=='\0')&&(readdata.Number[0]=='\0')){
totallen=0;
return -1;
}
pstrinfo = mmi_Sys_Sim((char *)readdata.info, &outLen,&(sms_parameter.dcs));
SmsSend_set_dcs_number (&sms_parameter);
//整合写结构
memset(psenddata,0,sizeof(T_MFW_SMS_MO));
psenddata->msg_len=outLen;
wstrcpy(psenddata->sms_msg,(char *)readdata.info );
strcpy(psenddata->dest_addr.number,readdata.Number );
strcpy(psenddata->sc_addr,readdata.sc_addr);
sms_submit(MFW_SMS_SUBMIT,psenddata->dest_addr.number,(UBYTE *)pstrinfo,psenddata->msg_len,psenddata->sc_addr);
return 0;
}
void save_send_sms(T_MFW_SMS_MO_TYPE type)
{
T_MFW_SMS_INFO sms_parameter;
USHORT outLen;
UBYTE* pstrinfo;
MmiTrace("save_send_sms");
MmiTraceInt(type);
pstrinfo = mmi_Sys_Sim((char *)psenddata->sms_msg, &outLen,&(sms_parameter.dcs));
SmsSend_set_dcs_number (&sms_parameter);
sms_store( type, psenddata->dest_addr.number, (UBYTE *)pstrinfo, psenddata->msg_len, NULL);
command=SAVE_SEND_SMS;
PcCmdStatus.isPcCmdRun=1;
}
int hstrcpy( char *d,const char *r)
{
int size;
size=hstrlen(r);
memcpy(d,r,size);
return size;
}
int hstrlen(const char * txt)
{
int lenth=0;
unsigned char * ss=(unsigned char*)txt;
if(*ss==0x80)//if unicode
{
ss++;
lenth++;
while((*ss<<8)+*(ss+1)!=0)
{
lenth+=2;
ss+=2;
}
lenth+=2;//add two zero
}
else//if ascii
{
while(*ss++!=0)
lenth++;
lenth+=1;//add one zero
}
return lenth;
}
/*******************************************************************************
$Function: IsExcutefileEnd
$Description: This function check the operation for excute file before.
$Returns:
$Arguments:
*******************************************************************************/
UWORD8 IsPcCmdExcuteEnd(char *value)
{
T_MFW_SMS_IDX smsidx[MAX_MESSAGES];//sms的存储index T_MFW_SMS_MSG
MmiTrace("IsPcCmdExcuteEnd()");
PcCmdStatus.nNewsms=(UWORD8)(sms_index_list(MFW_SMS_UNREAD,smsidx,1));
memcpy(value,(char *)&PcCmdStatus,sizeof(PCCMDSTATUS));
return sizeof(PCCMDSTATUS);
}
static void InitPcCmdStatus(void)
{
PcCmdStatus.isPcCmdRun=0;
PcCmdStatus.isdelsmsok=0;
PcCmdStatus.iscmdreterr=0;
k=0;
}
static int return_info(int ret,void *p1,int p1len,void *p2,int p2len)
{
PcCmdStatus.isPcCmdRun=0;//当执行结束时置标志
k=0;
i=0;
if(p1!=NULL)
FREE_MEMORY( p1, p1len);
if(p2!=NULL)
FREE_MEMORY(p2,p2len);
return ret;
}
void Sleep_wait(unsigned short times) //waiting....
{
unsigned short i=0;
unsigned short endtimes = times*10;
for(i=0; i<=endtimes; i++)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -