//function to call periodically to refresh the values red by the radar void radarRefresh(){ unsigned long time=millis(); static unsigned long time_prev_rad=0; static int pos_rad = RAD_POS_MIN, etat_rad = 0,sens_rad=1; // gestion radar if(etat_rad) { if((time-time_prev_rad)>=RAD_TIMER_1) { if ((time-time_prev_rad)>=RAD_TIMER_1+RAD_TIMER_1/2) time_prev_rad=time-RAD_TIMER_1; //to avoid problems due to long loop time_prev_rad = time_prev_rad + RAD_TIMER_1; // get the ranges for(int nb = 0; nb<RAD_NB_SENSORS; nb++) { C_rad[ (pos_rad-RAD_POS_MIN)/RAD_POS_INC + (RAD_NB_SENSORS-1-nb)*RAD_NB_POS] = getRangeResult(nb); } if(servoRad.attached()){ //move the servo if(sens_rad && pos_rad < RAD_POS_MAX) { pos_rad = pos_rad + RAD_POS_INC; if(pos_rad == RAD_POS_MAX) sens_rad = 0; } else if(!sens_rad && pos_rad > RAD_POS_MIN) { pos_rad = pos_rad - RAD_POS_INC; if(pos_rad == RAD_POS_MIN) sens_rad = 1; } servoRad.write(pos_rad); } etat_rad = 0; #ifdef DEBUG_RADAR int i; for (i=0;i<RAD_NB_PTS;i++) { Serial.print(C_rad[i]); Serial.print("|"); Serial.print(C_rad_limit[i]); Serial.print(",\t"); } Serial.println(" "); #endif } } else { if((time-time_prev_rad)>=RAD_TIMER_2) { if ((time-time_prev_rad)>=RAD_TIMER_2+(RAD_TIMER_2)/2) time_prev_rad=time-RAD_TIMER_2; //to avoid problems due to long loop time_prev_rad = time_prev_rad + RAD_TIMER_2; // start the ranges for(int nb = 0; nb<RAD_NB_SENSORS; nb++) { startRange(nb); } etat_rad = 1; } } }
void node_mgr::handle_split(const string& key) { /* Find interval_db that contains the split point */ // Does not lock the db. interval_db* db = findIntervalDb(&key, NOLOCK); if (db != NULL) { fawn::FawnDS<FawnDS_Flash>* h = db->h; // Insert new interval file at the end of list // Current DB will always be found until we change its range. // Don't need lock on h to read startID because no one else should be splitting this range. const DBID *d_start_id = h->getStartID(); string startRange((char*)d_start_id->const_data(), DBID_LENGTH); interval_db* new_interval_db = init_interval_db(key, db->vid, startRange); delete d_start_id; if (new_interval_db != NULL) { // update interval list insertIntervalFile(new_interval_db); cout << "Beginning split" << endl; stat_file << "Beginning split" << endl; bool success = h->Split(new_interval_db->h, &(db->dbLock)); // h's lock is held if (success == true) { /* Update split Interval_DB with new start id */ DBID new_start_id(key); db->h->setStartID(new_start_id); db->splitPoint = ""; // We hold the lock on db, and we don't need to hold the lock // on new_interval_db because no puts have been directed to it. while (!db->seq_msg_queue_tmp.empty()) { new_interval_db->seq_msg_queue.push_back(db->seq_msg_queue_tmp.front()); db->seq_msg_queue_tmp.pop_front(); } // unlock h's dblock pthread_rwlock_unlock(&(db->dbLock)); cout << "Ending split" << endl; stat_file << "Ending split" << endl; } else { cerr << "Error: split failed in splitConsumer." << endl; } } else { cerr << "Unable to allocate new interval file in splitConsumer." << endl; } } else { /* Error, hash not found */ cerr << "Error: key does not lie in the DB ranges owned by this node!" << endl; } }