void SampleApp_SendPointToPointMessage( void )
{
//uint8 *abc ;
//abc= *pBuf++; //How to deal with this pointer, or how to deal with the following parameters
// uint16 data = 10;
//uint16 j = 0;
rtgItem_t rt;
NLME_GetRequest(nwkRoutingTable,0,&rt);
char msg[100] = {0};
uint16 i = 0x2040;
//i=NLME_GetRequest(nwkNumRoutingTableEntries ,j,&data);
i=NLME_GetShortAddr();
sprintf(msg, "number:%x\n", i ); //The \nASCII code of the newline symbol is 10, which is actually output as A. Because the ASCII code value of A is 1
HalUARTWrite( 0, msg,osal_strlen("number:%x\n"));
//sprintf(msg, "ssssss:%x\n", i );
//HalUARTWrite( 0, msg, 9);
}
As shown in the above code, in this case, the newline character is output as an ASCII value, which cannot achieve the desired output effect. The following code is in Zstack:
modify it as follows to achieve the desired output and wrap:
void SampleApp_SendPointToPointMessage( void )
{
//uint8 *abc ;
//abc= *pBuf++; //How to deal with this pointer, or how to deal with the following parameters
// uint16 data = 10;
//uint16 j = 0;
rtgItem_t rt;
NLME_GetRequest(nwkRoutingTable,0,&rt);
char msg[100] = {0};
uint16 i = 0x2040;
//i=NLME_GetRequest(nwkNumRoutingTableEntries ,j,&data);
i=NLME_GetShortAddr();
sprintf(msg, "number:%x\n", i );
HalUARTWrite( 0, msg,osal_strlen("number:%x\n"));
HalUARTWrite( 0, "\n",1);
//sprintf(msg, "ssssss:%x\n", i );
//HalUARTWrite( 0, msg, 9);
}
PS:另外熟悉知识点:
HalUARTWrite函数中的字符长度不包括\0,strlen函数也不包括,sizeof函数包括需要加1(长度)。字符串输出函数的长度一定要控制好,要不然就会出现意想不到的错误。