void Task1() { int8_t rssi, slot,length; //all parameters recieved along with an rx printf( "Task1 PID=%d\r\n",nrk_get_pid()); printf( "Node ID=%d\r\n",NODE_ID); nrk_led_set(RED_LED); rtl_init (RTL_COORDINATOR); rtl_set_channel(MY_CHANNEL); rtl_set_schedule( RTL_RX, NODE_2_RX_SLOT, 1 ); rtl_set_schedule( RTL_RX, NODE_3_RX_SLOT, 1 ); rtl_set_schedule( RTL_TX, MY_TX_SLOT, 1 ); //rtl_set_tx_power(MAX_POWER); rtl_rx_pkt_set_buffer(rx_buf, RF_MAX_PAYLOAD_SIZE); //to limit payload size rtl_start(); while(!rtl_ready()) nrk_wait_until_next_period(); while(1) { if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 ) { //printf("Pending TX"); } else { nrk_time_get(¤tTime); if(currentTime.secs-exchangeTime.secs>EXCHANGE_INTERVAL) { //TODO:Data to be transmitted int8_t length; //sprintf( &tx_buf[PKT_DATA_START],"",); length = sprintf(&tx_buf[PKT_DATA_START], "%-+5d%-+5d",myX,myY); //TODO: Data printf ("(%s) is the result of our sprintf, which is %d characters long",tx_buf,length); length=length+PKT_DATA_START+1; printf("Sending: "); /* for(int i=PKT_DATA_START; i<length; i++ )*/ /* {*/ /* printf("%c",tx_buf[i] );*/ /* }*/ /* printf("\n\r");*/ addToTXBuffer(tx_buf,length); nrk_time_get(&exchangeTime); } fetchTxBuffer(); //Actual Transmit nrk_led_toggle(BLUE_LED); } if( rtl_rx_pkt_check()!=0 ) { int8_t senderNode; nrk_led_set(ORANGE_LED); uint8_t *local_rx_buf; local_rx_buf=rtl_rx_pkt_get(&length, &rssi, &slot); printf( "Got Packet on slot %d %d: ",slot,length ); senderNode=slot/2; if(senderNode==0) { int li = atoi (&local_rx_buf[NODE_ID]); printf ("\nXrecd=%d",li); myX=li; li = atoi (&local_rx_buf[NODE_ID+5]); printf ("\nYrecd=%d",li); myY=li; } else { int li = atoi (&local_rx_buf[NODE_ID]); printf ("\nXrecd=%d",li); X[senderNode]=li; li = atoi (&local_rx_buf[NODE_ID+5]); printf ("\nYrecd=%d",li); Y[senderNode]=li; } } rtl_wait_until_rx_or_tx(); } }
void Task1() { uint8_t j, i; char *local_rx_buf; uint8_t cnt,cont; int8_t rssi; uint8_t length,slot; uint16_t counter; volatile nrk_time_t t; uint16_t tx_count, rx_count; printf( "Task1 PID=%d, MOBILE\r\n",nrk_get_pid()); counter=0; cnt=0; cont=0; uint8_t val,fd,fd2,buf[2],buf2[2]; uint16_t adc_int,adc_int2,light,temp; uint8_t k,l,m,n; //rtl_init (RTL_COORDINATOR); rtl_init (RTL_MOBILE); rtl_set_schedule( RTL_TX, MY_TX_SLOT, 1 ); rtl_set_schedule( RTL_RX, MY_RX_SLOT1, 1); //rtl_set_schedule( RTL_RX, MY_RX_SLOT2, 1); // rtl_set_contention(8,1); rtl_start(); rtl_rx_pkt_set_buffer(rx_buf, RF_MAX_PAYLOAD_SIZE); nrk_kprintf( PSTR("start done\r\n") ); while(!rtl_ready()) nrk_wait_until_next_period(); tx_count = 0; rx_count = 0; while(1) { if (tx_count >= 250) { printf("Transmissions: %d \r\n", tx_count); printf("Receptions: %d \r\n", rx_count); } if (tx_count < 250) { /*fd = nrk_open(FIREFLY_SENSOR_BASIC,READ); wait_ms(1); val = nrk_set_status(fd,SENSOR_SELECT,LIGHT); val = nrk_set_status(fd2,SENSOR_SELECT,TEMP); val = nrk_read(fd , &buf[0] , 2); val = nrk_read(fd2 , &buf2[0] , 2); adc_int = buf[0] + (buf[1]<<8); adc_int2 = buf2[0] + (buf2[1]<<8); light = adc_int; temp = adc_int2; k = light & 0xFF; l = (light >> 8) & 0xFF; m = temp & 0xFF; n = (temp >> 8) & 0xFF;*/ if( rtl_rx_pkt_check()!=0 ) { nrk_led_set(BLUE_LED); local_rx_buf=rtl_rx_pkt_get(&length, &rssi, &slot); printf( "Got Packet on slot %d %d: ",slot,length ); rx_count++; for(i=PKT_DATA_START; i<length; i++ ) { printf( "%c",local_rx_buf[i] ); } printf("\r\n"); rtl_rx_pkt_release(); nrk_led_clr(BLUE_LED); } if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 ) { printf( "Pending on slot %d\r\n",MY_TX_SLOT ); } else { nrk_led_set(RED_LED); cnt++; sprintf( &tx_buf[PKT_DATA_START], "Mobile1 %d", cnt); //printf(" %d %d %d %d \r\n",k,l,m,n); /*tx_buf[PKT_DATA_START] = k; tx_buf[PKT_DATA_START+1] = ' '; tx_buf[PKT_DATA_START+2] = l; tx_buf[PKT_DATA_START+3] = ' '; tx_buf[PKT_DATA_START+4] = m; tx_buf[PKT_DATA_START+5] = ' '; tx_buf[PKT_DATA_START+6] = n;*/ length=strlen(&tx_buf[PKT_DATA_START])+PKT_DATA_START; rtl_tx_pkt( tx_buf, length, MY_TX_SLOT ); printf( "Sending Packet on slot %d\r\n",MY_TX_SLOT); tx_count++; nrk_led_clr(RED_LED); } //nrk_wait_until_next_period(); rtl_wait_until_rx_or_tx(); } } }
void Task1() { uint8_t j, i; uint8_t *local_rx_buf; uint8_t length,slot; int8_t rssi; uint8_t cnt; uint16_t counter; volatile nrk_time_t t; printf( "Task1 PID=%d\r\n",nrk_get_pid()); counter=0; cnt=0; // nrk_led_set(0); rtl_init (RTL_MOBILE); rtl_set_schedule( RTL_RX, MY_RX_SLOT, 1 ); //rtl_set_schedule( RTL_RX, 12, 1 ); rtl_set_schedule( RTL_TX, MY_TX_SLOT, 1 ); // rtl_set_contention( 8, 1 ); rtl_start(); rtl_rx_pkt_set_buffer(rx_buf, RF_MAX_PAYLOAD_SIZE); while(!rtl_ready()) nrk_wait_until_next_period(); nrk_led_clr(0); while(1) { if( rtl_rx_pkt_check()!=0 ) { nrk_led_set(BLUE_LED); local_rx_buf=rtl_rx_pkt_get(&length, &rssi, &slot); printf( "Got Packet on slot %d %d: ",slot,length ); for(i=PKT_DATA_START; i<length; i++ ) { printf( "%c",local_rx_buf[i] ); } nrk_kprintf( PSTR("\r\n") ); rtl_rx_pkt_release(); nrk_led_clr(BLUE_LED); } if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 ) { printf( "Pending on slot %d\r\n",MY_TX_SLOT ); } else { nrk_led_set(GREEN_LED); cnt++; sprintf( &tx_buf[PKT_DATA_START], "Hello World %d", cnt ); length=strlen(&tx_buf[PKT_DATA_START])+PKT_DATA_START; rtl_tx_pkt( tx_buf, length, MY_TX_SLOT ); printf( "Sending Packet on slot %d\r\n",MY_TX_SLOT ); nrk_led_clr(GREEN_LED); } rtl_wait_until_rx_or_tx(); } }
void Task1() { uint8_t j, i; uint8_t *local_rx_buf; uint8_t cnt; int8_t rssi; uint8_t length,slot; uint16_t counter; volatile nrk_time_t t; printf( "Task1 PID=%d\r\n",nrk_get_pid()); counter=0; cnt=0; #ifdef COORDINATOR nrk_kprintf( PSTR( "Coordinator\r\n")); rtl_init (RTL_COORDINATOR); nrk_led_set(RED_LED); #else nrk_kprintf( PSTR( "Mobile\r\n")); rtl_init (RTL_MOBILE); #endif printf( "Node %d ",NODE_ID ); printf( "TX %d ",MY_TX_SLOT); printf( "RX %d\r\n",MY_RX_SLOT); rtl_set_schedule( RTL_TX, MY_TX_SLOT, 1 ); rtl_set_schedule( RTL_RX, MY_RX_SLOT, 1 ); rtl_start(); rtl_rx_pkt_set_buffer(rx_buf, RF_MAX_PAYLOAD_SIZE); nrk_kprintf( PSTR("start done\r\n") ); while(!rtl_ready()) nrk_wait_until_next_period(); while(1) { #if NODE_ID==1 if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 ) { printf( "Pending on slot %d\r\n",MY_TX_SLOT ); } else { nrk_led_set(2); cnt++; sprintf( &tx_buf[PKT_DATA_START], "Hello World %d", cnt ); length=strlen(&tx_buf[PKT_DATA_START])+PKT_DATA_START+1; rtl_tx_pkt( tx_buf, length, MY_TX_SLOT ); printf( "Sending Packet on slot %d\r\n",MY_TX_SLOT ); nrk_led_clr(2); } #else if( rtl_rx_pkt_check()!=0 ) { nrk_led_set(1); local_rx_buf=rtl_rx_pkt_get(&length, &rssi, &slot); printf( "Got Packet on slot %d %d: ",slot,length ); for(i=PKT_DATA_START; i<length; i++ ) { // copy the rx buffer to the tx buffer // tx_buf[i]=local_rx_buf[i]; printf( "%c",local_rx_buf[i] ); } nrk_kprintf( PSTR("\r\n") ); if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 ) { printf( "Pending on slot %d\r\n",MY_TX_SLOT ); } else { nrk_led_set(2); sprintf( &tx_buf[PKT_DATA_START], "%s %d",&local_rx_buf[PKT_DATA_START], NODE_ID ); length=strlen(&tx_buf[PKT_DATA_START])+PKT_DATA_START+1; rtl_tx_pkt( tx_buf, length, MY_TX_SLOT ); printf( "Sending [%d] %s\r\n",length, &tx_buf[PKT_DATA_START] ); //printf( "Sending Packet on slot %d\r\n",MY_TX_SLOT ); nrk_led_clr(2); } rtl_rx_pkt_release(); nrk_led_clr(1); } #endif rtl_wait_until_rx_or_tx(); } }