|
碰到的问题跟http://study-bbs.com/viewthread.php?tid=27810&highlight=%B4%AE%BF%DA一样,不知道怎么解决。
手机程序能往串口调试助手中写HelloWorldUartEchoExampleStarted!、
HelloWorldUartEchoExampleStop!
但串口调试助手发送的信息,手机程序无法接收到。
怎么解决啊?哪位高人知道指点一下。
程序如下:
#include"stdC.h"
#include"MMI_Features.h"/*编译开关会出现在这个由makeupdate生成的文件里面*/
#include"L4Dr.h"
#include"L4Dr1.h"
#include"AllAppGprot.h"
#include"FrameworkStruct.h"
#include"GlobalConstants.h"
#include"EventsGprot.h"
#include"mmiappfnptrs.h"
#include"HistoryGprot.h"
#include"HelloWorldProt.h"
#include"HelloWorldTypes.h"
#include"HelloWorldDefs.h"
#include"MainMenuDef.h"
#include"wgui_categories.h"
#include"Unicodexdcl.h"
#include"gui_data_types.h"
#include"Uart_sw.h"
#defineHELLO_WORLD_UART_PORTuart_port1//手机接USB下载线的地方
#defineMOD_HELLO_WORLDMOD_MMI
#defineMAX_ECHO_PACKET_LEN128
externmodule_typeUART_GetOwnerID(UART_PORTport);
externvoidUART_ClrTxBuffer(UART_PORTport,module_typeownerid);
externvoidUART_ClrRxBuffer(UART_PORTport,module_typeownerid);
staticvoidinit_uart(void);
staticvoidmmi_HelloWorld_uart_readyToRead_ind_handler(void*msg);
staticU16read_from_uart(U8*pbyBuf,U16wLenMax,UART_PORThPort,module_typehOwner);
staticU8write_to_uart(U8*pbyBuf,U16wLenBuf,UART_PORThPort,module_typehOwner);
staticvoidexit_uart();
staticvoidstart_uart_echo(void);
staticvoiduart_echo_process(void);
staticvoidstop_uart_echo(void);
//睡眠模式句柄
statickal_uint8ghSleepMode;
staticmodule_typegnOrigUartOwner;
statickal_boolgbUartInitialized=KAL_FALSE;
statickal_boolgbUartEchoStarted=KAL_FALSE;
staticU16gwLenUartBuffer=0;
staticU8gabyUartBuffer[MAX_ECHO_PACKET_LEN];
staticvoid init_uart(void)
{
#ifdef__MMI_HELLOWORLD_ENABLED__
if(gbUartInitialized)
{
return;
}
ghSleepMode=L1SM_GetHandle();
L1SM_SleepDisable(ghSleepMode);
//记录我们要用的串口的当前占有者
gnOrigUartOwner=UART_GetOwnerID(HELLO_WORLD_UART_PORT);
//下面我们申明要占用这个串口了
UART_SetOwner(HELLO_WORLD_UART_PORT,MOD_HELLO_WORLD);
UART_SetBaudRate(HELLO_WORLD_UART_PORT,UART_BAUD_115200,MOD_HELLO_WORLD);
SetProtocolEventHandler(mmi_HelloWorld_uart_readyToRead_ind_handler,MSG_ID_UART_READY_TO_READ_IND);
gbUartInitialized=KAL_TRUE;
#endif
}
static U16 read_from_uart(U8*pbyBuf,U16wLenMax,UART_PORThPort,module_typehOwner)
{
U16 wLenAvail;
U16 wLenRead;
U16 wLenRet=0;
U8 byStatus=0;
#ifdef__MMI_HELLOWORLD_ENABLED__
//收取数据,超出最大包长的数据将简单丢弃,这一层需要具体的应用协议做相应处理
while((wLenAvail=UART_GetBytesAvail(hPort)>0&&wLenRet<wLenMax))
{
if(wLenAvail+wLenRet>wLenMax)
{
wLenAvail=wLenMax-wLenRet;
}
wLenRead=UART_GetBytes(hPort,(kal_uint8*)(pbyBuf+wLenRet),(kal_uint16)wLenAvail,&byStatus,hOwner);
wLenRet+=wLenRead;
}
//读完之后,清除接收Buffer
UART_ClrRxBuffer(hPort,hOwner);
#endif
returnwLenRet;
}[/COLOR][/COLOR]
staticU8write_to_uart(U8*pbyBuf,U16wLenBuf,UART_PORThPort,module_typehOwner)
{
U16wSent=0;
U8bRet=FALSE;
#ifdef__MMI_HELLOWORLD_ENABLED__
//发送前清FIFO和Buffer,注意:这一步必须做,否则收发会有问题
UART_Purge(hPort,RX_BUF,hOwner);//清除设备输入FIFO
UART_Purge(hPort,TX_BUF,hOwner);//清除设备输出FIFO
UART_ClrTxBuffer(hPort,hOwner);//清除发送Buffer
UART_ClrRxBuffer(hPort,hOwner);//清除接收Buffer
wSent=UART_PutBytes(hPort,(kal_uint8*)pbyBuf,(kal_uint16)wLenBuf,hOwner);
#endif
if(wSent==wLenBuf)
{
bRet=TRUE;
}
returnbRet;
}
staticvoidexit_uart()
{
#ifdef__MMI_HELLOWORLD_ENABLED__
if(gbUartInitialized)
{
//恢复成原有的端口占用者
UART_SetOwner(HELLO_WORLD_UART_PORT,(kal_uint8)gnOrigUartOwner);
//允许休眠
L1SM_SleepEnable(ghSleepMode);
gbUartInitialized=KAL_FALSE;
}
#endif
}
staticvoidmmi_HelloWorld_uart_readyToRead_ind_handler(void*msg)
{
#ifdef__MMI_HELLOWORLD_ENABLED__
uart_ready_to_read_ind_struct*uart_rtr_ind=(uart_ready_to_read_ind_struct*)msg;
if(KAL_FALSE==gbUartEchoStarted||
HELLO_WORLD_UART_PORT!=uart_rtr_ind->port||
MOD_HELLO_WORLD!=UART_GetOwnerID(uart_rtr_ind->port))
{
//如果底层能做成钩子链,这里就可以调用钩子链的下一个钩子了
return;
}
gwLenUartBuffer=read_from_uart(gabyUartBuffer,sizeof(gabyUartBuffer),HELLO_WORLD_UART_PORT,MOD_HELLO_WORLD);
//呼叫数据处理部分
uart_echo_process();
#endif
}
staticvoidstart_uart_echo(void)
{
#ifdef__MMI_HELLOWORLD_ENABLED__
S8strHello[]="HelloWorldUartEchoExampleStarted!\r\n";
if(gbUartEchoStarted)
{
return;
}
init_uart();
write_to_uart((kal_uint8*)strHello,(kal_uint16)strlen(strHello),HELLO_WORLD_UART_PORT,MOD_HELLO_WORLD);
gbUartEchoStarted=KAL_TRUE;
SetKeyHandler(stop_uart_echo,KEY_LSK,KEY_EVENT_UP);
#endif
}
staticvoiduart_echo_process(void)
{
#ifdef__MMI_HELLOWORLD_ENABLED__
U8i;
//稍稍处理一下,这样就能看出是否确实是我们的程序在处理数据
for(i=0;i<gwLenUartBuffer;i++)
{
if(gabyUartBuffer>='a'&&gabyUartBuffer<='z')
{
gabyUartBuffer-=0x20;
}
}
//回显
write_to_uart(gabyUartBuffer,gwLenUartBuffer,HELLO_WORLD_UART_PORT,MOD_HELLO_WORLD);
#endif
}
staticvoidstop_uart_echo(void)
{
#ifdef__MMI_HELLOWORLD_ENABLED__
S8strBye[]="HelloWorldUartEchoExampleStop!\r\n";
if(gbUartEchoStarted)
{
write_to_uart((kal_uint8*)strBye,(kal_uint16)strlen(strBye),HELLO_WORLD_UART_PORT,MOD_HELLO_WORLD);
gbUartEchoStarted=KAL_FALSE;
SetKeyHandler[/COLOR](start_uart_echo,KEY_LSK,KEY_EVENT_UP);
}
exit_uart();
#endif
}
gdi_handlehAnimation;
voidstop_play_anim(void)
{
gdi_anim_stop(hAnimation);
}
/*模块入口*/
voidmmi_HelloWorld_entry(void)
{
#ifdef__MMI_HELLOWORLD_ENABLED__
S32x,y,w,h;
colorcolorText={255,255,128,100};
colorcolorFill={207,252,109,100};
colorcolorShadow={166,201,81,100};
stFontAttributetFont={0};
U8dotted_line_bitvalues[]={1,0,1,0,1,0,1};
UI_filled_areatFiller={0};
staticcolorg_colors[3]={{255,0,0},{0,255,0},{0,0,255}};
staticU8perc[2]={50,50};
gradient_colorgc={g_colors,perc,3};
tFont.size=LARGE_FONT;
tFont.italic=1;
EntryNewScreen(SCR_HELLOWORLD,mmi_HelloWorld_exit,NULL,NULL);
gui_lock_double_buffer();
/*关掉屏幕顶部的状态条,我们要用整个屏幕*/
entry_full_screen();
/*擦除当前背景*/
clear_screen();
tFiller.flags=UI_FILLED_AREA_TYPE_GRADIENT_COLOR|UI_FILLED_AREA_VERTICAL_FILL|UI_FILLED_AREA_DOUBLE_BORDER;
tFiller.border_color=UI_COLOR_GREEN;
tFiller.gc=&gc;
gui_draw_filled_area(0,0,UI_device_width-1,UI_device_height-1,&tFiller);
/*设置字体颜色*/
gui_set_text_color(colorText/*UI_COLOR_RED*/);
gui_set_font(&tFont);
gui_set_text_border_color(UI_COLOR_GREEN);
gui_measure_string((UI_string_type)GetString(STR_HELLOWORLD_HELLO),&w,&h);
x=(UI_device_width-w)>>1;
y=UI_device_height-((UI_device_height-h)>>2);
gui_draw_rectangle(x-7,y-7,x+w+7,y+h+7,UI_COLOR_RED);
gui_fill_rectangle(x-6,y-6,x+w+6,y+h+6,colorFill);
gui_line(x-4,y+h+4,x+w+4,y+h+4,colorShadow);
gui_line(x-5,y+h+5,x+w+5,y+h+5,colorShadow);
gui_line(x-6,y+h+6,x+w+6,y+h+6,colorShadow);
gui_line(x+w+4,y-4,x+w+4,y+h+4,colorShadow);
gui_line(x+w+5,y-5,x+w+5,y+h+5,colorShadow);
gui_line(x+w+6,y-6,x+w+6,y+h+6,colorShadow);
/*移动文本输出光标*/
gui_move_text_cursor(x,y);
/*输出文本到显示缓冲,注意是Unicode编码*/
//gui_print_text((UI_string_type)GetString(STR_HELLOWORLD_HELLO));
gui_print_bordered_text((UI_string_type)GetString(STR_HELLOWORLD_HELLO));
gdi_draw_line_style(x,y+h+2,x+w+2,y+h+2,
gdi_act_color_from_rgb(100,255,0,0),
sizeof(dotted_line_bitvalues),
dotted_line_bitvalues);
//显示图片
gdi_image_get_dimension_id(MAIN_MENU_MATRIX_ORGANIZER_ICON,&w,&h);
x=(UI_device_width-w)>>1;
y=(UI_device_height-h)>>1;
gdi_image_draw_id(x,10,MAIN_MENU_MATRIX_ORGANIZER_ICON);
//显示动画
gdi_image_get_dimension_id(MAIN_MENU_MATRIX_ORGANIZER_ANIMATION,&w,&h);
x=(UI_device_width-w)>>1;
y=(UI_device_height-h)>>1;
gdi_anim_draw_id(x,10+h,MAIN_MENU_MATRIX_ORGANIZER_ANIMATION,&hAnimation);
gui_unlock_double_buffer();
/*刷新屏幕显示,MMI用的是双缓冲绘图方式,而且需要显式刷新*/
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
/*注册一个按键处理,右软键弹起时返回到之前被我们强制退出的模块*/
SetKeyHandler(GoBackHistory,KEY_RSK,KEY_EVENT_UP);
//SetKeyHandler(stop_play_anim,KEY_LSK,KEY_EVENT_UP);
SetKeyHandler(start_uart_echo,KEY_LSK,KEY_EVENT_UP);
#endif
}
voidmmi_HelloWorld_exit(void)
{
#ifdef__MMI_HELLOWORLD_ENABLED__
historycurrHistory;
S16nHistory=0;
currHistory.scrnID=MAIN_MENU_SCREENID;
currHistory.entryFuncPtr=mmi_HelloWorld_entry;
pfnUnicodeStrcpy((S8*)currHistory.inputBuffer,(S8*)&nHistory);
AddHistory(currHistory);
stop_uart_echo();
#endif
}
voidmmi_HelloWorld_hilite(void)
{
#ifdef__MMI_HELLOWORLD_ENABLED__
SetLeftSoftkeyFunction(mmi_HelloWorld_entry,KEY_EVENT_UP);
#endif
}
voidmmi_HelloWorld_init(void)
{
#ifdef__MMI_HELLOWORLD_ENABLED__
SetHiliteHandler(MENU_ID_HELLOWORLD,mmi_HelloWorld_hilite);
#endif
}
|
|