Example #1
0
void inter_tx_task () {
    uint8_t i;
    nrk_sig_t tx_done_signal;
    while (!bmac_started ())
        nrk_wait_until_next_period ();
    tx_done_signal = bmac_get_tx_done_signal ();
    nrk_signal_register (tx_done_signal);
    bmac_addr_decode_enable();
    bmac_addr_decode_set_my_mac(MyOwnAddress);
    while (1) {
        if(ipQue>0) {
            if(itxPtr>queMax-1) {
                itxPtr=0;
            }
            bmac_addr_decode_enable();
            bmac_addr_decode_set_my_mac(MyOwnAddress);
            nrk_led_set(BLUE_LED);
            bmac_auto_ack_disable();
            for(i=0; i<ipLen[itxPtr]; i++) {
                itx_buf[i]=ipDat[itxPtr][i];
            }
            if(ipDes[itxPtr]==0xFF) {
                bmac_addr_decode_dest_mac(0xFFFF);
            }
            else {
                bmac_addr_decode_dest_mac(ipDes[itxPtr]);
            }
            bmac_tx_pkt((char*)itx_buf,ipLen[itxPtr]);
            ipQue--;
            itxPtr++;
            nrk_led_clr(BLUE_LED);
        }
        nrk_wait_until_next_period ();
    }
}
Example #2
0
int main(void)

{
    int r;
    int i;
    
    // Data to be transmitted
    for(i=0;i<MAX_MOLES;i++)
    {
        for(r=0;r<512;r++)
        {
            data[r+(512*i)] = r;

        }
    }
    // Initialize the packet handlers
    init();
    initPacketHandler();

    //Start transmission
    startDataTransmission(2,10);
    startDataTransmission(1,10);

    nrk_setup_ports();
    nrk_init();
    bmac_task_config();
    nrk_create_taskset();
    bmac_init (MY_CHANNEL);
    bmac_auto_ack_disable();
    nrk_start();
    
    return 0;

}
Example #3
0
int main(void)
{   
		nrk_setup_ports();
	  nrk_init();
    nrk_register_drivers();
	  bmac_task_config();
    nrk_create_taskset();
    bmac_init (MY_CHANNEL);
    bmac_auto_ack_disable();
    nrk_start();
    return 0;

}
Example #4
0
int main(void)

{
		table_function.nrk_led_toggle = &nrk_led_toggle;
    nrk_setup_ports();
    nrk_init();
    bmac_task_config();
    nrk_create_taskset();
    bmac_init (MY_CHANNEL);
    bmac_auto_ack_disable();
    nrk_start();
    return 0;

}
Example #5
0
void tx_task ()
{
  uint8_t j, i, val, len;
  int8_t v;
  nrk_sig_t tx_done_signal;
  nrk_sig_mask_t ret;
  nrk_time_t r_period;
	
	
  while (!bmac_started ())
    nrk_wait_until_next_period ();

  tx_done_signal = bmac_get_tx_done_signal ();
  nrk_signal_register (tx_done_signal);

  ctr_cnt[0]=0; ctr_cnt[1]=0; ctr_cnt[2]=0; ctr_cnt[3]=0;
  tx_count = 0;
  while (1) {
		if (tx_count >= 300) {
		printf("Total packets sent : %d \r\n", tx_count);
		}
    // Build a TX packet
		if (tx_count < 300) {
			sprintf(tx_buf, "Hello World");
			nrk_led_set (BLUE_LED);
		   
			bmac_auto_ack_disable();

			val=bmac_tx_pkt(tx_buf, strlen(tx_buf));
			if(val==NRK_OK) tx_count++;		 
			else printf("NO ack or Reserve Violated! \r\n");		
		 
			printf("Tx task sent data!\r\n");
			nrk_led_clr (BLUE_LED);
			printf("tx_task PID=%d\r\n", nrk_get_pid ());
		}
		nrk_wait_until_next_period ();
  }
}
Example #6
0
void tx_task ()
{
  uint8_t j, i, val, len, cnt;
  int8_t v;
  nrk_sig_t tx_done_signal;
  nrk_sig_mask_t ret;
  nrk_time_t r_period;
	
	// printf("tx_task PID=%d\r\n", nrk_get_pid ());

  // Wait until the tx_task starts up bmac
  // This should be called by all tasks using bmac that
  // do not call bmac_init()...
  while (!bmac_started ())
    nrk_wait_until_next_period ();


  // Sample of using Reservations on TX packets
  // This example allows 2 packets to be sent every 5 seconds
  // r_period.secs=5;
  // r_period.nano_secs=0;
  // v=bmac_tx_reserve_set( &r_period, 2 );
  // if(v==NRK_ERROR) nrk_kprintf( PSTR("Error setting b-mac tx reservation (is NRK_MAX_RESERVES defined?)\r\n" ));


  // Get and register the tx_done_signal if you want to
  // do non-blocking transmits
  tx_done_signal = bmac_get_tx_done_signal ();
  nrk_signal_register (tx_done_signal);

  ctr_cnt[0]=0; ctr_cnt[1]=0; ctr_cnt[2]=0; ctr_cnt[3]=0;
  cnt = 0;
	
  while (1) {
    // Build a TX packet
    sprintf (tx_buf, "This is a test %d", cnt);
    nrk_led_set (BLUE_LED);
		
    // Auto ACK is an energy efficient link layer ACK on packets
    // If Auto ACK is enabled, then bmac_tx_pkt() will return failure
    // if no ACK was received. In a broadcast domain, the ACK's will
    // typically collide.  To avoid this, one can use address decoding. 
    // The functions are as follows:
    // bmac_auto_ack_enable();
			 bmac_auto_ack_disable();

    // Address decoding is a way of preventing the radio from receiving
    // packets that are not address to a particular node.  This will 
    // supress ACK packets from nodes that should not automatically ACK.
    // The functions are as follows:
    // bmac_addr_decode_set_my_mac(uint16_t MAC_ADDR); 
    // bmac_addr_decode_dest_mac(uint16_t DST_ADDR);  // 0xFFFF is broadcast
    // bmac_addr_decode_enable();
    // bmac_addr_decode_disable();
/*
     ctr_cnt[0]=cnt; 
     if(ctr_cnt[0]==255) ctr_cnt[1]++; 
     if(ctr_cnt[1]==255) ctr_cnt[2]++; 
     if(ctr_cnt[2]==255) ctr_cnt[3]++; 
     // You need to increase the ctr on each packet to make the 
     // stream cipher not repeat.
     bmac_encryption_set_ctr_counter(&ctr_cnt,4);

*/  // For blocking transmits, use the following function call.
    // For this there is no need to register  
     val=bmac_tx_pkt(tx_buf, strlen(tx_buf));
		 if(val==NRK_OK) cnt++;
 		 else printf("NO ack or Reserve Violated! \r\n");

    // This function shows how to transmit packets in a
    // non-blocking manner  
    // val = bmac_tx_pkt_nonblocking(tx_buf, strlen (tx_buf));
    // printf ("Tx packet enqueued\r\n");
    // This functions waits on the tx_done_signal
    //ret = nrk_event_wait (SIG(tx_done_signal));

    // Just check to be sure signal is okay
    //if(ret & SIG(tx_done_signal) == 0 ) 
    //printf ("TX done signal error\r\n");
   
    // If you want to see your remaining reservation
    // printf( "reserve=%d ",bmac_tx_reserve_get() );
    
    // Task gets control again after TX complete
    printf("Tx task sent data!\r\n");
    nrk_led_clr (BLUE_LED);
		printf("tx_task PID=%d\r\n", nrk_get_pid ());
    nrk_wait_until_next_period ();
  }

}
Example #7
0
void tx_task () {
    uint8_t i;
    nrk_sig_t tx_done_signal;
    while (!bmac_started ())
        nrk_wait_until_next_period ();
    tx_done_signal = bmac_get_tx_done_signal ();
    nrk_signal_register (tx_done_signal);
    bmac_addr_decode_enable();
    bmac_addr_decode_set_my_mac(MyOwnAddress);
    while (1) {
        if(updateCnt==0) {
            updateCnt = updateCntMax;
            for(i=0; i<MaxuIDTrack; i++) {
                uniqueIDsRREQ[i]=0;
            }
            for(i=0; i<MaxuIDTrack; i++) {
                uniqueIDsRSAL[i]=0;
            }
            for(i=0; i<MaxuIDTrack; i++) {
                if(ackTrackR[i]==ackTrackS[i]) {
                    ackTrackR[i]=0;
                    ackTrackS[i]=0;
                    ackTrack[i]=0;
                }
            }
            for(i=0; i<MaxuIDTrack; i++) {
                if(ackTrack[i]!=0) {
                    if(cache[1]==ackTrack[i]) {
                        cache[0]=0;
                    }
                    ackTrackS[i]=0;
                    ackTrackR[i]=0;
                    RsalInitiate(ackTrack[i]);
                    ackTrack[i]=0;
                }
            }
            for(i=0; i<MaxuIDTrack; i++) {
                ackTrack[i]=ackTrackS[i];
            }
        }
        else {
            updateCnt--;
        }
        if(cache[0]==0) {
            if(rDiscCnt==0) {
                RouteDiscovery();
                rDiscCnt=rDiscCntMax;
            }
            else {
                rDiscCnt--;
            }
        }
        else {
            DataInitiate();
            rDiscCnt=0;
        }
        if(pQue>0) {
            if(txPtr>queMax-1) {
                txPtr=0;
            }
            bmac_addr_decode_enable();
            bmac_addr_decode_set_my_mac(MyOwnAddress);
            nrk_led_set(GREEN_LED);
            bmac_auto_ack_disable();
            for(i=0; i<pLen[txPtr]; i++) {
                tx_buf[i]=pDat[txPtr][i];
            }
            if(pDes[txPtr]==0xFF) {
                bmac_addr_decode_dest_mac(0xFFFF);
            }
            else {
                bmac_addr_decode_dest_mac(pDes[txPtr]);
            }
            bmac_tx_pkt((char*)tx_buf,pLen[txPtr]);
            for(i=0; i<pLen[txPtr]; i++) {
                putchar(tx_buf[i]);
            }
            putchar(pDes[txPtr]);
            pQue--;
            txPtr++;
            nrk_led_clr(GREEN_LED);
        }
        nrk_wait_until_next_period ();
    }
}
Example #8
0
/*
void inter_tx_task ()
{
  
	uint8_t j, i, val, len, cnt;
  nrk_sig_t tx_done_signal;
  nrk_sig_mask_t ret;
  nrk_time_t r_period;
  	
	
  while (!bmac_started ())
    nrk_wait_until_next_period ();

  tx_done_signal = bmac_get_tx_done_signal ();
  nrk_signal_register (tx_done_signal);
  cnt = 0;
  
  while (1) {
    if(inter_flag==1){
		printf("Hi..\n");
	  bmac_addr_decode_disable();
    bmac_addr_decode_set_my_mac(MY_MAC_ADDR);
	  sprintf(&tx_buf[0],"%d",MY_MAC_ADDR);
	  for(i=0;i<strlen(inter_tx_buf);i++){
	  tx_buf[i+1]=inter_tx_buf[i];
	}
	  nrk_led_set (BLUE_LED);
    bmac_auto_ack_disable();
    bmac_addr_decode_dest_mac(dst_addr);  // 0xFFFF is broadcast
	  val=bmac_tx_pkt(tx_buf, strlen(tx_buf));
	  inter_flag=0;
    printf("Tx task sent data!\r\n");
    nrk_led_clr (BLUE_LED);
	  printf("tx_task PID=%d\r\n", nrk_get_pid ());
}  
  nrk_wait_until_next_period ();
  }

}
*/
void tx_task ()
{
  uint8_t j, i, val, len, cnt,turn=0;
  nrk_sig_t tx_done_signal;
  nrk_sig_mask_t ret;
  nrk_time_t r_period;
   while (!bmac_started ())
     nrk_wait_until_next_period ();
  tx_done_signal = bmac_get_tx_done_signal ();
  nrk_signal_register (tx_done_signal);
  cnt = 0;
  
  while (1) {
    if(inter_flag==0 ){
		printf("Hi..\n");
	  bmac_addr_decode_disable();
    bmac_addr_decode_set_my_mac(MY_MAC_ADDR);
	  sprintf(tx_buf,"node_id:%d count:%d",MY_MAC_ADDR,cnt);
    nrk_led_set (BLUE_LED);
		
   
    bmac_auto_ack_disable();
    bmac_addr_decode_dest_mac(dst_addr);  // 0xFFFF is broadcast
	  val=bmac_tx_pkt(tx_buf, strlen(tx_buf));
    printf("Tx task sent data!\r\n");
    nrk_led_clr (BLUE_LED);
		printf("tx_task PID=%d\r\n", nrk_get_pid ());
    }
	  
			if(inter_flag==1){
				if(turn==0){
					printf("Hi..\n");
	  bmac_addr_decode_disable();
    bmac_addr_decode_set_my_mac(MY_MAC_ADDR);
	  sprintf(tx_buf,"Path: %d-1 node_id:%d count:%d",MY_MAC_ADDR,MY_MAC_ADDR,cnt);
    nrk_led_set (BLUE_LED);
		bmac_auto_ack_disable();
    bmac_addr_decode_dest_mac(dst_addr);  // 0xFFFF is broadcast
	  val=bmac_tx_pkt(tx_buf, strlen(tx_buf));
    printf("Tx task sent data!\r\n");
    nrk_led_clr (BLUE_LED);
		printf("tx_task PID=%d\r\n", nrk_get_pid ());
					turn=1;
				}
				else{
	  bmac_addr_decode_disable();
    bmac_addr_decode_set_my_mac(MY_MAC_ADDR);
	  sprintf(&tx_buf[0],"%d",MY_MAC_ADDR);
	  for(i=0;i<strlen(inter_tx_buf);i++){
	  tx_buf[i+1]=inter_tx_buf[i];
	}
	  nrk_led_set (BLUE_LED);
    bmac_auto_ack_disable();
    bmac_addr_decode_dest_mac(dst_addr);  // 0xFFFF is broadcast
	  val=bmac_tx_pkt(tx_buf, strlen(tx_buf));
	  printf("Tx task sent data!\r\n");
    nrk_led_clr (BLUE_LED);
	  printf("tx_task PID=%d\r\n", nrk_get_pid ());
	  turn=0;
}
}

  cnt++;
nrk_wait_until_next_period ();
   }

}