예제 #1
0
파일: mobile6.c 프로젝트: jcairo/313L2
static EVENT_HANDLER(listening)
{
    char	buf[1024];
    size_t	len	= sizeof(buf);
    int		link, from;
    double	rx_signal, rx_angle;

    CHECK(CNET_read_physical(&link, buf, &len));
    memcpy(&from, buf, sizeof(int));
    CHECK(CNET_wlan_arrival(link, &rx_signal, &rx_angle));
    fprintf(stdout,"\t\t%d: received from %d (%.3fdBm @%.3f)\n",
		    nodeinfo.nodenumber, from, rx_signal, rx_angle);
}
예제 #2
0
static EVENT_HANDLER(receive)
{
    WLAN_FRAME	frame;
    size_t	len;
    int		link;

//  READ THE ARRIVING FRAME FROM OUR PHYSICAL LINK
    len	= sizeof(frame);
    CHECK(CNET_read_physical(&link, &frame, &len));
    if(verbose) {
	double	rx_signal;
	CHECK(CNET_wlan_arrival(link, &rx_signal, NULL));
	fprintf(stdout, "\t%5s: received '%s' @%.3fdBm\n",
			    nodeinfo.nodename, frame.payload, rx_signal);
    }

//  IS THIS FRAME FOR ME?
    if(frame.header.dest == nodeinfo.nodenumber) {
	++stats[1];
	if(verbose)
	    fprintf(stdout, "\t\tfor me!\n");
    }

//  NO; RETRANSMIT FRAME IF WE'RE CLOSER TO THE DESTINATION THAN THE PREV NODE
    else {
	CnetPosition	dest	= positions[frame.header.dest];
	double		prev	= distance(frame.header.prevpos, dest);
	double		now	= distance(positions[nodeinfo.nodenumber],dest);

	if(now < prev) {	// closer?
	    frame.header.prevpos = positions[nodeinfo.nodenumber]; // me!
	    len			 = sizeof(WLAN_HEADER) + frame.header.length;
	    CHECK(CNET_write_physical_reliable(link, &frame, &len));
	    if(verbose)
		fprintf(stdout, "\t\tretransmitting\n");
	}
    }
}