nesC中使用TinyOS进行洪泛数据包确认时出现分段错误错误

问题描述

对于我的任务,我打算在网络拓扑上实施Flooding。以下是数据包到达其最终目的地时要返回的确认代码。细分错误似乎发生在if语句中: if(myMsg-> protocol == PROTOCOL_PING)。为什么会发生这种情况以及如何解决

event message_t* receiveFlood.receive(message_t* msg,void* payload,uint8_t len){
        dbg(FLOODING_CHANNEL,"Packet Received:  %s\n",msg);
      
        if(len==sizeof(pack)){
            pack* myMsg=(pack*) payload;
            
            if(myMsg->TTL == 0){
                return msg;    
            }
            
            if(CheckCache(myMsg)){
                return msg;
            }

            //We have reached the destination of the packet
            else if(TOS_NODE_ID == myMsg->dest){
                dbg(GENERAL_CHANNEL,"The packet has reached its destination with the message: %s\n",myMsg->payload);
                dbg(FLOODING_CHANNEL,"[Src:Dest] %d : %d\n",myMsg->src,myMsg->dest);
                printf("Hello what is going on \n");

                //This statement is the ackNowledgement to the src NODE
                if(myMsg->protocol == PROTOCOL_PING){
                    dbg(GENERAL_CHANNEL,"AckNowledged: %s\n");
                    dbg(FLOODING_CHANNEL,"[Dest:Src] %d : %d\n",myMsg->dest,myMsg->src);
                    
                    dbg(GENERAL_CHANNEL,"Payload: %s\n:",myMsg->payload);
                    //Cache the packet
                    dbg(GENERAL_CHANNEL,"Now Storing msg into cache... %s\n");
                    NodeCache(myMsg);
                    return msg;
                }
                return msg;
            }

            
            dbg(FLOODING_CHANNEL,"Package Payload: %s\n",myMsg->payload);
        
            return msg;
        }
        dbg(GENERAL_CHANNEL,"UnkNown Packet Type %d\n",len);
        return msg;
    }

以下是输出结果:

enter code here
Creating Topo!
Number of Motes 19
  1   2   -54.0
  2   3   -54.0
  3   4   -54.0
  4   5   -54.0
  5   6   -54.0
  6   7   -54.0
  7   8   -54.0
  8   9   -54.0
  9   10   -54.0
  10   11   -54.0
  11   12   -54.0
  12   13   -54.0
  13   14   -54.0
  14   15   -54.0
  15   16   -54.0
  16   17   -54.0
  17   18   -54.0
  18   19   -54.0
  2   1   -54.0
  3   2   -54.0
  4   3   -54.0
  5   4   -54.0
  6   5   -54.0
  7   6   -54.0
  8   7   -54.0
  9   8   -54.0
  10   9   -54.0
  11   10   -54.0
  12   11   -54.0
  13   12   -54.0
  14   13   -54.0
  15   14   -54.0
  16   15   -54.0
  17   16   -54.0
  18   17   -54.0
  19   18   -54.0
Creating noise model for  1
Creating noise model for  2
Creating noise model for  3
Creating noise model for  4
Creating noise model for  5
Creating noise model for  6
Creating noise model for  7
Creating noise model for  8
Creating noise model for  9
Creating noise model for  10
Creating noise model for  11
Creating noise model for  12
Creating noise model for  13
Creating noise model for  14
Creating noise model for  15
Creating noise model for  16
Creating noise model for  17
Creating noise model for  18
Creating noise model for  19
Adding Channel command
Adding Channel general
Adding Channel flooding
0:0:0.000000133 DEBUG (1): Booted
0:0:0.000000143 DEBUG (1): Radio On
0:0:0.000000266 DEBUG (2): Booted
0:0:0.000000276 DEBUG (2): Radio On
0:0:0.000000399 DEBUG (3): Booted
0:0:0.000000409 DEBUG (3): Radio On
0:0:0.000000533 DEBUG (4): Booted
0:0:0.000000543 DEBUG (4): Radio On
0:0:0.000000666 DEBUG (5): Booted
0:0:0.000000676 DEBUG (5): Radio On
0:0:0.000000799 DEBUG (6): Booted
0:0:0.000000809 DEBUG (6): Radio On
0:0:0.000000933 DEBUG (7): Booted
0:0:0.000000943 DEBUG (7): Radio On
0:0:0.000001066 DEBUG (8): Booted
0:0:0.000001076 DEBUG (8): Radio On
0:0:0.000001199 DEBUG (9): Booted
0:0:0.000001209 DEBUG (9): Radio On
0:0:0.000001333 DEBUG (10): Booted
0:0:0.000001343 DEBUG (10): Radio On
0:0:0.000001466 DEBUG (11): Booted
0:0:0.000001476 DEBUG (11): Radio On
0:0:0.000001599 DEBUG (12): Booted
0:0:0.000001609 DEBUG (12): Radio On
0:0:0.000001732 DEBUG (13): Booted
0:0:0.000001742 DEBUG (13): Radio On
0:0:0.000001866 DEBUG (14): Booted
0:0:0.000001876 DEBUG (14): Radio On
0:0:0.000001999 DEBUG (15): Booted
0:0:0.000002009 DEBUG (15): Radio On
0:0:0.000002132 DEBUG (16): Booted
0:0:0.000002142 DEBUG (16): Radio On
0:0:0.000002266 DEBUG (17): Booted
0:0:0.000002276 DEBUG (17): Radio On
0:0:0.000002399 DEBUG (18): Booted
0:0:0.000002409 DEBUG (18): Radio On
0:0:0.000002532 DEBUG (19): Booted
0:0:0.000002542 DEBUG (19): Radio On
0:1:57.945314110 DEBUG (1): A Command has been Issued.
0:1:57.945314110 DEBUG (1): Command Type: Ping
0:1:57.945314110 DEBUG (1): PING EVENT 
0:1:57.945314110 DEBUG (1): Hello? 
0:1:57.945314110 DEBUG (1): before floodsender 
0:1:57.945314110 DEBUG (1): Flooding Network: Hello,World
0:1:57.945314110 DEBUG (1): after floodsender 
0:1:57.967224226 DEBUG (2): Packet Received:  
0:1:57.967224226 DEBUG (2): The packet has reached its destination with the message: Hello,World
0:1:57.967224226 DEBUG (2): [Src:Dest] 1 : 2
Hello what is going on 
Segmentation fault (core dumped)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)