Esempio n. 1
0
void
startup(void)
{
	int		i, my_id = *NIC_OUI - '0';
	ulong		lastxmit = 0;
    int src, dst;
    unsigned char buf[200];


	/*	If we are the clone of someone, my_id is already set, keep it, for timeslot stuff	*/
	if (my_id == -1)
	{
		int addrchars = strlen((unsigned char *)NIC_OUI);

		my_id = 0;

		for (i = addrchars-1; i >= 0; i--)
		{
			my_id +=  (*(NIC_OUI+i) - '0') * pow10(addrchars - 1 - i);
		}
	}

	hdlr_install();
	printf("[%d] installing vector code...\n", my_id);

    dst = 0;
    src = 7;
    
    for(i = 0; i <  200; i++)
    {
        buf[i] = i*i;
    }

	/*	LPF needs at least NUM_TAPS+1 inputs; get_floats is fine.	*/
	if(my_id == src)
	{
while(1) {
	    printf("node [%d]) sending [%d] bytes to (node [%d])\n",
		my_id, 200, dst);
	
	    while (devnoc_xmit(dst, buf, 200) < 0)
	    {
			printf("re-transmitting...\n");
		    sleep();
	    }
}
	}

	while(1);


	return;		
}
void
startup(void)
{
        /*      Monitor code is @ 0x8001000     */
        void    	(*fptr)() = (void *)0x8001000;
	int		frames_rcvd = 0, addrchars, i;
	uchar		demod_dst[16+1];
	LPFData		lpf_data;


	/*	If we are the clone of someone, my_id is already set, keep it, for timeslot stuff	*/
	if (my_id == -1)
	{
		addrchars = strlen((char *)NIC_OUI);

		my_id = 0;

		for (i = addrchars-1; i >= 0; i--)
		{
			my_id +=  (*(NIC_OUI+i) - '0') * pow10(addrchars - 1 - i);
		}
	}
	sprint(&demod_dst[0], "%d", my_id+1);

	hdlr_install();

	/*	Power up both RX interfaces	*/
	devnet_ctl(NIC_NCR_WRITE, NIC_CMD_POWERUP, 0);
	devnet_ctl(NIC_NCR_WRITE, NIC_CMD_POWERUP, 1);

	print("swradio-lpf [%d] installing vector code...\n", my_id);



	/*	Make sure we're talking on regular segment		*/
	/*	uncommenmt if doing segmented network	*/
	sample_flag = 0;
	syn_sent = 0;

	fb1.rpos = fb1.rlen = 0;
	fb2.rpos = fb2.rlen = 0;
	init_lpf_data(&lpf_data, CUTOFF_FREQUENCY, NUM_TAPS, DECIMATION);

	/*	LPF needs at least NUM_TAPS+1 inputs; get_floats is fine.	*/
	while (!sample_flag)
	{
		sleep();
	}
	run_lpf((void *)&fb1, (void *)&fb2, &lpf_data);
	sample_flag = 0;

	/*									*/
	/*	run_demod needs 1 input, OK here. run_equalizer needs 51 	*/
	/*	inputs (same reason as for LPF).  This means running the 	*/
	/*	pipeline up to demod 50 times in advance: 			*/
	/*									*/
	while (frames_rcvd < NUM_TAPS)
	{
		while (!sample_flag)
		{
			sleep();
		}

		frames_rcvd++;
		sample_flag = 0;
		run_lpf((void *)&fb1, (void *)&fb2, &lpf_data);

			/*
			print("swradio-lpf (node [%d]) sending [%d] bytes to DEMOD (node [%s])\n",
				my_id, sizeof(fb1), demod_dst);
			print("fb2.rpos = [%d], fb2.rlen = [%d]\n", fb2.rpos, fb2.rlen);
			*/

		devnet_xmit((uchar *)&demod_dst, 0, (uchar *)&fb2, sizeof(fb2), 1);
		/*									*/
		/*	Since we are doing Call-By-Value, we must make this change 	*/
		/*	here. The corresponding calculation in run_demod is a No-op	*/
		/*									*/
		fb2.rpos++;
	}

	/*	Wait till intr_hdlr is done	*/
	done_flag = 0;
	while (!done_flag)
	{
		if (sample_flag)
		{
			run_lpf((void *)&fb1, (void *)&fb2, &lpf_data);

			
			/*
			print("swradio-lpf (node [%d]) sending [%d] bytes to DEMOD (node [%s])\n",
				my_id, sizeof(fb1), demod_dst);
			print("fb2.rpos = [%d], fb2.rlen = [%d]\n", fb2.rpos, fb2.rlen);
			*/


			/*	Now send fb2 to be Demod'd. We dont re-xmit	*/
			devnet_xmit((uchar *)&demod_dst, 0, (uchar *)&fb2, sizeof(fb2), 1);
			/*									*/
			/*	Since we are doing Call-By-Value, we must make this change 	*/
			/*	here. The corresponding calculation in run_demod is a No-op	*/
			/*									*/
			fb2.rpos++;

			sample_flag = 0;
		}

		sleep();
	}

	/*	Forcefully go to monitor	*/
	fptr();


	return;		
}
void
startup(int argc, char *argv[])
{
	Dampkt		dam_p;
	char		tmp;
	char		*ep = &tmp;
	ulong		start = 0;
	long		sluimer;
	int		period = 0;
	int		tmpperiod, tmp_alpha, tmp_beta, tmp_ftable_alpha,
			tmp_eij, tmp_maxhops;


	strncpy(dam_myID, (char *)NIC_OUI, DAM_ID_LEN);
	hdlr_install();
	print("DAM node [%s] installed vector code.\n", dam_myID);

	devmac_ctl(NIC_NCR_WRITE, NIC_CMD_POWERUP, 0);
	print("DAM node [%s] powered up NIC.\n", dam_myID);

	dam_period = DAM_PROTOCOL_PERIOD;
	if (argc == 6)
	{
		tmpperiod = strtol(argv[0], &ep, 0);
		if (*ep != '\0')
		{
			printf("Invalid DAM period supplied as argument.\n");
		}
		else
		{
			dam_period = tmpperiod;
			printf("Set dam_period to [%d] usecs\n", dam_period);
		}

		tmp_alpha = strtol(argv[1], &ep, 0);
		if (*ep != '\0')
		{
			printf("Invalid EAR alpha supplied as argument.\n");
		}
		
		tmp_beta = strtol(argv[2], &ep, 0);
		if (*ep != '\0')
		{
			printf("Invalid EAR beta supplied as argument.\n");
		}

		tmp_ftable_alpha = strtol(argv[3], &ep, 0);
		if (*ep != '\0')
		{
			printf("Invalid EAR ftable_alpha supplied as argument.\n");
		}

		tmp_eij = strtol(argv[4], &ep, 0);
		if (*ep != '\0')
		{
			printf("Invalid EAR eij supplied as argument.\n");
		}

		tmp_maxhops = strtol(argv[5], &ep, 0);
		if (*ep != '\0')
		{
			printf("Invalid EAR maxhops supplied as argument.\n");
		}

		Ear = ear_init(dam_myID, 0, tmp_alpha, tmp_beta, tmp_ftable_alpha,
				tmp_eij, tmp_maxhops,
			(uchar)devloc_getxloc(), (uchar)devloc_getyloc(), (uchar)devloc_getzloc());
		fprintf(stderr, "DAM node [%s] completed EAR init with runtime args:\n"
			"\talpha=%d\n\tbeta=%d\n\tftable_alpha=%d\n\teij=%d\n\tmaxhops=%d\n\n\n\n", 
			dam_myID, tmp_alpha, tmp_beta, tmp_ftable_alpha, tmp_eij, tmp_maxhops);

	}
	else
	{
		Ear = ear_init(dam_myID, 0, 1, 50, 1, 1 /* eij */, 8 /* maxhops */,
			(uchar)devloc_getxloc(), (uchar)devloc_getyloc(), (uchar)devloc_getzloc());
		print("DAM node [%s] completed EAR init using defaults.\n\n\n", dam_myID);
	}


	/*							*/
	/*	Implemented to mirror description in paper	*/
	/*	All variables beginning w/ dam_ correspond	*/
	/*	to variables in the paper's algorithm descr.	*/
	/*							*/
	while (1)
	{
		start = devrtc_getusecs();
		dam_p.timestamp = start;

		/*									*/
		/*	Write the log for the previous period. We want all actions to	*/
		/*	be in the timed loop, and though this log writing may seem to	*/
		/*	be not inherent to application, you can think of it as some	*/
		/*	post-peak detection actions that the algorithm must perform.	*/
		/*									*/
		if ((period > 0) && dam_participating)
		{
			if (strlen(dam_sink) > 0)
			{
				int		id;
				char		tmp;
				char		*ep = &tmp;

				id = strtol(dam_leaderID, &ep, 0);
				ear_response(Ear, dam_sink, NULL, 0, id);
			}
//print("\n\ndam_sink = [%s]\n\n\n", dam_sink);
		
			write_log(period - 1);
		}

		/*								*/
		/*	The values in this case are in Lux (see test.m)		*/
		/*	Noise floor is 0.1 Lux. DAM_THRESHOLD_ELECTION is	*/
		/*	thus set to 10 Lux.					*/
		/*								*/
		dam_myPr = devsignal_read(LIGHT_SENSOR);

		/*								*/
		/*	Algorithm description in PARC paper does not reset	*/
		/*	maxPrHeard. For each DAM period, until a packet is	*/
		/*	received, or our local reading is > threshold, the	*/
		/*	maxPrHeard should be 0.					*/
		/*								*/
		dam_maxPrHeard = 0;

		if (dam_myPr > DAM_THRESHOLD_ELECTION)
		{
LOGMARK(12);
			dam_participating = TRUE;
			dam_maxPrHeard = dam_myPr;
			strncpy(dam_leaderID, dam_myID, DAM_ID_LEN);
			dam_p.maxPr = dam_p.transPr = dam_myPr;
			strncpy((char *)dam_p.transID, dam_myID, DAM_ID_LEN);
			strncpy((char *)dam_p.maxID, dam_myID, DAM_ID_LEN);

			dam_broadcast(&dam_p);
LOGMARK(13);
		}
		else
		{
			dam_participating = FALSE;
		}

		sluimer = dam_period - (devrtc_getusecs() - start);
		sluimer = max(sluimer, 0);
LOGMARK(2);
		xusleep(sluimer);
LOGMARK(3);
		period++;
	}

	return;		
}