示例#1
0
/**
 * Verifies the title has a valid checksum
 * @param title title and checksum
 * @param len   the length of the title to read/checksum
 * @return true iff the title is valid
 * @note the title (incl. checksum) has to be at least 41/49 (HEADER_SIZE) bytes long!
 */
static bool VerifyOldNameChecksum(char *title, uint len)
{
	uint16 sum = 0;
	for (uint i = 0; i < len - 2; i++) {
		sum += title[i];
		sum = ROL(sum, 1);
	}

	sum ^= 0xAAAA; // computed checksum

	uint16 sum2 = title[len - 2]; // checksum in file
	SB(sum2, 8, 8, title[len - 1]);

	return sum == sum2;
}
示例#2
0
libmaus2::network::LogReceiver::ControlDescriptor libmaus2::network::LogReceiver::getControlDescriptor()
{
	::libmaus2::network::SocketBase::shared_ptr_type SBS;
	uint64_t id = 0;
	int fd = -1;
	std::string hostname;
	
	try
	{
		// receiver id
		::libmaus2::network::SocketBase SB(SPpass->childGet());
		id = SB.readSingle<uint64_t>();
		hostname = SB.readString();
		SB.releaseFD();
			
		fd = SPpass->receiveFd();
			
		if ( fd < 0 )
		{
			::libmaus2::exception::LibMausException se;
			se.getStream() << "Received invalid negative file descriptor " << fd << " for id " << id << std::endl;
			se.finish();
			throw se;
		}
			
		SBS = ::libmaus2::network::SocketBase::shared_ptr_type(new ::libmaus2::network::SocketBase(fd));
		fd = -1;
	}
	catch(...)
	{
		if ( fd != -1 )
		{
			::close(fd);
			fd = -1;
		}
		passsem.assureNonZero();
		throw;
	}

	// std::cerr << "*Got hostname " << hostname << std::endl;

	passsem.assureNonZero();	
	return ControlDescriptor(SBS,id,hostname);
}
示例#3
0
	void var_SB_izo::getdXdX0(const vector<double> &X, Matrix &Fi)
	{
		SB sv = SB(X);

		double r = sv.q.getAbs();
		Matrix dydY = sv.dydY();

		Matrix dYdY0(Niter, Niter);
		dYdY0.setFromVec(Niter, X);
		Matrix dtdY0(1, Niter);
		dtdY0.setFromVec(121, X);

		vector<double> F(N);

		force(0, X, F);
		Matrix G(Niter, 1);
		G.setFromVec(0, F);

		//according to equation 14  in (Shefer V.A., 2005)
		Fi = dydY*(dYdY0 - (1 / r)*G *dtdY0)*dY0dy0;

	};
示例#4
0
cv::Mat L0Smoothing(cv::Mat Im, double lambda = 0.02, double kappa = 2.0)
{
	cv::Mat out(Im.rows, Im.cols, CV_32FC3);
	Matrix SR(Im.rows, Im.cols);
	Matrix SG(Im.rows, Im.cols);
	Matrix SB(Im.rows, Im.cols);
	for(int j = 0; j < Im.cols; ++j)
	{
		for(int i = 0; i < Im.rows; ++i)
		{
			cv::Vec3f& v1 = Im.at<cv::Vec3f>(i, j);
			SR(i, j) = v1[0];
			SG(i, j) = v1[1];
			SB(i, j) = v1[2];
		}
	}
	double betamax = 1e5;
	Matrix fx(1, 2);
	fx(0, 0) = 1;
	fx(0, 1) = -1;
	Matrix fy(2, 1);
	fy(0, 0) = 1;
	fy(1, 0) = -1;
	Matrix sizeI2D(1, 2);
	sizeI2D(0, 0) = Im.rows;
	sizeI2D(0, 1) = Im.cols;
	Matrix2 otfFx = psf2otf(fx, sizeI2D);
	Matrix2 otfFy = psf2otf(fy, sizeI2D);
	Matrix otfFx2 = MatAbsPow2(otfFx);
	Matrix otfFy2 = MatAbsPow2(otfFy);
	Matrix2 Normin1R = fft2(SR);
	Matrix2 Normin1G = fft2(SG);
	Matrix2 Normin1B = fft2(SB);
	Matrix Denormin2 = otfFx2 + otfFy2;
	float beta = 2 * lambda;
	int count = 1;
	while(beta < betamax)
	{
		float lb = lambda / beta;
		Matrix Denormin = beta * Denormin2;
		MatAdd(Denormin, 1);
		Matrix hR = Matdiff(SR, 2);
		Matrix vR = Matdiff(SR, 1);
		Matrix hG = Matdiff(SG, 2);
		Matrix vG = Matdiff(SG, 1);
		Matrix hB = Matdiff(SB, 2);
		Matrix vB = Matdiff(SB, 1);
		Matrix Pos2Sum = MatPow2(hR) + MatPow2(vR) +
						 MatPow2(hG) + MatPow2(vG) +
						 MatPow2(hB) + MatPow2(vB);
		for(int j = 0; j < Im.cols; ++j)
		{
			for(int i = 0; i < Im.rows; ++i)
			{
				if(Pos2Sum(i, j) < lb)
				{
					hR(i, j) = 0;
					vR(i, j) = 0;
					hG(i, j) = 0;
					vG(i, j) = 0;
					hB(i, j) = 0;
					vB(i, j) = 0;
				}
			}
		}
		Matrix Normin2R = Matdiffinv(hR, 2) + Matdiffinv(vR, 1);
		Matrix Normin2G = Matdiffinv(hG, 2) + Matdiffinv(vG, 1);
		Matrix Normin2B = Matdiffinv(hB, 2) + Matdiffinv(vB, 1);
		Matrix2 FSR = (Normin1R + fft2(Normin2R) * beta) / Denormin;
		Matrix2 FSG = (Normin1G + fft2(Normin2G) * beta) / Denormin;
		Matrix2 FSB = (Normin1B + fft2(Normin2B) * beta) / Denormin;
		SR = ifft2(FSR);
		SG = ifft2(FSG);
		SB = ifft2(FSB);
		beta = beta * kappa;
		printf(".");
		for(uint i = 0; i < out.rows; ++i)
		{
			for(uint j = 0; j < out.cols; ++j)
			{
				cv::Vec3f& v1 = out.at<cv::Vec3f>(i, j);
				v1[0] = SR(i, j);
				v1[1] = SG(i, j);
				v1[2] = SB(i, j);
			}
		}
		cv::imshow("out", out);
		char filename[100];
		sprintf(filename, "o%02d.png", count++);
		cv::Mat theout;
		out.convertTo(theout, CV_8UC3, 255);
		cv::imwrite(filename, theout);
		cv::waitKey(1);
	}
	for(uint j = 0; j < out.cols; ++j)
	{
		for(uint i = 0; i < out.rows; ++i)
		{
			cv::Vec3f& v1 = out.at<cv::Vec3f>(i, j);
			v1[0] = SR(i, j);
			v1[1] = SG(i, j);
			v1[2] = SB(i, j);
		}
	}
	return out;
}
示例#5
0
/**
 * Perform all steps to upgrade from the old station buoys to the new version
 * that uses waypoints. This includes some old saveload mechanics.
 */
void MoveBuoysToWaypoints()
{
	/* Buoy orders become waypoint orders */
	OrderList *ol;
	FOR_ALL_ORDER_LISTS(ol) {
		VehicleType vt = ol->GetFirstSharedVehicle()->type;
		if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;

		for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o);
	}

	Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		VehicleType vt = v->type;
		if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;

		UpdateWaypointOrder(&v->current_order);
	}

	/* Now make the stations waypoints */
	Station *st;
	FOR_ALL_STATIONS(st) {
		if ((st->had_vehicle_of_type & HVOT_WAYPOINT) == 0) continue;

		StationID index    = st->index;
		TileIndex xy       = st->xy;
		Town *town         = st->town;
		StringID string_id = st->string_id;
		char *name         = st->name;
		st->name           = NULL;
		Date build_date    = st->build_date;
		/* TTDPatch could use "buoys with rail station" for rail waypoints */
		bool train         = st->train_station.tile != INVALID_TILE;
		TileArea train_st  = st->train_station;

		/* Delete the station, so we can make it a real waypoint. */
		delete st;

		/* Stations and waypoints are in the same pool, so if a station
		 * is deleted there must be place for a Waypoint. */
		assert(Waypoint::CanAllocateItem());
		Waypoint *wp   = new (index) Waypoint(xy);
		wp->town       = town;
		wp->string_id  = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
		wp->name       = name;
		wp->delete_ctr = 0; // Just reset delete counter for once.
		wp->build_date = build_date;
		wp->owner      = train ? GetTileOwner(xy) : OWNER_NONE;

		if (IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->town_cn = string_id - STR_SV_STNAME_BUOY;

		if (train) {
			/* When we make a rail waypoint of the station, convert the map as well. */
			TILE_AREA_LOOP(t, train_st) {
				if (!IsTileType(t, MP_STATION) || GetStationIndex(t) != index) continue;

				SB(_me[t].m6, 3, 3, STATION_WAYPOINT);
				wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
			}

			wp->train_station = train_st;
			wp->facilities |= FACIL_TRAIN;
		} else if (IsBuoyTile(xy) && GetStationIndex(xy) == index) {
			wp->rect.BeforeAddTile(xy, StationRect::ADD_FORCE);
			wp->facilities |= FACIL_DOCK;
		}
	}
示例#6
0
void model_parameters::move_grow_die(void)
{
	dvariable tB;
	for(int i=2;i<=ntstp;i++)
	{
		//if(i>12)exit(1);
		switch (indmonth(i)) {
            case 1:           	
            	Nage(i)(sage) = (So*SB(i-nmon)/(1.+beta*SB(i-nmon)))*mfexp(wt(indyr(i))*err);
            	for(int a = sage+1;a<=nage;a++)
            	{
            		Nage(i)(a) = Nage(i-1)(a-1)*mfexp(-(m+q*Effage(i-1)(a-1)*va(a-1))/12);
            	}
            	break;
            default: 
            	Nage(i) = elem_prod(Nage(i-1),mfexp(-(m+q*elem_prod(Effage(i-1),va))/12));
            	break;
        }
		VulB(i) = elem_prod(elem_prod(Nage(i),va),wa);
		SB(i) = elem_prod(Nage(i),fa)*wa/2;
		maxPos.initialize();
		tB = Nage(i)*wa;
		calcmaxpos(tB);
		//cout<<"maxPos "<<maxPos<<endl;
		varPos = maxPos*cvPos;
		PosX(i) = minPos + (maxPos - minPos) * (0.5+0.5*sin(indmonth(i)*PI/6 - mo*PI/6)); 
		VBarea(i,sarea) = VulB(i)* (cnorm(areas(sarea)+0.5,PosX(i),varPos));
		for(int r = sarea+1;r <= narea;r++)
		{
			VBarea(i)(r) = VulB(i)* (cnorm(areas(r)+0.5,PosX(i),varPos)-cnorm(areas(r)-0.5,PosX(i),varPos));
			NAreaAge(i)(r) = elem_prod(Nage(i)(sage,nage),(cnorm(areas(r)+0.5,PosX(i),varPos)-cnorm(areas(r)-0.5,PosX(i),varPos)));
		}	
		//VBarea(i,narea) = VulB(i)* (1.0-cnorm(areas(narea)-0.5,PosX(i),varPos));
		NationVulB(i,1) = sum(VBarea(i)(sarea,sarea+nationareas(1)-1)); 
		NationVulB(i,2) = sum(VBarea(i)(sarea+nationareas(1),narea)); 
		dvar_vector tmp1(sarea,narea);
		dvar_vector tmp2(sarea,narea);
		for(int rr= sarea; rr<=narea; rr++)
		{
			tmp1(rr)= VBarea(i)(rr)/ (NationVulB(i)(indnatarea(rr)) + 1);
			tmp2(rr) = tmp1(rr)*TotEffyear(indnatarea(rr))(indyr(i));
			Effarea(i)(rr) = tmp2(rr)*TotEffmonth(indnatarea(rr))(indmonth(i));
		}
		for(int a = sage; a<=nage;a++)
		{
			dvar_vector propVBarea(sarea,narea);
			for(int rr =sarea; rr<=narea; rr++)
			{
				propVBarea(rr) = (cnorm(areas(rr)+0.5,PosX(i),varPos)-cnorm(areas(rr)-0.5,PosX(i),varPos))(a-sage+1);
				EffNatAge(indnatarea(rr))(i)(sage-2) = i;
				EffNatAge(indnatarea(rr))(i)(sage-1) = indnatarea(rr);
				EffNatAge(indnatarea(rr))(i)(a) += Effarea(i)(rr)* propVBarea(rr);
			}
			//cout<<"propVBarea "<<propVBarea<<endl;
			//cout<<"Effarea(1) "<<Effarea(1)<<endl;
			Effage(i)(a) = Effarea(i)*propVBarea;
		}
		for(int r = sarea+1;r <= narea-1;r++)
		{
			for(int a = sage; a<=nage;a++)
			{
				CatchAreaAge(i)(r)(a) = q*Effarea(i)(r)*va(a)/(q*Effarea(i)(r)*va(a)+m)*(1-mfexp(-(q*Effarea(i)(r)*va(a)+m)))*NAreaAge(i)(r)(a);
				CatchNatAge(i)(indnatarea(r))(a)+= CatchAreaAge(i)(r)(a);
			}
		}
	}
}
示例#7
0
void PreferencesDialog::syncSettings()
{
	QSettings s;

	// Graph
	s.beginGroup("TecDetails");

	SB("phegraph", ui.phe);
	SB("po2graph", ui.po2);
	SB("pn2graph", ui.pn2);
	s.setValue("phethreshold", ui.pheThreshold->value());
	s.setValue("po2threshold", ui.po2Threshold->value());
	s.setValue("pn2threshold", ui.pn2Threshold->value());
	SB("ead", ui.ead_end_eadd);
	SB("mod", ui.mod);
	s.setValue("modppO2", ui.maxppo2->value());
	SB("dcceiling", ui.dc_reported_ceiling);
	SB("redceiling", ui.red_ceiling);
	SB("calcceiling", ui.calculated_ceiling);
	SB("calcceiling3m", ui.increment_3m);
	SB("calcndltts", ui.calc_ndl_tts);
	SB("calcalltissues", ui.all_tissues);
	s.setValue("gflow", ui.gflow->value());
	s.setValue("gfhigh", ui.gfhigh->value());
	SB("gf_low_at_maxdepth", ui.gf_low_at_maxdepth);
	SB("show_sac", ui.show_sac);
	s.endGroup();

	// Units
	s.beginGroup("Units");
	QString unitSystem = ui.metric->isChecked() ? "metric" : (ui.imperial->isChecked() ? "imperial" : "personal");
	s.setValue("unit_system", unitSystem);
	s.setValue("temperature", ui.fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS);
	s.setValue("length", ui.feet->isChecked() ? units::FEET : units::METERS);
	s.setValue("pressure", ui.psi->isChecked() ? units::PSI : units::BAR);
	s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER);
	s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG);
	s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS);
	s.endGroup();
	// Defaults
	s.beginGroup("GeneralSettings");
	s.setValue("default_filename", ui.defaultfilename->text());
	s.setValue("default_cylinder", ui.default_cylinder->currentText());
	s.endGroup();

	s.beginGroup("Display");
	s.value("divelist_font", ui.font->font().family());
	s.value("font_size", ui.fontsize->value());
	s.value("displayinvalid", ui.displayinvalid->isChecked());
	s.endGroup();
	s.sync();

	emit settingsChanged();
}
示例#8
0
void NormalMode(void){
	SB(0x0C, 0, 1);			//Normal display
}
示例#9
0
void InvertMode(void){
	SB(0x0D, 0, 1);			//Normal display
}
示例#10
0
	void var_SB_izo::force(const double Ti, const vector<double> &X, vector<double> & F)
	{
		SB sv = SB(X);

		double r = sv.q.getAbs();
		double r2 = r*r;
		triple v3d = sv.p / r;

		//acceleration and acceleration partials
		ForceIzo f_(sv.t, sv.q, v3d);
		triple f = f_.force_pert();
		Matrix ddFdy = f_.get_ddFdsv();

		Matrix F3d(f);
		Matrix  Q(sv.q), P(sv.p), A(sv.a);

		//Vector 2 Matrix
		Matrix dYdY0(11, 11), dqdY0(3, 11), dpdY0(3, 11), dadY0(3, 11), dhdY0(1, 11);

		dYdY0.setFromVec(11, X);
		dqdY0.setFromVec(11, X);
		dpdY0.setFromVec(44, X);
		dadY0.setFromVec(77, X);
		dhdY0.setFromVec(110, X);

		Matrix E3(3, 3);
		E3.Identy();

		Matrix dydY = sv.dydY();
		Matrix dFdY0 = ddFdy*dydY*dYdY0;

		//Equations 0-10
#pragma region Equations 0-10

		triple dpds = (2.0*sv.h)*sv.q - sv.a + r2*f;
		double dhds = sv.p*f;
		double qtf = sv.q*f;
		double qtp = sv.q*sv.p;
		triple dads = (2.0*dhds)*sv.q - (qtf)*sv.p - qtp*f;

		for (int i = 0; i < 3; i++)
		{
			F[i] = sv.p[i];
			F[i + 3] = dpds[i];
			F[i + 6] = dads[i];
		}
		F[9] = dhds;
		F[10] = r;
#pragma endregion

		Matrix fqt = triple::xxt(f, sv.q);
		Matrix q_pt = triple::xxt(sv.q, sv.p);

		Matrix D = sv.h*E3 + fqt;
		D *= 2.0;
		Matrix D1 = (2.0*dhds)*E3 - triple::xxt(sv.p, f) - triple::xxt(f, sv.p);
		Matrix D2 = 2.0*triple::xxt(sv.q, f) - qtf*E3 - fqt;
		Matrix D3 = 2.0*q_pt - q_pt.Transpose() - qtp*E3;

		//Equations 11-43
		//Matrix ddqdY0 = dpdY0;

		//Equations 44-76
		Matrix ddpdY0 = D*dqdY0 + 2.0*Q*dhdY0 - dadY0 + r2*dFdY0;

		//Equations 77-109
		Matrix ddadY0 = D1*dqdY0 + D2*dpdY0 + D3*dFdY0;

		//Equations 110-120
		Matrix ddhdY0 = F3d.Transpose()*dpdY0 + P.Transpose()*dFdY0;

		//Equations 120-131
		Matrix ddtdY0 = (Q.Transpose()*dqdY0) / r;

		dpdY0.copyToVec(11, F);
		ddpdY0.copyToVec(44, F);
		ddadY0.copyToVec(77, F);
		ddhdY0.copyToVec(110, F);
		ddtdY0.copyToVec(120, F);

		Global::N_rp++;
	}
示例#11
0
t_stat fprint_sym_m (FILE *of, t_addr addr, t_value *val,
    UNIT *uptr, int32 sw)
{
  uint16 op, arg1, arg2, arg3;
  int16 sarg;
  t_stat size = 0;
  int optype, sz;
  t_bool hexdec = (sw & SWMASK('H')) ? TRUE : FALSE;
  addr = ADDR_OFF(addr);

  op = val[0];
  if (op > 0xe7) return SCPE_ARG;

  optype = optable[op].flags;
  if (optype > OP_ERROR) {
    fprintf(of,"%-8s", optable[op].name);
    switch (optype) {
    case OP_NULL:
      break;
    case OP_UB:
      size = 1; arg1 = UB(val[1]);
      print_hd(of, arg1, hexdec, FALSE);
      break;
    case OP_W:
      size = 2; sarg = W(val[1],val[2]);
      print_hd(of, sarg, hexdec, FALSE);
      break;
    case OP_AB:
      arg1 = B(val[1],val[2], &sz); size = sz;
      fprintf(of,"#%x", arg1*2);
      break;
    case OP_B:
      arg1 = B(val[1],val[2], &sz); size = sz;
      print_hd(of, arg1, hexdec, FALSE);
      break;
    case OP_DBB:
      arg1 = DB(val[1]);
      arg2 = B(val[2],val[3], &sz); size = sz+1;
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, FALSE);
      break;
    case OP_UBB:
      arg1 = UB(val[1]);
      arg2 = B(val[2],val[3], &sz); size = sz+1;
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, FALSE);
      break;
    case OP_BUB:
      arg1 = B(val[1],val[2], &sz); size = sz+1;
      arg2 = UB(val[sz+1]);
      print_hd(of, arg1, hexdec, FALSE); fputc(',',of); 
      print_hd(of, arg2, hexdec, TRUE);
      break;
    case OP_SB:
      size = 1; sarg = SB(val[1]);
      fprintf(of,"#%x", addr+sarg+2);
      break;
    case OP_SW:
      size = 2; sarg = SW(val[1],val[2]);
      fprintf(of,"#%x", addr+sarg+3);
      break;
    case OP_DBUB:
      size = 2; arg1 = DB(val[1]);
      arg2 = UB(val[2]);
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, TRUE);
      break;
    case OP_UBUB:
      size = 2; arg1 = UB(val[1]);
      arg2 = UB(val[2]);
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, TRUE);
      break;
    case OP_UBDBUB:
      size  = 3; arg1 = UB(val[1]);
      arg2 = DB(val[2]);
      arg3 = UB(val[3]);
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg3, hexdec, TRUE);
      break;
    case OP_DB:
      size = 1; arg1 = DB(val[1]);
      print_hd(of, arg1, hexdec, TRUE);
      break;
    }
    return -size;
  } else {
    fprintf(of,"%-8s","DB"); print_hd(of, op, hexdec, TRUE);
    return SCPE_OK;
  }
}
示例#12
0
void PreferencesNetwork::syncSettings()
{
	QSettings s;
	s.setValue("subsurface_webservice_uid", ui->default_uid->text().toUpper());
	set_save_userid_local(ui->save_uid_local->checkState());

	s.beginGroup("Network");
	s.setValue("proxy_type", ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt());
	s.setValue("proxy_host", ui->proxyHost->text());
	s.setValue("proxy_port", ui->proxyPort->value());
	SB("proxy_auth", ui->proxyAuthRequired);
	s.setValue("proxy_user", ui->proxyUsername->text());
	s.setValue("proxy_pass", ui->proxyPassword->text());
	s.endGroup();

	s.beginGroup("CloudStorage");
	QString email = ui->cloud_storage_email->text();
	QString password = ui->cloud_storage_password->text();
	QString newpassword = ui->cloud_storage_new_passwd->text();
	if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) {
		// deal with password change
		if (!email.isEmpty() && !password.isEmpty()) {
			// connect to backend server to check / create credentials
			QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
			if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) {
				report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
			} else {
				CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
				connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded()));
				connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull()));
				QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword);
				ui->cloud_storage_new_passwd->setText("");
				free(prefs.cloud_storage_newpassword);
				prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword));
			}
		}
	} else if (prefs.cloud_verification_status == CS_UNKNOWN ||
		   prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD ||
		   email != prefs.cloud_storage_email ||
		   password != prefs.cloud_storage_password) {

		// different credentials - reset verification status
		prefs.cloud_verification_status = CS_UNKNOWN;
		if (!email.isEmpty() && !password.isEmpty()) {
			// connect to backend server to check / create credentials
			QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
			if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) {
				report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
			} else {
				CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
				connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded()));
				QNetworkReply *reply = cloudAuth->backend(email, password);
			}
		}
	} else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) {
		QString pin = ui->cloud_storage_pin->text();
		if (!pin.isEmpty()) {
			// connect to backend server to check / create credentials
			QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
			if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) {
				report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
			}
			CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
			connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded()));
			QNetworkReply *reply = cloudAuth->backend(email, password, pin);
		}
	}
	SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email);
	SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui->save_password_local->isChecked());
	if (ui->save_password_local->isChecked()) {
		SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password);
	} else {
		s.remove("password");
		free(prefs.cloud_storage_password);
		prefs.cloud_storage_password = strdup(qPrintable(password));
	}
	SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status);
	SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui->cloud_background_sync->isChecked());

	// at this point we intentionally do not have a UI for changing this
	// it could go into some sort of "advanced setup" or something
	SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url);
	s.endGroup();
}
示例#13
0
文件: perf43_8.c 项目: P1K/SAC2014
/*
 * Simulates an implementation of a
 * Littlun-like cipher many times, for speed
 * evaluation
 */
__m128i dummy_cipher_eval()
{
  __m128i x, k;
  unsigned long long tick1, tick2, dum;

  x = _mm_set_epi64x(0x0001020304050607, 0x08090a0b0c0d0e0f);
  k = _mm_set_epi64x(0x0a030d0c0f050607, 0x08090a000c0d0e0f);

  dum = 0;

  for (tick1 = 0; tick1 < 1ull << 31; tick1++)
    dum += 2*tick1 & (~tick1 | (tick1 >> 2));
  
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);
  x = SB(x);
  x = M128(x);

  tick1 = rdtsc();

//  // r1
//  x = _mm_xor_si128(x,k);
//  x = SB(x);
//  x = M128(x);
//  // r2
//  x = _mm_xor_si128(x,k);
//  x = SB(x);
//  x = M128(x);
//  // r3
//  x = _mm_xor_si128(x,k);
//  x = SB(x);
//  x = M128(x);
//  // r4
//  x = _mm_xor_si128(x,k);
//  x = SB(x);
//  x = M128(x);
//  // r5
//  x = _mm_xor_si128(x,k);
//  x = SB(x);
//  x = M128(x);
//  // r6
//  x = _mm_xor_si128(x,k);
//  x = SB(x);
//  x = M128(x);
//  // r7
//  x = _mm_xor_si128(x,k);
//  x = SB(x);
//  x = M128(x);
//  // r8
//  x = _mm_xor_si128(x,k);
//  x = SB(x);
//  x = M128(x);
//  // final
//  x = _mm_xor_si128(x,k);

  tick2 = rdtsc();

  printf("%llu ~ %llu cycles\n\n", dum, tick2 - tick1); 

  return x;
}
示例#14
0
void SetAddr(uint8_t X1, uint8_t Y1, uint8_t X2, uint8_t Y2){
	SB(0x2A, Reg);
	SB(0x00, Dat);
	SB(X1, Dat);
	SB(0x00, Dat);
	SB(X2, Dat);
	SB(0x2B, Reg);
	SB(0x00, Dat);
	SB(32+Y1, Dat);
	SB(0x00, Dat);
	SB(32+Y2, Dat);

	SB(0x2C, Reg);
}
示例#15
0
void ILI9163Init(void){
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

	G.GPIO_Pin = CSPin | ResPin | AOPin | BLPin | VCCPin;
	G.GPIO_Mode = GPIO_Mode_OUT;
	G.GPIO_OType = GPIO_OType_PP;
	G.GPIO_PuPd = GPIO_PuPd_NOPULL;
	G.GPIO_Speed = GPIO_Speed_10MHz;
	GPIO_Init(GPIOA, &G);

	G.GPIO_Pin = DatPin | ClkPin;
	G.GPIO_Mode = GPIO_Mode_AF;
	GPIO_Init(GPIOA, &G);

	GPIO_PinAFConfig(GPIOA, DatPS, GPIO_AF_0);
	GPIO_PinAFConfig(GPIOA, ClkPS, GPIO_AF_0);

	S.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
	S.SPI_CPHA = SPI_CPHA_1Edge;
	S.SPI_CPOL = SPI_CPOL_Low;
	S.SPI_DataSize = SPI_DataSize_8b;
	S.SPI_FirstBit = SPI_FirstBit_MSB;
	S.SPI_Mode = SPI_Mode_Master;
	S.SPI_NSS = SPI_NSS_Soft;
	SPI_Init(SPI1, &S);
	SPI_Cmd(SPI1, ENABLE);

	GPIO_ResetBits(GPIOA, ResPin);
	Delay(20);
	GPIO_SetBits(GPIOA, ResPin);
	Delay(20);
	GPIO_ResetBits(GPIOA, CSPin);

	/*
	SB(0x11, Reg); //Exit sleep
	Delay(20);

	SB(0x26, Reg); //Set default gamma
	SB(0x04, Dat);

	SB(0xB1, Reg); //Set frame rate
	SB(0x0E, Dat);
	SB(0x10, Dat);

	SB(0xC0, Reg); //Set VRH1[4:0]...
	SB(0x08, Dat);
	SB(0x00, Dat);

	SB(0xC1, Reg);
	SB(0x05, Dat);
	SB(0xC5, Reg);
	SB(0x38, Dat);
	SB(0x40, Dat);

	SB(0x3A, Reg);
	SB(0x05, Dat);
	SB(0x36, Reg);
	SB(0x1C, Dat);

	SB(0x2A, Reg);
	SB(0x00, Dat);
	SB(0x00, Dat);
	SB(0x00, Dat);
	SB(0x7F, Dat);
	SB(0x2B, Reg);
	SB(0x00, Dat);
	SB(32, Dat);
	SB(0x00, Dat);
	SB(127+32, Dat);

	SB(0xB4, Reg);
	SB(0x00, Dat);

	SB(0xF2, Reg);
	SB(0x01, Dat);
	SB(0xE0, Reg);
	SB(0x3F, Dat);
	SB(0x22, Dat);
	SB(0x20, Dat);
	SB(0x30, Dat);
	SB(0x29, Dat);
	SB(0x0C, Dat);
	SB(0x4E, Dat);
	SB(0xB7, Dat);
	SB(0x3C, Dat);
	SB(0x19, Dat);
	SB(0x22, Dat);
	SB(0x1E, Dat);
	SB(0x02, Dat);
	SB(0x01, Dat);
	SB(0x00, Dat);
	SB(0xE1, Reg);
	SB(0x00, Dat);
	SB(0x1B, Dat);
	SB(0x1F, Dat);
	SB(0x0F, Dat);
	SB(0x16, Dat);
	SB(0x13, Dat);
	SB(0x31, Dat);
	SB(0x84, Dat);
	SB(0x43, Dat);
	SB(0x06, Dat);
	SB(0x1D, Dat);
	SB(0x21, Dat);
	SB(0x3D, Dat);
	SB(0x3E, Dat);
	SB(0x3F, Dat);

	SB(0x29, Reg);
	SB(0x2C, Reg);
	 */

	SB(0x01, Reg); //Software reset
	SB(0x11, Reg); //Exit Sleep
	Delay(20);

	SB(0x26, Reg); //Set default gamma
	SB(0x04, Dat);

	SB(0xC0, Reg); //Set Power Control 1
	SB(0x1F, Dat);

	SB(0xC1, Reg); //Set Power Control 2
	SB(0x00, Dat);

	SB(0xC2, Reg); //Set Power Control 3
	SB(0x00, Dat);
	SB(0x07, Dat);

	SB(0xC3, Reg); //Set Power Control 4 (Idle mode)
	SB(0x00, Dat);
	SB(0x07, Dat);

	SB(0xC5, Reg); //Set VCom Control 1
	SB(0x24, Dat); // VComH = 3v
	SB(0xC8, Dat); // VComL = 0v

	//SB(0x38, Reg); //Idle mode off
	SB(0x39, Reg); //Enable idle mode

	SB(0x3A, Reg); //Set pixel mode
	SB(0x05, Dat);

	SB(0x36, Reg); //Set Memory access mode
	SB(0x08, Dat);

	SB(0x29, Reg); //Display on

	InvMode(0);
	ClrScrn();
}
示例#16
0
void InvMode(uint8_t Mode){
	if(Mode==0) SB(0x20, Reg);
	else SB(0x21, Reg);
}
示例#17
0
void SleepMode(uint8_t Mode){
	if(Mode == Sleep) SB(0x10, Reg);
	else SB(0x11, Reg);
	Delay(120);
}
/** Translate python list of tuples to Config
 *
 *  [(K,V)]   -> Config
 *    float   -> double
 *    str     -> string
 *    [[()]]    -> vector<Config>  (recurse)
 *    ndarray -> vector<double>
 *    TODO: [0.0]   -> vector<double>
 */
void List2Config(Config& ret, PyObject *list, unsigned depth)
{
    if(depth>3)
        throw std::runtime_error("too deep for Dict2Config");

    PyRef<> iter(PyObject_GetIter(list));
    while(true) {
        PyObject *item = PyIter_Next(iter.py());
        if(!item) break;
        PyRef<> itemref(item);
        const char *kname;
        PyObject *value;
        if(!PyArg_ParseTuple(item, "sO", &kname, &value))
            throw std::runtime_error("list item is not a tuple?");

        if(PyArray_Check(value)) { // array as vector<double>
            PyRef<> arr(PyArray_ContiguousFromAny(value, NPY_DOUBLE, 0, 2));
            double *buf = (double*)PyArray_DATA(arr.py());
            std::vector<double> temp(PyArray_SIZE(arr.py()));
            std::copy(buf, buf+temp.size(), temp.begin());

            ret.swap<std::vector<double> >(kname, temp);

        } else if(PyNumber_Check(value)) { // scalar as double
            PyRef<> dval(PyNumber_Float(value));
            double val = PyFloat_AsDouble(dval.py());
            ret.set<double>(kname, val);

        } else if(PyUnicode_Check(value) || (PY_MAJOR_VERSION < 3 && PyBytes_Check(value))) { // string
            PyRef<> valref(value, borrow());
            PyCString sval(valref);
            const char *val = sval.c_str();

            ret.set<std::string>(kname, val);

        } else if(PySequence_Check(value)) { // list of dict
            Py_ssize_t N = PySequence_Size(value);

            Config::vector_t output;
            output.reserve(N);

            for(Py_ssize_t i=0; i<N; i++) {
                PyRef<> elem(PySequence_GetItem(value, i));

                if(PyDict_Check(elem.py())) {
                    elem.reset(PyMapping_Items(elem.py()));
                }
                if(!PyList_Check(elem.py())) {
                    PyTypeObject *valuetype = (PyTypeObject*)PyObject_Type(elem.py());
                    throw std::invalid_argument(SB()<<"lists must contain only dict or list of tuples, not "<<valuetype->tp_name);
                }

                output.push_back(ret.new_scope());

                List2Config(output.back(), elem.py(), depth+1); // inheirt parent scope
            }

            ret.set<Config::vector_t>(kname, output);

        } else {
            PyTypeObject *valuetype = (PyTypeObject*)PyObject_Type(value);
            throw std::invalid_argument(SB()<<"Must be a dict, not "<<valuetype->tp_name);
        }
    }
}
示例#19
0
文件: npf.cpp 项目: andrew889/OpenTTD
/**
 * Sets the given flag on the given AyStarNode to the given value.
 */
static inline void NPFSetFlag(AyStarNode *node, NPFNodeFlag flag, bool value)
{
	SB(node->user_data[NPF_NODE_FLAGS], flag, 1, value);
}
示例#20
0
void PCD8544_InitSetup(){
	static uint8_t Init = 1;

	if(Init==1){
		Init = 0;
		RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
		RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
		RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

		G.GPIO_Pin = DC | CE | RS;
		G.GPIO_Mode = GPIO_Mode_OUT;
		G.GPIO_OType = GPIO_OType_PP;
		G.GPIO_Speed = GPIO_Speed_10MHz;
		GPIO_Init(IOGPIO, &G);

		G.GPIO_Pin = VCC;
		GPIO_Init(VCCGPIO, &G);

		G.GPIO_Pin = Clk | DIn;
		G.GPIO_Mode = GPIO_Mode_AF;
		GPIO_Init(IOGPIO, &G);

		GPIO_PinAFConfig(GPIOA, ClkPS, GPIO_AF_0);
		GPIO_PinAFConfig(GPIOA, DInPS, GPIO_AF_0);

		G.GPIO_Pin = BL1 | BL2;
		G.GPIO_Mode = GPIO_Mode_OUT;
		G.GPIO_OType = GPIO_OType_OD;
		GPIO_Init(IOGPIO, &G);

		S.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
		S.SPI_CPHA = SPI_CPHA_1Edge;
		S.SPI_CPOL = SPI_CPOL_Low;
		S.SPI_DataSize = SPI_DataSize_8b;
		S.SPI_FirstBit = SPI_FirstBit_MSB;
		S.SPI_Mode = SPI_Mode_Master;
		S.SPI_NSS = SPI_NSS_Soft;
		SPI_Init(SPI1, &S);
		SPI_Cmd(SPI1, ENABLE);
	}

	GPIO_ResetBits(IOGPIO, DC|CE|RS);
	//Turn on screen
	GPIO_SetBits(VCCGPIO, VCC);
	Delay(50);
	GPIO_SetBits(IOGPIO, RS);
	GPIO_SetBits(IOGPIO, CE);
	Delay(100);
	SB(0x21, 0, 1);			//Power screen on, extended instruction
	SB(0x06, 0, 1);			//Temp co 2
	SB(0x13, 0, 1);			//Bias system 3
	SB(0x80|70, 0, 1);		//Contrast 55-5v, 64-3v

	SB(0x20, 0, 1);
	SB(0x80, 0, 1);			//X Address = 0
	SB(0x0C, 0, 1);			//Normal display
	//SB(0b1001, 0, 1);		//All display

	ClrBuf();					//Clear Display
	PScrn();					//Write display
}