原创 MTK之后台发送中英文短信篇

2010-8-20 15:54 5610 5 5 分类: 软件与OS

 个人理解和收集所书,有误请指出,转载请注明出处



 
 从网上看到很多关于后台发送中英文短信的方法,先自己总结了两种,并予以比较。


 


方法一


 


这种方法支持两种编码格式,SMSAL_DEFAULT_DCS(7bit 编码)和SMSAL_UCS2_DCS(Unicode编码)


 


弊端:1)不可以发送长短信,对于7bit编码最多支持160个字符,对Unicode编码只支持70字符
          2)不能得知短信发送的状态,如:是否正在发送,发送完毕等


 


既然这种方法这么大的弊端,为什么还列出来呢?
原因在于,如果你并不需要频繁的发送短信,而且发送的短信内容相对较少那还是可行的。


 


BOOL mmi_send_message(S8 *pPhoneNum, S8 *pMessageContent, U8 dcs)
{
       mmi_sms_send_msg_req_struct *sendmessage = NULL;
       S8 tmp;
       U8 i;
       U16 msg_len = 0;


 


       if(g_pwr_context.CurrentServiceType != FULL_SERVICE)
       {
             return FALSE;
       }


 


       sendmessage = (mmi_sms_send_msg_req_struct*)OslConstructDataPtr(sizeof(*sendmessage));
       sendmessage->ref_count = 1;
       sendmessage->msg_len = sizeof(mmi_sms_send_msg_req_struct);
       sendmessage->profile = 0;
       sendmessage->reply_index = MMI_FRM_SMS_INVALID_INDEX;
       sendmessage->para = 0;
       memset(sendmessage->sc_addr.number, 0xff, MAX_CC_ADDR_LEN);
       sendmessage->sc_addr.length = 0xff;
       sendmessage->sc_addr.type = 0xff;
       sendmessage->vp = 0xff;
       sendmessage->pid = 0xff;
       sendmessage->udhi = 0;
       sendmessage->seq_num = 0;
       memset(sendmessage->msg, 0, SMSAL_MAX_MSG_LEN);
       mmi_frm_sms_convert_ascii_num_to_l4_num(&sendmessage->dest, (U8*)pPhoneNum);


 


       if(SMSAL_DEFAULT_DCS == dcs)
       {
             msg_len = strlen((S8*)pMessgeContent);
        }
       else
       {
             msg_len = pfnUnicodeStrlen((S8*)pMessgeContent) * 2;


 


             for(i=0; i<msg_len; i+=2)
             {
                     tmp = pMessageContent;
                     pMessageContent = pMessageContent[i+1];
                     pMessageContent[i+1] = tmp;
              }



        }


 


       if(SMSAL_MAX_MSG_LEN < msg_len)
       {
               return FALSE;
       }


 


       sendmessage->length = msg_len;
       memcpy(sendmessage->msg, (U8*)pMessageContent, sendmessage->length);


 


       mmi_frm_sms_send_message(MOD_MMI,
                                                              MOD_L4C,
                                                              0,
                                                              PRT_MSG_ID_MMI_SMS_SEND_MSG_REQ,
                                                              (oslParaType*)sendmessage,
                                                              NULL);



 
          return TRUE;
}


 


方法二


 


这种方法是将所传入的短信内容都转为Unicode编码方式进行发送


 


弊端:如果是7bit编码的话被转为了Unicode编码,大大减少了发送的内容


 


优势:支持长短信发送,并且可以明确知道短信发送状态(有回调函数)


 


void mmi_send_message(S8 *pPhoneNum, S8 *pMessageContent)
{
         U8 i;
         byte result;
         S8 textbufUCS2[(MAX_SMS_CONTENT_LEN+1)*2];
         EMSData *pEMS = NULL;


 


         if(g_pwr_context.CurrentServiceType != FULL_SERVICE)
         {
                 return;
          }


 



         ReleaseEMSEditBuffer();
         pEMS = GetEMSDataForEdit(0, 0);


         PendingSaveSendData.mti = SMSAL_MTI_SUBMIT;
         memset(PendingSaveSendData.TPUD, 0, sizeof(PendingSaveSendData.TPUD));


 


          for (i = 1; i < mmi_msg_get_seg_num(); i++)
          {
                 PendingSaveSendData.TPUDLen = 0;
                 PendingSaveSendData.TPUD_p = NULL;
                 PendingSaveSendData.l4index = SMS_INVALID_INDEX;
                 PendingSaveSendData.TPUD_udhi = FALSE;
           }


 


          memset(textbufUCS2, 0, sizeof(textbufUCS2));
          mmi_chset_text_to_ucs2((kal_uint8*)textbufUCS2, sizeof(textbufUCS2),  (kal_uint8*)pMessageContent);


 


          result = AppendEMSString(IMM_INPUT_TYPE_SENTENCE,
                                                          pEMS,
                                                          (U8*)textbufUCS2,
                                                          SMSAL_UCS2_DCS,
                                                          NULL); 


 


 /* mmi_get_sms_segments函数的实现,可以参看手机输入短信的时候右上角显示的可输入的字符个数,例如,如果输入了长短信的话,第一页可以输入160,第二页可是输入146,从第三页之后都是152。这个长短不一和是因为每段短信的头处加入一些数据头,以便进行拼接所用的。
支持的长短信的页数定义在custom\ps\XXX_XX_bb\Customer_ps_inc.h,名称为MMI_SMS_MAX_MSG_SEG
 该值默认为4
 */


 


           PendingSaveSendData.totalSegments = mmi_get_sms_segments(pEMS->textLength); //获取短信的段数


 


           if(0xFF == PendingSaveSendData.totalSegments)
           {
                  gb_sending_sms = FALSE;
                  return;
            }



  
           if (result)
           {
                 mmi_frm_sms_send_struct *sendData = OslMalloc(sizeof(mmi_frm_sms_send_struct));
                 gb_sending_sms = TRUE;
  
                 memset((S8 *) sendData,0,sizeof(mmi_frm_sms_send_struct));
                 memset(sendData->number,0,MAX_DIGITS_SMS); 
                 strcpy((S8 *) sendData->number, (S8*)pPhoneNum);


                  mmi_frm_sms_send_sms(send_message_callback, MOD_MMI, sendData);
                  OslMfree(sendData);
                 return;
         }


 


         gb_sending_sms = FALSE;
         return; 
}


 


//发送短信完成后的回调函数
void send_message_callback(void *number, module_type mod, U16 result)
{
         U16 currentSCRID;


          gb_sending_sms = FALSE;
          mmi_frm_sms_delete_screen_history();
          currentSCRID = GetActiveScreenId();



 
          if((currentSCRID == SCR_ID_MSG_SENDING)
               || (currentSCRID == SCR_ID_MSG_PROCESSING))
          {
                      GoBackHistory();
          }


 


         return;
}

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
5
关闭 站长推荐上一条 /3 下一条