Beispiel #1
0
  EReturn OMPLsolver::Solve(Eigen::VectorXdRefConst q0,
      Eigen::MatrixXd & solution)
  {
    ros::Time startTime = ros::Time::now();
    finishedSolving_ = false;

    ompl::base::ScopedState<> ompl_start_state(state_space_);
    if (ok(
        compound_ ?
            boost::static_pointer_cast<OMPLSE3RNCompoundStateSpace>(
                state_space_)->EigenToOMPLState(q0, ompl_start_state.get()) :
            boost::static_pointer_cast<OMPLStateSpace>(state_space_)->copyToOMPLState(
                ompl_start_state.get(), q0)))
    {
      if (compound_)
        boost::static_pointer_cast<OMPLSE3RNCompoundStateSpace>(state_space_)->setStart(
            q0);
      ompl_simple_setup_->setStartState(ompl_start_state);
      preSolve();
      // Solve here
      ompl::time::point start = ompl::time::now();
      ob::PlannerTerminationCondition ptc =
          ob::timedPlannerTerminationCondition(
              timeout_ - ompl::time::seconds(ompl::time::now() - start));
      registerTerminationCondition(ptc);
      if (ompl_simple_setup_->solve(ptc)
          == ompl::base::PlannerStatus::EXACT_SOLUTION)
      {
        double last_plan_time_ =
            ompl_simple_setup_->getLastPlanComputationTime();
        unregisterTerminationCondition();

        finishedSolving_ = true;

        if (!ompl_simple_setup_->haveSolutionPath()) return FAILURE;
        planning_time_ = ros::Time::now() - startTime;
        getSimplifiedPath(ompl_simple_setup_->getSolutionPath(), solution, ptc);
        planning_time_ = ros::Time::now() - startTime;
        if (saveResults_->data) recordData();
        postSolve();
        succ_cnt_++;
        return SUCCESS;
      }
      else
      {
        finishedSolving_ = true;
        planning_time_ = ros::Time::now() - startTime;
        if (saveResults_->data) recordData();
        postSolve();
        return FAILURE;
      }
    }
    else
    {
      ERROR("Can't copy start state!");
      planning_time_ = ros::Time::now() - startTime;
      return FAILURE;
    }

  }
void idleDisplay() {
	speedControl();
	if (displayMode == 1) {
		verticalBar();
	} else if (displayMode == 2) {
		sineGradient();
	} else if (displayMode == 3) {
		horizontalBar();
	} else if (displayMode == 4) {
		solidCircle();
	}
	if (recordMode == 1) {
		recordData();
	}
	if (runMode == 1) {
		glutPostRedisplay();
	}
}
/* Main glutDisplayLoop; controls the higher level GL functions between the rendering functions. */
void display(void) {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	if (displayMode == 1) {
		verticalBar();
	} else if (displayMode == 2) {
		sineGradient();
	} else if (displayMode == 3) {
		horizontalBar();
	} else if (displayMode == 4) {
		solidCircle();
	}

	if (recordMode == 1) {
		recordData();
	}
	
	glPopMatrix();
	glutSwapBuffers();
}
/* traverse page by page */
void findReadOnlyPages(Mem * mem) {
	int i;
	int pageSize = 4 * 1024; //4k
	int totalPageNumber = mem->mem_size / (4 * 1024); //assume that every page has 4k

	int calledPages[totalPageNumber];
	int dsmPages[totalPageNumber];
	//record virtual address
	unsigned virtualAddrs[totalPageNumber];
	for (i = 0; i < totalPageNumber; i++) {
		calledPages[i] = 0;
		dsmPages[i] = 0;
		virtualAddrs[i] = 0;
	}

	unsigned cr3Pages[100];
	for (i = 0; i < 100; i++) {
		cr3Pages[i] = 0;
	}
	//start address
	unsigned startVirtualAddr = 0x80000000;
	//step 1. kdi
	int kdi_time =0;
	int allPages=0;
	int cluster_index= kdi(startVirtualAddr, mem,pageSize,cr3Pages, &kdi_time, &allPages);

	//step 2. signature generation
	struct timeval earlier;
	struct timeval later;
	if (gettimeofday(&earlier, NULL)) {
		perror("gettimeofday() error");
		exit(1);
	}
	int cr3ClusterNo = 0;
	int cr3PageNo = 0;
	ranges[0].end = 0;

	//find the cluster which has max cr3 number
	int maxcr3Index = findClusterHasMaxCr3(cluster_index, clusters, cr3Pages, &cr3ClusterNo);
	if (maxcr3Index == -1) {
		puts("Cannot find clusters have cr3.");
//		return ;
	}

	unsigned codePageNo = 0;
	newstart = 1;
	unsigned vAddr;
	for (vAddr = clusters[maxcr3Index].start; vAddr < clusters[maxcr3Index].end; vAddr += 0x1000) {
		cr3PageNo++;
		unsigned pAddr = vtop(mem->mem, mem->mem_size, mem->pgd, vAddr);
		if (vAddr == out_pc)
			code_init(mem, vAddr, pageSize, dsmPages, virtualAddrs, 1, calledPages, &codePageNo);
		else
			code_init(mem, vAddr, pageSize, dsmPages, virtualAddrs, 0, calledPages, &codePageNo);
	}
	ranges[range_index].end = clusters[maxcr3Index].end;
	ranges[range_index].len = ranges[range_index].end - ranges[range_index].start;

	//find the max range
	int max_len = 0, max_index = 0;
	for (i = 1; i <= range_index; i++) {
		if (containKernelAddresForRange(ranges[i], cr3Pages) != 0) {
			continue;
		}
		printf("start:%x, end:%x: len:%x kernel\n", ranges[i].start, ranges[i].end, ranges[i].len);
		if (ranges[i].len > max_len) {
			max_index = i;
			max_len = ranges[i].len;
		}
	}

	unsigned pAddr = vtop(mem->mem, mem->mem_size, mem->pgd, ranges[max_index].start);
	int pageIndex = pAddr / pageSize;
	char *page = (char*) ((unsigned) mem->mem + pAddr);
	code_preprocess(mem, page, ranges[max_index].len, 0x1000, ranges + max_index,
			dsmPages + pageIndex);

	printf("step2: cluster: %d\n", range_index);

	//print md5 of pages that can be disassembled
	startVirtualAddr = ranges[max_index].start;
	unsigned disasPageNo = 0;
	unsigned totalPageNo = 0;
	for (; startVirtualAddr <= ranges[max_index].end; startVirtualAddr += 0x1000) {
		totalPageNo++;
		unsigned pAddr = vtop(mem->mem, mem->mem_size, mem->pgd, startVirtualAddr);
		if (pAddr == -1 || pAddr > mem->mem_size)
			continue;

		int pageIndex = pAddr / pageSize;
		if (dsmPages[pageIndex] == 1) {
			unsigned offset = startVirtualAddr - ranges[max_index].start;
			void *startAdress = (void*) ((unsigned) mem->mem + pageIndex * pageSize);
			genMd5WithOffset(startAdress, pageSize, startVirtualAddr, offset);
			disasPageNo++;
		}
	}

	if (gettimeofday(&later, NULL)) {
		perror("gettimeofday() error");
		exit(1);
	}
	int sigGen_time = timeval_diff(NULL, &later, &earlier) / 1000;
	printf("step2: time cost is %d milliseconds\n", sigGen_time);
	float byerate = (float) ranges[max_index].disasBytes / (4096 * disasPageNo);
	printf("Success pages: %u/%u disassembled bytes rate: %f, page rate: %f\n", disasPageNo,
			totalPageNo, (float) ranges[max_index].disasBytes / (4096 * disasPageNo),
			(float) disasPageNo / totalPageNo);

	//record data;
	recordData(allPages, cluster_index, cr3ClusterNo, cr3PageNo, totalPageNo, disasPageNo, byerate);

	//begin match
	int match_time = 0;
	sigMatch(ranges[max_index], mem, pageSize, dsmPages, &match_time);

	//record performance
	recordPerformance(kdi_time, sigGen_time, match_time);
	return;
}
void QmlPreviewRunner::setServerUrl(const QUrl &serverUrl)
{
    recordData(QmlServerUrl, serverUrl);
}
Beispiel #6
0
RecordCut::RecordCut(RDCart *cart,QString cut,bool use_weight,
		     QWidget *parent)
  : QDialog(parent,"",true)
{
  bool valid;
  bool is_track=cart->owner().isEmpty();
  bool allow_modification=rda->user()->modifyCarts()&&is_track;
  bool allow_editing=rda->user()->editAudio()&&is_track;
  rec_use_weighting=use_weight;

  //
  // Fix the Window Size
  //
  setMinimumWidth(sizeHint().width());
  setMaximumWidth(sizeHint().width());
  setMinimumHeight(sizeHint().height());
  setMaximumHeight(sizeHint().height());

  //
  // Generate Fonts
  //
  QFont font=QFont("Helvetica",12,QFont::Bold);
  font.setPixelSize(12);
  QFont small_font=QFont("Helvetica",10,QFont::Bold);
  small_font.setPixelSize(10);
  QFont large_font=QFont("Helvetica",18,QFont::Bold);
  large_font.setPixelSize(18);
  QFont timer_font=QFont("Helvetica",20,QFont::Bold);
  timer_font.setPixelSize(20);
  QFont day_font=QFont("helvetica",10,QFont::Normal);
  day_font.setPixelSize(10);

  setCaption(tr("RDLibrary - Record"));
  rec_cut=new RDCut(cut);
  is_playing=false;
  is_ready=false;
  is_recording=false;
  is_closing=false;
  rec_timer_value=0;

  //
  // Load Audio Assignments
  //
  rec_card_no[0]=rda->libraryConf()->inputCard();
  rec_port_no[0]=rda->libraryConf()->inputPort();
  rec_card_no[1]=rda->libraryConf()->outputCard();
  rec_port_no[1]=rda->libraryConf()->outputPort();
  rec_play_handle=-1;

  //
  // CAE Connection
  //
  connect(rda->cae(),SIGNAL(isConnected(bool)),this,SLOT(initData(bool)));
  connect(rda->cae(),SIGNAL(playing(int)),this,SLOT(playedData(int)));
  connect(rda->cae(),SIGNAL(playStopped(int)),this,SLOT(playStoppedData(int)));
  connect(rda->cae(),SIGNAL(recordLoaded(int,int)),
	  this,SLOT(recordLoadedData(int,int)));
  connect(rda->cae(),SIGNAL(recordUnloaded(int,int,unsigned)),
	  this,SLOT(recordUnloadedData(int,int,unsigned)));
  connect(rda->cae(),SIGNAL(recording(int,int)),this,SLOT(recordedData(int,int)));
  connect(rda->cae(),SIGNAL(recordStopped(int,int)),
	  this,SLOT(recordStoppedData(int,int)));
  connect(rda->cae(),SIGNAL(inputStatusChanged(int,int,bool)),
	  this,SLOT(aesAlarmData(int,int,bool)));

  //
  // Audio Parameters
  //
  rec_card_no[0]=rda->libraryConf()->inputCard();
  rec_card_no[1]=rda->libraryConf()->outputCard();
  rec_name=rec_cut->cutName();
  switch(rec_cut->codingFormat()) {
      case 0:
	rec_format=RDCae::Pcm16;
	break;
	
      case 1:
	rec_format=RDCae::MpegL2;
	break;

      default:
	rec_format=RDCae::Pcm16;
	break;
  }	
  rec_channels=rec_cut->channels();
  rec_samprate=rec_cut->sampleRate();
  rec_bitrate=rec_cut->bitRate();
  rec_length=rec_cut->length();

  //
  // Cut Description
  //
  cut_description_edit=new QLineEdit(this);
  cut_description_edit->setGeometry(10,30,355,19);
  cut_description_edit->setMaxLength(64);
  QLabel *cut_description_label=
    new QLabel(cut_description_edit,tr("&Description"),this);
  cut_description_label->setGeometry(15,11,120,19);
  cut_description_label->setFont(font);
  cut_description_label->setAlignment(Qt::AlignLeft|Qt::TextShowMnemonic);

  //
  // Cut Outcue
  //
  cut_outcue_edit=new QLineEdit(this);
  cut_outcue_edit->setGeometry(10,75,355,19);
  cut_outcue_edit->setMaxLength(64);
  QLabel *cut_outcue_label=new QLabel(cut_outcue_edit,tr("&Outcue"),this);
  cut_outcue_label->setGeometry(15,56,120,19);
  cut_outcue_label->setFont(font);
  cut_outcue_label->setAlignment(Qt::AlignLeft|Qt::TextShowMnemonic);

  //
  // Cut ISCI Code
  //
  cut_isci_edit=new QLineEdit(this);
  cut_isci_edit->setGeometry(10,120,355,19);
  cut_isci_edit->setMaxLength(32);
  QLabel *cut_isci_label=new QLabel(cut_isci_edit,tr("&ISCI Code"),this);
  cut_isci_label->setGeometry(15,101,120,19);
  cut_isci_label->setFont(font);
  cut_isci_label->setAlignment(Qt::AlignLeft|Qt::TextShowMnemonic);

  //
  // Cut Origin
  //
  cut_origin_edit=new QLineEdit(this);
  cut_origin_edit->setGeometry(10,165,190,19);
  cut_origin_edit->setReadOnly(true);
  cut_origin_edit->setMaxLength(64);
  QLabel *cut_origin_label=new QLabel(cut_origin_edit,tr("Origin"),this);
  cut_origin_label->setGeometry(15,146,120,19);
  cut_origin_label->setFont(font);
  cut_origin_label->setAlignment(Qt::AlignLeft|Qt::TextShowMnemonic);

  //
  // Cut ISRC
  //
  cut_isrc_edit=new QLineEdit(this);
  cut_isrc_edit->setGeometry(220,165,145,19);
  cut_isrc_edit->setMaxLength(64);
  QLabel *cut_isrc_label=new QLabel(cut_isrc_edit,tr("ISRC"),this);
  cut_isrc_label->setGeometry(225,146,120,19);
  cut_isrc_label->setFont(font);
  cut_isrc_label->setAlignment(Qt::AlignLeft|Qt::TextShowMnemonic);

  //
  // Cut Weight
  //
  cut_weight_box=new QSpinBox(this);
  cut_weight_box->setGeometry(10,210,61,19);
  cut_weight_box->setRange(0,100);
  QLabel *cut_weight_label=new QLabel(cut_weight_box,tr("Weight"),this);
  cut_weight_label->setGeometry(10,191,61,19);
  cut_weight_label->setFont(font);
  cut_weight_label->setAlignment(Qt::AlignHCenter|Qt::TextShowMnemonic);

  //
  // Cut Play Date Time
  //
  cut_playdate_edit=new QLineEdit(this);
  cut_playdate_edit->setGeometry(100,210,150,19);
  cut_playdate_edit->setReadOnly(true);
  cut_playdate_edit->setMaxLength(64);
  QLabel *cut_playdate_label=
    new QLabel(cut_playdate_edit,tr("Last Played"),this);
  cut_playdate_label->setGeometry(105,191,120,19);
  cut_playdate_label->setFont(font);
  cut_playdate_label->setAlignment(Qt::AlignLeft|Qt::TextShowMnemonic);

  //
  // Cut Play Counter
  //
  cut_playcounter_edit=new QLineEdit(this);
  cut_playcounter_edit->setGeometry(285,210,80,19);
  cut_playcounter_edit->setAlignment(Qt::AlignRight);
  cut_playcounter_edit->setReadOnly(true);
  cut_playcounter_edit->setMaxLength(64);
  QLabel *cut_playcounter_label=
    new QLabel(cut_playcounter_edit,tr("# of Plays"),this);
  cut_playcounter_label->setGeometry(290,191,120,19);
  cut_playcounter_label->setFont(font);
  cut_playcounter_label->setAlignment(Qt::AlignLeft|Qt::TextShowMnemonic);

  //
  // Evergreen Checkbox
  //
  rec_evergreen_box=new QCheckBox(this);
  rec_evergreen_box->setGeometry(10,245,15,15);
  rec_evergreen_label=new QLabel(rec_evergreen_box,tr("Cut is EVERGREEN"),this);
  rec_evergreen_label->setGeometry(30,245,sizeHint().width()-40,15);
  rec_evergreen_label->setFont(font);
  rec_evergreen_label->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
  connect(rec_evergreen_box,SIGNAL(toggled(bool)),
	  this,SLOT(evergreenToggledData(bool)));

  //
  // Cut Air Date Times
  //
  cut_killdatetime_label=new QLabel(tr("Air Date/Time"),this);
  cut_killdatetime_label->setGeometry(50,268,100,19);
  cut_killdatetime_label->setAlignment(Qt::AlignHCenter);
  cut_killdatetime_label->setFont(font);
  Q3ButtonGroup *button_group=new Q3ButtonGroup(this);
  button_group->hide();
  connect(button_group,SIGNAL(clicked(int)),this,SLOT(airDateButtonData(int)));
  cut_startdatetime_enable_button=new QRadioButton(tr("Enabled"),this,
					       "air_date_enabled_button");
  cut_startdatetime_enable_button->setGeometry(40,290,100,20);
  button_group->insert(cut_startdatetime_enable_button,true);
  cut_startdatetime_disable_button=new QRadioButton(tr("Disabled"),this);
  cut_startdatetime_disable_button->setGeometry(40,310,100,20);
  button_group->insert(cut_startdatetime_disable_button,false);

  cut_startdatetime_edit=new Q3DateTimeEdit(this);
  cut_startdatetime_edit->setGeometry(165,289,170,19);
  cut_startdatetime_label=new QLabel(cut_startdatetime_edit,tr("&Start"),this);
  cut_startdatetime_label->setGeometry(120,293,40,12);
  cut_startdatetime_label->setFont(small_font);
  cut_startdatetime_label->setAlignment(Qt::AlignRight|Qt::TextShowMnemonic);

  cut_enddatetime_edit=new Q3DateTimeEdit(this);
  cut_enddatetime_edit->setGeometry(165,309,170,19);
  cut_enddatetime_label=new QLabel(cut_enddatetime_edit,tr("End"),this);
  cut_enddatetime_label->setGeometry(120,313,40,12);
  cut_enddatetime_label->setFont(small_font);
  cut_enddatetime_label->setAlignment(Qt::AlignRight|Qt::TextShowMnemonic);

  //
  // Cut Daypart
  //
  cut_daypart_label=new QLabel(tr("Daypart"),this);
  cut_daypart_label->setGeometry(50,348,65,19);
  cut_daypart_label->setAlignment(Qt::AlignHCenter);
  cut_daypart_label->setFont(font);
  button_group=new Q3ButtonGroup(this);
  button_group->hide();
  connect(button_group,SIGNAL(clicked(int)),this,SLOT(daypartButtonData(int)));
  cut_starttime_enable_button=new QRadioButton(tr("Enabled"),this);
  cut_starttime_enable_button->setGeometry(57,370,100,20);
  button_group->insert(cut_starttime_enable_button,true);
  cut_starttime_disable_button=new QRadioButton(tr("Disabled"),this);
  cut_starttime_disable_button->setGeometry(57,390,100,20);
  button_group->insert(cut_starttime_disable_button,false);

  cut_starttime_edit=new RDTimeEdit(this);
  cut_starttime_edit->setGeometry(222,369,90,19);
  cut_starttime_label=new QLabel(cut_starttime_edit,tr("&Start Time"),this);
  cut_starttime_label->setGeometry(137,373,80,12);
  cut_starttime_label->setFont(small_font);
  cut_starttime_label->setAlignment(Qt::AlignRight|Qt::TextShowMnemonic);

  cut_endtime_edit=new RDTimeEdit(this);
  cut_endtime_edit->setGeometry(222,389,90,19);
  cut_endtime_label=new QLabel(cut_endtime_edit,tr("End Time"),this);
  cut_endtime_label->setGeometry(137,393,80,12);
  cut_endtime_label->setFont(small_font);
  cut_endtime_label->setAlignment(Qt::AlignRight|Qt::TextShowMnemonic);

  //
  // Days of the Week
  //
  rec_dayofweek_label=new QLabel(tr("Day of the Week"),this);
  rec_dayofweek_label->setGeometry(50,428,125,19);
  rec_dayofweek_label->setAlignment(Qt::AlignHCenter);
  rec_dayofweek_label->setFont(font);
  rec_weekpart_button[0]=new QCheckBox(this);
  rec_weekpart_button[0]->setGeometry(40,447,15,15);
  rec_weekpart_label[0]=new QLabel(rec_weekpart_button[0],tr("Monday"),
		   this,"rec_weekpart_label[0]");
  rec_weekpart_label[0]->setGeometry(62,445,80,20);
  rec_weekpart_label[0]->setFont(day_font);
  rec_weekpart_label[0]->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);

  rec_weekpart_button[1]=new QCheckBox(this);
  rec_weekpart_button[1]->setGeometry(120,447,15,15);
  rec_weekpart_label[1]=new QLabel(rec_weekpart_button[1],tr("Tuesday"),this);
  rec_weekpart_label[1]->setGeometry(142,445,80,20);
  rec_weekpart_label[1]->setFont(day_font);
  rec_weekpart_label[1]->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);

  rec_weekpart_button[2]=new QCheckBox(this);
  rec_weekpart_button[2]->setGeometry(200,447,15,15);
  rec_weekpart_label[2]=new QLabel(rec_weekpart_button[2],tr("Wednesday"),this);
  rec_weekpart_label[2]->setGeometry(222,445,80,20);
  rec_weekpart_label[2]->setFont(day_font);
  rec_weekpart_label[2]->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);

  rec_weekpart_button[3]=new QCheckBox(this);
  rec_weekpart_button[3]->setGeometry(80,467,15,15);
  rec_weekpart_label[3]=new QLabel(rec_weekpart_button[3],tr("Thursday"),this);
  rec_weekpart_label[3]->setGeometry(102,465,80,20);
  rec_weekpart_label[3]->setFont(day_font);
  rec_weekpart_label[3]->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);

  rec_weekpart_button[4]=new QCheckBox(this);
  rec_weekpart_button[4]->setGeometry(180,467,15,15);
  rec_weekpart_label[4]=new QLabel(rec_weekpart_button[4],tr("Friday"),this);
  rec_weekpart_label[4]->setGeometry(202,465,80,20);
  rec_weekpart_label[4]->setFont(day_font);
  rec_weekpart_label[4]->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);

  rec_weekpart_button[5]=new QCheckBox(this);
  rec_weekpart_button[5]->setGeometry(80,487,15,15);
  rec_weekpart_label[5]=new QLabel(rec_weekpart_button[5],tr("Saturday"),this);
  rec_weekpart_label[5]->setGeometry(102,485,80,20);
  rec_weekpart_label[5]->setFont(day_font);
  rec_weekpart_label[5]->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);

  rec_weekpart_button[6]=new QCheckBox(this);
  rec_weekpart_button[6]->setGeometry(180,485,15,15);
  rec_weekpart_label[6]=new QLabel(rec_weekpart_button[6],tr("Sunday"),this);
  rec_weekpart_label[6]->setGeometry(202,485,80,20);
  rec_weekpart_label[6]->setFont(day_font);
  rec_weekpart_label[6]->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);

  rec_set_button=new QPushButton(tr("Set All"),this);
  rec_set_button->setGeometry(sizeHint().width()-80,441,55,30);
  rec_set_button->setFont(small_font);
  connect(rec_set_button,SIGNAL(clicked()),this,SLOT(setAllData()));

  rec_clear_button=new QPushButton(tr("Clear All"),this);
  rec_clear_button->setGeometry(sizeHint().width()-80,476,55,30);
  rec_clear_button->setFont(small_font);
  connect(rec_clear_button,SIGNAL(clicked()),this,SLOT(clearAllData()));

  //
  // Audio Meter
  //
  rec_meter=new RDStereoMeter(this);
  rec_meter->setGeometry(20,520,rec_meter->geometry().width(),
			 rec_meter->geometry().height());
  rec_meter->setReference(0);
  rec_meter->setMode(RDSegMeter::Independent);
  QTimer *timer=new QTimer(this);
  connect(timer,SIGNAL(timeout()),this,SLOT(meterData()));
  timer->start(RD_METER_UPDATE_INTERVAL);

  //
  // AES Alarm
  //
  rec_aes_alarm_label=new QLabel(this);
  rec_aes_alarm_label->setGeometry(15,592,110,22);
  rec_aes_alarm_label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
  rec_aes_alarm_label->setFont(large_font);
  rec_aes_alarm_label->setPalette(QColor(Qt::red));
  rec_aes_alarm_label->setText(tr("AES ALARM"));
  rec_aes_alarm_label->hide();

  //
  // Record Timer
  //
  rec_timer=new QTimer(this);
  connect(rec_timer,SIGNAL(timeout()),this,SLOT(recTimerData()));
  rec_timer_label=new QLabel(this);
  rec_timer_label->setGeometry(130,580,120,50);
  rec_timer_label->setFont(timer_font);
  rec_timer_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
  rec_timer_label->setText(RDGetTimeLength(rec_length,true));

  //
  // Channels
  //
  rec_channels_box=new QComboBox(this);
  rec_channels_box->setGeometry(20,635,60,35);
  rec_channels_edit=new QLineEdit(this);
  rec_channels_edit->setGeometry(20,635,60,35);
  QLabel *rec_channels_box_label=
    new QLabel(rec_channels_box,tr("Channels"),this);
  rec_channels_box_label->setGeometry(10,616,80,16);
  rec_channels_box_label->setAlignment(Qt::AlignHCenter);
  rec_channels_box_label->setFont(font);
  connect(rec_channels_box,SIGNAL(activated(int)),
	  this,SLOT(channelsData(int)));

  //
  //  Record Button
  //
  rec_record_button=new RDTransportButton(RDTransportButton::Record,this);
  rec_record_button->setGeometry(100,620,80,50);
  rec_record_button->setDefault(true);
  connect(rec_record_button,SIGNAL(clicked()),this,SLOT(recordData()));

  //
  //  Play Button
  //
  rec_play_button=new RDTransportButton(RDTransportButton::Play,this);
  rec_play_button->setGeometry(190,620,80,50);
  rec_play_button->setDefault(true);
  connect(rec_play_button,SIGNAL(clicked()),this,SLOT(playData()));

  //
  //  Stop Button
  //
  rec_stop_button=new RDTransportButton(RDTransportButton::Stop,this);
  rec_stop_button->setGeometry(280,620,80,50);
  rec_stop_button->setDefault(true);
  rec_stop_button->setState(RDTransportButton::On);
  rec_stop_button->setOnColor(QColor(Qt::red));
  connect(rec_stop_button,SIGNAL(clicked()),this,SLOT(stopData()));

  //
  // Record Mode 
  //
  rec_mode_box=new QComboBox(this);
  rec_mode_box->setGeometry(10,695,100,35);
  QLabel *rec_mode_box_label=new QLabel(rec_mode_box,tr("Record Mode"),this);
  rec_mode_box_label->setGeometry(10,676,100,16);
  rec_mode_box_label->setAlignment(Qt::AlignHCenter);
  rec_mode_box_label->setFont(font);

  //
  // AutoTrim Mode 
  //
  rec_trim_box=new QComboBox(this);
  rec_trim_box->setGeometry(145,695,70,35);
  QLabel *rec_trim_box_label=new QLabel(rec_trim_box,tr("AutoTrim"),this);
  rec_trim_box_label->setGeometry(130,676,100,16);
  rec_trim_box_label->setAlignment(Qt::AlignHCenter);
  rec_trim_box_label->setFont(font);

  //
  //  Close Button
  //
  QPushButton *close_button=new QPushButton(this);
  close_button->setGeometry(sizeHint().width()-90,sizeHint().height()-60,80,50);
  close_button->setDefault(true);
  close_button->setFont(font);
  close_button->setText(tr("&Close"));
  connect(close_button,SIGNAL(clicked()),this,SLOT(closeData()));

  //
  // Populate Fields
  //
  cut_description_edit->setText(rec_cut->description());
  cut_outcue_edit->setText(rec_cut->outcue());
  cut_origin_name=rec_cut->originName();
  cut_origin_datetime=rec_cut->originDatetime(&valid);
  if(valid) {
    cut_origin_edit->setText(cut_origin_name+" - "+
	       	     cut_origin_datetime.toString("M/d/yyyy hh:mm:ss"));
  }
  cut_isci_edit->setText(rec_cut->isci());
  cut_isrc_edit->setText(rec_cut->isrc(RDCut::FormattedIsrc));
  if(use_weight) {
    cut_weight_label->setText(tr("Weight"));
    cut_weight_box->setValue(rec_cut->weight());
  }
  else {
    cut_weight_label->setText(tr("Order"));
    cut_weight_box->setValue(rec_cut->playOrder());
  }
  if(rec_cut->playCounter()>0) {
    cut_playdate_edit->
      setText(rec_cut->lastPlayDatetime(&valid).toString("M/d/yyyy hh:mm:ss"));
  }
  else {
    cut_playdate_edit->setText("Never");
  }
  cut_playcounter_edit->
    setText(QString().sprintf("%d",rec_cut->playCounter()));
  rec_evergreen_box->setChecked(rec_cut->evergreen());
  evergreenToggledData(rec_evergreen_box->isChecked());
  cut_startdatetime_edit->setDateTime(rec_cut->startDatetime(&valid));
  cut_enddatetime_edit->setDateTime(rec_cut->endDatetime(&valid));
  cut_startdatetime_enable_button->setChecked(valid);
  cut_startdatetime_disable_button->setChecked(!valid);
  airDateButtonData(valid);
  cut_starttime_edit->setTime(rec_cut->startDaypart(&valid));
  cut_endtime_edit->setTime(rec_cut->endDaypart(&valid));
  cut_starttime_enable_button->setChecked(valid);
  cut_starttime_disable_button->setChecked(!valid);
  daypartButtonData(valid);
  for(int i=0;i<7;i++) {
    if(rec_cut->weekPart(i+1)) {
      rec_weekpart_button[i]->setChecked(true);
    }
  }
  rec_channels_box->insertItem("1");
  rec_channels_box->insertItem("2");
  rec_channels_box->setCurrentItem(rec_cut->channels()-1);
  rec_channels_edit->setText(QString().sprintf("%d",rec_cut->channels()));
  rec_mode_box->insertItem(tr("Manual"));
  rec_mode_box->insertItem(tr("VOX"));
  switch(rda->libraryConf()->defaultRecordMode()) {
      case RDLibraryConf::Manual:
	rec_mode_box->setCurrentItem(0);
	break;

      case RDLibraryConf::Vox:
	rec_mode_box->setCurrentItem(1);
	break;
  }
  rec_trim_box->insertItem(tr("On"));
  rec_trim_box->insertItem(tr("Off"));
  if(rda->libraryConf()->defaultTrimState()) {
    rec_trim_box->setCurrentItem(0);
  }
  else {
    rec_trim_box->setCurrentItem(1);
  }
  aesAlarmData(rec_card_no[0],rec_port_no[0],
	       rda->cae()->inputStatus(rec_card_no[0],rec_port_no[0]));

  //
  // Set Control Perms
  //
  cut_description_edit->setReadOnly(!allow_modification);
  cut_outcue_edit->setReadOnly(!allow_modification);
  cut_isci_edit->setReadOnly(!allow_modification);
  cut_starttime_edit->setReadOnly(!allow_modification);
  cut_endtime_edit->setReadOnly(!allow_modification);
  if(!allow_modification) {
    cut_weight_box->setRange(cut_weight_box->value(),cut_weight_box->value());
    if(cut_startdatetime_enable_button->isChecked()) {
      cut_startdatetime_edit->dateEdit()->
	setRange(cut_startdatetime_edit->dateEdit()->date(),
		 cut_startdatetime_edit->dateEdit()->date());
      cut_startdatetime_edit->timeEdit()->
	setRange(cut_startdatetime_edit->timeEdit()->time(),
		 cut_startdatetime_edit->timeEdit()->time());
      cut_enddatetime_edit->dateEdit()->
	setRange(cut_enddatetime_edit->dateEdit()->date(),
		 cut_enddatetime_edit->dateEdit()->date());
    }
    if(cut_starttime_enable_button->isChecked()) {
      cut_enddatetime_edit->timeEdit()->
	setRange(cut_enddatetime_edit->timeEdit()->time(),
		 cut_enddatetime_edit->timeEdit()->time());
    }
  }
  rec_evergreen_box->setEnabled(allow_modification);
  if(!allow_modification) {
    cut_startdatetime_enable_button->setDisabled(true);
    cut_startdatetime_disable_button->setDisabled(true);
    cut_starttime_enable_button->setDisabled(true);
    cut_starttime_disable_button->setDisabled(true);
    rec_set_button->setDisabled(true);
    rec_clear_button->setDisabled(true);
  }
  for(int i=0;i<7;i++) {
    rec_weekpart_button[i]->setEnabled(allow_modification);
  }
  rec_record_button->
    setEnabled(allow_editing&&(rec_card_no[0]>=0)&&(rec_port_no[0]>=0));
  rec_mode_box->setEnabled(allow_editing);
  rec_trim_box->setEnabled(allow_editing);
  if(allow_editing) {
    rec_channels_edit->hide();
  }
  else {
    rec_channels_box->hide();
  }
}
Beispiel #7
0
int main() 
{

#if VISUAL
    plotGrid* pg = new plotGrid;
#endif

    // number of reps
    int numBlocks = 128;
    // length of grid
    int Nx = 8;
    int N = Nx * Nx;
    int N2 = 0.5 * N;
    int N4 = 0.5 * N2;
    int N_ALL = N * numBlocks;



    dim3 threadGrid(Nx, Nx);
    curandState *devRands;
    CUDA_CALL(cudaMalloc((void **)&devRands, N_ALL * sizeof(curandState)));

    srand (time(NULL));
    initRands(threadGrid, numBlocks, devRands, rand());


    float* d_wg;
    CUDA_CALL(cudaMalloc((void**)&d_wg, sizeof(float) *  (N_ALL) ));
    int* d_states;
    CUDA_CALL(cudaMalloc((void**)&d_states, sizeof(int) * N_ALL));
    int* d_states2;
    CUDA_CALL(cudaMalloc((void**)&d_states2, sizeof(int) * N_ALL));

    float* d_up;
    CUDA_CALL(cudaMalloc((void**)&d_up, sizeof(float) *  (N + 1) ));

    float* h_up = new float [N+1];

    float* d_down;
    CUDA_CALL(cudaMalloc((void**)&d_down, sizeof(float) *  (N + 1) ));

    float* h_down = new float [N+1];

    int* d_upcount;
    CUDA_CALL(cudaMalloc((void**)&d_upcount, sizeof(int) *  (N + 1) ));

    int* h_upcount = new int [N+1];

    int* d_downcount;
    CUDA_CALL(cudaMalloc((void**)&d_downcount, sizeof(int) *  (N + 1) ));

    int* h_downcount = new int [N+1];



    int* d_blockTotals;
    CUDA_CALL(cudaMalloc((void**)&d_blockTotals, sizeof(int) * numBlocks));

    float* h_wg = new float [N_ALL];
    int* h_states = new int[N_ALL];
    int* h_blockTotals = new int[numBlocks];
    int* h_blockTimes = new int[numBlocks];
    int wgCount = 1;

    const unsigned int shape[] = {N+1,2};

    float* results = new float[(N+1)*2];
    for (int i=0;i<(N+1)*2;i++)
       results[i]=0.0f;



    for (int G=0;G<wgCount;G++)
    {
        float wg = 0.25;//5 + 0.2 * float(G);
        for (int i=0;i<N_ALL;i++)
        {
            h_wg[i]=wg;
            float unum =rand()/double(RAND_MAX);
   //         cout<<unum<<endl;
 //           if (unum<0.2345)
 //               h_wg[i]+=0.833;
        }
        CUDA_CALL(cudaMemcpy(d_wg, h_wg, (N_ALL) * sizeof(float), cudaMemcpyHostToDevice));


        for (int b=0;b<numBlocks;b++)
            h_blockTimes[b] = -1;
        int maxTime = 100000;
        int checkTime = 100;
        float sw = 1.0f;

        char fileName[30];
        sprintf(fileName, "potential%d-%d.npy", int(10*wg),int(100.0*sw));
//        cout<<fileName<<endl;

        CUDA_CALL(cudaMemset (d_states, 0, sizeof(int) * (N_ALL)));
        CUDA_CALL(cudaMemset (d_blockTotals, 0, sizeof(int) * (numBlocks)));
        CUDA_CALL(cudaMemset (d_up, 0, sizeof(float) * (N + 1)));
        CUDA_CALL(cudaMemset (d_down, 0, sizeof(float) * (N + 1)));
        CUDA_CALL(cudaMemset (d_upcount, 0, sizeof(int) * (N + 1)));
        CUDA_CALL(cudaMemset (d_downcount, 0, sizeof(int) * (N + 1)));





        for (int t=0;t<maxTime;t++)
        {
            
            advanceTimestep(threadGrid, numBlocks, devRands, d_wg, d_states, Nx, sw, t);
            recordData(threadGrid, numBlocks, d_states, d_states2, Nx, d_up, d_down, d_upcount, d_downcount, t);
            /*
            CUDA_CALL(cudaMemcpy(h_states, d_states, (N_ALL) * sizeof(int), cudaMemcpyDeviceToHost));
            int countUp = 0;
            for (int i=0;i<N_ALL;i++)
                if (h_states[i]>0)
                    countUp++;
            cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<countUp<<endl;
//            */
#if VISUAL
            CUDA_CALL(cudaMemcpy(h_states, d_states, (N_ALL) * sizeof(int), cudaMemcpyDeviceToHost));
            pg->draw(Nx, h_states);
#endif
            if (t%checkTime == 0 ) 
            {
                countStates(N, numBlocks, d_states, d_blockTotals, N_ALL);
                cout<<t<<" check"<<endl;

                CUDA_CALL(cudaMemcpy(h_blockTotals, d_blockTotals, (numBlocks) * sizeof(int), cudaMemcpyDeviceToHost));
                bool allDone = true;
                for (int b=0;b<numBlocks;b++)
                {
                    if (h_blockTotals[b]>0.75*N)
                    {
    //                    cout<<"block total : "<<h_blockTotals[b]<<endl;
                        if (h_blockTimes[b]<0)
                            h_blockTimes[b]=t;
                    }
                    else
                        allDone = false;
                }
                if (allDone)
                {
                    for (int b=0;b<numBlocks;b++)
                        h_blockTimes[b] = -1;
                    CUDA_CALL(cudaMemset (d_states, 0, sizeof(int) * (N_ALL)));
                } 
            }

        }
        CUDA_CALL(cudaMemcpy(h_up, d_up, (N + 1) * sizeof(float), cudaMemcpyDeviceToHost));
        CUDA_CALL(cudaMemcpy(h_down, d_down, (N + 1) * sizeof(float), cudaMemcpyDeviceToHost));
        CUDA_CALL(cudaMemcpy(h_upcount, d_upcount, (N + 1) * sizeof(int), cudaMemcpyDeviceToHost));

        for (int i=0;i<N+1;i++)
        {
            results[2*i]=h_up[i];
            results[2*i+1]=h_down[i];
            cout<<i/float(N)<<" : "<<h_up[i]<<" : "<<h_down[i]<<" : "<<h_upcount[i]<<endl;
        }

        cnpy::npy_save(fileName,results,shape,2,"w");
    }
    return 0;
}
bool Authenticator::loadStore() {
    KexiDB::TableSchema* table = KexiWebForms::Model::gConnection->tableSchema("kexi__users");

    if (!table) {
        // the table doesn't exist, create it (programmatically)
        kDebug() << "kexi__users table does not exist, creating it";
        KexiDB::TableSchema* kexi__users = new KexiDB::TableSchema("kexi__users");
        kexi__users->setNative(true);
        KexiDB::Field* id = new KexiDB::Field("u_id", KexiDB::Field::Integer);
        id->setAutoIncrement(true);
        id->setPrimaryKey(true);
        kexi__users->insertField(0, id);
        KexiDB::Field* name = new KexiDB::Field("u_name", KexiDB::Field::Text);
        kexi__users->insertField(1, name);
        KexiDB::Field* password = new KexiDB::Field("u_password", KexiDB::Field::Text);
        kexi__users->insertField(2, password);
        KexiDB::Field* create = new KexiDB::Field("u_create", KexiDB::Field::Boolean);
        kexi__users->insertField(3, create);
        KexiDB::Field* read = new KexiDB::Field("u_read", KexiDB::Field::Boolean);
        kexi__users->insertField(4, read);
        KexiDB::Field* update = new KexiDB::Field("u_update", KexiDB::Field::Boolean);
        kexi__users->insertField(5, update);
        KexiDB::Field* fdelete = new KexiDB::Field("u_delete", KexiDB::Field::Boolean);
        kexi__users->insertField(6, fdelete);
        KexiDB::Field* fquery = new KexiDB::Field("u_query", KexiDB::Field::Boolean);
        kexi__users->insertField(7, fquery);

        if (!KexiWebForms::Model::gConnection->createTable(kexi__users)) {
            // Table was not created, fatal error
            kError() << "Failed to create system table kexi__users";
            kError() << "Error string: " << KexiWebForms::Model::gConnection->errorMsg();
            delete kexi__users;
            return false;
        } else {
            // Table was created, create two standard accounts
            KexiDB::QuerySchema query(*kexi__users);
            KexiDB::Cursor* cursor = KexiWebForms::Model::gConnection->prepareQuery(query);
            KexiDB::RecordData recordData(kexi__users->fieldCount());
            KexiDB::RowEditBuffer editBuffer(true);
            // root
            QVariant vtrue(true);
            QVariant vfalse(false);
            kDebug() << "Creating user root with password root";
            QVariant user_root("root");
            QVariant password_root("root");
            editBuffer.insert(*query.columnInfo(name->name()), user_root);
            editBuffer.insert(*query.columnInfo(password->name()), password_root);
            editBuffer.insert(*query.columnInfo(create->name()), vtrue);
            editBuffer.insert(*query.columnInfo(read->name()), vtrue);
            editBuffer.insert(*query.columnInfo(update->name()), vtrue);
            editBuffer.insert(*query.columnInfo(fdelete->name()), vtrue);
            editBuffer.insert(*query.columnInfo(fquery->name()), vtrue);
            kDebug() << "Registering user within database";
            if (cursor->insertRow(recordData, editBuffer)) {
                kDebug() << "Succeeded";
                User* u = new User("root", "root");
                m_users.append(*u);
                m_auth->addUser(u->name().toUtf8().constData(), u->password().toUtf8().constData());
            } else {
                kError() << "An error occurred";
                return false;
            }

            // anonymous
            kDebug() << "Creating user anonymous with password guest";
            QVariant user_anonymous("anonymous");
            QVariant password_anonymous("guest");
            editBuffer.insert(*query.columnInfo(name->name()), user_anonymous);
            editBuffer.insert(*query.columnInfo(password->name()), password_anonymous);
            editBuffer.insert(*query.columnInfo(create->name()), vfalse);
            editBuffer.insert(*query.columnInfo(read->name()), vfalse);
            editBuffer.insert(*query.columnInfo(update->name()), vfalse);
            editBuffer.insert(*query.columnInfo(fdelete->name()), vfalse);
            editBuffer.insert(*query.columnInfo(fquery->name()), vfalse);
            if (cursor->insertRow(recordData, editBuffer)) {
                kDebug() << "Succeeded";
                User* u = new User("anonymous", "guest");
                m_users.append(*u);
                m_auth->addUser(u->name().toUtf8().constData(), u->password().toUtf8().constData());
            } else {
                kError() << "An error occurred";
                return false;
            }
            KexiWebForms::Model::gConnection->deleteCursor(cursor);
        }
    } else {
        // load stuff from the store, create appropriated User objects, store them within
        // Authenticator
        KexiDB::QuerySchema query(*table);
        KexiDB::Cursor* cursor = KexiWebForms::Model::gConnection->executeQuery(query);
        while (cursor->moveNext()) {
            // Skip id
            QString* username = new QString(cursor->value(1).toString());
            QString* password = new QString(cursor->value(2).toString());
            QList<Permission>* perms = new QList<Permission>;

            if (cursor->value(3).toBool()) perms->append(CREATE);
            if (cursor->value(4).toBool()) perms->append(READ);
            if (cursor->value(5).toBool()) perms->append(UPDATE);
            if (cursor->value(6).toBool()) perms->append(DELETE);
            if (cursor->value(7).toBool()) perms->append(QUERY);

            User* u = new User(*username, *password, *perms);
            m_users.append(*u);
            m_auth->addUser(u->name().toUtf8().constData(), u->password().toUtf8().constData());
            kDebug() << "Loaded user " << *username << " from store";
        }
    }

    return true;
}