工具与软件:
你(们)好、
RF_postCmd ()函数调用用户指定的事件处理程序,并使用事件掩码指定感兴趣的事件。 可以轻松地指定和处理良好事件、但如何检测任何/所有错误并处理它们?
下面是在传输数据包之前执行空闲通道评估的示例代码:
void rf_modem_tx_callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { if(e & RF_EventLastCmdDone) { e &= ~RF_EventLastCmdDone; if(RF_cmdPropTx.status == PROP_DONE_OK) { rf_modem_on_evt(RF_MODEM_EVT_TX_DONE); } else { rf_modem_on_evt(RF_MODEM_EVT_TX_TIMEOUT); } } // Unhandled event? if(e != 0) { rf_modem_on_evt(RF_MODEM_EVT_TX_ERROR); } } bool rf_modem_tx_cca_start(uint8_t * data, uint8_t nr_of_bytes, int8_t rssi_th) { RF_cmdPropCs.status = IDLE; RF_cmdPropCs.pNextOp = (rfc_radioOp_t *)&RF_cmdPropTx; RF_cmdPropCs.condition.rule = COND_STOP_ON_TRUE; RF_cmdPropCs.csConf.bEnaRssi = 1; RF_cmdPropCs.csConf.busyOp = 1; RF_cmdPropCs.csConf.idleOp = 1; RF_cmdPropCs.rssiThr = rssi_th; RF_cmdPropCs.csEndTrigger.triggerType = TRIG_NEVER; RF_cmdPropTx.status = IDLE; RF_cmdPropTx.pktLen = nr_of_bytes; RF_cmdPropTx.pPkt = data; RF_cmdPropTx.startTrigger.triggerType = TRIG_NOW; rf_modem_cmd_handle = RF_postCmd(rf_modem_handle, (RF_Op *)&RF_cmdPropCs, RF_PriorityNormal, &rf_modem_tx_callback, RF_EventLastCmdDone); return (rf_modem_cmd_handle >= 0); }
使用 bmEvent = RF_EventLastCmdDone 调用 RF_postCmd。 即使 RF_cmdPropcs 或 RF_cmdPropTx 期间发生了错误、在任何情况下都是否会调用 RF_MODEM_TX_CALLBACK ()?
在某些情况下、可以通过设置多个事件位来调用回调函数吗? 那么、我清除特定事件位的方法是否更安全、以便检测任何未处理的事件?
以下是我接收数据包的示例代码:
static void rf_modem_rx_callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { if(e & RF_EventRxEntryDone) { rfc_dataEntryGeneral_t * data_entry; uint8_t * packet_data; e &= ~RF_EventRxEntryDone; data_entry = RFQueue_getDataEntry(); rf_modem_rx_packet_length = *(uint8_t *)(&data_entry->data); packet_data = (uint8_t *)(&data_entry->data + 1); memcpy(rf_modem_rx_packet, packet_data, rf_modem_rx_packet_length); rf_modem_on_evt(RF_MODEM_EVT_RX_DONE); RFQueue_nextEntry(); } if(e & RF_EventLastCmdDone) { e &= ~RF_EventLastCmdDone; if(rf_modem_rx_packet_length == 0) { rf_modem_on_evt(RF_MODEM_EVT_RX_TIMEOUT); } } if(e != 0) { rf_modem_on_evt(RF_MODEM_EVT_RX_ERROR); } } bool rf_modem_rx_start(uint32_t timeout_ms) { memset(&rf_modem_rx_stats, 0, sizeof(rf_modem_rx_stats)); RF_cmdPropRx.status = IDLE; rf_modem_rx_packet_length = 0; RF_cmdPropRx.pktConf.bUseCrc = 0; RF_cmdPropRx.endTrigger.triggerType = TRIG_REL_START; RF_cmdPropRx.endTime = (ratmr_t)timeout_ms * (4e6 / 1000); rf_modem_cmd_handle = RF_postCmd(rf_modem_handle, (RF_Op *)&RF_cmdPropRx, RF_PriorityNormal, &rf_modem_rx_callback, RF_EventLastCmdDone | RF_EventRxEntryDone); return (rf_modem_cmd_handle >= 0); }
这是否也是处理所有情况(包括任何错误)的正确/最佳方式?
提前感谢、
Pieter