Esempio n. 1
0
//This handler responds to routing updates.
TOS_MsgPtr TOS_MSG_EVENT(CONNECT_UPDATE)(TOS_MsgPtr msg){
    TOS_MsgPtr tmp;
    char* data = msg->data;

    //clear LED2 when update is received.
    TOS_CALL_COMMAND(CONNECT_LED2_OFF)();

    update_connections(data[(int)data[0]], data[28]);
    //if route hasn't already been set this period...
    if(VAR(set) == 0){
	//record route
	VAR(route) = data[(int)data[0]];
	VAR(set) = 8;
       	data[0] ++;
	//create a update packet to be sent out.
        data[(int)data[0]] = TOS_LOCAL_ADDRESS;
	//send the update packet.
	if(VAR(msg_send_pending) == 0){
		VAR(msg_send_pending) = TOS_CALL_COMMAND(CONNECT_SUB_SEND_MSG)(TOS_BCAST_ADDR, AM_MSG(CONNECT_UPDATE),msg);
	}else{
		return msg;
	}
	printf("route set to %x\n", VAR(route));
    	tmp = VAR(msg);
    	VAR(msg) = msg;
    	return tmp;

    }else{
	    printf("route already set to %x\n", VAR(route));
	    return msg;
    }
}
Esempio n. 2
0
TOS_MsgPtr      TOS_MSG_EVENT(DATA_MSG) (TOS_MsgPtr msg) {
    char           *data = msg->data;
    TOS_MsgPtr      tmp = msg;
    char            source;
    // this handler forwards packets traveling to the base.
    TOS_CALL_COMMAND(CONNECT_LED2_OFF) ();
    // if this is the first hop on the route, then use the origin of the
    // packet< 
    // as the name of the person who sent the packet to you instead of the 
    // 
    // 
    // last hop ID (which is null)
    source = data[2];
    if (source == 0) {
	source = data[0];
    }
    update_connections(source, data[28]);
    // if a route is known, forward the packet towards the base.
    if (VAR(route) != 0 && data[1] == TOS_LOCAL_ADDRESS) {
#ifdef BASE_STATION
	if (VAR(msg_send_pending) == 0) {
	    VAR(msg_send_pending) =
		TOS_CALL_COMMAND(CONNECT_SUB_SEND_MSG) (TOS_UART_ADDR,
							AM_MSG(DATA_MSG),
							msg);
	    tmp = VAR(msg);
	    VAR(msg) = msg;
	}
#else
	// update the packet.
	data[5] = data[4];
	data[4] = data[3];
	data[3] = data[2];
	data[2] = data[1];
	data[1] = VAR(route);
	// send the packet.
	if (VAR(msg_send_pending) == 0) {
	    VAR(msg_send_pending) =
		TOS_CALL_COMMAND(CONNECT_SUB_SEND_MSG) (TOS_BCAST_ADDR,
							AM_MSG
							(CONNECT_UPDATE),
							msg);
	    tmp = VAR(msg);
	    VAR(msg) = msg;
	}
#endif
	printf("routing to home %x\n", VAR(route));
    }
    return tmp;
}
Esempio n. 3
0
TOS_MsgPtr TOS_MSG_EVENT(AGRO_DATA_MSG)(TOS_MsgPtr msg){
   agroDataPacket* pack = (agroDataPacket*)msg->data;	
   update_connections(pack->readings[0].nodeID, pack->readings[0].value);
   return msg;
}