//------------------------------------------------------
修改特征值初始化
{
uint8_t charValue1 = 1;
uint8_t charValue2 = 2;
uint8_t charValue3 = 3;
uint8_t charValue4 = 4;
uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = { 1, 2, 3, 4, 5 };
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, sizeof(uint8_t),
&charValue1);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2, sizeof(uint8_t),
&charValue2);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR3, sizeof(uint8_t),
&charValue3);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(uint8_t),
&charValue4);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN,
charValue5);
}
成
{
uint8_t charValue1 = 1;
uint8_t charValue2 = 2;
uint8_t charValue3 = 3;
uint8_t charValue4[20] = {0};
uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = { 1, 2, 3, 4, 5 };
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, sizeof(uint8_t),
&charValue1);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2, sizeof(uint8_t),
&charValue2);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR3, sizeof(uint8_t),
&charValue3);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, 20,
charValue4);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN,
charValue5);
}
当手机蓝牙连接以后,发送字符串将会回调用SimplePeripheral_processCharValueChangeEvt函数
修改
static void SimplePeripheral_processCharValueChangeEvt(uint8_t paramId)
{
uint8_t newValue;
switch(paramId)
{
case SIMPLEPROFILE_CHAR1:
SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR1, &newValue);
Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "Char 1: %d", (uint16_t)newValue);
break;
case SIMPLEPROFILE_CHAR3:
SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR3, &newValue);
Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "Char 3: %d", (uint16_t)newValue);
break;
default:
// should not reach here!
break;
}
}
成
static void SimplePeripheral_processCharValueChangeEvt(uint8_t paramId)
{
uint8_t newValue[20] = {0};
switch(paramId)
{
case SIMPLEPROFILE_CHAR4:
SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR4, newValue);
Display_printf(dispHandle, 20, 0, "Char 4: %s", (char *)newValue);
// If the RPA has changed, update the display
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(newValue), newValue);
//Display_printf(dispHandle, MR_ROW_CHARSTAT, 0, "Char 3: %d", (uint16_t)newValue);
break;
default:
// should not reach here!
break;
}
}
其中 SimpleProfile_GetParameter获取手机端接收到字符串
SimpleProfile_SetParameter发送字符串到手机端(手机端需要打开notify,最多单次调用该函数4次)
函数SimplePeripheral_performPeriodicTask其中的内容可以全部注释掉
static void SimplePeripheral_performPeriodicTask(void)
{
#if 0
uint8_t valueToCopy;
// Call to retrieve the value of the third characteristic in the profile
if (SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR3, &valueToCopy) == SUCCESS)
{
// Call to set that value of the fourth characteristic in the profile.
// Note that if notifications of the fourth characteristic have been
// enabled by a GATT client device, then a notification will be sent
// every time this function is called.
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, sizeof(uint8_t),
&valueToCopy);
}
#endif
}
该函数默认 每3秒执行一次
|