Wireless-Tech
抱歉,额。我通过另一种方式解决了这个问题。
case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
{
ret_code_t ret;
static uint8_t index = 0;
index++;
do
{
if ((m_cdc_data_array[index - 1] == '\n') ||
(m_cdc_data_array[index - 1] == '\r') ||
(index >= (244)))
{
if (index > 1)
{
nrf_gpio_pin_toggle(BSP_LED_0);
uint16_t length = (uint16_t)index;
if (length + sizeof(ENDLINE_STRING) < 244)
{
memcpy(m_cdc_data_array + length, ENDLINE_STRING, sizeof(ENDLINE_STRING));
length += sizeof(ENDLINE_STRING);
}
if (strcmp(m_cdc_data_array, "on\r\r\n") == 0) SetState = true;
else SetState = false;
DataChange = true;
}
index = 0;
}
/* Fetch data until internal buffer is empty */
ret = app_usbd_cdc_acm_read(&m_app_cdc_acm,
&m_cdc_data_array[index],
1);
if (ret == NRF_SUCCESS)
{
index++;
}
}
while (ret == NRF_SUCCESS);
break;
}
在这里我添加了一个DataChange
变量来判断一次USB CDC ACM
事件。然后自定义一个定时器对此的触发事件
APP_TIMER_DEF(zqaking_timer_id);
static void zqaking_app_timer_handler(void * p_unused)
{
if (DataChange)
{
//app_usbd_cdc_acm_write(&m_app_cdc_acm, my_data_buffer, my_data_buffer_lenght);
DataChange = false;
uint32_t status;
generic_onoff_set_params_t set_params;
model_transition_t transition_params;
static uint8_t tid = 0;
if (SetState) set_params.on_off = APP_STATE_ON;
else set_params.on_off = APP_STATE_OFF;
SetState = false;
set_params.tid = tid++;
transition_params.delay_ms = APP_ONOFF_DELAY_MS;
transition_params.transition_time_ms = APP_ONOFF_TRANSITION_TIME_MS;
status = hx_model_client_opcode_tx_unreliable(&m_hx_model_client[0], (uint8_t *)str, (uint16_t)StrLen, APP_UNACK_MSG_REPEAT_COUNT);
if (status == NRF_SUCCESS) app_usbd_cdc_acm_write(&m_app_cdc_acm, str, StrLen);
status = generic_onoff_client_set_unack(&m_clients[1], &set_params,
&transition_params, APP_UNACK_MSG_REPEAT_COUNT);
}
}
static void start(void)
{ ···
ERROR_CHECK(app_timer_create(&zqaking_timer_id, APP_TIMER_MODE_REPEATED, zqaking_app_timer_handler));
ERROR_CHECK(app_timer_start(zqaking_timer_id, 6000, NULL));
···
};