Beispiel #1
0
PROCESS_THREAD(glossy_print_stats_process, ev, data)
{
	PROCESS_BEGIN();

	while(1) {
		PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
		// Print statistics only if Glossy is not still bootstrapping.
		if (!GLOSSY_IS_BOOTSTRAPPING()) {
			if (get_rx_cnt()) {	// Packet received at least once.
				// Increment number of successfully received packets.
				packets_received++;
				// Compute latency during last Glossy phase.
				rtimer_clock_t lat = get_t_first_rx_l() - get_t_ref_l();
				// Add last latency to sum of latencies.
				sum_latency += lat;
				// Convert latency to microseconds.
				latency = (unsigned long)(lat) * 1e6 / RTIMER_SECOND;
				// Print information about last packet and related latency.
				printf("Glossy received %u time%s: seq_no %lu, latency %lu.%03lu ms\n",
						get_rx_cnt(), (get_rx_cnt() > 1) ? "s" : "", glossy_data.seq_no,
								latency / 1000, latency % 1000);
			} else {	// Packet not received.
				// Increment number of missed packets.
				packets_missed++;
				// Print failed reception.
				printf("Glossy NOT received\n");
			}
#if GLOSSY_DEBUG
//			printf("skew %ld ppm\n", (long)(period_skew * 1e6) / GLOSSY_PERIOD);
			printf("high_T_irq %u, rx_timeout %u, bad_length %u, bad_header %u, bad_crc %u\n",
					high_T_irq, rx_timeout, bad_length, bad_header, bad_crc);
#endif /* GLOSSY_DEBUG */
			// Compute current average reliability.
			unsigned long avg_rel = packets_received * 1e5 / (packets_received + packets_missed);
			// Print information about average reliability.
			printf("average reliability %3lu.%03lu %% ",
					avg_rel / 1000, avg_rel % 1000);
			printf("(missed %lu out of %lu packets)\n",
					packets_missed, packets_received + packets_missed);
#if ENERGEST_CONF_ON
			// Compute average radio-on time, in microseconds.
			unsigned long avg_radio_on = (unsigned long)GLOSSY_PERIOD * 1e6 / RTIMER_SECOND *
					(energest_type_time(ENERGEST_TYPE_LISTEN) + energest_type_time(ENERGEST_TYPE_TRANSMIT)) /
					(energest_type_time(ENERGEST_TYPE_CPU) + energest_type_time(ENERGEST_TYPE_LPM));
			// Print information about average radio-on time.
			printf("average radio-on time %lu.%03lu ms\n",
					avg_radio_on / 1000, avg_radio_on % 1000);
#endif /* ENERGEST_CONF_ON */
			// Compute average latency, in microseconds.
			unsigned long avg_latency = sum_latency * 1e6 / (RTIMER_SECOND * packets_received);
			// Print information about average latency.
			printf("average latency %lu.%03lu ms\n",
					avg_latency / 1000, avg_latency % 1000);
		}
	}

	PROCESS_END();
}
Beispiel #2
0
char can_check(request* r)
{
	unsigned char* rx_buf;
	rx_buf = get_can_rx_ptr(r->canal);
	if(rx_buf==0) return -1;
	switch(r->cmd)
	{
		case RD_RAM:
			if(get_rx_cnt(r->canal)==1+r->amount+2)
			{
				if(GetCRC16(rx_buf,3+r->amount)==0)	{r->rx = &rx_buf[1];return 1;}
			}
			break;
		case RD_US:
			if(get_rx_cnt(r->canal)==1+r->amount+2)
			{
				if(GetCRC16(rx_buf,3+r->amount)==0)	{r->rx = &rx_buf[1];return 1;}
			}
			break;
		case RD_XRAM:
			if(get_rx_cnt(r->canal)==1+8+2)
			{
				if(GetCRC16(rx_buf,11)==0) {r->rx = &rx_buf[1];return 1;}
			}
			break;
		case RD_IO:
			if(get_rx_cnt(r->canal)==1+r->amount+2)
			{
				if(GetCRC16(rx_buf,3+r->amount)==0)	{r->rx = &rx_buf[1];return 1;}
			}
			break;
		case RD_HLD:
			if(get_rx_cnt(r->canal)==3+r->amount*2+2)
			{
				if(GetCRC16(rx_buf,3+r->amount*2+2)==0)	{r->rx = &rx_buf[3];return 1;}
			}
			break;
		case RD_INP:
			if(get_rx_cnt(r->canal)==3+r->amount*2+2)
			{
				if(GetCRC16(rx_buf,3+r->amount*2+2)==0)	{r->rx = &rx_buf[3];return 1;}
			}
			break;
		case RD_DINP:
			if(get_rx_cnt(r->canal)>=3+(r->amount>>3)+2)
			{
				if(GetCRC16(rx_buf,get_rx_cnt(r->canal))==0)	{r->rx = &rx_buf[3];return 1;}
			}
			break;
		case RD_COILS:
			if(get_rx_cnt(r->canal)>=3+(r->amount>>3)+2)
			{
				if(GetCRC16(rx_buf,get_rx_cnt(r->canal))==0)	{r->rx = &rx_buf[3];return 1;}
			}
			break;
        case RD_XRAM51:
            if(get_rx_cnt(r->canal)==1+8+2)
			{
				if(GetCRC16(rx_buf,get_rx_cnt(r->canal))==0)	{r->rx = &rx_buf[1];return 1;}
			}
            break;
        case RD_RAM51:
            if(get_rx_cnt(r->canal)==1+8+2)
			{
				if(GetCRC16(rx_buf,get_rx_cnt(r->canal))==0)	{r->rx = &rx_buf[1];return 1;}
			}
            break;
	}
	return 0;
}