0

Iam trying to using this function to set the node which send packet to other node in code unicast contiki , but this function doesn't work , what's the problem ? Can you help me ,please ! I want to topo 2 node which require : If node 2 received packet from node 1 then node2 send the packet ACK to node 1 to announce that node 2 has received the packet from node 1 . I use unicast program in contiki . , I use function linkaddr_set_node_addr (linkaddr_t *addr) to set node 1 to send packet, but this function doesn't work , can someone help me , please . This is my code :

    linkaddr_t addr;
    addr.u8[0]=2;
    addr.u8[1]=0;
    packetbuf_copyfrom("GINDBK",5);
    unicast_send(&uc,&addr);
    if (linkaddr_node_addr.u8[0]==1 && linkaddr_node_addr.u8[1]==0)
    {
        linkaddr_t addr;
        addr.u8[0]=2;
        addr.u8[1]=0;
        linkaddr_set_node_addr(&addr);
        packetbuf_copyfrom("ACK",20);
        addr.u8[0]=1;
        addr.u8[1]=0;
        unicast_send(&uc,&addr);

    }
  • Welcome to Stack Overflow! Please provide a [mcve] where you clearly describe what is the desired outcome as well as what do you mean by "does not work". – kfx Feb 29 '20 at 11:49

1 Answers1

0

I think the problem is with the address assignment. You cannot simple assign values to the bytes of the address. Instead of:

linkaddr_t addr;
addr.u8[1] = 2;
addr.u8[0] = 0;
linkaddr_set_node_addr(&addr);

Assign value to addr this way:

linkaddr_t addr = {{2,0}};
linkaddr_set_node_addr(&addr);

and if you wish to check if two addresses are equal use:

linkaddr_cmp(&addr, &addr2)
Bálint Béres
  • 168
  • 1
  • 1
  • 9