代码之家  ›  专栏  ›  技术社区  ›  rick87

Contiki在循环时不执行函数

  •  0
  • rick87  · 技术社区  · 9 年前

    我有以下问题,我的模拟结果被困在while循环中。在我看来,原因是我们无法在循环结束之前在mote 1.0上执行recv_uc。

    unicast_send(&my_conn, &addr);
    

    哪些变化

    value = true;
    

    我需要避免陷入while循环。

    static void my_func(struct unicast_conn *c, const rimeaddr_t *addr){
      value = true;
    ...
    }
    
    static const struct unicast_callbacks my_call = {my_func};
    //only mote 1 execute recv_uc
    static void recv_uc(struct unicast_conn *c, const rimeaddr_t *from)
    {
      my_msg_t mess_rec;
      rimeaddr_t addr;
    
      addr.u8[0]= from->u8[0];
      addr.u8[1]= from->u8[1];
    
      memcpy(&mess_rec, packetbuf_dataptr(), sizeof(mess_rec));
      ...
      packetbuf_copyfrom(&mess_rec, 16);
      unicast_send(&my_conn, &addr);
    }
    
    static const struct unicast_callbacks unicast_call = {recv_uc};
    
    PROCESS_THREAD(sending_rand, ev, data)
    {
    ...
    
    PROCESS_BEGIN();
    unicast_open(&unicast, 120, &unicast_call); //importante
    unicast_open(&my_conn, 130, &my_call); //importante
    ...
    addr.u8[0] = 1;
    addr.u8[1] = 0;
    if(!rimeaddr_cmp(&addr, &rimeaddr_node_addr)){
    ...
    while(value == false){
      packetbuf_copyfrom(&mess, 16);
      unicast_send(&unicast, &addr);
    }
    }
    PROCESS_END();
    }
    

    非常感谢。

    1 回复  |  直到 9 年前
        1
  •  0
  •   PaulR    9 年前

    我建议将while循环替换为以下内容:

    while(value == false){
      packetbuf_copyfrom(&mess, 16);
      unicast_send(&unicast, &addr);
      PROCESS_YIELD(); // this allows other processes to run
    }