Reputation: 1
I am writing a module implementation in nesC for a network of 7 motes identified by the means of ID. Each mote is assumed to have a routing table with a specific structure, defined as:
// Define routing table structure
typedef nx_struct routing_table_t {
nx_uint16_t destination;
nx_uint16_t next_hop;
nx_uint16_t cost;
} routing_table_t;
routing_table_t routing_table[7]; // 7 since I assume to have 7 nodes in the network
I have launched a TOSSIM simulation of my project but I keep getting this type of errors on my .nc file:
RadioRouteC.nc: In function `Receive.receive':
RadioRouteC.nc:208: invalid type argument of `unary *'
RadioRouteC.nc:238: invalid type argument of `unary *'
RadioRouteC.nc:240: invalid type argument of `unary *'
RadioRouteC.nc:241: invalid type argument of `unary *'
RadioRouteC.nc:242: invalid type argument of `unary *'
RadioRouteC.nc:264: invalid type argument of `unary *'
The problem seems to hide in the definition of the routing table structure. The function Receive.receive that I am trying to debug looks as following:
event message_t* Receive.receive(message_t* bufPtr,
void* payload, uint8_t len) {
/*
* THIS EVENT IMPLEMENTS FOLLOWING FUNCTIONALITIES:
* Parse the receive packet.
* Perform the packet send using the generate_send function
* Implement the LED logic and print LED status on Debug
*/
// Update LED status
int code = 10310011; // take my person code
digit = code % 10; // take the digit
led_index = digit % 3; // perform the modulo division if the digit
if (led_index == 0) { // if index equals 0, toggle only LED 0 (same for 1 and 2 accordingly)
call Leds.led0Toggle();
} else if (led_index == 1) {
call Leds.led1Toggle();
} else if (led_index == 2) {
call Leds.led2Toggle();
}
dbg("LED", "LED%d is toggled.\n", led_index); // notify about LED status change
code = code / 10; // update the value of the person code (becomes 1 digit shorter for the next msg receipt)
// Parse the received packet
switch (bufPtr->type)
{ // implement the fuctionality switch based on message type that can be 0,1 or 2
case 0: // Data message
// Check if the node is the destination
if (bufPtr->destination == TOS_NODE_ID) {
// If the node is the destination, print the received data
dbg("Data", "Received data %d from %d\n", bufPtr->value, bufPtr->sender);
} else {
// If the node is not the destination, forward the data - to do so, check the routing table
// Check if the node has an entry in the routing table
if (routing_table[bufPtr->destination].destination != 0) {
// If the node has an entry in the routing table, forward the data
bufPtr->sender = TOS_NODE_ID;
generate_send(routing_table[bufPtr->destination]->next_hop, bufPtr, 0); // ERROR LINE 208
}
}
break;
case 1: // Route Request message
// Check if the node is the requested node
if (bufPtr->node_requested == TOS_NODE_ID) {
// If the node is the requested node, send a Route Reply message
message_t reply;
reply.type = 2;
reply.sender = TOS_NODE_ID;
reply.node_requested = bufPtr->node_requested;
reply.cost = 1;
generate_send(AM_BROADCAST_ADDR, &reply, 2);
} else {
// If the node is not the requested node, broadcast the Route Request message
// Check if the node has already sent a Route Request message
if (route_req_sent == FALSE) {
// If the node has not sent a Route Request message, broadcast the Route Request message
generate_send(AM_BROADCAST_ADDR, bufPtr, bufPtr->type);
route_req_sent = TRUE;
}
}
break;
case 2: // Route Reply message
// Check if the node is the requested node
if (bufPtr->node_requested == TOS_NODE_ID) {
// If the node is the requested node, do nothing
} else {
// If the node is not the requested node, check if the node has an entry in the routing table
if (routing_table[bufPtr->node_requested].destination == 0 || routing_table[bufPtr->node_requested]->cost > bufPtr->cost) // ERROR LINE 238
{
// If the node does not have an entry in the routing table or the new cost is lower than the current cost, update the routing table
routing_table[bufPtr->node_requested]->destination = bufPtr->node_requested; // ERROR LINE 240
routing_table[bufPtr->node_requested]->next_hop = bufPtr->sender; // ERROR LINE 241
routing_table[bufPtr->node_requested]->cost = bufPtr->cost + 1; // ERROR LINE 242
// Forward the Route Reply message
bufPtr->cost += 1;
generate_send(AM_BROADCAST_ADDR, bufPtr, bufPtr->type);
}
}
break;
default:
// Handle any unexpected message types
break;
}
// Check if the node is node 1
if (TOS_NODE_ID == 1) {
// If the node is node 1, check if the node has an entry in the routing table
if (routing_table[1].destination == 7) { // checks if node 1 has an entry for node 7
// If the node has an entry in the routing table, send a Data message
message_t data;
data.type = 0; // message type = data message
data.sender = TOS_NODE_ID; // data sender is the current node (1)
data.destination = 7; // message is destined to node 7
data.value = 5; // message value is 5
generate_send(routing_table[7]->next_hop, &data, 0); // ERROR LINE 264
}
else {
// If the node does not have an entry in the routing table, send a Route Request message
message_t req;
req.type = 1;
req.node_requested = 7;
generate_send(AM_BROADCAST_ADDR, &req, 1);
}
return bufPtr;}
}
Any ideas on how to modify this function to make it work?
To provide you some context on what I expect the .Receive function to do:
event void Timer1.fired() {
/*
* Implement here the logic to trigger the Node 1 to send the first REQ packet
*/
message_t packet;
packet.type = 1;
packet.node_requested = 7;
generate_send(TOS_BCAST_ADDR, &packet, 1); // 1 for route req message
}
a. If the packet type is 0 (data message), the code checks if the node is the destination.
If it is, it prints the received data.
If it is not, it checks the routing table to see if it has an entry for the destination node, and if it does, it forwards the data.
b. If the packet type is 1 (route request message), the code checks if the node is the requested node.
If it is, it sends a route reply message.
If it is not, it checks if it has already sent a route request message, and if it has not, it broadcasts the route request message.
c. If the packet type is 2 (route reply message), the code checks if the node is the requested node.
If it is not, it checks if it has an entry in the routing table, and
if it does not or the new cost is lower than the current cost, it updates the routing table and forwards the route reply message.
d. Finally, if the node is node 1, it checks if 5 seconds have passed since the radio is on, and if it has, it checks if it has an entry in the routing table.
If it does not, it sends a route request message, and if it does, it sends a data message.
The data message variable is defined as follows:
// Define message structure
typedef nx_struct message_t {
// Define mesage type
nx_uint8_t type; // 0 for data msg, 1 for for route request, 2 for route reply
// Data messages
nx_uint16_t destination;
nx_uint16_t value;
// Route Reply messages
nx_uint16_t sender;
nx_uint16_t node_requested; // Route Request msg
nx_uint16_t cost;
} message_t;
Disclaimer: I am a total beginner to nesC, so the function might have problems in addition to the one mentioned above. Would appreciate your help. Thanks in advance.
Upvotes: 0
Views: 64