您好,我现在做从机发送温度数据,发现在GATTServApp_ProcessCharCfg之前我的数据还是正确的(如:19.50),但是通过手机接收到的数据结构是3139e3530,每位中间都夹着一位3,是在哪儿对我的数据做了更改吗?
这是我的周期事件部分:
defined( SENSOR_DS18B20 )
if(1)
{
static uint8 skKey = 0;
uint16 numBytes;
char pktBuffer[128];
float ft;
extern float DS18B20_ReadMain(void);
if(1)
{
static uint8 skKey = 0;
uint16 numBytes;
char pktBuffer[128];
float ft;
extern float DS18B20_ReadMain(void);
ft = DS18B20_ReadMain();
sprintf((char *)pktBuffer, "%.2f",ft);
HalLcdWriteString((char *)pktBuffer, HAL_LCD_LINE_6);//Added by zbh 显示温度值
numBytes = osal_strlen((char *)pktBuffer);
SK_SetParameter( SK_UART_ATTR, numBytes, pktBuffer );
}
sprintf((char *)pktBuffer, "%.2f",ft);
HalLcdWriteString((char *)pktBuffer, HAL_LCD_LINE_6);//Added by zbh 显示温度值
numBytes = osal_strlen((char *)pktBuffer);
SK_SetParameter( SK_UART_ATTR, numBytes, pktBuffer );
}
然后:
bStatus_t SK_SetParameter( uint8 param, uint8 len, void *pValue )
{
bStatus_t ret = SUCCESS;
switch ( param )
{
{
bStatus_t ret = SUCCESS;
switch ( param )
{
case SK_UART_ATTR:
if ( len > 0) {
if(len > MAX_NUM_SEND_BYTES)
len = MAX_NUM_SEND_BYTES;
static uint8 skKey = 0;
sprintf((char *)skKeyPressed, "%s", pValue);
HalLcdWriteString((char *)skKeyPressed, HAL_LCD_LINE_4); //Added by zbh
skKeyPressed_len = len;
if ( len > 0) {
if(len > MAX_NUM_SEND_BYTES)
len = MAX_NUM_SEND_BYTES;
static uint8 skKey = 0;
sprintf((char *)skKeyPressed, "%s", pValue);
HalLcdWriteString((char *)skKeyPressed, HAL_LCD_LINE_4); //Added by zbh
skKeyPressed_len = len;
GATTServApp_ProcessCharCfg( skConfig,skKeyPressed, FALSE, simplekeysAttrTbl, GATT_NUM_ATTRS( simplekeysAttrTbl ),
INVALID_TASK_ID );
INVALID_TASK_ID );
问题来了,标红之前的skKeyPressed = 19.50,是正确的温度数据,但是我手机接收到的却在每一位中间夹着个3,请问这个数据结构是在哪儿改的?
Yue TANG:
skKeyPressed 是字符串。如下操作后,skKeyPressed里的就是“19.50”的字符串了,而不是float
sprintf((char *)skKeyPressed, "%s", pValue);
你手机侧要把字符串转成float.
Yue TANG:
不知你的skKeyPressed 是啥类型的。如果是ft ,这种写法还有可能导致内存overflow。