0

我正在尝试在 NesC 中实现一个应用程序,该应用程序能够计算在模拟过程中执行的传输次数,但是我面临很多困难。我尝试过的任何方法都不起作用。有人可以帮我吗?这是我的应用程序:

模块洪水C {

uses {
    interface Boot;
    interface SplitControl as AMControl;
    interface Timer<TMilli> as MilliTimer;
    interface Receive;
    interface AMSend;
    interface Packet;
    interface AMPacket;
    interface RootControl;
    interface PacketAcknowledgements as PackAck;
}

}

执行 {

message_t packet;

bool locked = FALSE;
uint16_t flag;

event void Boot.booted() {
    flag = 0;
    call AMControl.start();
}

event void AMControl.startDone(error_t err) {
    if(err == SUCCESS) {
        if(TOS_NODE_ID == 1)
            call RootControl.setRoot();


        call MilliTimer.startOneShot(1024);
    }
    else {
        call AMControl.start();
    }
}

event void AMControl.stopDone(error_t err) {
}

void sendMsg(){
    floodingMsg_t* msg = (floodingMsg_t* ) call Packet.getPayload(&packet, sizeof(floodingMsg_t));
    if(msg == NULL) {   
        return;
    }
    flag = 1; 
    msg->nodeid = TOS_NODE_ID;
    msg->counter = 1;
    call PackAck.requestAck(&packet);
    if(call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(floodingMsg_t)) == SUCCESS) {
        locked = TRUE;
    }
}

event void MilliTimer.fired() {

    if(locked) {
        return;
    }
    else {
        if (call RootControl.isRoot()){
            sendMsg();
        }
    }
}

event void AMSend.sendDone(message_t *msg, error_t error){
    if (call PackAck.wasAcked(msg) == SUCCESS){
        locked = FALSE;
    }
    else{
        sendMsg();
    }
}

event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) {
    floodingMsg_t* newMsg = (floodingMsg_t* )payload;

    if (locked == TRUE) return msg;

    if(flag == 0) {
        flag = 1;
        newMsg->nodeid = TOS_NODE_ID;
        newMsg->counter++;
        call AMSend.send(AM_BROADCAST_ADDR, msg, call Packet.maxPayloadLength());

    }

    return msg;
}   

}

谢谢

4

1 回答 1

0

您可以使用 BaseStation 嗅探器(包含在 tinyos 中)对它们进行计数,或者在传输的数据包上添加序列号。

于 2014-10-23T18:47:14.070 回答