예제 #1
0
void tosthread_main(void* arg) {
  mutex_init(&data_mutex);
  barrier_reset(&send_barrier, NUM_SENSORS+1);
  barrier_reset(&sense_barrier, NUM_SENSORS+1);
  sensor_data = radioGetPayload(&send_msg, sizeof(sensor_data_t));
  sensor_data->seq_no = 0;

  amRadioStart();
  tosthread_create(&humidity, humidity_thread, NULL, 200);
  tosthread_create(&temperature, temperature_thread, NULL, 200);
  tosthread_create(&total_solar, total_solar_thread, NULL, 200);
  tosthread_create(&photo_active, photo_active_thread, NULL, 200);
  tosthread_create(&send_handler, send_thread, NULL, 200);
}
/*
 * This method is called when a packet is received
 *
 * @param recv_func Function pointer to either serial or radio receive function
 * @p Parameters of environment
 */
void bs_receive(error_t (*recv_func)(message_t*, uint32_t, am_id_t), bs_params_t* p) {
  message_t m;
  BlinkToRadioMsg_t* btrpkt;

  for(;;) {
    if( (*(recv_func))(&m, 0, AM_RECEIVE_FROM_ANY) == SUCCESS ) {
      btrpkt = (BlinkToRadioMsg_t*)radioGetPayload(&m, sizeof(BlinkToRadioMsg_t));
      if( isValidMsgID(btrpkt->msgID) ) { //only accept if new msgID
        messageID = btrpkt->msgID;  //save newest msgID
        if(isValidDestination(btrpkt->destMask)){ //check if current mote is addressed
          setLeds(btrpkt->ledID);
        }
	      mutex_lock( &(p->mutex) );
	        while( enqueueMsg(p, &m) == FAIL )
	          condvar_wait( &(p->condvar), &(p->mutex) );
	      mutex_unlock( &(p->mutex) );
	      condvar_signalAll( &(p->condvar) );
      }
	  }
  }
}