Recently, when the ZigBee protocol was simulated in NS2. after the energy model was added, it was found that all nodes were green, and the changes in node color in the program were ineffective, you cannot add tags to a node. After carefully observing the source code, we found that the following two lines of the void mac802_15_4mac.cc line 919th: Recv (packet * P, Handler * h) function are in the p802_15_4mac.cc file:
If (! Nam802_15_4: emstatus)
Nam802_15_4: emstatus = (netif _-> node ()-> energy_model ()? True: false );
It is exactly these two statements that assign emstatus a value of false so that when the node color is changed, the code runs to the row 321 of the file p802_15_4nam.cc: void nam802_15_4: changenodecolor (double attime, const char * newcolor) if (! Nam_status) return; (row 326) returns directly, so that the node color change operation fails. Similarly, the operation on other node attributes fails because emstatus is assigned to false.
Therefore, if you want to change the node attributes in the energy model, you only need to add the following line void mac802_15_4mac.cc: Recv (packet * P, Handler * h) in the p802_15_4mac.cc file) comment out the following two statements in the function:
/*
If (! Nam802_15_4: emstatus)
Nam802_15_4: emstatus = (netif _-> node ()-> energy_model ()? True: false );
*/
Make sure that the MAC/802_15_4 wpannam namstatus on is added to the Tcl file. You can assign the initial emstatus value to true.