📄 myapp_success.c
字号:
#include "MMI_features.h"
#define __NEWSIMULATOR
#include "stdC.h"
#include "L4Dr1.h"
#include "PixtelDataTypes.h"
#include "GlobalDefs.h"
#include "GlobalConstants.h" /* KEY ID define */
#include "Fat_fs.h" /* File System, must after "GlobalConstants.h" */
//#include "FileSystemDef.h" /* file function */
#include "GlobalDefs.h" /* Golbal Image and String ID. */
#include "gui.h" /* Gui functions */
#include "wgui_categories.h" /* Categories */
#include "HistoryGprot.h" /* Screen history */
#include "Unicodexdcl.h" /* Unicode transform functions */
#include "EventsGprot.h" /* Event handling */
#include "SettingDefs.h" /* popup sound */
#include "DebugInitDef.h" /* MMI_ASSERT */
#include "CommonScreens.h" /* Popup */
#include "SubLCDHistoryGprot.h" /* SubLCD */
#include "lcd_sw_rnd.h" /* lcd */
#include "lcd_if.h" /* lcd */
#include "gdi_include.h" /* graphic library */
#include "mdi_datatype.h" /* mdi datatype */
#include "mdi_audio.h" /* audio lib */
#include "kal_release.h" /* kal */
#include "Unicodexdcl.h" /* string manipulation */
#define __NEWSIMULATOR
//the head of functions of NetWork and File
#include "FileManagerGProt.h"
#include "StdC.h"
#include "L4Dr1.h"
#include "L4Dr.h"
#include "DebugInitDef.h"
#include "FrameworkStruct.h"
#include "globalconstants.h"
#include "CommonScreens.h" //redifined gIndexIconsImageList
#include "wgui_categories.h"
#include "GlobalDefs.h"
#include "historyGprot.h"
#include "ProtocolEvents.h"
#include "PixtelDataTypes.h"
#include "MMI_trc.h"
#include "app_mine.h"
#include "Conversions.h"
#include "FileMgr.h"
#include "MainMenuDef.h"
#include "soc_api.h"
#include "app2soc_struct.h"
#include "custom_em.h"
#undef __NEWSIMULATOR
//the head of functions of SMS
#include "SmsGuiInterfaceType.h"
#include "Wgui_categories_inputsenum.h"
#include "SMSApi.h"
#include "Ems.h"
#define RCVD_BUFFER_SIZE 1024*2
S8 rcvd_buffer[RCVD_BUFFER_SIZE];
//S8 rcvd_buffer[]
S8 phone_num[30]={0};
/*****************************************************************************
* FUNCTION
* Convert_GBK_to_Unicode
* DESCRIPTION
* To convert GBK code to unicode code.
* PARAMETERS
* pGBk [IN] The string would be converted.
* pUnicode [IN] The string have been converted.
* len [IN/OUT] The string length.
* RETURNS
* void
*****************************************************************************/
void Convert_GBK_to_Unicode(const char *pGBK, U16 *pUnicode, U16 len)
{
//memset(pUnicode, 0, 125);
#ifndef MMI_ON_WIN32
mmi_chset_text_to_ucs2_str((kal_uint8*)pUnicode, len, (kal_uint8*)pGBK, GB2312_ENCODING_TYPE);
#else
MultiByteToWideChar(CP_ACP, 0, pGBK, len, (U16 *)pUnicode, len);
#endif
}
void Convert_GBK_to_Unicode2(const char *pGBK, U16 *pUnicode)
{
memset(pUnicode, 0, 125);
#ifndef MMI_ON_WIN32
mmi_chset_text_to_ucs2_str((kal_uint8*)pUnicode, 125, (kal_uint8*)pGBK, GB2312_ENCODING_TYPE);
#else
MultiByteToWideChar(CP_ACP, 0, pGBK, 125, (U16 *)pUnicode, 125);
#endif
}
//declare my functions.
void NetWork(void);
/*****************************************************************************
* FUNCTION
* LyreSMSSendHandle
* DESCRIPTION
* To send SMS message.
* PARAMETERS
* pMsgText [IN] the information would be sent.
* pSMSPhoneNumber [IN] the phone NO. of the aim.
* dcs [IN] the tag of ascii or unicode.
* RETURNS
* Bool ?????
*****************************************************************************/
//发送短信Handle //There is NULL point
extern int AppendEMSString(S16 input_type, EMSData *data, U8 *s, U8 dcs, U8 *history_buffer);
extern msg_context_struct g_msg_cntx;
extern EMSData * GetEMSDataForEdit (EMSData ** p, U8 force);
BOOL LyreSMSSendHandle2(PS8 pMsgText, PS8 pSMSPhoneNumber, U8 dcs)
{
U16 len;
S8 singleText[(SMSAL_MAX_MSG_LEN + 1)] = {0};
S8 textbufUCS2[(SMSAL_MAX_MSG_LEN + 1) * 2];
EMSData * pEMS;
byte result;
ReleaseEMSEditBuffer();
pEMS = GetEMSDataForEdit (0, 0);
g_msg_cntx.sendSaveStatus = SEND_SAVE_NIL;
memset (g_msg_cntx.smsPhoneNumber, 0, sizeof(g_msg_cntx.smsPhoneNumber));
AnsiiToUnicodeString((S8 *)textbufUCS2, (S8 *)pSMSPhoneNumber);
pfnUnicodeStrcpy(g_msg_cntx.smsPhoneNumber, textbufUCS2);
g_msg_cntx.sendMessageCase = SEND_CASE_SEND_ONLY;
memset(textbufUCS2, 0, sizeof(textbufUCS2));
if (dcs == 0) //ascii dcs
{
len = strlen((PS8)pMsgText);
if ( len >= SMSAL_MAX_MSG_LEN )
{
strncpy((S8*)singleText, (S8*)pMsgText, SMSAL_MAX_MSG_LEN);
singleText[SMSAL_MAX_MSG_LEN] = '\0';
}
else
{
strcpy((char *)singleText, (const char *)pMsgText);
}
AnsiiToUnicodeString((S8 *) textbufUCS2, ( S8 *) singleText);
#ifdef __SOLAR_STAR_MTK_08A
result = AppendEMSString (IMM_INPUT_TYPE_SENTENCE,
pEMS, (U8*)textbufUCS2, SMSAL_DEFAULT_DCS, NULL);
#else
result = AppendEMSString (INPUT_TYPE_ALPHANUMERIC_SENTENCECASE,
pEMS, (U8*)textbufUCS2, SMSAL_DEFAULT_DCS, NULL);
#endif
}
else if (dcs == 1) //unicode dsc
{
len = pfnUnicodeStrlen((PS8)pMsgText);
if ( len >= 70 )
{
pMsgText[(70)*2] = '\0';
pMsgText[(70)*2 + 1] = '\0';
}
pfnUnicodeStrcpy((S8*)textbufUCS2, (S8*)pMsgText);
#ifdef __SOLAR_STAR_MTK_08A
result = AppendEMSString (IMM_INPUT_TYPE_SENTENCE,
pEMS, (U8*)textbufUCS2, SMSAL_UCS2_DCS, NULL );
#else
result = AppendEMSString (INPUT_TYPE_ALPHANUMERIC_SENTENCECASE,
pEMS, (U8*)textbufUCS2, SMSAL_UCS2_DCS, NULL );
#endif
}
if (result == 1)
{
mmi_frm_sms_send_struct * sendData = OslMalloc(sizeof(mmi_frm_sms_send_struct));
memset((S8*)sendData, 0, sizeof(mmi_frm_sms_send_struct));
memset(sendData->number, 0, MAX_DIGITS_SMS);
strcpy((S8*)(sendData->number), pSMSPhoneNumber);
sendData->sendcheck = sendData->sendcheck | MMI_FRM_SMS_SCR;
#ifdef __SOLAR_DUAL_SIM_0812_
if (1)
{
E_MTPNP_AD_SIMCARD_STATUS sim1_status, sim2_status;
sim1_status = MTPNP_AD_Get_Card1Status();
sim2_status = MTPNP_AD_Get_Card2Status();
if ((mobile_card_status & MTPNP_AD_CARD1) && sim1_status == MTPNP_AD_SIMCARD_VALID)
{
MTPNP_AD_Free_Channel(MTPNP_AD_SMS_CHANNEL);
MTPNP_AD_Set_Channel(MTPNP_AD_SMS_CHANNEL, MTPNP_AD_CHANNEL_MASTER);
}
else if ((mobile_card_status & MTPNP_AD_CARD2) && sim2_status == MTPNP_AD_SIMCARD_VALID)
{
MTPNP_AD_Free_Channel(MTPNP_AD_SMS_CHANNEL);
MTPNP_AD_Set_Channel(MTPNP_AD_SMS_CHANNEL, MTPNP_AD_CHANNEL_SLAVE);
}
sendData->sendrequire &= ~MMI_FRM_SMS_DISP_SIM_OPT; //silence
}
#endif
mmi_frm_sms_send_sms(NULL, MOD_MMI, sendData);
OslMfree(sendData);
return TRUE;
}
else
{
//继续扫描扣费
//
return FALSE;
}
}
/*****************************************************************************
* FUNCTION
* File
* DESCRIPTION
* To read phone a NO. from a file in T card.
* PARAMETERS
* void
* RETURNS
* char point of the phone NO.
*****************************************************************************/
void Read_File(void)
{
//the varitys of function File
S8 str[15]={0};
S8 str2[30];
U16 file_len = 0;
kal_int16 a;
U16 actread;
FS_HANDLE hFile = -1;
S8 file_str[12] = ":\\soc.txt";
//S8 disk_tk = 'd';
S8 disk_tk = MMI_CARD_DRV;
S8 file_add[20] ={0}; //一定要初始化
S8 file_add_chan[40];
sprintf(file_add,"%c%s",MMI_CARD_DRV,file_str);
//file_add[0] = disk_tk;
//strcat(file_add,file_str); //为什么可以???
Convert_GBK_to_Unicode(file_add,(U16 *)file_add_chan,40);
hFile = FS_Open((PU16)file_add_chan, FS_READ_ONLY);
if(hFile<0)
{
gui_move_text_cursor(20,20);
gui_set_text_color(UI_COLOR_BLACK);
gui_print_text(L"file open failed!");
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
return;
}
if(FS_GetFileSize(hFile, (UINT*)&file_len) != FS_NO_ERROR)
{
//FS_Close(hFile); //读取文件大小失败 //append_log("get file size error");
gui_move_text_cursor(20,20);
gui_print_text(L"file GET failed!");
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
return;
}
a=FS_Read(hFile,str,file_len,(UINT*)&actread); //把str写成了str2,应该写转换前的,却写成转换后的!
if(a < 0)
{
//FS_Close(hFile);
//append_log("read file error");
gui_move_text_cursor(40,40);
gui_set_text_color(UI_COLOR_BLACK);
gui_print_text(L"file READ failed!");
gui_BLT_double_buffer(0,0,UI_device_height-1,UI_device_width-1);
return;
}
strcpy(phone_num, str);
FS_Close(hFile);
}
void ConnectGPRS(void)
{
//the varitys of function NetWork
kal_int8 hsock = 0;
kal_int32 ret = 0;
S8 url_buffer[512] = {"GET http://202.105.179.137/test.html HTTP/1.1\r\n\r\n"};
U32 url_long = strlen(url_buffer);
S8 tmp_buffer[128];
kal_int32 revd_len;
static U8 cmwap_nad = 10;
static sockaddr_struct sockaddr;
S8 err_str2[10];
S8 find_str[10];
kal_int16 c_t;
EntryNewScreen(4551,NULL,NULL,NULL);
entry_full_screen();
clear_screen();
#ifndef MMI_ON_HARDWARE_P
soc_init_win32();
#endif
hsock = soc_create(PF_INET, SOCK_STREAM, 0, MOD_MMI, cmwap_nad);
if(hsock < 0 )
{
gui_move_text_cursor(40,40);
gui_set_text_color(UI_COLOR_BLACK);
gui_print_text(L"create failed!");
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
return;
}
else
{
gui_move_text_cursor(40,40);
gui_set_text_color(UI_COLOR_BLACK);
gui_print_text(L"create");
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
}
#ifndef MMI_ON_WIN32
sockaddr.addr[0] = 10;
sockaddr.addr[1] = 0;
sockaddr.addr[2] = 0;
sockaddr.addr[3] = 172;
sockaddr.port = 80;
sockaddr.addr_len = 4;
#else
sockaddr.addr[0] = 202;
sockaddr.addr[1] = 105;
sockaddr.addr[2] = 179;
sockaddr.addr[3] = 137;
sockaddr.port = 80;
sockaddr.addr_len = 4;
#endif
ret = soc_connect((kal_int8)hsock,&sockaddr);
if(ret < 0)
{
gui_move_text_cursor(40,40);
gui_set_text_color(UI_COLOR_BLACK);
gui_print_text(L"connect failed!");
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
return;
}
else
{
gui_move_text_cursor(40,60);
gui_set_text_color(UI_COLOR_BLACK);
gui_print_text(L"connect");
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
}
//开始发送数据包,注意发送的数据方式,用HTTP格式的数据发送!
ret = soc_send((kal_int8)hsock, (kal_uint8*)url_buffer,(kal_int32)url_long, 0);
if(ret < 0)
{
gui_move_text_cursor(40,80);
gui_set_text_color(UI_COLOR_BLACK);
gui_print_text(L"send failed!");
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
return;
}
else
{
gui_move_text_cursor(40,80);
gui_set_text_color(UI_COLOR_BLACK);
gui_print_text(L"send");
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
}
revd_len = 0;
ret = soc_recv(hsock,(kal_uint8*) tmp_buffer,128, 0);
while (ret > 0)
{
memcpy(rcvd_buffer+revd_len,tmp_buffer,ret);
revd_len += ret;
ret = soc_recv(hsock, (kal_uint8*)tmp_buffer,128,0);
}
}
void Play_Music(void)
{
//S8 disk_tk = 'd';
S8 disk_tk = MMI_CARD_DRV;
S8 music_str[10] = ":\\1.mp3";
S8 music_add[20] ={0} ;
S8 music_add_chan[40]={0};
int count_i;
music_add[0] = disk_tk;
strcat(music_add,music_str); //一定要对music_add初始化,否则连接到本数组最后地址的后面了,所以到了music_str上面去了。
Convert_GBK_to_Unicode(music_add,(U16 *)music_add_chan,40);
//if have "Error:****", then play MP3
mdi_audio_play_file(music_add_chan,DEVICE_AUDIO_PLAY_ONCE,NULL,NULL);
}
void Send_SMS(void)
{
S8 sms_info_str[40] = "this is message information";
S8 sms_info_chan[80];
S8 over_msss[30] = "send over";
S8 over_mess_chan[60]={0};
//send SMS , which is "Error:****", to the NO. readed from the T card.
//after SMS, popup during 20ms.
gui_move_text_cursor(10,80);
gui_set_text_color(UI_COLOR_RED);
gui_print_text(L"message sending");
Convert_GBK_to_Unicode(sms_info_str, (U16 *)sms_info_chan,80); //SUCCESS
if(LyreSMSSendHandle2((PS8)sms_info_chan, phone_num, 1))
{
Convert_GBK_to_Unicode(over_msss,(U16 *)over_mess_chan,60);
//DisplayPopup((U8 *)over_mess_chan,IMG_GLOBAL_INFO,1,5000,0);
gui_move_text_cursor(10,110);
gui_set_text_color(UI_COLOR_RED);
gui_print_text((U16 *)over_mess_chan);
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
}
//program over
//return;
}
void My_Main(void)
{
S8* aim_p;
S8 rec_change[90]={0};
typedef struct _UI_filled_area
{
dword flags;
UI_image_type b;
gradient_color* gc;
color c;
color ac;
color border_colr;
color shadow_color;
UI_transparent_color_type transparent_color;
}MY_filled_area;
MY_filled_area filler = {0};
ConnectGPRS();
filler.flags = UI_FILLED_AREA_TYPE_3D_BORDER;
filler.c = UI_COLOR_GREY;
gui_draw_filled_area(20,20,100,100,(UI_filled_area *)&filler);
if((aim_p = strstr(rcvd_buffer,"0001"))!= NULL)
{
aim_p += 39;
*aim_p= '\0';
aim_p=aim_p-39;
Convert_GBK_to_Unicode(aim_p,(U16 *)rec_change,90);
DisplayPopup((U8 *)rec_change,IMG_GLOBAL_WARNING,1,10000,0);
//gui_move_text_cursor(10,50);
//gui_set_text_color(UI_COLOR_RED);
//gui_print_text((U16 *)rec_change);
//gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
}
else
{
gui_move_text_cursor(10,50);
gui_set_text_color(UI_COLOR_RED);
gui_print_text(L"no error");
//StartTimer(145, 20000, ConnectGPRS);
}
//StartTimer(149, 10000, Play_Music);
Play_Music();
//read file from T card, after mp3
//StartTimer(150, 1000, Read_File);
Read_File();
//StartTimer(156, 10000, Send_SMS);
Send_SMS();
//program over
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -