如何在 INET 中管理状态转换

How to manage state transitions in INET

我正在尝试在 x-mac 协议中实现数据确认。该算法是,数据包传输结束后,发送节点将等待接收方的确认。为此,我添加了一个新状态 WAIT_ACK。但是在运行时,我可以看到节点无法从 WAIT_TX_DATA_OVERWAIT_ACK 进行状态转换。我收到以下错误。

<!> Undefined event of type 204 in state 7 (Radio state 2)! -- in module (inet::XMac1) SensorNetworkShowcaseA.sensor3.wlan[0].mac (id=181), at t=0.10677288732s, event #62

注:XMAC1_DATA_TX_OVER = 204 状态 7 为 WAIT_ACK

case SEND_DATA:

    if (msg->getKind() == XMAC1_STOP_PREAMBLES) {
        sendDataPacket();
        macState = WAIT_TX_DATA_OVER;
        return;
    }
    else if (msg->getKind() == XMAC1_SWITCHING_FINISHED) {
        sendDataPacket();
        macState = WAIT_TX_DATA_OVER;
        return;
    }
    else {
        return;
    }
    break;

case WAIT_TX_DATA_OVER:
     if (msg->getKind() == XMAC1_DATA_TX_OVER) {
        scheduleAt(simTime() + (slotDuration / 2), data_ack_timeout);
        macState = WAIT_ACK;
        radio->setRadioMode(IRadio::RADIO_MODE_RECEIVER);
        changeDisplayColor(GREEN);

    }
    break;
case WAIT_ACK:
    if (msg->getKind() == XMAC1_DATA_TX_OVER) {
        delete msg;
        return;
    }
   ...
   }
    
    break;

更新

在运行时,下面是执行停止后我能看到的

INFO (XMac1)SensorNetworkShowcaseA.sensor3.wlan[0].mac: node 0A-AA-00-00-00-04 : State WAIT_TX_DATA_OVER, message XMAC_DATA_TX_OVER, new state WAIT_ACK INFO (ApskScalarRadio)SensorNetworkShowcaseA.sensor3.wlan[0].radio: SensorNetworkShowcaseA.sensor3.wlan[0].radio: Radio mode changed from TRANSMITTER to RECEIVER. INFO (ApskScalarRadio)SensorNetworkShowcaseA.sensor3.wlan[0].radio: SensorNetworkShowcaseA.sensor3.wlan[0].radio: Changing radio reception state from UNDEFINED to IDLE. INFO (ApskScalarRadio)SensorNetworkShowcaseA.sensor3.wlan[0].radio: SensorNetworkShowcaseA.sensor3.wlan[0].radio: Changing radio transmission state from IDLE to UNDEFINED. <!> Undefined event of type 204 in state 7 (Radio state 2)! -- in module (inet::XMac1) SensorNetworkShowcaseA.sensor3.wlan[0].mac (id=181), at t=0.10677288732s, event #62

根据您提供的信息,这不应该发生,所以您的假设有些地方是错误的。很可能,您没有 运行 宁此代码。确保此代码确实已执行(您可以构建发布版本和 运行 调试版本或其他版本)。在这些情况下,我经常临时修改代码中的错误消息,以查看代码更改是否真的编译到可执行文件中,只是为了确保我 运行 确实是我假设的代码 运行宁.