其实这个功能在昨天的那个贴子就应实现,只不过考虑问题进入胡同,我总想利用现有的函数来实现,看了坛友的贴子才明白了,其实MCU单片机部分是一样的,就是BLE部分,我少定义了两个宏:https://bbs.eeworld.com.cn/thread-1214354-1-1.html
那么现在我来说说我的实现吧:
一、单片机部分:
at_cmd.h增加四个个宏:
#define AT_CMD_IO_SET_2 "AT+IOSET2\r\n"
#define AT_CMD_IO_SET_3 "AT+IOSET3\r\n"
#define AT_CMD_IOSET2 (0x03)
#define AT_CMD_IOSET3 (0x04)
main.c中增加相应的定义及函数处理:
struct at_cmd_msg at_cmd_list[] =
{
{AT_CMD_IO_SET_LOW, AT_CMD_IOSET0},
{AT_CMD_IO_SET_HIGH, AT_CMD_IOSET1},
{AT_CMD_IO_GET, AT_CMD_IOGET},
{AT_CMD_IO_SET_2, AT_CMD_IOSET2},
{AT_CMD_IO_SET_3, AT_CMD_IOSET3},
};
switch(at_cmd_list[msg_id].msg_id)
{
case AT_CMD_IOSET0:
{
at32_led_off(LED2);
at_cmd_send(AT_RESULT_OK0);
break;
}
case AT_CMD_IOSET1:
{
at32_led_on(LED2);
at_cmd_send(AT_RESULT_OK1);
break;
}
case AT_CMD_IOGET:
{
if(gpio_output_data_bit_read(GPIOB, GPIO_PINS_7))
{
at_cmd_send(AT_RESULT_OK1);
}
else
{
at_cmd_send(AT_RESULT_OK0);
}
break;
}
case AT_CMD_IOSET2:
{
at32_led_on(LED3);
break;
}
case AT_CMD_IOSET3:
{
at32_led_off(LED3);
break;
}
default:
{
at_cmd_send(AT_RSP_ERROR);
break;
}
}
recv_cmp_flag = RESET;
memset(recv_data, 0, strlen(recv_data));
二、BLE部分
app.h:
#define AT_CMD_IO_SET_2 "AT+IOSET2\r\n"
#define AT_CMD_IO_SET_3 "AT+IOSET3\r\n"
custom_task.c:
增加两个发送命令:
static int gattc_write_req_ind_handler(ke_msg_id_t const msgid, struct gattc_write_req_ind const *param,
ke_task_id_t const dest_id, ke_task_id_t const src_id)
{
struct gattc_write_cfm * cfm;
uint8_t status = GAP_ERR_NO_ERROR;
//Send AT command
if(uart_tp_mode_flag == false)
{
switch(param->value[0])
{
case 0:
case 1:
UART_SEND_DATA(AT_CMD_IO_SET, param->value[0]);
break;
case 3:
UART_SEND_DATA(AT_CMD_IO_SET_2, param->value[0]);
break;
case 4:
UART_SEND_DATA(AT_CMD_IO_SET_3, param->value[0]);
}
}
cfm = KE_MSG_ALLOC(GATTC_WRITE_CFM, src_id, dest_id, gattc_write_cfm);
cfm->handle = param->handle;
cfm->status = status;
ke_msg_send(cfm);
return (KE_MSG_CONSUMED);
}
编译BLE时遇到了,命令提示符已被管理员禁止的提示,生成不了我要烧入的BIN文件。
我照:https://www.dadighost.com/help/dnjc/7450.html
解决了。
重新上电,久违的LED3亮了,当然发0x04又灭了。