PROCESS_THREAD(test, ev, data) { static struct etimer et; ConReceivedFrame *r; PROCESS_BEGIN(); printf("rimeaddr_node_addr = [%u, %u]\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]); conmsg = (ConMsg * ) malloc (sizeof(ConMsg)); setChannel(17); start(); while(1){ etimer_set(&et,20*CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); r = get_received() ; printf("%s : %d\n",r->payload, r->paylen ); printf("dest : "); printf("%x",BYTE_LOW(r->dstaddr)); printf(" : " ); printf("%x\n",BYTE_HIGH(r->dstaddr) ); printf("src : "); printf("%x",BYTE_LOW(r->srcaddr)); printf(" : " ); printf("%x\n",BYTE_HIGH(r->srcaddr) ); skip_received(); r = get_received() ; printf("%s : %d\n",r->payload, r->paylen ); printf("dest : "); printf("%x",BYTE_LOW(r->dstaddr)); printf(" : " ); printf("%x\n",BYTE_HIGH(r->dstaddr) ); printf("src : "); printf("%x",BYTE_LOW(r->srcaddr)); printf(" : " ); printf("%x\n",BYTE_HIGH(r->srcaddr) ); skip_received(); } PROCESS_END(); }
void record() { struct timeval start, end; ssize_t amt; long long int diff; double bps, last_bps = 0, total_bps = 0, first_bps; int total_adds = 0; int trial = 1; gettimeofday(&start, NULL); while(1) { usleep(1000000); gettimeofday(&end, NULL); amt = get_received(); diff = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec); bps = (amt * 8 * 1000000) / diff; /* Beginning */ if(last_bps == 0.0 && bps != 0.0) { first_bps = bps; } /* Any of them in the middle */ if(last_bps != 0.0 && bps != 0.0) { total_bps += bps; total_adds++; } /* Just got the last one */ else if(last_bps != 0.0 && bps == 0.0) { if(total_adds <= 1) { printf("*One or Two Intervals -- Including edges*\n"); } else { total_bps -= last_bps; total_adds--; if(total_adds != 0) printf("%.2f\t%f\n", total_bps / total_adds, (total_bps / total_adds) / 1000000); } trial++; total_bps = 0.0; total_adds = 0; first_bps = 0.0; } last_bps = bps; start = end; } }