Exemple #1
0
int send_ping (void)
{
  int v, size;
  PKT_T my_pkt;
  char buffer[128];
  // Send a ping at startup
  my_pkt.src_mac = 0x00000000;
  my_pkt.dst_mac = 0xffffffff;
  my_pkt.type = PING;
  my_pkt.payload_len = 0;
  size = pkt_to_buf (&my_pkt, buffer);
  v = slipstream_send (buffer, size);
  if (v == 0)
    printf ("Error sending\n");
  return v;
}
Exemple #2
0
void tx_task ()
{
  uint8_t j, i, val, cnt;
  int8_t len;
  int8_t v,fd;
  uint8_t buf[2];
  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

  while (!tdma_started ())
    nrk_wait_until_next_period ();

 


  while (1) {
    	tx_pkt.payload[0] = 1;  // ELEMENTS
   	tx_pkt.payload[1] = 5;  // Key
	tx_pkt.payload[2]=Gain;
    	tx_pkt.payload_len=3;
	if(gpio_pin) nrk_led_set(BLUE_LED);
	else nrk_led_clr(BLUE_LED);

    	tx_pkt.src_mac=mac_address;
    	tx_pkt.dst_mac=0;
    	tx_pkt.type=APP;

    	len=pkt_to_buf(&tx_pkt,&tx_buf );
    if(len>0)
    {
    v = tdma_send (&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING);
    if (v == NRK_OK) {
      //nrk_kprintf (PSTR ("App Packet Sent\n"));
    }
    } else nrk_wait_until_next_period();

  }



}
Exemple #3
0
int node_sleep (uint32_t mac, uint8_t state)
{
  int v, size;
  PKT_T my_pkt;
  char buffer[128];

  my_pkt.src_mac = 0x00000000;
  my_pkt.dst_mac = mac;
  my_pkt.type = NW_CONFIG;
  my_pkt.payload[0] = 1;        // Number of Elements
  my_pkt.payload[1] = NW_CONFIG_SLEEP;        // KEY (1-> sleep ) 
  my_pkt.payload[2] = state;    // Outlet state 0/1
  my_pkt.payload_len = 3;
  size = pkt_to_buf (&my_pkt, buffer);
  v = slipstream_acked_send(buffer, size,3);
  return v;
}
Exemple #4
0
int outlet_actuate (uint32_t mac, uint8_t socket, uint8_t state)
{
  int v, size;
  PKT_T my_pkt;
  char buffer[128];

  my_pkt.src_mac = 0x00000000;
  my_pkt.dst_mac = mac;
  my_pkt.type = APP;
  my_pkt.payload[0] = 1;        // Number of Elements
  my_pkt.payload[1] = 2;        // KEY (2->actuate, 1-> Power Packet) 
  my_pkt.payload[2] = socket;   // Outlet number 0/1
  my_pkt.payload[3] = state;    // Outlet state 0/1
  my_pkt.payload_len = 4;
  size = pkt_to_buf (&my_pkt, buffer);
  v = slipstream_send (buffer, size);
  return v;
}
Exemple #5
0
void tx_task ()
{
    uint8_t j, i, val, cnt;
    int8_t len;
    int8_t v,fd;
    uint8_t buf[2];
    nrk_sig_mask_t ret;
    nrk_time_t t;



    // Set Port D.0 as input
    // On the FireFly nodes we use this for motion or syntonistor input
    // It can be interrupt driven, but we don't do this with TDMA since updates are so fast anyway
//  DDRD &= ~(0x1);



    printf ("tx_task PID=%d\r\n", nrk_get_pid ());

    // setup a software watch dog timer
    t.secs=10;
    t.nano_secs=0;
    nrk_sw_wdt_init(0, &t, NULL);
    nrk_sw_wdt_start(0);

    while (!tdma_started ())
        nrk_wait_until_next_period ();

    // set port G as input for gpio
    DDRG=0;


    while (1) {

        nrk_led_clr(RED_LED);


        tx_pkt.payload[0] = 1;  // ELEMENTS
        tx_pkt.payload[1] = 3;  // Key

        fd=nrk_open(FIREFLY_3_SENSOR_BASIC,READ);
        if(fd==NRK_ERROR) nrk_kprintf(PSTR("Failed to open sensor driver\r\n"));


        val=nrk_set_status(fd,SENSOR_SELECT,MOTION);
        val=nrk_read(fd,&buf,2);
        tx_pkt.payload[28]=buf[1];
        tx_pkt.payload[29]=buf[0];



        val=nrk_set_status(fd,SENSOR_SELECT,BAT);
        val=nrk_read(fd,&buf,2);
        tx_pkt.payload[2]=buf[1];
        tx_pkt.payload[3]=buf[0];
        //printf( "Task bat=%d",buf);

//	tx_pkt.payload[2]=0;
//	tx_pkt.payload[3]=0;

        val=nrk_set_status(fd,SENSOR_SELECT,LIGHT);
        val=nrk_read(fd,&buf,2);
        tx_pkt.payload[4]=buf[1];
        tx_pkt.payload[5]=buf[0];
        //printf( " light=%d",buf);
        val=nrk_set_status(fd,SENSOR_SELECT,TEMP);
        val=nrk_read(fd,&buf,2);
        tx_pkt.payload[6]=buf[1];
        tx_pkt.payload[7]=buf[0];
        //printf( " temp=%d",buf);
        val=nrk_set_status(fd,SENSOR_SELECT,ACC_X);
        val=nrk_read(fd,&buf,2);
        tx_pkt.payload[8]=buf[1];
        tx_pkt.payload[9]=buf[0];
        //printf( " acc_x=%d",buf);
        val=nrk_set_status(fd,SENSOR_SELECT,ACC_Y);
        val=nrk_read(fd,&buf,2);
        tx_pkt.payload[10]=buf[1];
        tx_pkt.payload[11]=buf[0];
        //printf( " acc_y=%d",buf);
        val=nrk_set_status(fd,SENSOR_SELECT,ACC_Z);
        val=nrk_read(fd,&buf,2);
        tx_pkt.payload[12]=buf[1];
        tx_pkt.payload[13]=buf[0];
        //printf( " acc_z=%d",buf);


        val=nrk_set_status(fd,SENSOR_SELECT,HUMIDITY);
        val=nrk_read(fd,&buf,4);
        tx_pkt.payload[16]=buf[3];
        tx_pkt.payload[17]=buf[2];
        tx_pkt.payload[18]=buf[1];
        tx_pkt.payload[19]=buf[0];


        val=nrk_set_status(fd,SENSOR_SELECT,TEMP2);
        val=nrk_read(fd,&buf,4);
        tx_pkt.payload[20]=buf[3];
        tx_pkt.payload[21]=buf[2];
        tx_pkt.payload[22]=buf[1];
        tx_pkt.payload[23]=buf[0];


        val=nrk_set_status(fd,SENSOR_SELECT,PRESS);
        val=nrk_read(fd,&buf,4);
        tx_pkt.payload[24]=buf[3];
        tx_pkt.payload[25]=buf[2];
        tx_pkt.payload[26]=buf[1];
        tx_pkt.payload[27]=buf[0];


        val=nrk_set_status(fd,SENSOR_SELECT,AUDIO_P2P);
        val=nrk_read(fd,&buf,2);
        tx_pkt.payload[14]=buf[1];
        tx_pkt.payload[15]=buf[0];


        // GPIO data
//	gpio_pin = !!(PINE & 0x4);
        gpio_pin = PING & 0x1;
        tx_pkt.payload[30]=gpio_pin;
        //printf( " audio=%d\r\n",buf);

        nrk_close(fd);

        tx_pkt.payload_len=31;
        tx_pkt.src_mac=mac_address;
        tx_pkt.dst_mac=0;
        tx_pkt.type=APP;

        len=pkt_to_buf(&tx_pkt,&tx_buf );

        if(len>0)
        {
            v = tdma_send (&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING);
            if (v == NRK_OK) {
            }
        } else {
            nrk_kprintf(PSTR("Pkt tx error\r\n"));
            nrk_wait_until_next_period();
        }


        nrk_sw_wdt_update(0);
    }



}
Exemple #6
0
void tx_task ()
{
  uint8_t j, i, val, cnt;
  int8_t len;
  int8_t v,fd;
  uint8_t buf[2];
  nrk_sig_mask_t ret;
  nrk_time_t t;
  int8_t* success;
  int16_t acbuf[3];
  int gyrobuf[3];
  int magbuf[3];

	/* Setup application timer with:
	 * Prescaler = 5 
	 * Compare Match = 2500
	 * Sys Clock = 1.0 MHz according to Mega128RFA1 manual pg149
	 * Prescaler 5 means divide sys clock by 1024
	 * 1000000 / 1024 = 976.5625 Hz clock
	 * 1 / 976.5625 = 1.024 ms per tick
	 * 1.024 ms * 1000 = ~1024 ms / per interrupt callback
	 */
	
	val=nrk_timer_int_configure(NRK_APP_TIMER_0, 5, 1000, &my_timer_callback );
	if(val==NRK_OK) nrk_kprintf( PSTR("Callback timer setup\r\n"));
	else nrk_kprintf( PSTR("Error setting up timer callback\r\n"));
	
	// Zero the timer...
	nrk_timer_int_reset(NRK_APP_TIMER_0);
	// Start the timer...
	nrk_timer_int_start(NRK_APP_TIMER_0);

  // Set Port D.0 as input
  // On the FireFly nodes we use this for motion or syntonistor input
  // It can be interrupt driven, but we don't do this with TDMA since updates are so fast anyway
  //  DDRD &= ~(0x1);
  	
   
   //nrk_kprintf( PSTR("Booting Up ADXL345. . .\r\n") );
  /**** Start Accelerometer and check connections 
   * Start up accelerometer
   * Ensure ADXL is connected. 
   * Enable continous measurement
   * INT_SCALER =  10000 
   * Set accelerometer range to maximum og 2G
   * Set sample rate to 1.6Khz
   ****/	
   set_up_ADXL345();
	
  /**** Start Gyro and check connections 
   * Start up gyro
   * Zero calibrate gyro.
   * INT_SCALER_GYRO =  100  
   * Leave gyro still for about 2 seconds to zero-calibrate
   * sets gyro sample rate to 8Khz with a 256Hz BW(bandwidth) LP (low pass) filter
   ****/
   set_up_ITG3200();	
	
  /**** Start magnetometer and check connections 
   * set scale to +/- 1.3 gauss
   * set measurement mode to continous	
   * INT_SCALER_MAG = 1000
   * sets sample rate to highest value of 75Hz
   * sets averaging value to 8 samples per reading givein at 75 Hz
   ****/
   success = set_up_HMC5883L();
   
   if (*success) nrk_kprintf( PSTR("HMC5883L(Magnetometer) boot success. Scale +/- 1.3 Ga. . .\r\n"));
   if ( *(success+1) ) nrk_kprintf( PSTR("HMC5883L measurement mode: continuous . .\r\n") );
	
	//printf( "My node's address is %d\r\n",NODE_ADDR );

  printf ("tx_task PID=%d\r\n", nrk_get_pid ());

   // setup a software watch dog timer
   t.secs=10;
   t.nano_secs=0;
   nrk_sw_wdt_init(0, &t, NULL);
   nrk_sw_wdt_start(0);

   while (!tdma_started ())
   nrk_wait_until_next_period ();

	

  while (1) {

	//nrk_led_toggle(GREEN_LED);


	tx_pkt.payload[0] = 1;  // ELEMENTS
	tx_pkt.payload[1] = 3;  // Key

   /* 	fd=nrk_open(FIREFLY_3_SENSOR_BASIC,READ);
        if(fd==NRK_ERROR) nrk_kprintf(PSTR("Failed to open sensor driver\r\n"));
//	val=nrk_set_status(fd,SENSOR_SELECT,BAT);
//	val=nrk_read(fd,&buf,2);
//	tx_pkt.payload[2]=buf[1];
//	tx_pkt.payload[3]=buf[0];
	//printf( "Task bat=%d",buf);
	tx_pkt.payload[2]=0;
	tx_pkt.payload[3]=0;
	
	//val=nrk_set_status(fd,SENSOR_SELECT,LIGHT);
	//val=nrk_read(fd,&buf,2);
	tx_pkt.payload[4]=buf[1];
	tx_pkt.payload[5]=buf[0];
	//printf( " light=%d",buf);
	
	//val=nrk_set_status(fd,SENSOR_SELECT,TEMP);
	//val=nrk_read(fd,&buf,2);
	tx_pkt.payload[6]=buf[1];
	tx_pkt.payload[7]=buf[0];
	//printf( " temp=%d",buf);
	
	//val=nrk_set_status(fd,SENSOR_SELECT,ACC_X);
	//val=nrk_read(fd,&buf,2);
	tx_pkt.payload[8]=buf[1];
	tx_pkt.payload[9]=buf[0];
	//printf( " acc_x=%d",buf);
	
	//val=nrk_set_status(fd,SENSOR_SELECT,ACC_Y);
	//val=nrk_read(fd,&buf,2);
	tx_pkt.payload[10]=buf[1];
	tx_pkt.payload[11]=buf[0];
	//printf( " acc_y=%d",buf);
	
	//val=nrk_set_status(fd,SENSOR_SELECT,ACC_Z);
	//val=nrk_read(fd,&buf,2);
	tx_pkt.payload[12]=buf[1];
	tx_pkt.payload[13]=buf[0];
	//printf( " acc_z=%d",buf);
	
	/*
	val=nrk_set_status(fd,SENSOR_SELECT,HUMIDITY);
	val=nrk_read(fd,&buf,4);
	tx_pkt.payload[16]=buf[3];
	tx_pkt.payload[17]=buf[2];
	tx_pkt.payload[18]=buf[1];
	tx_pkt.payload[19]=buf[0];


	val=nrk_set_status(fd,SENSOR_SELECT,TEMP2);
	val=nrk_read(fd,&buf,4);
	tx_pkt.payload[20]=buf[3];
	tx_pkt.payload[21]=buf[2];
	tx_pkt.payload[22]=buf[1];
	tx_pkt.payload[23]=buf[0];


	val=nrk_set_status(fd,SENSOR_SELECT,PRESS);
	val=nrk_read(fd,&buf,4);
	tx_pkt.payload[24]=buf[3];
	tx_pkt.payload[25]=buf[2];
	tx_pkt.payload[26]=buf[1];
	tx_pkt.payload[27]=buf[0];

	//val=nrk_set_status(fd,SENSOR_SELECT,MOTION);
	//val=nrk_read(fd,&buf,2);
	tx_pkt.payload[28]=buf[1];
	tx_pkt.payload[29]=buf[0];

	//val=nrk_set_status(fd,SENSOR_SELECT,AUDIO_P2P);
	//val=nrk_read(fd,&buf,2);
	tx_pkt.payload[14]=buf[1];
	tx_pkt.payload[15]=buf[0];


	// GPIO data
	//gpio_pin = !!(PINE & 0x4);
	//tx_pkt.payload[30]=gpio_pin;
	//printf( " audio=%d\r\n",buf);

    	nrk_close(fd);*/
	  tx_pkt.payload[30]=30;
	  tx_pkt.payload[29]=29;
	  tx_pkt.payload[28]=8;
	  tx_pkt.payload[27]=0;
	  tx_pkt.payload[26]=0;
	  tx_pkt.payload[25]=29;
	  tx_pkt.payload[24]=8;
	  tx_pkt.payload[23]=0;
	  tx_pkt.payload[22]=0;
	  tx_pkt.payload[21]=8;
	  tx_pkt.payload[20]=0;
	  tx_pkt.payload[19]=0;
	  tx_pkt.payload[18]=0;
	  tx_pkt.payload[17]=0;
	  tx_pkt.payload[16]=0;
      tx_pkt.payload[15]=60;
	  tx_pkt.payload[14]=0;
	  tx_pkt.payload[13]=0;
	  tx_pkt.payload[12]=0;
	  tx_pkt.payload[11]=0;
	  tx_pkt.payload[10]=0;
	  tx_pkt.payload[9]=0;
	  tx_pkt.payload[8]=0;
	  tx_pkt.payload[7]=155;
	  tx_pkt.payload[6]=45;
	  tx_pkt.payload[5]=8;
	  tx_pkt.payload[4]=5;
	  tx_pkt.payload[3]=3;
	  tx_pkt.payload[2]=2;

  	 tx_pkt.payload_len=31;
	 tx_pkt.src_mac=mac_address;
	 tx_pkt.dst_mac=0;
	 tx_pkt.type=APP;

    len=pkt_to_buf(&tx_pkt,&tx_buf );

 if(len>0){
    v = tdma_send (&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING);
    if (v == NRK_OK) {
 	 }
 }
 else { 
	nrk_kprintf(PSTR("Pkt tx error\r\n")); 
	nrk_wait_until_next_period(); 
 }
   

	nrk_sw_wdt_update(0);  
  }
}
Exemple #7
0
void tx_task ()
{
  uint8_t j, i, val, cnt;
  int8_t len;
  int8_t v,fd;
  uint8_t buf[2];
  nrk_sig_t tx_done_signal;
  nrk_sig_mask_t ret;
  nrk_time_t r_period;



  // Set Port D.0 as input
  // On the FireFly nodes we use this for motion or syntonistor input
  // It can be interrupt driven, but we don't do this with TDMA since updates are so fast anyway
  DDRD &= ~(0x1);



  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

  while (!tdma_started ())
    nrk_wait_until_next_period ();

 


  while (1) {

    	fd=nrk_open(FIREFLY_SENSOR_BASIC,READ);
    	if(fd==NRK_ERROR) nrk_kprintf(PSTR("Failed to open sensor driver\r\n"));


    	tx_pkt.payload[0] = 1;  // ELEMENTS
   	 tx_pkt.payload[1] = 3;  // Key

	val=nrk_set_status(fd,SENSOR_SELECT,BAT);
	val=nrk_read(fd,&buf,2);
	tx_pkt.payload[2]=buf[1];
	tx_pkt.payload[3]=buf[0];
	//printf( "Task bat=%d",buf);
	val=nrk_set_status(fd,SENSOR_SELECT,LIGHT);
	val=nrk_read(fd,&buf,2);
	tx_pkt.payload[4]=buf[1];
	tx_pkt.payload[5]=buf[0];
	//printf( " light=%d",buf);
	val=nrk_set_status(fd,SENSOR_SELECT,TEMP);
	val=nrk_read(fd,&buf,2);
	tx_pkt.payload[6]=buf[1];
	tx_pkt.payload[7]=buf[0];
	//printf( " temp=%d",buf);
	val=nrk_set_status(fd,SENSOR_SELECT,ACC_X);
	val=nrk_read(fd,&buf,2);
	tx_pkt.payload[8]=buf[1];
	tx_pkt.payload[9]=buf[0];
	//printf( " acc_x=%d",buf);
	val=nrk_set_status(fd,SENSOR_SELECT,ACC_Y);
	val=nrk_read(fd,&buf,2);
	tx_pkt.payload[10]=buf[1];
	tx_pkt.payload[11]=buf[0];
	//printf( " acc_y=%d",buf);
	val=nrk_set_status(fd,SENSOR_SELECT,ACC_Z);
	val=nrk_read(fd,&buf,2);
	tx_pkt.payload[12]=buf[1];
	tx_pkt.payload[13]=buf[0];
	//printf( " acc_z=%d",buf);
	val=nrk_set_status(fd,SENSOR_SELECT,AUDIO_P2P);
	nrk_spin_wait_us(60000);
	val=nrk_read(fd,&buf,2);
	tx_pkt.payload[14]=buf[1];
	tx_pkt.payload[15]=buf[0];
	// GPIO data
	gpio_pin = (PIND & 0x1);
	tx_pkt.payload[16]=gpio_pin;
	//printf( " audio=%d\r\n",buf);
    	tx_pkt.payload_len=17;

    	nrk_close(fd);

    	tx_pkt.src_mac=mac_address;
    	tx_pkt.dst_mac=0;
    	tx_pkt.type=APP;

    len=pkt_to_buf(&tx_pkt,&tx_buf );
    if(len>0)
    {
    v = tdma_send (&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING);
    if (v == NRK_OK) {
      //nrk_kprintf (PSTR ("App Packet Sent\n"));
    }
    } else nrk_wait_until_next_period();

  }



}
Exemple #8
0
void tx_task ()
{
    uint8_t j, i, val, cnt;
    int8_t len;
    int8_t v,fd;
    nrk_sig_mask_t ret;
    nrk_time_t t;



    // Set Port D.0 as input
    // On the FireFly nodes we use this for motion or syntonistor input
    // It can be interrupt driven, but we don't do this with TDMA since updates are so fast anyway



    printf ("tx_task PID=%d\r\n", nrk_get_pid ());

    // setup a software watch dog timer
    t.secs=10;
    t.nano_secs=0;
    nrk_sw_wdt_init(0, &t, NULL);
    nrk_sw_wdt_start(0);

    while (!tdma_started ())
        nrk_wait_until_next_period ();

    // set port G as input for gpio
    nrk_gpio_direction(NRK_PORTG_0,NRK_PIN_INPUT );

    send_ack=0;

    while (1) {
        nrk_led_clr(RED_LED);

        tx_pkt.payload[0] = 1;  // ELEMENTS
        tx_pkt.payload[1] = 4;  // Key
        tx_pkt.payload[2] = nrk_gpio_get(NRK_PORTG_0);  // Key
        tx_pkt.payload_len=3;
        tx_pkt.src_mac=mac_address;
        tx_pkt.dst_mac=0;
        tx_pkt.type=APP;

        if(send_ack==1)
        {
            tx_pkt.type=ACK;
            tx_pkt.payload_len=0;
            send_ack=0;
        }


        len=pkt_to_buf(&tx_pkt,&tx_buf );

        if(len>0)
        {
            v = tdma_send (&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING);
            if (v == NRK_OK) {
            }
        } else {
            nrk_kprintf(PSTR("Pkt tx error\r\n"));
            nrk_wait_until_next_period();
        }


        nrk_sw_wdt_update(0);
    }



}