Esempio n. 1
0
pulsesequence()
{
  double satdly = getval("satdly");
  int prgcycle=(int)(getval("prgcycle")+0.5);
  char	satmode[MAXSTR],
	sspul[MAXSTR];

  getstr("satmode",satmode);
  getstr("sspul",sspul);

  assign(ct,v17);
  assign(zero,v18);
  assign(zero,v19);

  if (getflag("prgflg") && (satmode[0] == 'y') && (prgcycle > 1.5))
    {
        hlv(ct,v17);
        mod2(ct,v18); dbl(v18,v18);
  	if (prgcycle > 2.5)
	   {
        	hlv(v17,v17);
		hlv(ct,v19); mod2(v19,v19); dbl(v19,v19);
	   }
     }

  settable(t1,4,phs1);
  settable(t2,8,phs2);
  settable(t3,4,phs3);
  getelem(t1,v17,v1);
  getelem(t2,v17,v2);
  getelem(t3,v17,v3);
  assign(v1,oph);
  add(oph,v18,oph);
  add(oph,v19,oph);

  if (getflag("prgflg") && (satmode[0] == 'y'))
	assign(v3,v2);

   /* equilibrium period */
   status(A);

   delay(5.0e-5);
   if (sspul[0] == 'y')
        steadystate();

   if (satmode[0] == 'y')
     {
        if ((d1-satdly) > 0.02)
                delay(d1-satdly);
        else
                delay(0.02);
	if (getflag("slpsat"))
	   {
		shaped_satpulse("relaxD",satdly,v2);
                if (getflag("prgflg"))
                   shaped_purge(v1,v2,v18,v19);
	   }
	else
	   {
        	satpulse(satdly,v2,rof1,rof1);
		if (getflag("prgflg"))
		   purge(v1,v2,v18,v19);
	   }
     }
   else
	delay(d1);

   status(B);

   pulse(p1,zero); 
   hsdelay(d2); 
   rgpulse(pw,v1,rof1,rof2);

   status(C);
}
Esempio n. 2
0
int
main(int argc, char *argv[])
{
	const char *ifname, *cmd;
	unsigned char bnounit = 0;
	char *if_base = NULL;
	unsigned int unit_res = -1;
	int res = 0;

	if (argc < 2 ||
	  strncmp(argv[1],"-h",2) == 0 || strncmp(argv[1],"--h",3) == 0)
		usage();

	ifname = argv[1];

	if (argc == 2) {
		ieee80211_status(ifname);
		return 0;
	}

	cmd = argv[2];
	if (streq(cmd, "create")) {
		struct ieee80211_clone_params cp;
		struct ifreq ifr;

		memset(&ifr, 0, sizeof(ifr));

		memset(&cp, 0, sizeof(cp));
		strncpy(cp.icp_name, ifname, IFNAMSIZ);
		/* NB: station mode is the default */
		cp.icp_opmode = IEEE80211_M_STA;
		/* NB: default is to request a unique bssid/mac */
		cp.icp_flags = IEEE80211_CLONE_BSSID;

		while (argc > 3) {
			if (strcmp(argv[3], "wlanmode") == 0) {
				if (argc < 5)
					usage();
				cp.icp_opmode = (u_int16_t) getopmode(argv[4]);
				argc--;
				argv++;
			} else if (strcmp(argv[3], "wlandev") == 0) {
				if (argc < 5)
					usage();
				strncpy(ifr.ifr_name, argv[4], IFNAMSIZ);
				argc--;
				argv++;
			} else if (strcmp(argv[3], "nounit" ) == 0) {
				bnounit = 1;
			} else {
				int flag = getflag(argv[3]);
				if (flag < 0)
					cp.icp_flags &= ~(-flag);
				else
					cp.icp_flags |= flag;
			}
			argc--;
			argv++;
		}
		if (ifr.ifr_name[0] == '\0')
			errx(1, "no device specified with wlandev");

		res = if_split_name(cp.icp_name, &if_base, &unit_res);
		if (res < 0) {
			err(1, "if_split_name() - malloc");
		} else if ((res == 0) && (bnounit == 0)) {
			/* user gave a string only and using a unit */
			unit_res = if_find_unit(if_base);

			if (unit_res < 0) {
				err(1, "if_find_unit - failed");
			} else {
				snprintf(cp.icp_name + strlen(if_base),
					IFNAMSIZ - strlen(if_base), "%d", unit_res);
			}
		}

		free(if_base);
		if_base = NULL;

		ifr.ifr_data = (void *) &cp;
		vap_create(&ifr);
		printf("%s\n", ifr.ifr_name);
	} else if (streq(cmd, "destroy")) {
		vap_destroy(ifname);
	} else if (streq(cmd, "list")) {
		if (argc > 3) {
			const char *arg = argv[3];

			if (streq(arg, "sta"))
				list_stations(ifname);
			else if (streq(arg, "scan") || streq(arg, "ap"))
				list_scan(ifname);
			else if (streq(arg, "chan") || streq(arg, "freq"))
				list_channels(ifname, 1);
			else if (streq(arg, "active"))
				list_channels(ifname, 0);
			else if (streq(arg, "keys"))
				list_keys(ifname);
			else if (streq(arg, "caps"))
				list_capabilities(ifname);
			else if (streq(arg, "wme"))
				list_wme(ifname);
			else
				err(1, "unknown 'list' option: %s", arg);
		} else				/* NB: for compatibility */
			list_stations(ifname);
	} else
		usage();

	return 0;
}
void MCButton::GetAutoHilite(MCExecContext& ctxt, bool& r_setting)
{
	r_setting = getflag(F_AUTO_HILITE);
}
Esempio n. 4
0
void pulsesequence()
{
   double          slpwr,
                   slpw,
                   mix,
                   hsglvl,
                   hsgt,
                   gzlvlz,
                   gtz,
		   zfpw,
		   zfpwr,
                   cycles;
   int             iphase;
   char            sspul[MAXSTR],
		   composit[MAXSTR],
		   compshape[MAXSTR],
		   zfilt[MAXSTR],
		   zfshp[MAXSTR];


/* LOAD AND INITIALIZE PARAMETERS */
   mix = getval("mix");
   iphase = (int) (getval("phase") + 0.5);
   slpwr = getval("slpwr");
   slpw = getval("slpw");
   getstr("sspul", sspul);
   hsglvl = getval("hsglvl");
   hsgt = getval("hsgt");
   gzlvlz = getval("gzlvlz");
   gtz = getval("gtz");
   zfpwr = getval("zfpwr");
   zfpw = getval("zfpw");
   getstr("zfshp",zfshp);
   getstr("zfilt",zfilt);
   getstr("composit",composit);
   getstr("compshape",compshape);

   sub(ct,ssctr,v7);

   settable(t1,4,ph1);	getelem(t1,v7,v1);
   settable(t2,8,ph2);	getelem(t2,v7,v2);	add(v2,two,v3);
   settable(t3,8,ph3);	getelem(t3,v7,oph);
   settable(t4,8,ph4);	getelem(t4,v7,v4);
   settable(t5,4,ph5);	getelem(t5,v7,v5);
   settable(t6,8,ph6);	getelem(t5,v7,v6);
   
   if (zfilt[0] == 'n') assign(v1,oph);

   if (iphase == 2)
      {incr(v1); incr(v6);}			/* hypercomplex method */

   initval(2.0*(double)(((int)(d2*getval("sw1")+0.5)%2)),v13);
       add(v1,v13,v1);
       add(v6,v13,v6);
       add(oph,v13,oph);

   cycles = mix / (4.0 * slpw);
   initval(cycles, v10);	/* mixing time cycles */


/* BEGIN ACTUAL PULSE SEQUENCE */
   status(A);
      obspower(tpwr);
      delay(5.0e-6);
   if (sspul[0] == 'y')
   {
         zgradpulse(hsglvl,hsgt);
         rgpulse(pw,zero,rof1,rof1);
         zgradpulse(hsglvl,hsgt);
   }

   delay(d1);

	if (getflag("wet"))
		wet4(zero,one);
   status(B);
      rgpulse(pw, v1, rof1, rof1);
      if (d2 > (POWER_DELAY + (2.0*pw/PI) + rof1))
       delay(d2 - POWER_DELAY - (2.0*pw/PI) - rof1);
      
      else {
	if (ix == 1)
	  dps_show("delay",d2);
	else if ((ix > 2) && (iphase < 2))
	  text_error("increment %d cannot be timed properly\n", (int) ix/2);
      }

      obspower(slpwr);

      if (cycles > 1.5000)
       {
	 obsunblank(); xmtron();
         starthardloop(v10);
		txphase(v2);
		delay(2*slpw);
		txphase(v3);
		delay(2*slpw);
         endhardloop();
	 xmtroff(); obsblank();
       }

       if (zfilt[0] == 'y')
        {
           obspower(tpwr);
           rgpulse(pw,v4,1.0e-6,rof1);
           zgradpulse(gzlvlz,gtz);
           delay(gtz/3);
           obspower(zfpwr);
           shaped_pulse(zfshp,zfpw,zero,2.0e-6,2.0e-6);
           zgradpulse(gzlvlz/4,gtz/3);
           obspower(tpwr);
           delay(gtz/8);
	   if (composit[0] == 'y')
    	   {
       		  if (rfwg[OBSch-1] == 'y')
       		   shaped_pulse(compshape,4.0*pw+0.8e-6,v5,rof1,rof2);
       		  else
       		   comp90pulse(pw,v5,rof1,rof2);
    	   }
           else
           	  rgpulse(pw,v5,rof1,rof2);
        }
       else
           delay(rof2);

   status(C);
}
Esempio n. 5
0
void pulsesequence()
{
   double          ss,
                   arraydim,
                   p1lvl,
                   trim,
                   mix,
                   window,
                   cycles,
                   phase;
   int             iphase;
   char            sspul[MAXSTR];


/* LOAD AND INITIALIZE VARIABLES */
   ni = getval("ni");
   arraydim = getval("arraydim");
   mix = getval("mix");
   trim = getval("trim");
   phase = getval("phase");
   iphase = (int) (phase + 0.5);
   p1lvl = getval("p1lvl");
   ss = getval("ss");
   window=getval("window");
   getstr("sspul", sspul);

   if (iphase == 3)
   {
      initval((double)((int)((ix-1)/(arraydim/ni)+1.0e-6)), v14);
   }
   else
   {
      assign(zero, v14);
   }


/* CHECK CONDITIONS */
   if ((iphase != 3) && (arrayelements > 2))
   {
      fprintf(stdout, "PHASE=3 is required if MIX is arrayed!\n");
      psg_abort(1);
   }
   if (satdly > 9.999)
   {
      fprintf(stdout, "Presaturation period is too long.\n");
      psg_abort(1);
   }
   if (!newtransamp)
   {
      fprintf(stdout, "TOCSY requires linear amplifiers on transmitter.\n");
      fprintf(stdout, "Use DECTOCSY with the appropriate re-cabling,\n");
      psg_abort(1);
   }
   if ((p1 == 0.0) && (ix == 1))
      fprintf(stdout, "Warning:  P1 has a zero value.\n");
   if ((rof1 < 9.9e-6) && (ix == 1))
      fprintf(stdout,"Warning:  ROF1 is less than 10 us\n");

   if (satpwr > 40)
        {
         printf("satpwr too large  - acquisition aborted./n");
         psg_abort(1);
        }

/* DETERMINE STEADY-STATE MODE */
   if (ss < 0)
   {
      ss = (-1) * ss;
   }
   else
   {   
      if ((ss > 0) && (ix == 1))
      {
         ss = ss;
      }
      else
      {   
         ss = 0;
      }
   }
   initval(ss, ssctr);
   initval(ss, ssval);


/* STEADY-STATE PHASECYCLING */
/* This section determines if the phase calculations trigger off of (SS - SSCTR)
   or off of CT */

   ifzero(ssctr);
      hlv(ct, v13);
      mod2(ct, v1);
      hlv(ct, v2);
   elsenz(ssctr);
      sub(ssval, ssctr, v12);	/* v12 = 0,...,ss-1 */
      hlv(v12, v13);
      mod2(v12, v1);
      hlv(v12, v2);
   endif(ssctr);


/* CALCULATE PHASES */
/* A 2-step cycle is performed on the first pulse (90 degrees) to suppress
   axial peaks in the first instance.  Second, the 2-step F2 quadrature image
   suppression subcycle is added to all pulse phases and receiver phase.
   Finally, a 2-step cycle is performed on the spin-lock pulses. */

   mod2(v13, v13);
   dbl(v1, v1);
   incr(v1);
   hlv(v2, v2);
   mod2(v2, v2);
   dbl(v2, v2);
   incr(v2);
   add(v13, v2, v2);
   sub(v2, one, v3);
   add(two, v2, v4);
   add(two, v3, v5);
   add(v1, v13, v1);
   assign(v1, oph);
   if (iphase == 2)
      incr(v1);
   if (iphase == 3)
      add(v1, v14, v1);

 /*HYPERCOMPLEX MODE USES REDFIELD TRICK TO MOVE AXIAL PEAKS TO EDGE*/
   initval(2.0*(double)(((int)(d2*getval("sw1")+0.5)%2)),v6);
   if ((iphase==1)||(iphase==2)) {add(v1,v6,v1); add(oph,v6,oph);} 

/* CALCULATE AND INITIALIZE LOOP COUNTER */
      if (pw > 0.0)
      {
         cycles = (mix - trim) / (64.66*pw+32*window);
         cycles = 2.0*(double) (int) (cycles/2.0);
      }
      else
      {
         cycles = 0.0;
      }
      initval(cycles, v9);			/* V9 is the MIX loop count */

/* BEGIN ACTUAL PULSE SEQUENCE CODE */
   status(A);
      rlpower(p1lvl, TODEV);
      if (sspul[0] == 'y')
      {
         rgpulse(1000*1e-6, zero, rof1, 0.0e-6);
         rgpulse(1000*1e-6, one, 0.0e-6, rof1);
      }
      hsdelay(d1);
if (getflag("wet")) wet4(zero,one);
rlpower(p1lvl, TODEV);
     if (satmode[A] == 'y')
     { rlpower(satpwr,TODEV);
      rgpulse(satdly,zero,rof1,rof2);
      rlpower(p1lvl,TODEV);}
   status(B);
      rgpulse(p1, v1, rof1, 1.0e-6);
      if (satmode[B] =='y')
       {
        if (d2 > 0.0)
         {
           rlpower(satpwr,TODEV);
           rgpulse(d2 - (2*POWER_DELAY) - 1.0e-6 - (2*p1/3.1416),zero,0.0,0.0);
         }
       }
      else
       {
        if (d2 > 0.0)
          delay(d2 - POWER_DELAY - 1.0e-6  - (2*p1/3.1416));
       } 
      rcvroff();
      rlpower(tpwr,TODEV); 
      txphase(v13);
      xmtron();
      delay(trim);
      if (cycles > 1.0)
      {
         starthardloop(v9);
            mleva(window); mleva(window); mlevb(window); mlevb(window);
            mlevb(window); mleva(window); mleva(window); mlevb(window);
            mlevb(window); mlevb(window); mleva(window); mleva(window);
            mleva(window); mlevb(window); mlevb(window); mleva(window);
            rgpulse(.66*pw,v3,rof1,rof2);
         endhardloop();
      }
      txphase(v13);
      xmtroff();

/* detection */
      delay(rof2);
      rcvron();
   status(C);
}
Esempio n. 6
0
void pulsesequence()
{
   double          mixN = getval("mixN"),
		   mixNcorr,
		   gzlvl1 = getval("gzlvl1"),
		   gt1 = getval("gt1"),
		   gstab = getval("gstab"),
                   zqfpw1 = getval("zqfpw1"),
                   zqfpwr1 = getval("zqfpwr1"),
                   gzlvlzq1 = getval("gzlvlzq1");
   char		   satmode[MAXSTR],
		   zqfpat1[MAXSTR],
		   wet[MAXSTR];
   int		   phase1 = (int)(getval("phase")+0.5);

/* LOAD VARIABLES */
   getstr("satmode",satmode);
   getstr("wet",wet);
   getstr("zqfpat1",zqfpat1);
   mixNcorr = 0.0;
   if (getflag("PFGflg"))
   {
	mixNcorr = gt1 + gstab;
	if (getflag("Gzqfilt"))
		mixNcorr += gstab + zqfpw1;
   	if (wet[1] == 'y')
		mixNcorr += 4*(getval("pwwet")+getval("gtw")+getval("gswet"));
   }

   if (mixNcorr > mixN)
	mixN=mixNcorr;

   settable(t1,16,phs1);
   settable(t2,32,phs2);
   settable(t3,16,phs3);
   settable(t5,16,phs5);
   settable(t4,32,phs4);
   
   getelem(t1,ct,v1);
   getelem(t4,ct,oph);
   assign(oph,v7);
   assign(zero,v6);
   getelem(t2,ct,v2);
   getelem(t3,ct,v3);
/*
   mod2(id2,v14);
   dbl(v14,v14);
*/
  initval(2.0*(double)(((int)(d2*getval("sw1")+0.5)%2)),v14);

   if (phase1 == 2)                                        /* hypercomplex */
      incr(v1);

   add(v1, v14, v1);
   add(oph,v14,oph);
    

/* BEGIN THE ACTUAL PULSE SEQUENCE */
   status(A);
   obspower(tpwr);

   delay(5.0e-5);
   if (getflag("sspul"))
        steadystate();

   if (satmode[0] == 'y')
     {
        if ((d1-satdly) > 0.02)
                delay(d1-satdly);
        else
                delay(0.02);
        satpulse(satdly,v6,rof1,rof1);
     }
   else
        delay(d1);

   if (wet[0] == 'y')
     wet4(zero,one);

   status(B);
      rgpulse(pw, v1, rof1, rof1);
      if (d2>0)
       delay(d2- 2*rof1 -(4*pw/PI));  /*corrected evolution time */
      else
       delay(d2);
      rgpulse(pw, v2, rof1, rof1);

      if (satmode[1] == 'y')
	satpulse((mixN-mixNcorr)*0.7,v7,rof1,rof1);
      else
	delay((mixN - mixNcorr)*0.7);

      if (getflag("PFGflg"))
      {
        if (getflag("Gzqfilt"))
        {
         obspower(zqfpwr1);
         rgradient('z',gzlvlzq1);
         delay(100.0e-6);
         shaped_pulse(zqfpat1,zqfpw1,zero,rof1,rof1);
         delay(100.0e-6);
         rgradient('z',0.0);
         delay(gstab);
	 obspower(tpwr);
        }
        zgradpulse(gzlvl1,gt1);
        delay(gstab);
      }
      if (satmode[1] == 'y')
        satpulse((mixN-mixNcorr)*0.3,v7,rof1,rof1);
      else
	delay((mixN - mixNcorr)*0.3);
      if (wet[1] == 'y')
	wet4(zero,one);
   status(C);
      rgpulse(pw, v3, rof1, rof2);
}
Esempio n. 7
0
pulsesequence()
{
	double	gzlvl0 = getval("gzlvl0"),
		gzlvl1 = getval("gzlvl1"),
		gzlvl2 = getval("gzlvl2"),
		gt0 = getval("gt0"),
		gt1 = getval("gt1"),
		gstab = getval("gstab"),
		compH = getval("compH");
	char	sspul[MAXSTR], pshape[MAXSTR];
	int	iphase;
        shape  hdx;

	getstr("sspul",sspul);
	iphase = (int)(getval("phase")+0.5);

  /* Make HADAMARD encoding waveforms */
  
        getstr("pshape", pshape);
        hdx = pboxHT_F1e(pshape, pw*compH, tpwr);

  /* Setup Phase Cycling */

	settable(t1,8,ph1);
	settable(t2,8,ph2);
	settable(t3,8,ph3);

	getelem(t1,ct,v1);
	getelem(t2,ct,v2);
	getelem(t3,ct,oph);

	initval(2.0*(double)(((int)(d2*getval("sw1")+0.5)%2)),v10);
		add(v1,v10,v1);
		add(oph,v10,oph);

  status(A);

 	delay(5.0e-5);
	zgradpulse(gzlvl0,gt0);
	if (sspul[0] == 'y')
	{
	  rgpulse(pw,zero,rof1,rof1);
	  zgradpulse(gzlvl0,gt0);
	}

        pre_sat();
      
        if (getflag("wet"))
          wet4(zero,one);

        obspower(tpwr);
      
  status(B);

       pbox_pulse(&hdx, v1, rof1, 2.0e-6);
       obspower(tpwr);

       rgpulse(pw, v2, 2.0e-6, rof1);
       delay(gt1 + gstab + 2*GRADIENT_DELAY);
       rgpulse(2*pw, v2, rof1, rof1);
       zgradpulse(-gzlvl1,gt1);
       delay(gstab);
       rgpulse(pw, v2, rof1, rof2);
       zgradpulse(gzlvl2,gt1);
       delay(gstab - 2*GRADIENT_DELAY);

  status(C);
}
Esempio n. 8
0
pulsesequence()
{
   double          mult = getval("mult"),
                   pp = getval("pp"),
		   pplvl = getval("pplvl"),
		   qphase = getval("qphase"),
		   qtip = getval("qtip"),
		   qrelax = getval("qrelax"),
		   gzlvl5 = getval("gzlvl5"),
		   gt5 = getval("gt5"),
		   tpwr180 = getval("tpwr180"),
		   pw180 = getval("pw180"),
		   qpw,
                   tau;
   char		   pw180ad[MAXSTR],
		   sbbiflg[MAXSTR],
		   bipflg[MAXSTR];

//synchronize gradients to srate for probetype='nano'
//   Preserve gradient "area"
        gt5 = syncGradTime("gt5","gzlvl5",1.0);
        gzlvl5 = syncGradLvl("gt5","gzlvl5",1.0);

  getstr("pw180ad", pw180ad);
  getstr("bipflg", bipflg);
  getstr("sbbiflg",sbbiflg);

  if (bipflg[0] == 'y')
  {
        tpwr180=getval("tnbippwr");
        pw180=getval("tnbippw");
        getstr("tnbipshp",pw180ad);
  }

   tau    = 1.0 / (2.0 * (getval("j1xh")));
  if (getflag("PFGflg"))
	tau = tau - gt5;
   qpw = qtip*pw/90.0;

/* CHECK CONDITIONS */

   if ((dm[0] == 'y') || (dm[1] == 'y'))
   {
      fprintf(stdout, "Decoupler must be set as dm='nny'.\n");
      psg_abort(1);
   }
   if ((dmm[0] != 'c') || (dmm[1] != 'c'))
   {
      fprintf(stdout, "Decoupler must be set as dmm='ccf' or dmm='ccw'.\n");
      psg_abort(1);
   }


/* PHASECYCLE CALCULATIONS */
   settable(t3,2, phi3);
   settable(t4,8, phi4);
   settable(t9,16, rec_1);
   settable(t2,16,phi2);

   assign(zero,v1);		/* proton 90 */
   getelem(t2,ct,v2);		/* proton 180 */
   getelem(t3,ct,v3);		/* proton theta pulse */
   getelem(t4,ct,v4);		/* carbon 90 */
   getelem(t9,ct,oph);          /* Receiver */

   add(v4,one,v7);		/* 1st pair of carbon 180 */
   assign(v4,v5);		/* 2nd pair of carbon 180 */
   add(oph,one,v6);		/* carbon alpha pulse qphase=1 */

   if (qphase < -0.5)
	add(v6,two,v6);		/* carbon alpha phase qphase=-1 */

   add(one,v5,v10);
   add(one,v7,v11);

   add(oph,two,oph);
   if (getflag("sbbiflg"))
	sub(oph,two,oph);
	
/* ACTUAL PULSESEQUENCE BEGINS */
   status(A);
      decpower(pplvl);
      obspower(tpwr);

      if ((qphase != 0.0) && (qrelax > d1))
	{ 
	    decpower(dpwr);
	    status(C);
		delay(qrelax - d1);
	    status(A);
	    decpower(pplvl);
	}
      delay(d1);

   status(B);
	if (getflag("sbbiflg"))
	{
      	   if (qphase != 0.0) 
	   {
	   	rgpulse(qpw,v6,rof1,rof1);
	   	obspower(tpwr180);
	   	shaped_pulse(pw180ad,pw180,v7,rof1,rof1);
	   	obspower(tpwr);
	   	if (getflag("PFGflg"))
			zgradpulse(gzlvl5,gt5);
	   	delay(tau + pp + 2*rof1 + (2*qpw/PI));
	   	obspower(tpwr180);
	   	shaped_pulse(pw180ad,pw180,v7,rof1,rof1);
	   	obspower(tpwr);
	   }
	
           decrgpulse(pp, v1,rof1,rof1);
	   if (getflag("PFGflg"))
		zgradpulse(gzlvl5,gt5);
	   delay(tau - pp - 2*rof1);
           simpulse(pw, 2.0 * pp, v4, v2, rof1, rof1);
	   if (getflag("PFGflg"))
		zgradpulse(gzlvl5,gt5);
	   delay(tau - pp - 2*rof1 - mult*pp);
	   decrgpulse(mult*pp,v3,rof1,rof1);

	   obspower(tpwr180);
	   shaped_pulse(pw180ad,pw180,v5,rof1,rof1);
	   obspower(tpwr);
	   if (getflag("PFGflg"))
           	zgradpulse(gzlvl5,gt5);
	   decpower(dpwr);
	   delay(tau - POWER_DELAY);
	   obspower(tpwr180);
	   shaped_pulse(pw180ad,pw180,v5,rof1,rof2);
	   obspower(tpwr);
	}
	else
	{
	   if (qphase != 0.0)
	   {
           	rgpulse(qpw,v6,rof1,rof1);
           	if (getflag("PFGflg"))
                    zgradpulse(gzlvl5,gt5);
           	delay(tau - rof1 - (2*qpw/PI));
           	rgpulse(pw,v7,rof1,rof1);
           	simpulse(2*pw,pp,v11,v1,rof1,rof1);
           	rgpulse(pw,v7,rof1,rof1);
	   }
	   else
	      	decrgpulse(pp,v1,rof1,rof1);
           if (getflag("PFGflg"))
                zgradpulse(gzlvl5,gt5);
	   if (qphase !=0.0)
           	delay(tau - pp - rof1);
	   else
		delay(tau - pp - (2*pp/PI) - 2*rof1);
           simpulse(pw, 2.0 * pp, v4, v2, rof1, rof1);
           if (getflag("PFGflg"))
                zgradpulse(gzlvl5,gt5);
           delay(tau - pp - rof1 - (2*pw/PI));
           rgpulse(pw,v5,rof1,rof1);
           simpulse(2*pw,mult*pp,v10,v3,rof1,rof1);
           rgpulse(pw,v5,rof1,rof1);
           if (getflag("PFGflg"))
                zgradpulse(gzlvl5,gt5);
           decpower(dpwr);
           delay(tau - POWER_DELAY + rof2);
	}

   status(C);
}
Esempio n. 9
0
pulsesequence()
{
    /* DECLARE VARIABLES */
    char     satmode[MAXSTR],f1180[MAXSTR],sspul[MAXSTR],comm[MAXSTR],
             pwx180ad[MAXSTR],pwx180adR[MAXSTR],pwx180ref[MAXSTR];
    int	  phase,satmove,maxni,t1_counter,icosel=1,
                                         prgcycle = (int)(getval("prgcycle")+0.5);
    double   tau1,tauxh, tauxh1, taucc,av180,
             hsgt   = getval("hsgt"),
             gt1    = getval("gt1"),
             gt2    = getval("gt2"),
             gt3    = getval("gt3"),
             hsglvl = getval("hsglvl"),
             gzlvl1 = getval("gzlvl1"),
             gzlvl2 = getval("gzlvl2"),
             gzlvl3 = getval("gzlvl3"),
             pwx    = getval("pwx"),
             pwxlvl = getval("pwxlvl"),
             j1xh   = getval("j1xh"),
             jcc    = getval("jcc"),
             satdly = getval("satdly"),
             satpwr = getval("satpwr"),
             satfrq = getval("satfrq"),
             sw1    = getval("sw1"),
             gstab  = getval("gstab"),
             kappa  = getval("kappa"),
             dofdec = getval("dofdec"),
             pwx180 = getval("pwx180"),
             pwxlvl180  = getval("pwxlvl180");

    getstr("f1180",f1180);
    getstr("satmode",satmode);
    getstr("sspul",sspul);
    getstr("pwx180ad", pwx180ad);
    ni = getval("ni");
    av180 = (double)((int)(1e6*(9.45*4*pwx/1.54+0.5e-6))/1e6); /* round it to 1usec */
    phase = (int) (getval("phase") + 0.5);
    satmove = ( fabs(tof - satfrq) >= 0.1 );

    /* construct a command line for Pbox */

    if((getval("arraydim") < 1.5) || (ix==1))        /* execute only once */
    {   sprintf(comm, "Pbox ad180 -u %s -w \"cawurst-10 %.1f/%.6f\" -s 1.0 -0\n",
                userdir, 1.0/pwx, 30*pwx);
        system(comm);                         /* create adiabatic 180 pulse */
        sprintf(comm, "Pbox av180 -u %s -w \"av180b %.6f\" -s 1.0 -0\n", userdir, av180);
        system(comm);                        /* create refocusing 180 pulse */
    }

    /* LOAD VARIABLES */

    settable(t1, 1, phi1);
    settable(t2, 1, phi2);
    settable(t4, 2, phi4);
    settable(t5, 4, phi5);
    settable(t6, 4, phi6);
    settable(t8, 1, phi8);
    settable(t9, 8, phi9);
    settable(t10, 16, phi10);
    settable(t11, 1, phi11);
    settable(t31, 16, phi31);

    /* INITIALIZE VARIABLES */
    if (j1xh != 0.0)
    {
        tauxh = 1/(4*j1xh);
        tauxh1 = 1/(6*j1xh);
    }
    else
    {
        tauxh = 1.80e-3;
        tauxh1 = 1.80e-3;
    }

    if ( jcc != 0.0 ) taucc = 1/(4*jcc);
    else  taucc = 1/(4*40);

    /*  Phase incrementation for hypercomplex echo-antiecho 2D data */

    if (phase == 2)
    {
        tsadd(t6,2,4);
        icosel=-1;
    }
    else icosel=1;

    /* Calculate modifications to phases for States-TPPI acquisition          */

    if( ix == 1) d2_init = d2 ;
    t1_counter = (int) ( (d2-d2_init)*sw1 + 0.5 );
    if(t1_counter % 2)
    {
        tsadd(t9,2,4);
        tsadd(t31,2,4);
    }

    /* Check constant-time conditions */
    if (kappa == 1.0)
    {
        maxni = (int) (taucc*sw1*2.0);
        if (maxni < ni)
        {
            abort_message("too many increments! maxni = %d   ",maxni);
        }
    }

    /* SET UP FOR (-90,180) PHASE CORRECTIONS IF f1180='y' */
    tau1 = d2;
    if(f1180[A] == 'y')  tau1 += ( 1.0/(2.0*sw1) ); /* Wait half a dwell time */
    tau1 = tau1/2.0;

    /* BEGIN ACTUAL PULSE SEQUENCE */

    status(A);
    decpower(pwxlvl);
    decoffset(dof);     /* Set decoupler power to pwxlvl */

    delay(5.0e-5);
    if (getflag("sspul"))
        steadystate();

    if (satmode[0] == 'y')
    {
        if ((d1-satdly) > 0.02)
            delay(d1-satdly);
        else
            delay(0.02);
        if (getflag("slpsat"))
        {
            shaped_satpulse("relaxD",satdly,v4);
            if (getflag("prgflg"))
                shaped_purge(v1,v4,v18,v19);
        }
        else
        {
            satpulse(satdly,v4,rof1,rof1);
            if (getflag("prgflg"))
                purge(v1,v4,v18,v19);
        }

    }
    else
        delay(d1);

    if (getflag("wet"))
        wet4(zero,one);

    status(B);
    rcvroff();
    rgpulse(pw,t1,1.0e-6,0.0);
    txphase(t1);
    decphase(t1);
    delay(tauxh-15.0*pwx);                        /* delay=1/4J(XH) */
    simshaped_pulse("","ad180",2*pw,30*pwx,t1,t1,0.0,0.0);
    txphase(t2);
    decphase(t4);
    delay(tauxh-15.0*pwx);
    simpulse(pw,pwx,t2,t4,0.0,0.0);
    decphase(t8);
    delay(taucc);
    decshaped_pulse("av180",av180,t8,0.0,0.0);
    decphase(t9);
    delay(taucc);
    decrgpulse(pwx,t9,0.0,0.0);
    delay(tau1);
    rgpulse(2*pw,t1,1.0e-6,0.0);
    delay(tau1);
    delay(gt1 + gstab + 2*GRADIENT_DELAY - 2*pw -1.0e-6);
    decshaped_pulse("av180",av180,t11,1.0e-6,0.0);
    zgradpulse(gzlvl1, gt1);
    delay(gstab);
    decrgpulse(pwx*1.3333,t10,1.0e-6,0.0);   /* 120 Grad pulse */
    decphase(t11);
    delay(taucc - kappa*tau1);
    decshaped_pulse("av180",av180,t11,0.0,0.0);
    delay(10.0e-6);
    zgradpulse(gzlvl2,gt2);
    delay(gstab);
    delay(taucc - 10.0e-6 - gstab - gt2 - 2*GRADIENT_DELAY - 1.0e-6);
    rgpulse(kappa*2*pw,t1,1.0e-6,0.0);
    delay(kappa*tau1);
    simpulse(pw,pwx,t1,t5,1.0e-6,0.0);
    txphase(t1);
    decphase(t1);
    delay(tauxh1);                        /* delay=1/4J (XH);1/6J XH,XH2, XH3) */
    simshaped_pulse("","av180",2*pw,av180,t1,t1,0.0,0.0);
    txphase(t2);
    decphase(t6);
    delay(tauxh1);
    simpulse(pw,pwx,t2,t6,0.0,0.0);
    txphase(t1);
    decphase(t1);
    delay(tauxh-15.0*pwx);
    simshaped_pulse("","ad180",2*pw,30*pwx,t1,t1,0.0,0.0);
    txphase(t1);
    delay(tauxh-15.0*pwx-0.5e-6);
    rgpulse(pw,t1,0.0,0.0);
    decpower(dpwr);
    decoffset(dofdec);  /* lower decoupler power for decoupling */
    delay(gt3 + gstab + 2*GRADIENT_DELAY-POWER_DELAY-1.0e-6);
    rgpulse(2*pw,t1,1.0e-6,0.0);
    zgradpulse(icosel*gzlvl3, gt3);
    delay(gstab);
    rcvron();
    status(C);
    setreceiver(t31);
}
Esempio n. 10
0
/*
 *	Write captured packet to file
 *
 *	uint8_t *flag : filter is set or not
 *	const uint8_t *packet : captured packet
 *	char *fltrload : filter for payload
 *	cosnt int payloadlen : length of captured payload
 */
static void printfile(uint8_t *flag, const uint8_t *packet, char *fltrload, const int payloadlen)
{
	FILE *fp = fopen(LOGFILE, "a");
	const uint8_t *http = NULL;
	char *timestamp;
	struct ether_header *eth;
	struct ip *iphdr;
	struct tcphdr *tcphdr;
	struct udphdr *udphdr;
	uint8_t prot;
	int hdrlen, i;

	flag += 2;  // remove unused member

	eth = (struct ether_header *)packet;
	hdrlen = sizeof(struct ether_header);

	iphdr = (struct ip *)(packet + hdrlen);
	hdrlen += sizeof(struct ip);

	prot = iphdr->ip_p;
	if( prot == 17 ) {
		udphdr = (struct udphdr *)(packet + hdrlen);
		hdrlen += sizeof(struct udphdr);
	}else {
		tcphdr = (struct tcphdr *)(packet + hdrlen);
		hdrlen += sizeof(struct tcphdr);

		// HTTP request check 
		if( PROTOCOL(flag) ) {
			if( prot == 3 ) {
				if( HTTPTEST("GET",3) == false )
					return;

			}else if( prot == 5 ) {
				if( HTTPTEST("PUT",3) == false )
					return;

			}else if(prot == 7) {
				if( HTTPTEST("POST",4) == false )
					return;
			}
		}
	}

	
	

	// Timestamp
	timestamp = (char *)gettime();
	fprintf(fp, "%s ------\n", timestamp);
	free(timestamp);

	/* Ethernet Header */
	i = 0;
	if( DSTMAC(flag) ) {
		fprintf(fp, "\x1b[45mDestination MAC\x1b[0m\t: \x1b[45m");
		while( i < 5 )
			fprintf(fp, "%02X:", eth->ether_dhost[i++]);
		fprintf(fp, "%02X\x1b[0m\n", eth->ether_dhost[i]);
	}else {
		fprintf(fp, "Destination MAC\t: ");
		while( i < 5 )
			fprintf(fp, "%02X:", eth->ether_dhost[i++]);
		fprintf(fp, "%02X\n", eth->ether_dhost[i]);
	}

	i = 0;
	if( SRCMAC(flag) ) {
		fprintf(fp, "\x1b[45mSource MAC\x1b[0m\t: \x1b[45m");
		while( i < 5 )
			fprintf(fp, "%02X:", eth->ether_shost[i++]);
		fprintf(fp, "%02X\x1b[0m\n", eth->ether_shost[i]);
	}else {
		fprintf(fp, "Source MAC\t: ");
		while( i < 5 )
			fprintf(fp, "%02X:", eth->ether_shost[i++]);
		fprintf(fp, "%02X\n", eth->ether_shost[i]);
	}

	if( ETHERTYPE(flag) )
		fprintf(fp, "\x1b[45mEthernet Type\x1b[0m\t: \x1b[45m%s\x1b[0m\n", gettype(eth->ether_type));
	else
		fprintf(fp, "Ethernet Type\t: %s\n", gettype(eth->ether_type));

	/* IP Header */
	if( VERSION(flag) & 0xf0 )
		fprintf(fp, "\x1b[44mVersion\x1b[0m\t\t: \x1b[44m%d\x1b[0m\n", iphdr->ip_v);
	else
		fprintf(fp, "Version\t\t: %d\n", iphdr->ip_v);

	if( IPHLEN(flag) & 0x0f )
		fprintf(fp, "\x1b[44mIP Header length\x1b[0m: \x1b[44m%d\x1b[0m\n", iphdr->ip_hl);
	else
		fprintf(fp, "IP Header length: %d\n", iphdr->ip_hl);

	if( TOS(flag) )
		fprintf(fp, "\x1b[44mType of Service\x1b[0m\t: \x1b[44m%s\x1b[0m\n", gettos(iphdr->ip_tos));
	else
		fprintf(fp, "Type of Service\t: %s\n", gettos(iphdr->ip_tos));

	if( IPLEN(flag) )
		fprintf(fp, "\x1b[44mTotal length\x1b[0m\t: \x1b[44m%d\x1b[0m\n", ntohs(iphdr->ip_len));
	else
		fprintf(fp, "Total length\t: %d\n", ntohs(iphdr->ip_len));

	if( IPID(flag) )
		fprintf(fp, "\x1b[44mIdentification\x1b[0m\t: \x1b[44m%d\x1b[0m\n", ntohs(iphdr->ip_id));
	else
		fprintf(fp, "Identification\t: %d\n", ntohs(iphdr->ip_id));

	if( FRAGMENT(flag) )
		fprintf(fp, "\x1b[44mFragment\x1b[0m\t: \x1b[44m%d\x1b[0m\n", iphdr->ip_off);
	else
		fprintf(fp, "Fragment\t: %d\n", iphdr->ip_off);

	if( TTL(flag) )
		fprintf(fp, "\x1b[44mTime to live\x1b[0m\t: \x1b[44m%d\x1b[0m\n", iphdr->ip_ttl);
	else
		fprintf(fp, "Time to live\t: %d\n", iphdr->ip_ttl);

	if( PROTOCOL(flag) )
		fprintf(fp, "\x1b[44mProtocol\x1b[0m\t: \x1b[44m%s\x1b[0m\n", getprot(iphdr->ip_p));
	else
		fprintf(fp, "Protocol\t: %s\n", getprot(iphdr->ip_p));

	if( IPCKSUM(flag) )
		fprintf(fp, "\x1b[44mChecksum\x1b[0m\t: \x1b[44m%d\x1b[0m\n", ntohs(iphdr->ip_sum));
	else
		fprintf(fp, "Checksum\t: %d\n", ntohs(iphdr->ip_sum));

	if( SRCIP(flag) )
		fprintf(fp, "\x1b[44mSource IP\x1b[0m\t: \x1b[44m%s\x1b[0m\n", inet_ntoa(iphdr->ip_src));
	else
		fprintf(fp, "Source IP\t: %s\n", inet_ntoa(iphdr->ip_src));

	if( DSTIP(flag) )
		fprintf(fp, "\x1b[44mDestination IP\x1b[0m\t: \x1b[44m%s\x1b[0m\n", inet_ntoa(iphdr->ip_dst));
	else
		fprintf(fp, "Destination IP\t: %s\n", inet_ntoa(iphdr->ip_dst));

	if( iphdr->ip_p == 17 ) {
	/* UDP Header */
		if( SRCPORT(flag) )
			fprintf(fp, "\x1b[42mSource Port\x1b[0m\t: \x1b[42m%d\x1b[0m\n", ntohs(udphdr->source));
		else
			fprintf(fp, "Source Port\t: %d\n", ntohs(udphdr->source));

		if( DSTPORT(flag) )
			fprintf(fp, "\x1b[42mDestination Port\x1b[0m: \x1b[42m%d\x1b[0m\n", ntohs(udphdr->dest));
		else
			fprintf(fp, "Destination Port: %d\n", ntohs(udphdr->dest));

		if( UDPLEN(flag) )
			fprintf(fp, "\x1b[42mTotal length\x1b[0m\t: \x1b[42m%d\x1b[0m\n", ntohs(udphdr->len));
		else
			fprintf(fp, "Total length\t: %d\n", ntohs(udphdr->len));

		if( UDPCKSUM(flag) )
			fprintf(fp, "\x1b[42mCheckSum\x1b[0m\t: \x1b[42m%d\x1b[0m\n", ntohs(udphdr->check));
		else
			fprintf(fp, "Checksum\t: %d\n", ntohs(udphdr->check));
	}else {
	/* TCP Header */
		if( SRCPORT(flag) )
			fprintf(fp, "\x1b[31;43mSource Port\x1b[0m\t: \x1b[31;43m%d\x1b[0m\n", ntohs(tcphdr->source));
		else
			fprintf(fp, "Source Port\t: %d\n", ntohs(tcphdr->source));

		if( DSTPORT(flag) )
			fprintf(fp, "\x1b[31;43mDestination Port\x1b[0m: \x1b[31;43m%d\x1b[0m\n", ntohs(tcphdr->dest));
		else
			fprintf(fp, "Destination Port: %d\n", ntohs(tcphdr->dest));

		if( SEQ(flag) )
			fprintf(fp, "\x1b[31;43mSequence Number\x1b[0m\t: \x1b[31;43m%u\x1b[0m\n", ntohl(tcphdr->seq));
		else
			fprintf(fp, "Sequence Number\t: %u\n", ntohl(tcphdr->seq));

		if( ACK(flag) )
			fprintf(fp, "\x1b[31;43mAcknowledgement\x1b[0m\t: \x1b[31;43m%u\x1b[0m\n", ntohl(tcphdr->ack));
		else
			fprintf(fp, "Acknowledgement\t: %u\n", ntohl(tcphdr->ack));

		if( TCPOFF(flag) & 0x0f )
			fprintf(fp, "\x1b[31;43mOffset\x1b[0m\t\t: \x1b[31;43m%d\x1b[0m\n", tcphdr->doff);
		else
			fprintf(fp, "Offset\t\t: %d\n", tcphdr->doff);

		if( TCPRES(flag) & 0xf0 )
			fprintf(fp, "\x1b[31;43mReserved\x1b[0m\t: \x1b[31;43m%d\x1b[0m\n", tcphdr->res1);
		else
			fprintf(fp, "Reserved\t: %d\n", tcphdr->res1);

		char *tmp = getflag(*(packet + 47), tcphdr->res1, tcphdr->res2);
		if( TCPFLAG(flag) )
			fprintf(fp, "\x1b[31;43mFlags\x1b[0m\t\t: \x1b[31;43m%s\x1b[0m\n", tmp);
		else
			fprintf(fp, "Flags\t\t: %s\n", tmp);
		free(tmp);

		if( WINDOW(flag) )
			fprintf(fp, "\x1b[31;43mWindow size\x1b[0m\t: \x1b[31;43m%d\x1b[0m\n", ntohs(tcphdr->window));
		else
			fprintf(fp, "Window size\t: %d\n", ntohs(tcphdr->window));

		if( TCPCKSUM(flag) )
			fprintf(fp, "\x1b[31;43mChecksum\x1b[0m\t: \x1b[31;43m%d\x1b[0m\n", ntohs(tcphdr->check));
		else
			fprintf(fp, "Checksum\t: %d\n", ntohs(tcphdr->check));

		if( URGPTR(flag) )
			fprintf(fp, "\x1b[31;43mUrgent Pointer\x1b[0m\t: \x1b[31;43m%d\x1b[0m\n", ntohs(tcphdr->urg_ptr));
		else
			fprintf(fp, "Urgent Pointer\t: %d\n", ntohs(tcphdr->urg_ptr));
	}

	/* Payload */
	if( fltrload != NULL ) {
		const uint8_t *match = NULL;
		uint8_t highlight[MAXPAYLOAD];
		int fltrloadlen, unmatchlen = 0;
		int colorhex = 0, colorstr = 0;
		int i = 0, str = 0, colorlen = 0, highlen = 0;
		char ch;

		memset(highlight, 0, MAXPAYLOAD);

		packet += hdrlen;
		fltrloadlen = strlen(fltrload);

		fprintf(fp, "*** Payload ***\n");

		if( http != NULL ) {
			if( prot == 3 ) {
				memcpy(highlight, HTTPCOLOR, 5);
				memcpy(highlight + 5, "GET\x1b[0m", 7);
				highlen += 12;
				i += 3;

			}else if( prot == 5 ) {
				memcpy(highlight, HTTPCOLOR, 5);
				memcpy(highlight + 5, "PUT\x1b[0m", 7);
				highlen += 12;
				i += 3;

			}else if( prot == 7 ) {
				memcpy(highlight, HTTPCOLOR, 5);
				memcpy(highlight + 5, "POST\x1b[0m", 8);
				highlen += 13;
				i += 4;
			}
		}

		while( i < payloadlen ) {
			// move to next matching string
			match = memcmp_cont(packet + i, fltrload, fltrloadlen, payloadlen - i);
			if( match == NULL ) {
				unmatchlen = payloadlen - i;

				memcpy(highlight + highlen, packet + i, unmatchlen);
				highlen += unmatchlen;

				break;
			}else {

				if( http != NULL && match - packet > http - packet ) {
				// HTTP/1.1
					unmatchlen = http - (packet + i);

					memcpy(highlight + highlen, packet + i, unmatchlen);
					highlen += unmatchlen;
					i += unmatchlen;

					memcpy(highlight + highlen, "\x1b[46mHTTP/1.1\x1b[0m", 17);
					highlen += 17;
					i += 8;
					http = NULL;
				}else {
					unmatchlen = match - (packet + i);

					memcpy(highlight + highlen, packet + i, unmatchlen);
					highlen += unmatchlen;
					i += unmatchlen;

					memcpy(highlight + highlen, PAYLOADCOLOR, 5);
					highlen += 5;

					memcpy(highlight + highlen, packet + i, fltrloadlen);
					highlen += fltrloadlen;
					i += fltrloadlen;

					memcpy(highlight + highlen, NORMALCOLOR, 4);
					highlen += 4;
				}
			}
		}

		i = 0;
		while( i < highlen ) {
			ch = *(highlight + i);

			if( ch == '\x1b' ) {
				if( COLORTEST(i, PAYLOADCOLOR) == true ) {
					fprintf(fp, PAYLOADCOLOR);
					colorhex = 41;
					i += 5;
					colorlen += 5;
					continue;

				}else if( COLORTEST(i, HTTPCOLOR) == true ) {
					fprintf(fp, HTTPCOLOR);
					colorhex = 46;
					i += 5;
					colorlen += 5;
					continue;

				}else if( COLORTEST(i, NORMALCOLOR) == true ) {
					fprintf(fp, NORMALCOLOR);
					colorhex = 0;
					i += 4;
					colorlen += 4;
					continue;
				}
			}

			fprintf(fp, "%02X ", ch);
			i++;

			if( ++str == 16 ) {
				if( colorhex != 0 )
					fprintf(fp, NORMALCOLOR);

				fprintf(fp, "   ");

				if( colorstr == 41 ) {
					fprintf(fp, PAYLOADCOLOR);
					colorstr = 0;

				}else if( colorstr == 46 ) {
					fprintf(fp, HTTPCOLOR);
					colorstr = 0;
				}

				while( colorlen > 0 ) {
					ch = *(highlight + i - colorlen - str);
					if( ch > 126 || ch < 32 ) {
						if( ch == 27 ) {
							if( COLORTEST(i - colorlen - str, PAYLOADCOLOR) == true )
								colorstr = 41;

							else if( COLORTEST(i - colorlen - str, HTTPCOLOR) == true )
								colorstr = 46;

							else if( COLORTEST(i - colorlen - str, NORMALCOLOR) == true )
								colorstr = 0;

							else
								ch = '.';
						}else
							ch = '.';
					}
					fprintf(fp, "%c", ch);
					colorlen--;
				}

				while( str > 0 ) {
					ch = *(highlight + i - str);
					if( ch > 126 || ch < 32 ) {
						if( ch == 27 ) {
							if( COLORTEST(i - colorlen - str, PAYLOADCOLOR) == true )
								colorstr = 41;
							else if( COLORTEST(i - colorlen - str, HTTPCOLOR) == true )
								colorstr = 46;
							else if( COLORTEST(i - colorlen - str, NORMALCOLOR) == true )
								colorstr = 0;
							else
								ch = '.';
						}else
							ch = '.';
					}
					fprintf(fp, "%c", ch);
					str--;
				}

				if( colorstr != 0 )
					fprintf(fp, NORMALCOLOR);

				fprintf(fp, "\n");

				if( colorhex == 41 ) {
					fprintf(fp, PAYLOADCOLOR);
					colorhex = 0;

				}else if( colorhex == 46 ) {
					fprintf(fp, HTTPCOLOR);
					colorhex = 0;
				}
			}
		}

		if( str != 0 ) {
			int padd = 17;
			if( colorhex != 0 )
				fprintf(fp, NORMALCOLOR);

			while( str < padd-- )
				fprintf(fp, "   ");

			if( colorstr == 41 ) {
				fprintf(fp, PAYLOADCOLOR);
				colorstr = 0;

			}else if( colorstr == 46 ) {
				fprintf(fp, HTTPCOLOR);
				colorstr = 0;
			}

			while( colorlen > 0 ) {
				ch = *(highlight + i - colorlen - str);
				if( ch > 126 || ch < 32 ) {
					if( ch == 27 ) {
						if( COLORTEST(i - colorlen - str, PAYLOADCOLOR) == true )
							colorstr = 41;
						else if( COLORTEST(i - colorlen - str, HTTPCOLOR) == true )
							colorstr = 46;
						else if( COLORTEST(i - colorlen - str, NORMALCOLOR) == true )
							colorstr = 0;
						else
							ch = '.';
					}else
						ch = '.';
				}
				fprintf(fp, "%c", ch);
				colorlen--;
			}

			while( str > 0 ) {
				ch = *(highlight + i - str);
				if( ch > 126 || ch < 32 ) {
					if( ch == 27 ) {
						if( COLORTEST(i - colorlen - str, PAYLOADCOLOR) == true )
							colorstr = 41;
						else if( COLORTEST(i - colorlen - str, HTTPCOLOR) == true )
							colorstr = 46;
						else if( COLORTEST(i - colorlen - str, NORMALCOLOR) == true )
							colorstr = 0;
						else
							ch = '.';
					}else
						ch = '.';
				}
				fprintf(fp, "%c", ch);
				str--;
			}
			fprintf(fp, "\x1b[0m\n");
		}
	}else { // fltrload == NULL
		uint8_t highlight[MAXPAYLOAD];
		int unmatchlen = 0;
		int colorhex = 0, colorstr = 0;
		int i = 0, str = 0, colorlen = 0, highlen = 0;
		char ch;

		memset(highlight, 0, MAXPAYLOAD);

		packet += hdrlen;

		fprintf(fp, "*** Payload ***\n");

		if( http != NULL ) {
			if( prot == 3 ) {
				memcpy(highlight, HTTPCOLOR, 5);
				memcpy(highlight + 5, "GET\x1b[0m", 7);
				highlen += 12;
				i += 3;

			}else if( prot == 5 ) {
				memcpy(highlight, HTTPCOLOR, 5);
				memcpy(highlight + 5, "PUT\x1b[0m", 7);
				highlen += 12;
				i += 3;

			}else if( prot == 7 ) {
				memcpy(highlight, HTTPCOLOR, 5);
				memcpy(highlight + 5, "POST\x1b[0m", 8);
				highlen += 13;
				i += 4;
			}
		}

		while( i < payloadlen ) {
		// move to next matching string
			if( http != NULL ) {
			// HTTP/1.1
				unmatchlen = http - (packet + i);

				memcpy(highlight + highlen, packet + i, unmatchlen);
				highlen += unmatchlen;
				i += unmatchlen;

				memcpy(highlight + highlen, "\x1b[46mHTTP/1.1\x1b[0m", 17);
				highlen += 17;
				i += 8;
				http = NULL;
			}else {
				memcpy(highlight + highlen, packet + i, payloadlen - i);
				highlen += unmatchlen;
				i += unmatchlen;
			}
		}

		i = 0;
		while( i < highlen ) {
			ch = *(highlight + i);

			if( ch == '\x1b' ) {
				if( COLORTEST(i, PAYLOADCOLOR) == true ) {
					fprintf(fp, PAYLOADCOLOR);
					colorhex = 41;
					i += 5;
					colorlen += 5;
					continue;

				}else if( COLORTEST(i, HTTPCOLOR) == true ) {
					fprintf(fp, HTTPCOLOR);
					colorhex = 46;
					i += 5;
					colorlen += 5;
					continue;

				}else if( COLORTEST(i, NORMALCOLOR) == true ) {
					fprintf(fp, NORMALCOLOR);
					colorhex = 0;
					i += 4;
					colorlen += 4;
					continue;
				}
			}

			fprintf(fp, "%02X ", ch);
			i++;

			if( ++str == 16 ) {
				if( colorhex != 0 )
					fprintf(fp, NORMALCOLOR);

				fprintf(fp, "   ");

				if( colorstr == 41 ) {
					fprintf(fp, PAYLOADCOLOR);
					colorstr = 0;

				}else if( colorstr == 46 ) {
					fprintf(fp, HTTPCOLOR);
					colorstr = 0;
				}

				while( colorlen > 0 ) {
					ch = *(highlight + i - colorlen - str);
					if( ch > 126 || ch < 32 ) {
						if( ch == 27 ) {
							if( COLORTEST(i - colorlen - str, PAYLOADCOLOR) == true )
								colorstr = 41;
							else if( COLORTEST(i - colorlen - str, HTTPCOLOR) == true )
								colorstr = 46;
							else if( COLORTEST(i - colorlen - str, NORMALCOLOR) == true )
								colorstr = 0;
							else
								ch = '.';
						}else
							ch = '.';
					}
					fprintf(fp, "%c", ch);
					colorlen--;
				}

				while( str > 0 ) {
					ch = *(highlight + i - str);
					if( ch > 126 || ch < 32 ) {
						if( ch == 27 ) {
							if( COLORTEST(i - colorlen - str, PAYLOADCOLOR) == true )
								colorstr = 41;
							else if( COLORTEST(i - colorlen - str, HTTPCOLOR) == true )
								colorstr = 46;
							else if( COLORTEST(i - colorlen - str, NORMALCOLOR) == true )
								colorstr = 0;
							else
								ch = '.';
						}else
							ch = '.';
					}
					fprintf(fp, "%c", ch);
					str--;
				}

				if( colorstr != 0 )
					fprintf(fp, NORMALCOLOR);

				fprintf(fp, "\n");

				if( colorhex == 41 ) {
					fprintf(fp, PAYLOADCOLOR);
					colorhex = 0;

				}else if( colorhex == 46 ) {
					fprintf(fp, HTTPCOLOR);
					colorhex = 0;
				}
			}
		}

		if( str != 0 ) {
			int padd = 17;
			if( colorhex != 0 )
				fprintf(fp, NORMALCOLOR);

			while( str < padd-- )
				fprintf(fp, "   ");

			if( colorstr == 41 ) {
				fprintf(fp, PAYLOADCOLOR);
				colorstr = 0;

			}else if( colorstr == 46 ) {
				fprintf(fp, HTTPCOLOR);
				colorstr = 0;
			}

			while( colorlen > 0 ) {
				ch = *(highlight + i - colorlen - str);
				if( ch > 126 || ch < 32 ) {
					if( ch == 27 ) {
						if( COLORTEST(i - colorlen - str, PAYLOADCOLOR) == true )
							colorstr = 41;
						else if( COLORTEST(i - colorlen - str, HTTPCOLOR) == true )
							colorstr = 46;
						else if( COLORTEST(i - colorlen - str, NORMALCOLOR) == true )
							colorstr = 0;
						else
							ch = '.';
					}else
						ch = '.';
				}
				fprintf(fp, "%c", ch);
				colorlen--;
			}

			while( str > 0 ) {
				ch = *(highlight + i - str);
				if( ch > 126 || ch < 32 ) {
					if( ch == 27 ) {
						if( COLORTEST(i - colorlen - str, PAYLOADCOLOR) == true )
							colorstr = 41;
						else if( COLORTEST(i - colorlen - str, HTTPCOLOR) == true )
							colorstr = 46;
						else if( COLORTEST(i - colorlen - str, NORMALCOLOR) == true )
							colorstr = 0;
						else
							ch = '.';
					}else
						ch = '.';
				}
				fprintf(fp, "%c", ch);
				str--;
			}
			fprintf(fp, "\x1b[0m\n");
		}
	}
	fprintf(fp, "----------------------------\n");
	fclose(fp);
}
Esempio n. 11
0
void pulsesequence()
{
   double  hsglvl = getval("hsglvl"),
             hsgt = getval("hsgt"),
           satpwr = getval("satpwr"),
           satdly = getval("satdly");
   int     prgcycle = (int)(getval("prgcycle")+0.5);
   char    sspul[MAXSTR],satmode[MAXSTR],wet[MAXSTR];

   getstr("satmode",satmode);
   getstr("sspul", sspul);
   getstr("wet",wet);

  assign(ct,v17);
  assign(zero,v18);
  assign(zero,v19);

  if (getflag("prgflg") && (satmode[0] == 'y') && (prgcycle > 1.5))
    {
        hlv(ct,v17);
        mod2(ct,v18); dbl(v18,v18);
        if (prgcycle > 2.5)
           {
                hlv(v17,v17);
                hlv(ct,v19); mod2(v19,v19); dbl(v19,v19);
           }
     }

   settable(t1,4,ph1);     getelem(t1,v17,v1);
   settable(t2,8,ph2);     getelem(t2,v17,v2);
   assign(v1,oph);
   add(oph,v18,oph);
   add(oph,v19,oph);

/* BEGIN ACTUAL SEQUENCE */
   status(A);
      obspower(tpwr);
 
   delay(5.0e-5);
   if (getflag("sspul"))
	steadystate();

   if (satmode[0] == 'y')
     {
        if ((d1-satdly) > 0.02)
                delay(d1-satdly);
        else
                delay(0.02);
        if (getflag("slpsat"))
           {
                shaped_satpulse("relaxD",satdly,v4);
                if (getflag("prgflg"))
                   shaped_purge(v1,v4,v18,v19);
           }
        else
           {
                satpulse(satdly,v4,rof1,rof1);
                if (getflag("prgflg"))
                   purge(v1,v4,v18,v19);
           }

     }
   else
	delay(d1);

   if (getflag("wet"))
     wet4(zero,one);

   status(B);
      if (getflag("cpmgflg"))
      {
         rgpulse(pw, v1, rof1, 0.0);
         cpmg(v1, v15);
      }
      else
         rgpulse(pw, v1, rof1, rof1);
      delay(d2/2);
      rgpulse(2.0*pw, v2, rof1, 2*rof1);
      delay(d2/2 + 2*pw/PI);
   status(C);
}
Esempio n. 12
0
pulsesequence()

{
   double   gzlvlE = getval("gzlvlE"),
	    gtE = getval("gtE"),
	    EDratio = getval("EDratio"),
	    gstab = getval("gstab"),
	    mult = getval("mult"),
            hsglvl = getval("hsglvl"),
            hsgt = getval("hsgt"),
            tau,
	    evolcorr,
            taug;
   int	    icosel,
            prgcycle = (int)(getval("prgcycle")+0.5),
	    phase1 = (int)(getval("phase")+0.5),
	    ZZgsign;

//synchronize gradients to srate for probetype='nano'
//   Preserve gradient "area"
        gtE = syncGradTime("gtE","gzlvlE",0.5);
        gzlvlE = syncGradLvl("gtE","gzlvlE",0.5);

   tau  = 1/(4*(getval("j1xh")));
   evolcorr = 2*pw+4.0e-6;

   if (mult > 0.5)
    taug = 2*tau;
   else
    taug = gtE + gstab + 2*GRADIENT_DELAY;
   ZZgsign=-1;
   if (mult == 2) ZZgsign=1;
   icosel = 1;

  assign(ct,v17);
  assign(zero,v18);
  assign(zero,v19);

  if (getflag("prgflg") && (satmode[0] == 'y') && (prgcycle > 1.5))
    {
        hlv(ct,v17);
        mod2(ct,v18); dbl(v18,v18);
        if (prgcycle > 2.5)
           {
                hlv(v17,v17);
                hlv(ct,v19); mod2(v19,v19); dbl(v19,v19);
           }
     }

   settable(t1,4,ph1);
   settable(t2,2,ph2);
   settable(t3,8,ph3);
   settable(t4,16,ph4);
   settable(t5,16,ph5);

  getelem(t1, v17, v1);
  getelem(t3, v17, v3);
  getelem(t4, v17, v4);
  getelem(t2, v17, v2);
  getelem(t5, v17, oph);

  assign(zero,v6);
  add(oph,v18,oph);
  add(oph,v19,oph);

/*
   mod2(id2,v14);
   dbl(v14,v14);
*/
   initval(2.0*(double)(((int)(d2*getval("sw1")+0.5)%2)),v14);

   if ((phase1 == 2) || (phase1 == 5))
     icosel = -1;

   add(v2,v14,v2);
   add(oph,v14,oph);

status(A);
   obspower(tpwr);

   delay(5.0e-5);
   if (getflag("sspul"))
        steadystate();

   if (satmode[0] == 'y')
     {
        if ((d1-satdly) > 0.02)
                delay(d1-satdly);
        else
                delay(0.02);
        if (getflag("slpsat"))
           {
                shaped_satpulse("relaxD",satdly,zero);
                if (getflag("prgflg"))
                   shaped_purge(v6,zero,v18,v19);
           }
        else
           {
                satpulse(satdly,zero,rof1,rof1);
                if (getflag("prgflg"))
                   purge(v6,zero,v18,v19);
           }
     }
   else
	delay(d1);

   if (getflag("wet"))
     wet4(zero,one);

   decpower(pwxlvl);

status(B);

      if (getflag("nullflg"))
      {
        rgpulse(0.5*pw,zero,rof1,rof1);
        delay(2*tau);
        simpulse(2.0*pw,2.0*pwx,zero,zero,rof1,rof1);
        delay(2*tau);
        rgpulse(1.5*pw,two,rof1,rof1);
        zgradpulse(hsglvl,hsgt);
        delay(1e-3);
      }

     rgpulse(pw,v6,rof1,rof1);
     delay(tau);
     simpulse(2*pw,2*pwx,zero,zero,rof1,rof1);
     delay(tau);
     rgpulse(pw,v1,rof1,rof1);
	zgradpulse(hsglvl,2*hsgt);
	delay(1e-3);
     decrgpulse(pwx,v2,rof1,2.0e-6);
     
      delay(d2/2);
     rgpulse(2*pw,zero,2.0e-6,2.0e-6);
      delay(d2/2);
     zgradpulse(gzlvlE,gtE);
     delay(taug - gtE - 2*GRADIENT_DELAY);
     simpulse(mult*pw,2*pwx,zero,zero,rof1,rof1);
     delay(taug + evolcorr); 
     
     decrgpulse(pwx,v4,2.0e-6,rof1);
	zgradpulse(ZZgsign*0.6*hsglvl,1.2*hsgt);
	delay(1e-3);
     rgpulse(pw,v3,rof1,rof1);
     delay(tau - (2*pw/PI) - 2*rof1);
     simpulse(2*pw,2*pwx,zero,zero,rof1, rof2);
     decpower(dpwr);
     zgradpulse(icosel*2.0*gzlvlE/EDratio,gtE/2.0);
     delay(tau - gtE/2.0 - 2*GRADIENT_DELAY - POWER_DELAY);
   status(C);
}
Esempio n. 13
0
pulsesequence()
{

  double j1min = getval("j1min"),
         j1max = getval("j1max"),
         pwx180 = getval("pwx180"),
         pwxlvl180 = getval("pwxlvl180"),
         pwx180r = getval("pwx180r"),
         pwxlvl180r = getval("pwxlvl180r"),
         mult = getval("mult"),
         gzlvl0 = getval("gzlvl0"),
         gt0 = getval("gt0"),
         gzlvlE = getval("gzlvlE"),
         gtE = getval("gtE"),
         EDratio = getval("EDratio"),
         gstab = getval("gstab"),
	 tauA,
         tauB,
         tau,
         taumb,
         taug,
         grad1,
         grad2,
         grad3,
         grad4;

  char   pwx180ad[MAXSTR], 
         pwx180ref[MAXSTR];

  int 	 icosel,
         prgcycle = (int)(getval("prgcycle")+0.5),
	 phase1 = (int)(getval("phase")+0.5);

//synchronize gradients to srate for probetype='nano'
//   Preserve gradient "area"
        gtE = syncGradTime("gtE","gzlvlE",1.0);
        gzlvlE = syncGradLvl("gtE","gzlvlE",1.0);

  getstr("pwx180ad", pwx180ad);
  getstr("pwx180ref", pwx180ref);

  tauA = 1/(2*(j1min + 0.146*(j1max - j1min)));
  tauB = 1/(2*(j1max - 0.146*(j1max - j1min)));
  tau = 1/(j1max + j1min);
  taumb = 1 / (2 * (getval("jnxh")));

  taug = tau + getval("tauC");

  icosel = 1;

  assign(ct,v17);
  assign(zero,v18);
  assign(zero,v19);

  if (getflag("prgflg") && (satmode[0] == 'y') && (prgcycle > 1.5))
    {
        hlv(ct,v17);
        mod2(ct,v18); dbl(v18,v18);
        if (prgcycle > 2.5)
           {
                hlv(v17,v17);
                hlv(ct,v19); mod2(v19,v19); dbl(v19,v19);
           }
     }

  settable(t1, 4, ph1);
  settable(t2, 8, ph2);
  settable(t3, 16, ph3);
  settable(t4, 2, ph4);

  getelem(t1, v17, v1);
  getelem(t2, v17, v2);
  getelem(t3, v17, v3);
  getelem(t4, v17, oph);

  add(oph,v18,oph);
  add(oph,v19,oph);
  assign(zero,v6);

/*
  mod2(id2, v14);
  dbl(v14,v14);
*/
  initval(2.0*(double)(((int)(d2*getval("sw1")+0.5)%2)),v14);

  add(v2, v14, v2);
  add(oph, v14, oph);

  if ((phase1 == 2) || (phase1 == 5))
  {
    icosel = -1;
  }

  grad2 = gzlvlE;
  grad3 = -1.5*gzlvlE;
  grad1 = -1.0*grad2*(EDratio + icosel)/EDratio;
  grad4 = -1.0*grad3*(EDratio - icosel)/EDratio;

  if (mult > 0.5)
  {
    grad4 = -1.0*grad3*(EDratio + icosel)/EDratio;
  }

  status(A);

   delay(5.0e-5);
   if (getflag("sspul"))
        steadystate();

   if (satmode[0] == 'y')
     {
        if ((d1-satdly) > 0.02)
                delay(d1-satdly);
        else
                delay(0.02);
        if (getflag("slpsat"))
           {
                shaped_satpulse("relaxD",satdly,zero);
                if (getflag("prgflg"))
                   shaped_purge(v6,zero,v18,v19);
           }
        else
           {
                satpulse(satdly,zero,rof1,rof1);
                if (getflag("prgflg"))
                   purge(v6,zero,v18,v19);
           }
     }
   else
        delay(d1);

   if (getflag("wet"))
     wet4(zero,one);

   obspower(tpwr);
   decpower(pwxlvl);

  status(B);

    rgpulse(pw, v6, rof1, rof2);

/* Start of J filter  */

   if (getflag("jfilter"))
   {
     zgradpulse(gzlvl0,gt0);
     delay(tauA - gt0);
     decrgpulse(pwx, zero, rof1, rof1);
     zgradpulse(-gzlvl0*2/3,gt0);
     delay(tauB - gt0);
     decrgpulse(pwx, zero, rof1, rof1);
     zgradpulse(-gzlvl0/3,gt0);
    }

/* End of J filter */

    delay(taumb);

    zgradpulse(grad1,gtE);
    delay(gstab);

    decrgpulse(pwx, v2, rof1, rof1);

    if (mult > 0.5)
    {
    decpower(pwxlvl180r);
    zgradpulse(grad2,gtE);
    delay(taug-gtE-2*GRADIENT_DELAY);
    decshaped_pulse(pwx180ref, pwx180r, zero, rof1, rof1);

    delay(d2/2);
    rgpulse(2*pw,v3,rof1,rof1);
    delay(d2/2);

    delay(taug-(gtE+gstab+2*GRADIENT_DELAY)+(4*pwx/PI+2*rof1+2*POWER_DELAY-2*pw-2*rof1));
    zgradpulse(grad3,gtE);
    delay(gstab);
    decshaped_pulse(pwx180ref, pwx180r, zero, rof1, rof1);
    }

    else
    {
    decpower(pwxlvl180);
    zgradpulse(grad2,gtE);
    delay(taug/2+(pwx180r-pwx180)/2- gtE - 2*GRADIENT_DELAY);
    decshaped_pulse(pwx180ad, pwx180, zero, rof1, rof1);
    delay(taug/2+(pwx180r-pwx180)/2.0);

    delay(d2/2);
    rgpulse(2*pw,v3,rof1,rof1);
    delay(d2/2);

    delay(taug/2+(pwx180r-pwx180)/2.0+(4*pwx/PI+2*rof1+2*POWER_DELAY-2*pw-2*rof1));
    decshaped_pulse(pwx180ad, pwx180, zero, rof1, rof1);
    delay(taug/2+(pwx180r-pwx180)/2-gtE-gstab-2*GRADIENT_DELAY);
    zgradpulse(grad3,gtE);
    delay(gstab);
    }

    decpower(pwxlvl);

    decrgpulse(pwx, v1, rof1, rof2);
    decpower(dpwr);
    zgradpulse(grad4,gtE);
    delay(gstab);

  status(C);
}
Esempio n. 14
0
pulsesequence()
{
   double          selpwrA = getval("selpwrA"),
                   selpwA = getval("selpwA"),
                   gzlvlA = getval("gzlvlA"),
                   gtA = getval("gtA"),
                   selpwrB = getval("selpwrB"),
                   selpwB = getval("selpwB"),
                   gzlvlB = getval("gzlvlB"),
                   gtB = getval("gtB"),
                   gstab = getval("gstab"),
                   slpwrR = getval("slpwrR"),
                   slpwR = getval("slpwR"),
                   mixR = getval("mixR"),
                   gzlvlz = getval("gzlvlz"),
                   gtz = getval("gtz"),
		   alfa1,
		   t1dly,
		   zfphinc = getval("zfphinc");
   char		   slpatR[MAXSTR],
                   selshapeA[MAXSTR],
                   selshapeB[MAXSTR];
   int             phase1 = (int)(getval("phase")+0.5),
                   prgcycle = (int)(getval("prgcycle")+0.5);

//synchronize gradients to srate for probetype='nano'
//   Preserve gradient "area"
        gtA = syncGradTime("gtA","gzlvlA",1.0);
        gzlvlA = syncGradLvl("gtA","gzlvlA",1.0);
        gtB = syncGradTime("gtB","gzlvlB",1.0);
        gzlvlB = syncGradLvl("gtB","gzlvlB",1.0);

/* LOAD AND INITIALIZE PARAMETERS */
   getstr("selshapeA",selshapeA);
   getstr("selshapeB",selshapeB);
   getstr("slpatR",slpatR);

   alfa1 = POWER_DELAY + (2*pw/PI) + rof1;
   if (getflag("homodec"))
        alfa1 = alfa1 + 2.0e-6 + 2*pw;
   t1dly = d2-alfa1;
   if (t1dly > 0.0)
        t1dly = t1dly;
   else
        t1dly = 0.0;

   if (strcmp(slpatR,"cw") &&
        strcmp(slpatR,"troesy") &&
        strcmp(slpatR,"dante"))
        abort_message("SpinLock pattern %s not supported!.\n", slpatR);

  assign(ct,v17);
  assign(zero,v18);
  assign(zero,v19);

  if (getflag("prgflg") && (satmode[0] == 'y') && (prgcycle > 1.5))
    {
        hlv(ct,v17);
        mod2(ct,v18); dbl(v18,v18);
        if (prgcycle > 2.5)
           {
                hlv(v17,v17);
                hlv(ct,v19); mod2(v19,v19); dbl(v19,v19);
           }
     }

   settable(t1,4,ph1);	getelem(t1,v17,v1);
   settable(t2,8,ph2);	getelem(t2,v17,v20);
   settable(t3,8,ph3);	
   settable(t8,4,ph8);	getelem(t8,v17,v8);
   settable(t6,8,ph6);	getelem(t6,v17,v6);
  
   assign(v1,oph); 
   if (getflag("zfilt"))
	getelem(t3,v17,oph);

   assign(v20,v9);
   if (!strcmp(slpatR,"troesy"))
	assign(v20,v21);
   else
	add(v20,one,v21);

   add(oph,v18,oph);
   add(oph,v19,oph);

  if (getflag("prgflg") && (satmode[0] == 'y'))
	assign(v1,v6);
   if (phase1 == 2)
      {incr(v1); incr(v6);}			/* hypercomplex method */

  assign(v1,v11);
  add(v11,two,v12);
  assign(oph,v14);

/*
   mod2(id2,v13);
   dbl(v13,v13);
*/
  initval(2.0*(double)(((int)(d2*getval("sw1")+0.5)%2)),v13);

  if (getflag("fadflg"))
  {
       add(v1,v13,v1);
       add(v6,v13,v6);
       add(oph,v13,oph);
  }

  if (getflag("homodec"))
	add(oph,two,oph);

/* The following is for flipback pulse */
   zfphinc=zfphinc+180;
   if (zfphinc < 0) zfphinc=zfphinc+360;
   initval(zfphinc,v10);

/* BEGIN ACTUAL PULSE SEQUENCE */
   status(A);
      obspower(tpwr);

   delay(5.0e-5);
   if (getflag("sspul"))
        steadystate();

   if (satmode[0] == 'y')
     {
        if ((d1-satdly) > 0.02)
                delay(d1-satdly);
        else
                delay(0.02);
        if (getflag("slpsat"))
           {
                shaped_satpulse("relaxD",satdly,v6);
                if (getflag("prgflg"))
                   shaped_purge(v1,v6,v18,v19);
           }
        else
           {
                satpulse(satdly,v6,rof1,rof1);
                if (getflag("prgflg"))
                   purge(v1,v6,v18,v19);
           }
     }
   else
        delay(d1);

   if (getflag("wet"))
     wet4(zero,one);
   decpower(dpwr);

   status(B);
      rgpulse(pw, v1, rof1, rof1);
      if (getflag("homodec"))
       {
                delay(t1dly/2);
                rgpulse(2*pw,v14,1.0e-6,1.0e-6);
       }
      else
                delay(t1dly);

        zgradpulse(gzlvlA,gtA);
        delay(gstab);
        obspower(selpwrA);
        shaped_pulse(selshapeA,selpwA,v11,rof1,rof1);
        obspower(tpwr);
        zgradpulse(gzlvlA,gtA);
        delay(gstab);

      if (getflag("homodec"))
                delay(t1dly/2);

        zgradpulse(gzlvlB,gtB);
        delay(gstab);
        obspower(selpwrB);
        shaped_pulse(selshapeB,selpwB,v12,rof1,rof1);
        obspower(tpwr);
        zgradpulse(gzlvlB,gtB);
        delay(gstab);
      
      obspower(slpwrR);

      if (mixR > 0.0)
      {
        if (dps_flag)
          	rgpulse(mixR,v21,0.0,0.0);
        else
          SpinLock(slpatR,mixR,slpwR,v21);
      }

       if ((getflag("zfilt")) && (getflag("PFGflg")))
        {
           obspower(tpwr);
           rgpulse(pw,v9,1.0e-6,rof1);
           zgradpulse(gzlvlz,gtz);
           delay(gtz/3);
           if (getflag("flipback"))
                FBpulse(v8,v10);
           rgpulse(pw,v8,rof1,rof2);
        }
       else
           delay(rof2);

   status(C);
}
Esempio n. 15
0
static void
show_options(const uint8_t *data, int len)
{
	dhcpv6_option_t d6o;
	uint_t olen, retlen;
	uint16_t val16;
	uint16_t type;
	uint32_t val32;
	const uint8_t *ostart;
	char *str, *sp;
	char *oldnest;

	/*
	 * Be very careful with negative numbers; ANSI signed/unsigned
	 * comparison doesn't work as expected.
	 */
	while (len >= (signed)sizeof (d6o)) {
		(void) memcpy(&d6o, data, sizeof (d6o));
		d6o.d6o_code = ntohs(d6o.d6o_code);
		d6o.d6o_len = olen = ntohs(d6o.d6o_len);
		(void) snprintf(get_line(0, 0), get_line_remain(),
		    "Option Code = %u (%s)", d6o.d6o_code,
		    option_to_str(d6o.d6o_code));
		ostart = data += sizeof (d6o);
		len -= sizeof (d6o);
		if (olen > len) {
			(void) strlcpy(get_line(0, 0), "Option truncated",
			    get_line_remain());
			olen = len;
		}
		switch (d6o.d6o_code) {
		case DHCPV6_OPT_CLIENTID:
		case DHCPV6_OPT_SERVERID:
			if (olen < sizeof (val16))
				break;
			(void) memcpy(&val16, data, sizeof (val16));
			data += sizeof (val16);
			olen -= sizeof (val16);
			type = ntohs(val16);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  DUID Type = %u (%s)", type,
			    duidtype_to_str(type));
			if (type == DHCPV6_DUID_LLT || type == DHCPV6_DUID_LL) {
				if (olen < sizeof (val16))
					break;
				(void) memcpy(&val16, data, sizeof (val16));
				data += sizeof (val16);
				olen -= sizeof (val16);
				val16 = ntohs(val16);
				(void) snprintf(get_line(0, 0),
				    get_line_remain(),
				    "  Hardware Type = %u (%s)", val16,
				    arp_htype(val16));
			}
			if (type == DHCPV6_DUID_LLT) {
				time_t timevalue;

				if (olen < sizeof (val32))
					break;
				(void) memcpy(&val32, data, sizeof (val32));
				data += sizeof (val32);
				olen -= sizeof (val32);
				timevalue = ntohl(val32) + DUID_TIME_BASE;
				(void) snprintf(get_line(0, 0),
				    get_line_remain(),
				    "  Time = %lu (%.24s)", ntohl(val32),
				    ctime(&timevalue));
			}
			if (type == DHCPV6_DUID_EN) {
				if (olen < sizeof (val32))
					break;
				(void) memcpy(&val32, data, sizeof (val32));
				data += sizeof (val32);
				olen -= sizeof (val32);
				val32 = ntohl(val32);
				(void) snprintf(get_line(0, 0),
				    get_line_remain(),
				    "  Enterprise Number = %lu (%s)", val32,
				    entr_to_str(val32));
			}
			if (olen == 0)
				break;
			if ((str = malloc(olen * 3)) == NULL)
				pr_err("interpret_dhcpv6: no mem");
			sp = str + snprintf(str, 3, "%02x", *data++);
			while (--olen > 0) {
				*sp++ = (type == DHCPV6_DUID_LLT ||
				    type == DHCPV6_DUID_LL) ? ':' : ' ';
				sp = sp + snprintf(sp, 3, "%02x", *data++);
			}
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    (type == DHCPV6_DUID_LLT ||
			    type == DHCPV6_DUID_LL) ?
			    "  Link Layer Address = %s" :
			    "  Identifier = %s", str);
			free(str);
			break;
		case DHCPV6_OPT_IA_NA:
		case DHCPV6_OPT_IA_PD: {
			dhcpv6_ia_na_t d6in;

			if (olen < sizeof (d6in) - sizeof (d6o))
				break;
			(void) memcpy(&d6in, data - sizeof (d6o),
			    sizeof (d6in));
			data += sizeof (d6in) - sizeof (d6o);
			olen -= sizeof (d6in) - sizeof (d6o);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  IAID = %u", ntohl(d6in.d6in_iaid));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  T1 (renew) = %u seconds", ntohl(d6in.d6in_t1));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  T2 (rebind) = %u seconds", ntohl(d6in.d6in_t2));
			nest_options(data, olen, "IA: ",
			    "Identity Association");
			break;
		}
		case DHCPV6_OPT_IA_TA: {
			dhcpv6_ia_ta_t d6it;

			if (olen < sizeof (d6it) - sizeof (d6o))
				break;
			(void) memcpy(&d6it, data - sizeof (d6o),
			    sizeof (d6it));
			data += sizeof (d6it) - sizeof (d6o);
			olen -= sizeof (d6it) - sizeof (d6o);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  IAID = %u", ntohl(d6it.d6it_iaid));
			nest_options(data, olen, "IA: ",
			    "Identity Association");
			break;
		}
		case DHCPV6_OPT_IAADDR: {
			dhcpv6_iaaddr_t d6ia;

			if (olen < sizeof (d6ia) - sizeof (d6o))
				break;
			(void) memcpy(&d6ia, data - sizeof (d6o),
			    sizeof (d6ia));
			data += sizeof (d6ia) - sizeof (d6o);
			olen -= sizeof (d6ia) - sizeof (d6o);
			show_address("  Address", &d6ia.d6ia_addr);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Preferred lifetime = %u seconds",
			    ntohl(d6ia.d6ia_preflife));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Valid lifetime = %u seconds",
			    ntohl(d6ia.d6ia_vallife));
			nest_options(data, olen, "ADDR: ", "Address");
			break;
		}
		case DHCPV6_OPT_ORO:
			while (olen >= sizeof (val16)) {
				(void) memcpy(&val16, data, sizeof (val16));
				val16 = ntohs(val16);
				(void) snprintf(get_line(0, 0),
				    get_line_remain(),
				    "  Requested Option Code = %u (%s)", val16,
				    option_to_str(val16));
				data += sizeof (val16);
				olen -= sizeof (val16);
			}
			break;
		case DHCPV6_OPT_PREFERENCE:
			if (olen > 0) {
				(void) snprintf(get_line(0, 0),
				    get_line_remain(),
				    *data == 255 ?
				    "  Preference = %u (immediate)" :
				    "  Preference = %u", *data);
			}
			break;
		case DHCPV6_OPT_ELAPSED_TIME:
			if (olen == sizeof (val16)) {
				(void) memcpy(&val16, data, sizeof (val16));
				val16 = ntohs(val16);
				(void) snprintf(get_line(0, 0),
				    get_line_remain(),
				    "  Elapsed Time = %u.%02u seconds",
				    val16 / 100, val16 % 100);
			}
			break;
		case DHCPV6_OPT_RELAY_MSG:
			if (olen > 0) {
				oldnest = prot_nest_prefix;
				prot_nest_prefix = prot_prefix;
				retlen = interpret_dhcpv6(F_DTAIL, data, olen);
				prot_prefix = prot_nest_prefix;
				prot_nest_prefix = oldnest;
			}
			break;
		case DHCPV6_OPT_AUTH: {
			dhcpv6_auth_t d6a;

			if (olen < DHCPV6_AUTH_SIZE - sizeof (d6o))
				break;
			(void) memcpy(&d6a, data - sizeof (d6o),
			    DHCPV6_AUTH_SIZE);
			data += DHCPV6_AUTH_SIZE - sizeof (d6o);
			olen += DHCPV6_AUTH_SIZE - sizeof (d6o);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Protocol = %u (%s)", d6a.d6a_proto,
			    authproto_to_str(d6a.d6a_proto));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Algorithm = %u (%s)", d6a.d6a_alg,
			    authalg_to_str(d6a.d6a_proto, d6a.d6a_alg));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Replay Detection Method = %u (%s)", d6a.d6a_rdm,
			    authrdm_to_str(d6a.d6a_rdm));
			show_hex(d6a.d6a_replay, sizeof (d6a.d6a_replay),
			    "  RDM Data");
			if (olen > 0)
				show_hex(data, olen, "  Auth Info");
			break;
		}
		case DHCPV6_OPT_UNICAST:
			if (olen >= sizeof (in6_addr_t))
				show_address("  Server Address", data);
			break;
		case DHCPV6_OPT_STATUS_CODE:
			if (olen < sizeof (val16))
				break;
			(void) memcpy(&val16, data, sizeof (val16));
			val16 = ntohs(val16);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Status Code = %u (%s)", val16,
			    status_to_str(val16));
			data += sizeof (val16);
			olen -= sizeof (val16);
			if (olen > 0)
				(void) snprintf(get_line(0, 0),
				    get_line_remain(), "  Text = \"%.*s\"",
				    olen, data);
			break;
		case DHCPV6_OPT_VENDOR_CLASS:
			if (olen < sizeof (val32))
				break;
			(void) memcpy(&val32, data, sizeof (val32));
			data += sizeof (val32);
			olen -= sizeof (val32);
			val32 = ntohl(val32);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Enterprise Number = %lu (%s)", val32,
			    entr_to_str(val32));
			/* FALLTHROUGH */
		case DHCPV6_OPT_USER_CLASS:
			while (olen >= sizeof (val16)) {
				(void) memcpy(&val16, data, sizeof (val16));
				data += sizeof (val16);
				olen -= sizeof (val16);
				val16 = ntohs(val16);
				if (val16 > olen) {
					(void) strlcpy(get_line(0, 0),
					    "  Truncated class",
					    get_line_remain());
					val16 = olen;
				}
				show_hex(data, olen, "  Class");
				data += val16;
				olen -= val16;
			}
			break;
		case DHCPV6_OPT_VENDOR_OPT: {
			dhcpv6_option_t sd6o;

			if (olen < sizeof (val32))
				break;
			(void) memcpy(&val32, data, sizeof (val32));
			data += sizeof (val32);
			olen -= sizeof (val32);
			val32 = ntohl(val32);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Enterprise Number = %lu (%s)", val32,
			    entr_to_str(val32));
			while (olen >= sizeof (sd6o)) {
				(void) memcpy(&sd6o, data, sizeof (sd6o));
				sd6o.d6o_code = ntohs(sd6o.d6o_code);
				sd6o.d6o_len = ntohs(sd6o.d6o_len);
				(void) snprintf(get_line(0, 0),
				    get_line_remain(),
				    "  Vendor Option Code = %u", d6o.d6o_code);
				data += sizeof (d6o);
				olen -= sizeof (d6o);
				if (sd6o.d6o_len > olen) {
					(void) strlcpy(get_line(0, 0),
					    "  Vendor Option truncated",
					    get_line_remain());
					sd6o.d6o_len = olen;
				}
				if (sd6o.d6o_len > 0) {
					show_hex(data, sd6o.d6o_len,
					    "    Data");
					data += sd6o.d6o_len;
					olen -= sd6o.d6o_len;
				}
			}
			break;
		}
		case DHCPV6_OPT_REMOTE_ID:
			if (olen < sizeof (val32))
				break;
			(void) memcpy(&val32, data, sizeof (val32));
			data += sizeof (val32);
			olen -= sizeof (val32);
			val32 = ntohl(val32);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Enterprise Number = %lu (%s)", val32,
			    entr_to_str(val32));
			/* FALLTHROUGH */
		case DHCPV6_OPT_INTERFACE_ID:
		case DHCPV6_OPT_SUBSCRIBER:
			if (olen > 0)
				show_hex(data, olen, "  ID");
			break;
		case DHCPV6_OPT_RECONF_MSG:
			if (olen > 0) {
				(void) snprintf(get_line(0, 0),
				    get_line_remain(),
				    "  Message Type = %u (%s)", *data,
				    reconf_to_str(*data));
			}
			break;
		case DHCPV6_OPT_SIP_NAMES:
		case DHCPV6_OPT_DNS_SEARCH:
		case DHCPV6_OPT_NIS_DOMAIN:
		case DHCPV6_OPT_BCMCS_SRV_D: {
			dhcp_symbol_t *symp;
			char *sp2;

			symp = inittab_getbycode(
			    ITAB_CAT_STANDARD | ITAB_CAT_V6, ITAB_CONS_SNOOP,
			    d6o.d6o_code);
			if (symp != NULL) {
				str = inittab_decode(symp, data, olen, B_TRUE);
				if (str != NULL) {
					sp = str;
					do {
						sp2 = strchr(sp, ' ');
						if (sp2 != NULL)
							*sp2++ = '\0';
						(void) snprintf(get_line(0, 0),
						    get_line_remain(),
						    "  Name = %s", sp);
					} while ((sp = sp2) != NULL);
					free(str);
				}
				free(symp);
			}
			break;
		}
		case DHCPV6_OPT_SIP_ADDR:
		case DHCPV6_OPT_DNS_ADDR:
		case DHCPV6_OPT_NIS_SERVERS:
		case DHCPV6_OPT_SNTP_SERVERS:
		case DHCPV6_OPT_BCMCS_SRV_A:
			while (olen >= sizeof (in6_addr_t)) {
				show_address("  Address", data);
				data += sizeof (in6_addr_t);
				olen -= sizeof (in6_addr_t);
			}
			break;
		case DHCPV6_OPT_IAPREFIX: {
			dhcpv6_iaprefix_t d6ip;

			if (olen < DHCPV6_IAPREFIX_SIZE - sizeof (d6o))
				break;
			(void) memcpy(&d6ip, data - sizeof (d6o),
			    DHCPV6_IAPREFIX_SIZE);
			data += DHCPV6_IAPREFIX_SIZE - sizeof (d6o);
			olen -= DHCPV6_IAPREFIX_SIZE - sizeof (d6o);
			show_address("  Prefix", d6ip.d6ip_addr);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Preferred lifetime = %u seconds",
			    ntohl(d6ip.d6ip_preflife));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Valid lifetime = %u seconds",
			    ntohl(d6ip.d6ip_vallife));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Prefix length = %u", d6ip.d6ip_preflen);
			nest_options(data, olen, "ADDR: ", "Address");
			break;
		}
		case DHCPV6_OPT_INFO_REFTIME:
			if (olen < sizeof (val32))
				break;
			(void) memcpy(&val32, data, sizeof (val32));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Refresh Time = %lu seconds", ntohl(val32));
			break;
		case DHCPV6_OPT_GEOCONF_CVC: {
			dhcpv6_civic_t d6c;
			int solen;

			if (olen < DHCPV6_CIVIC_SIZE - sizeof (d6o))
				break;
			(void) memcpy(&d6c, data - sizeof (d6o),
			    DHCPV6_CIVIC_SIZE);
			data += DHCPV6_CIVIC_SIZE - sizeof (d6o);
			olen -= DHCPV6_CIVIC_SIZE - sizeof (d6o);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  What Location = %u (%s)", d6c.d6c_what,
			    cwhat_to_str(d6c.d6c_what));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Country Code = %.*s", sizeof (d6c.d6c_cc),
			    d6c.d6c_cc);
			while (olen >= 2) {
				(void) snprintf(get_line(0, 0),
				    get_line_remain(),
				    "  CA Element = %u (%s)", *data,
				    catype_to_str(*data));
				solen = data[1];
				data += 2;
				olen -= 2;
				if (solen > olen) {
					(void) strlcpy(get_line(0, 0),
					    "  CA Element truncated",
					    get_line_remain());
					solen = olen;
				}
				if (solen > 0) {
					show_ascii(data, solen, "  CA Data");
					data += solen;
					olen -= solen;
				}
			}
			break;
		}
		case DHCPV6_OPT_CLIENT_FQDN: {
			dhcp_symbol_t *symp;

			if (olen == 0)
				break;
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "  Flags = %02x", *data);
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "        %s", getflag(*data, DHCPV6_FQDNF_S,
			    "Perform AAAA RR updates", "No AAAA RR updates"));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "        %s", getflag(*data, DHCPV6_FQDNF_O,
			    "Server override updates",
			    "No server override updates"));
			(void) snprintf(get_line(0, 0), get_line_remain(),
			    "        %s", getflag(*data, DHCPV6_FQDNF_N,
			    "Server performs no updates",
			    "Server performs updates"));
			symp = inittab_getbycode(
			    ITAB_CAT_STANDARD | ITAB_CAT_V6, ITAB_CONS_SNOOP,
			    d6o.d6o_code);
			if (symp != NULL) {
				str = inittab_decode(symp, data, olen, B_TRUE);
				if (str != NULL) {
					(void) snprintf(get_line(0, 0),
					    get_line_remain(),
					    "  FQDN = %s", str);
					free(str);
				}
				free(symp);
			}
			break;
		}
		}
		data = ostart + d6o.d6o_len;
		len -= d6o.d6o_len;
	}
	if (len != 0) {
		(void) strlcpy(get_line(0, 0), "Option entry truncated",
		    get_line_remain());
	}
}
Esempio n. 16
0
int AgiEngine::print(const char *p, int lin, int col, int len) {
	if (p == NULL)
		return 0;

	debugC(4, kDebugLevelText, "print(): lin = %d, col = %d, len = %d", lin, col, len);

	if (col == 0 && lin == 0 && len == 0)
		lin = col = -1;

	if (len == 0)
		len = 30;

	blitTextbox(p, lin, col, len);

	if (getflag(fOutputMode)) {
		// non-blocking window
		setflag(fOutputMode, false);
		return 1;
	}

	// blocking

	_noSaveLoadAllowed = true;

	if (_game.vars[vWindowReset] == 0) {
		int k;
		setvar(vKey, 0);
		k = waitKey();
		closeWindow();

		_noSaveLoadAllowed = false;

		return k;
	}

	// timed window

	debugC(3, kDebugLevelText, "f15==0, v21==%d => timed", getvar(21));
	_game.msgBoxTicks = getvar(vWindowReset) * 10;
	setvar(vKey, 0);

	_menuSelected = false;

	do {
		if (getflag(fRestoreJustRan))
			break;

		if (_menuSelected)
			break;

		mainCycle();
		if (_game.keypress == KEY_ENTER) {
			debugC(4, kDebugLevelText, "KEY_ENTER");
			setvar(vWindowReset, 0);
			_game.keypress = 0;
			break;
		}
	} while (_game.msgBoxTicks > 0 && !(shouldQuit() || _restartGame));

	setvar(vWindowReset, 0);

	closeWindow();

	_noSaveLoadAllowed = false;

	return 0;
}
Esempio n. 17
0
bool Menu::keyhandler(int key) {
	static int clock_val;
	static int menu_active = false;
	static int button_used = 0;

	if (!getflag(F_menus_work))
		return false;

	if (!menu_active) {
		clock_val = game.clock_enabled;
		game.clock_enabled = false;
		draw_menu_bar();
	}
	/*
	 * Mouse handling
	 */
	if (mouse.button) {
		int hmenu, vmenu;

		button_used = 1;	/* Button has been used at least once */
		if (mouse.y <= CHAR_LINES) {
			/* on the menubar */
			hmenu = 0;

			MenuList::iterator iterh;
			for (iterh = menubar.begin(); iterh != menubar.end(); ++iterh) {
				agi_menu *m = *iterh;
				if (mouse_over_text(0, m->col, m->text)) {
					break;
				} else {
					hmenu++;
				}
			}

			if (hmenu <= h_max_menu) {
				if (h_cur_menu != hmenu) {
					v_cur_menu = -1;
					new_menu_selected(hmenu);
				}
				h_cur_menu = hmenu;
			}
		} else {
			/* not in menubar */
			vmenu = 0;

			agi_menu *m = get_menu(h_cur_menu);
			MenuOptionList::iterator iterv;
			for (iterv = m->down.begin(); iterv != m->down.end(); ++iterv) {
				agi_menu_option *do1 = *iterv;
				if (mouse_over_text(2 + do1->index, m->wincol + 1, do1->text)) {
					break;
				} else {
					vmenu++;
				}
			}

			if (vmenu <= v_max_menu[h_cur_menu]) {
				if (v_cur_menu != vmenu) {
					draw_menu_option(h_cur_menu);
					draw_menu_option_hilite(h_cur_menu, vmenu);
				}
				v_cur_menu = vmenu;
			}
		}
	} else if (button_used) {
		/* Button released */
		button_used = 0;

		debugC(6, kDebugLevelMenu | kDebugLevelInput, "button released!");

		if (v_cur_menu < 0)
			v_cur_menu = 0;

		draw_menu_option_hilite(h_cur_menu, v_cur_menu);

		if (mouse.y <= CHAR_LINES) {
			/* on the menubar */
		} else {
			/* see which option we selected */
			agi_menu *m = get_menu(h_cur_menu);
			MenuOptionList::iterator iterv;
			for (iterv = m->down.begin(); iterv != m->down.end(); ++iterv) {
				agi_menu_option *d = *iterv;
				if (mouse_over_text(2 + d->index, m->wincol + 1, d->text)) {
					/* activate that option */
					if (d->enabled) {
						debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event);
						game.ev_keyp[d->event].occured = true;
						game.ev_keyp[d->event].data = d->event;
						goto exit_menu;
					}
				}
			}
			goto exit_menu;
		}
	}

	if (!menu_active) {
		if (h_cur_menu >= 0) {
			draw_menu_hilite(h_cur_menu);
			draw_menu_option(h_cur_menu);
			if (!button_used && v_cur_menu >= 0)
				draw_menu_option_hilite(h_cur_menu, v_cur_menu);
		}
		menu_active = true;
	}

	switch (key) {
	case KEY_ESCAPE:
		debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ESCAPE");
		goto exit_menu;
	case KEY_ENTER:
	{
		debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ENTER");
		agi_menu_option* d = get_menu_option(h_cur_menu, v_cur_menu);
		if (d->enabled) {
			debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event);
			game.ev_keyp[d->event].occured = true;
			goto exit_menu;
		}
		break;
	}
	case KEY_DOWN:
	case KEY_UP:
		v_cur_menu += key == KEY_DOWN ? 1 : -1;

		if (v_cur_menu < 0)
			v_cur_menu = 0;
		if (v_cur_menu > v_max_menu[h_cur_menu])
			v_cur_menu = v_max_menu[h_cur_menu];

		draw_menu_option(h_cur_menu);
		draw_menu_option_hilite(h_cur_menu, v_cur_menu);
		break;
	case KEY_RIGHT:
	case KEY_LEFT:
		h_cur_menu += key == KEY_RIGHT ? 1 : -1;

		if (h_cur_menu < 0)
			h_cur_menu = h_max_menu;
		if (h_cur_menu > h_max_menu)
			h_cur_menu = 0;

		v_cur_menu = 0;
		new_menu_selected(h_cur_menu);
		draw_menu_option_hilite(h_cur_menu, v_cur_menu);
		break;
	}

	return true;

exit_menu:
	button_used = 0;
	show_pic();
	_text->write_status();

	setvar(V_key, 0);
	game.keypress = 0;
	game.clock_enabled = clock_val;
	old_input_mode();
	debugC(3, kDebugLevelMenu, "exit_menu: input mode reset to %d", game.input_mode);
	menu_active = false;

	return true;
}
Esempio n. 18
0
pulsesequence()
{
  double j1min = getval("j1min"),
	 j1max = getval("j1max"),
	 pwxlvlS6 = getval("pwxlvlS6"),
	 pwxS6 = getval("pwxS6"),
	 gzlvl0 = getval("gzlvl0"),
	 gt0 = getval("gt0"),
	 gzlvlE = getval("gzlvlE"),
	 gtE = getval("gtE"),
	 EDratio = getval("EDratio"),
	 gstab = getval("gstab"),
	 grad1,
	 grad2,
	 tauA,
	 tauB,
         taumb;
  int	 icosel,
	 phase1 = (int)(getval("phase")+0.5);

//synchronize gradients to srate for probetype='nano'
//   Preserve gradient "area"
        gtE = syncGradTime("gtE","gzlvlE",1.0);
        gzlvlE = syncGradLvl("gtE","gzlvlE",1.0);

  grad1 = gzlvlE;
  grad2 = -1.0*gzlvlE*(EDratio-1)/(EDratio+1);
  tauA = 1/(2*(j1min + 0.146*(j1max - j1min)));
  tauB = 1/(2*(j1max - 0.146*(j1max - j1min)));
  taumb = 1/(2*(getval("jnxh")));
  icosel = 1;

  settable(t1,1,ph1);
  settable(t2,1,ph2);
  settable(t3,2,ph3);
  settable(t4,1,ph4);
  settable(t5,4,ph5);
  settable(t6,4,ph6);
 
  getelem(t3,ct,v3);
  getelem(t6,ct,oph);
/*
  mod2(id2,v10);
  dbl(v10,v10);
*/
  initval(2.0*(double)(((int)(d2*getval("sw1")+0.5)%2)),v10);

  add(v3,v10,v3);
  add(oph,v10,oph);

  if ((phase1 == 2) || (phase1 == 5))
	{  icosel = -1;
           grad1 = gzlvlE*(EDratio-1)/(EDratio+1);
           grad2 = -1.0*gzlvlE;
        }


  status(A);

   delay(5.0e-5);
   if (getflag("sspul"))
        steadystate();

   if (satmode[0] == 'y')
     {
        if ((d1-satdly) > 0.02)
                delay(d1-satdly);
        else
                delay(0.02);
        satpulse(satdly,zero,rof1,rof1);
     }
   else
        delay(d1);

   if (getflag("wet"))
     wet4(zero,one);

   decpower(pwxlvl);

  status(B);
     rgpulse(pw,t1,rof1,rof2);

/* Start of J filter  */
   if (getflag("jfilter"))
   {
     zgradpulse(gzlvl0/2,gt0);
     delay(tauA - gt0);
     decrgpulse(pwx, zero, rof1, rof1);
     zgradpulse(-gzlvl0/3,gt0);
     delay(tauB - gt0);
     decrgpulse(pwx, zero, rof1, rof1);
     zgradpulse(-gzlvl0/6,gt0);
     delay(gstab);
    }
/* End of J filter */

     delay(taumb);
     decrgpulse(pwx,v3,rof1,rof1);

     delay(d2/2.0);
     rgpulse(2*pw,t4,rof1,rof1);
     delay(d2/2.0);

     decpower(pwxlvlS6);
        decrgpulse(158.0*pwxS6/90,zero,rof1,2.0e-6);
        decrgpulse(171.2*pwxS6/90,two,2.0e-6,2.0e-6);
        decrgpulse(342.8*pwxS6/90,zero,2.0e-6,2.0e-6);
        decrgpulse(145.5*pwxS6/90,two,2.0e-6,2.0e-6);
        decrgpulse(81.2*pwxS6/90,zero,2.0e-6,2.0e-6);
        decrgpulse(85.3*pwxS6/90,two,2.0e-6,rof1);

     delay(2*pw + 2*POWER_DELAY + 4*rof1 + (4*pwx/3.1416));

     zgradpulse(icosel*grad1,gtE);
     delay(gstab);

        decrgpulse(158.0*pwxS6/90,zero,rof1,2.0e-6);
        decrgpulse(171.2*pwxS6/90,two,2.0e-6,2.0e-6);
        decrgpulse(342.8*pwxS6/90,zero,2.0e-6,2.0e-6);
        decrgpulse(145.5*pwxS6/90,two,2.0e-6,2.0e-6);
        decrgpulse(81.2*pwxS6/90,zero,2.0e-6,2.0e-6);
        decrgpulse(85.3*pwxS6/90,two,2.0e-6,rof1);

     zgradpulse(icosel*grad2,gtE);
     decpower(pwxlvl);
     delay(gstab);

     decrgpulse(pwx,t5,rof1,rof2);
     decpower(dpwr);

  status(C);
} 
Esempio n. 19
0
pulsesequence()
{
        double rg1 = 2.0e-6,
	       compH = getval("compH"),
	       gt0=getval("gt0"),
	       gzlvl0=getval("gzlvl0"),
	       gt1=getval("gt1"),
	       gzlvl1=getval("gzlvl1"),
	       qlvl=getval("qlvl"),
	       grise=getval("grise"),
	       gstab=getval("gstab"),
	       taud2=getval("taud2"),
	       tau1=getval("tau1");
	int    icosel, iphase;
        char   pshape[MAXSTR], xptype[MAXSTR];
        shape  hdx;

  getstr("pshape", pshape);

  iphase = (int) (0.5 + getval("phase"));
  qlvl++ ; 
  icosel=1;    /* Default to N-type experiment */
  strcpy(xptype, "N-type");
  if (iphase == 2) 
  { 
    icosel=-1;
    strcpy(xptype, "P-type"); 
  }
  if (FIRST_FID) fprintf(stdout,"%s COSY\n", xptype);

  /* Make HADAMARD encoding waveforms */
  
    hdx = pboxHT_F1e(pshape, pw*compH, tpwr);

     status(A);
     
       delay(1.0e-4);
       zgradpulse(gzlvl0,gt0);

       pre_sat();
       if (getflag("wet"))
         wet4(zero,one);

       obspower(tpwr);
       delay(1.0e-5);

  status(B);

       pbox_pulse(&hdx, oph, rg1, rg1);
       obspower(tpwr);

       zgradpulse(gzlvl1,gt1);
       delay(grise); 
          
       rgpulse(pw, oph, rg1, rg1);
       delay(taud2);

       zgradpulse(gzlvl1,gt1);
       delay(grise+taud2); 

       rgpulse(pw,oph,rg1,rof2);
       delay(tau1);

       zgradpulse(gzlvl1*qlvl*(double)icosel,gt1);
       delay(grise+gstab); 

     status(C);
}
Esempio n. 20
0
pulsesequence()
{
   int          i,
		relay;

/* GET NEW PARAMETERS */
   relay = (int) (getval("relay") + 0.5);

/* CHECK CONDITIONS */
   if (p1 == 0.0)
      p1 = pw;


/* CALCULATE PHASES */
   sub(ct, ssctr, v11);		     /* v11 = ct-ss */
   initval(256.0, v12);
   add(v11, v12, v11);		     /* v11 = ct-ss+256 */
   hlv(v11, v1);		     /* v1 = cyclops = 00112233 */
   for (i = 0; i < relay + 1; i++)
      hlv(v1, v1);		     /* cyclops = 2**(relay+2) 0's, 1's, 2's,
					3's */

   mod4(v11, v2);		     /* v2 = 0123 0123... */
   dbl(v2, oph);		     /* oph = 0202 0202 */
   add(v2, v1, v2);		     /* v2 = 0123 0123 + cyclops */
   add(oph, v1, oph);		     /* oph = 0202 0202 + cyclops */
   hlv(v11, v3);		     /* v3 = 0011 2233 4455 ... */


/* PULSE SEQUENCE */
   status(A);
      if (rof1 == 0.0)
      {
         rof1 = 1.0e-6;		     /* phase switching time */
         rcvroff();
      }
      hsdelay(d1);		     /* preparation period */
     if (getflag("wet")) wet4(zero,one);

   status(B);
      rgpulse(pw, v1, rof1, rof1);
      delay(d2);		     /* evolution period */
   status(A);
      if (relay == 0)
         delay(tau);		     /* for delayed cosy */
      rgpulse(p1, v2, rof1, rof1);   /* start of mixing period */
      if (relay == 0)
         delay(tau);		     /* for delayed cosy */

      for (i = 0; i < relay; i++)    /* relay coherence */
      {
         hlv(v3, v3);		     /* v3=2**(relay+1) 0's, 1's, 2's, 3's */
         dbl(v3, v4);		     /* v4=2**(relay+1) 0's, 2's, 0's, 2's */
         add(v2, v4, v5);	     /* v5=v4+v2 (including cyclops) */
         delay(tau/2);
         rgpulse(2.0*pw, v2, rof1, rof1);
         delay(tau/2);
         rgpulse(pw, v5, rof1, rof1);
      }

   status(C);
      delay(rof2);
      rcvron();
}
Esempio n. 21
0
void cmdToggle(AgiGame *state, uint8 *p) {
	setflag(*p, !getflag(*p));
}
Esempio n. 22
0
void MCStack::realize()
{
	if (MCnoui)
	{
		start_externals();
		return;
	}

	if (MCModeMakeLocalWindows())
	{
		uint32_t wstyle, exstyle;
		loadwindowshape();
		getstyle(wstyle, exstyle);
		RECT wrect ;

		if ( getextendedstate(ECS_FULLSCREEN) )
		{
			const MCDisplay *t_display;
			t_display = MCscreen -> getnearestdisplay(rect);
			MCRectangle t_workarea, t_viewport;
			t_workarea = t_display -> workarea;
			t_viewport = t_display -> viewport ;
			setrect(t_viewport);
		}

		wrect = getwrect(rect, wstyle, exstyle);
		LONG x = wrect.left;
		LONG y = wrect.top;
		LONG width = wrect.right - wrect.left;
		LONG height = wrect.bottom - wrect.top;
		if (flags & F_WM_PLACE && !(state & CS_BEEN_MOVED))
			x = CW_USEDEFAULT;
		window = new _Drawable;
		window->type = DC_WINDOW;
		window->handle.window = 0; // protect against creation callbacks

		// MW-2011-02-15: [[ Bug 9396 ]] Tooltips should have a shadow on Windows.
		Boolean isxpmenu = (mode == WM_PULLDOWN || mode == WM_POPUP || mode == WM_CASCADE || mode == WM_TOOLTIP) \
		                   && (MCcurtheme && MCcurtheme->getthemeid() == LF_NATIVEWIN);

		// MW-2012-09-07: [[ Bug 10368 ]] If the 'no-shadow' bit is set, then we don't
		//   want to use the menu class.
		if (getflag(F_DECORATIONS) && (decorations & WD_NOSHADOW) != 0)
			isxpmenu = False;

		HWND t_parenthwnd = NULL;

		// MW-2007-07-06: [[ Bug 3226 ]] If the platform is NT always create a Unicode window
		if ((MCruntimebehaviour & RTB_NO_UNICODE_WINDOWS) == 0 && !isxpmenu && mode < WM_PULLDOWN)
			window -> handle . window = (MCSysWindowHandle)CreateWindowExW(exstyle, MC_WIN_CLASS_NAME_W, WideCString(getname_cstring()),wstyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, x, y, width, height,
		                 t_parenthwnd, NULL, MChInst, NULL);
		else
			window->handle.window = (MCSysWindowHandle)CreateWindowExA(exstyle, isxpmenu? MC_MENU_WIN_CLASS_NAME: mode >= WM_PULLDOWN ? MC_POPUP_WIN_CLASS_NAME
		                 : MC_WIN_CLASS_NAME, getname_cstring(), wstyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, x, y, width, height,
		                 t_parenthwnd, NULL, MChInst, NULL);

		SetWindowLongA((HWND)window->handle.window, GWL_USERDATA, mode);
		
		if (flags & F_DECORATIONS && !(decorations & WD_SHAPE) && !(decorations & WD_CLOSE))
			EnableMenuItem(GetSystemMenu((HWND)window->handle.window, False), SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);

		if (m_window_shape != nil && m_window_shape -> is_sharp)
		{
			MCRegionRef t_region;
			t_region = (MCRegionRef)m_window_shape -> handle;
			MCRegionOffset(t_region, rect . x - wrect . left, rect . y - wrect . top);
			MCRegionSetAsWindowShape(t_region, window->handle.window);

			// The window now owns the region.
			m_window_shape -> handle = nil;
		}

		if ((m_window_shape == NULL || m_window_shape -> is_sharp) && blendlevel != 100)
			setopacity(blendlevel * 255 / 100);
	}
	
	start_externals();
}
Esempio n. 23
0
pulsesequence()
{
   double	   slpwrT = getval("slpwrT"),
		   slpwT = getval("slpwT"),
		   mixT = getval("mixT"),
		   gzlvl1 = getval("gzlvl1"),
		   gt1 = getval("gt1"),
		   gzlvl2 = getval("gzlvl2"),
		   gt2 = getval("gt2"),
		   gstab = getval("gstab"),
                   selpwrA = getval("selpwrA"),
                   selpwA = getval("selpwA"),
                   gzlvlA = getval("gzlvlA"),
                   gtA = getval("gtA"),
                   selpwrB = getval("selpwrB"),
                   selpwB = getval("selpwB"),
                   gzlvlB = getval("gzlvlB"),
                   gtB = getval("gtB"),
		   selfrq = getval("selfrq"),
                   zqfpw1 = getval("zqfpw1"),
                   zqfpwr1 = getval("zqfpwr1"),
                   zqfpw2 = getval("zqfpw2"),
                   zqfpwr2 = getval("zqfpwr2"),
                   gzlvlzq1 = getval("gzlvlzq1"),
                   gzlvlzq2 = getval("gzlvlzq2"),
                   phincr1 = getval("phincr1");
   char		   slpatT[MAXSTR], selshapeA[MAXSTR], selshapeB[MAXSTR], zqfpat1[MAXSTR],
                   zqfpat2[MAXSTR], flipback[MAXSTR], alt_grd[MAXSTR];

//synchronize gradients to srate for probetype='nano'
//   Preserve gradient "area"
        gtA = syncGradTime("gtA","gzlvlA",1.0);
        gzlvlA = syncGradLvl("gtA","gzlvlA",1.0);
        gtB = syncGradTime("gtB","gzlvlB",1.0);
        gzlvlB = syncGradLvl("gtB","gzlvlB",1.0);

   getstr("slpatT",slpatT);
   getstr("selshapeA",selshapeA);
   getstr("selshapeB",selshapeB);
   getstr("zqfpat1",zqfpat1);
   getstr("zqfpat2",zqfpat2);
   getstr("flipback", flipback);
   getstr("alt_grd",alt_grd);
                     /* alternate gradient sign on every 2nd transient */

   if (strcmp(slpatT,"mlev17c") &&
        strcmp(slpatT,"dipsi2") &&
        strcmp(slpatT,"dipsi3") &&
        strcmp(slpatT,"mlev17") &&
        strcmp(slpatT,"mlev16"))
        abort_message("SpinLock pattern %s not supported!.\n", slpatT);

/* STEADY-STATE PHASECYCLING */
/* This section determines if the phase calculations trigger off of (SS - SSCTR) or off of CT */

   assign(ct,v17);

   ifzero(ssctr);
      assign(v17,v13);
   elsenz(ssctr);
        /* purge option does not adjust v13 during steady state*/
      sub(ssval, ssctr, v13); /* v13 = 0,...,ss-1 */
   endif(ssctr);

   mod4(v13,v1); /* v1 = 0 1 2 3 */
   hlv(v13,v13);
   hlv(v13,v13);
   mod4(v13,v11); /* v11 = 0000 1111 2222 3333 */
   dbl(v1,oph);
   add(v11,oph,oph);
   add(v11,oph,oph); /* oph = 2v1 + 2v11 */

/* CYCLOPS */
   hlv(v13,v13);
   hlv(v13,v14);
   add(v1,v14,v1);
   add(v11,v14,v11);
   add(oph,v14,oph);
   assign(v14,v21);
   add(one,v21,v21);
   add(two,v21,v12);

  if (phincr1 < 0.0) phincr1=360+phincr1;
  initval(phincr1,v5);

   mod2(ct,v2);    /* 01 01 */
   hlv(ct,v4); hlv(v4,v4); mod2(v4,v4); dbl(v4,v4); /* 0000 2222 */
   add(v4,v2,v4); mod4(v4,v4); /* 0101 2323  first echo in Excitation Sculpting */
   hlv(ct,v7); mod2(v7,v7);    /* 0011 */
   hlv(ct,v9); hlv(v9,v9); hlv(v9,v9); dbl(v9,v9); add(v9,v7,v9);
   mod4(v9,v9);   /* 0011 0011 2233 2233 second echo in Excitation Sculpting */

   dbl(v2,v2);    /* 0202 */
   dbl(v7,v7);    /* 0022 */
   add(v2,v7,v7); /* 0220 correct oph for Excitation Sculpting */
   add(oph,v7,oph); mod4(oph,oph);

  if (alt_grd[0] == 'y') mod2(ct,v10); /* alternate gradient sign on every 2nd transient */

/* BEGIN THE ACTUAL PULSE SEQUENCE */
status(A);

   if (getflag("lkgate_flg"))  lk_sample(); /* turn lock sampling on */

   obspower(tpwr);
   delay(5.0e-5);
   if (getflag("sspul"))
        steadystate();

   delay(d1);

   if (getflag("lkgate_flg"))  lk_hold(); /* turn lock sampling off */

   status(B);

        rgpulse(pw, v14, rof1, rof1);

      if (selfrq != tof)
        obsoffset(selfrq);

        ifzero(v10); zgradpulse(gzlvlA,gtA);
        elsenz(v10); zgradpulse(-gzlvlA,gtA); endif(v10);
        delay(gstab);
        obspower(selpwrA);
        shaped_pulse(selshapeA,selpwA,v1,rof1,rof1);
        obspower(tpwr);
        ifzero(v10); zgradpulse(gzlvlA,gtA);
        elsenz(v10); zgradpulse(-gzlvlA,gtA); endif(v10);
        delay(gstab);

      if (selfrq != tof)
        delay(2*OFFSET_DELAY);

        ifzero(v10); zgradpulse(gzlvlB,gtB);
        elsenz(v10); zgradpulse(-gzlvlB,gtB); endif(v10);
        delay(gstab);
        obspower(selpwrB);
        shaped_pulse(selshapeB,selpwB,v11,rof1,rof1);
        obspower(tpwr);
        ifzero(v10); zgradpulse(gzlvlB,gtB);
        elsenz(v10); zgradpulse(-gzlvlB,gtB); endif(v10);
        delay(gstab);

      if (selfrq != tof)
        obsoffset(tof);

        rgpulse(pw, v14, rof1, rof1);
        if (getflag("Gzqfilt"))
        {
         obspower(zqfpwr1);
         ifzero(v10); rgradient('z',gzlvlzq1);
         elsenz(v10); rgradient('z',-gzlvlzq1); endif(v10);
         delay(100.0e-6);
         shaped_pulse(zqfpat1,zqfpw1,v14,rof1,rof1);
         delay(100.0e-6);
         rgradient('z',0.0);
         delay(gstab);
        }
        obspower(slpwrT);
        ifzero(v10); zgradpulse(gzlvl1,gt1);
        elsenz(v10); zgradpulse(-gzlvl1,gt1); endif(v10);
        delay(gstab);

	if (mixT > 0.0)
	{
          if (dps_flag)
          	rgpulse(mixT,v21,0.0,0.0);
          else
          	SpinLock(slpatT,mixT,slpwT,v21);
        }

        if (getflag("Gzqfilt"))
        {
         obspower(zqfpwr2);
         ifzero(v10); rgradient('z',gzlvlzq2);
         elsenz(v10); rgradient('z',-gzlvlzq2); endif(v10);
         delay(100.0e-6);
         shaped_pulse(zqfpat2,zqfpw2,v14,rof1,rof1);
         delay(100.0e-6);
         rgradient('z',0.0);
         delay(gstab);
        }
        obspower(tpwr);
        ifzero(v10); zgradpulse(gzlvl2,gt2);
        elsenz(v10); zgradpulse(-gzlvl2,gt2); endif(v10);
        delay(gstab);

      if (flipback[A] == 'y')
         FlipBack(v14,v5);

      rgpulse(pw,v14,rof1,2.0e-6);
      ExcitationSculpting(v4,v9,v10);
      delay(rof2);

   status(C);
}
Esempio n. 24
0
int AgiEngine::handleController(int key) {
	VtEntry *v = &_game.viewTable[0];
	int i;

	// AGI 3.149 games, The Black Cauldron and King's Quest 4 need KEY_ESCAPE to use menus
	// Games with the GF_ESCPAUSE flag need KEY_ESCAPE to pause the game
	if (key == 0 ||
		(key == KEY_ESCAPE && getVersion() != 0x3149 && getGameID() != GID_BC && getGameID() != GID_KQ4 && !(getFeatures() & GF_ESCPAUSE)) )
		return false;

	if ((getGameID() == GID_MH1 || getGameID() == GID_MH2) && (key == KEY_ENTER) &&
			(_game.inputMode == INPUT_NONE)) {
		key = 0x20; // Set Enter key to Space in Manhunter when there's no text input
	}

	debugC(3, kDebugLevelInput, "key = %04x", key);

	for (i = 0; i < MAX_CONTROLLERS; i++) {
		if (_game.controllers[i].keycode == key) {
			debugC(3, kDebugLevelInput, "event %d: key press", _game.controllers[i].controller);
			_game.controllerOccured[_game.controllers[i].controller] = true;
			return true;
		}
	}

	if (key == BUTTON_LEFT) {
		if ((getflag(fMenusWork) || (getFeatures() & GF_MENUS)) && _mouse.y <= CHAR_LINES) {
			newInputMode(INPUT_MENU);
			return true;
		}
	}

	// Show predictive dialog if the user clicks on input area
	if (key == BUTTON_LEFT &&
			(int)_mouse.y >= _game.lineUserInput * CHAR_LINES &&
			(int)_mouse.y <= (_game.lineUserInput + 1) * CHAR_LINES) {
		GUI::PredictiveDialog _predictiveDialog;
		_predictiveDialog.runModal();
		strcpy(_predictiveResult, _predictiveDialog.getResult());
		if (strcmp(_predictiveResult, "")) {
			if (_game.inputMode == INPUT_NONE) {
				for (int n = 0; _predictiveResult[n]; n++)
					keyEnqueue(_predictiveResult[n]);
			} else {
				strcpy((char *)_game.inputBuffer, _predictiveResult);
				handleKeys(KEY_ENTER);
			}
		}
		/*
		if (predictiveDialog()) {
			if (_game.inputMode == INPUT_NONE) {
				for (int n = 0; _predictiveResult[n]; n++)
					keyEnqueue(_predictiveResult[n]);
			} else {
				strcpy((char *)_game.inputBuffer, _predictiveResult);
				handleKeys(KEY_ENTER);
			}
		}
		*/
		return true;
	}

	if (_game.playerControl) {
		int d = 0;

		if (!KEY_ASCII(key)) {
			switch (key) {
			case KEY_UP:
				d = 1;
				break;
			case KEY_DOWN:
				d = 5;
				break;
			case KEY_LEFT:
				d = 7;
				break;
			case KEY_RIGHT:
				d = 3;
				break;
			case KEY_UP_RIGHT:
				d = 2;
				break;
			case KEY_DOWN_RIGHT:
				d = 4;
				break;
			case KEY_UP_LEFT:
				d = 8;
				break;
			case KEY_DOWN_LEFT:
				d = 6;
				break;
			}
		}

		if (!(getFeatures() & GF_AGIMOUSE)) {
			// Handle mouse button events
			if (key == BUTTON_LEFT) {
				if (getGameID() == GID_PQ1 && _game.vars[vCurRoom] == 116) {
					// WORKAROUND: Special handling for mouse clicks in the newspaper
					// screen of PQ1. Fixes bug #3018770.
					d = 3;	// fake a right arrow key (next page)
				} else {
					// Click-to-walk mouse interface
					v->flags |= fAdjEgoXY;
					v->parm1 = WIN_TO_PIC_X(_mouse.x);
					v->parm2 = WIN_TO_PIC_Y(_mouse.y);
					return true;
				}
			}
		}

		if (d || key == KEY_STATIONARY) {
			v->flags &= ~fAdjEgoXY;
			v->direction = v->direction == d ? 0 : d;
			return true;
		}
	}

	return false;
}
Esempio n. 25
0
pulsesequence()
{

   double	   gtE = getval("gtE"),
		   gzlvlE=getval("gzlvlE"),
		   selpwrPS = getval("selpwrPS"),
		   selpwPS = getval("selpwPS"),
		   gzlvlPS = getval("gzlvlPS"),
		   droppts=getval("droppts"),
		   gstab = getval("gstab");
   char		   selshapePS[MAXSTR];

//synchronize gradients to srate for probetype='nano'
//   Preserve gradient "area"
        gtE = syncGradTime("gtE","gzlvlE",1.0);
        gzlvlE = syncGradLvl("gtE","gzlvlE",1.0);

   getstr("selshapePS",selshapePS);

   settable(t1,4,ph1);
   settable(t2,32,ph2);
   settable(t3,8,ph3);
   settable(t4,16,ph4);

   getelem(t1,ct,v1);
   getelem(t2,ct,v2);
   getelem(t3,ct,v3);
   getelem(t4,ct,v4);
   assign(v4,oph);

   assign(v1,v6);

/* BEGIN THE ACTUAL PULSE SEQUENCE */
   status(A);
      obspower(tpwr);

   delay(5.0e-5);
   if (getflag("sspul"))
        steadystate();

   if (satmode[0] == 'y')
     {
        if ((d1-satdly) > 0.02)
                delay(d1-satdly);
        else
                delay(0.02);
        satpulse(satdly,v6,rof1,rof1);
     }
   else
        delay(d1);

   if (getflag("wet"))
     wet4(zero,one);


   status(B);
      obspower(tpwr);
      rgpulse(pw, v1, rof1, rof2);

	delay(d2/2.0);

	delay((0.25/sw1) - gtE - gstab - 2*pw/PI - rof2 - 2*GRADIENT_DELAY);
	zgradpulse(gzlvlE,gtE);
	delay(gstab);
	rgpulse(2*pw,v2,rof1,rof1);
	delay(0.25/sw1);

	delay(gstab);
	zgradpulse(-1.0*gzlvlE,gtE);
	delay(gstab);
	obspower(selpwrPS);
	rgradient('z',gzlvlPS);
	shaped_pulse(selshapePS,selpwPS,v3,rof1,rof1);
	rgradient('z',0.0);
	obspower(tpwr);
	delay(gstab);
	zgradpulse(-2.0*gzlvlE,gtE);
	delay(gstab - droppts/sw);

	delay(d2/2.0);

   status(C);
}
Esempio n. 26
0
pulsesequence()
{

   double	   gt1 = getval("gt1"),
		   gzlvl1=getval("gzlvl1"),
		   gt2 = getval("gt2"),
		   gzlvl2=getval("gzlvl2"),
		   selpwrPS = getval("selpwrPS"),
		   selpwPS = getval("selpwPS"),
		   gzlvlPS = getval("gzlvlPS"),
		   droppts=getval("droppts"),
		   gstab = getval("gstab"),
  		   espw180 = getval("espw180"),
                   essoftpw = getval("essoftpw"),
                   essoftpwr = getval("essoftpwr"),
                   essoftpwrf = getval("essoftpwrf");
   char		   selshapePS[MAXSTR],
		   esshape[MAXSTR];

//synchronize gradients to srate for probetype='nano'
//   Preserve gradient "area"
        gt1 = syncGradTime("gt1","gzlvl1",1.0);
        gzlvl1 = syncGradLvl("gt1","gzlvl1",1.0);
	gt2 = syncGradTime("gt2","gzlvl2",1.0);
        gzlvl2 = syncGradLvl("gt2","gzlvl2",1.0);

   getstr("esshape",esshape);

   getstr("selshapePS",selshapePS);

  assign(ct,v17);

   settable(t1,2,ph1);
   settable(t2,8,ph2);
   settable(t3,8,ph3);
   settable(t4,4,ph4);
   settable(t5,4,ph5);
   settable(t6,4,ph6);
   settable(t7,8,ph7);

   getelem(t1,v17,v1);
   getelem(t2,v17,v2);
   getelem(t3,v17,v3);
   getelem(t4,v17,v4);
   getelem(t5,v17,v5);
   getelem(t6,v17,v6);
   getelem(t7,v17,v7);
   assign(v7,oph);

   /*assign(v1,v6);
   add(oph,v18,oph);
   add(oph,v19,oph);*/

/* BEGIN THE ACTUAL PULSE SEQUENCE */
   status(A);
      obspower(tpwr);

   delay(5.0e-5);
   if (getflag("sspul"))
        steadystate();

  delay(d1);

   status(B);
      obspower(tpwr);
      rgpulse(pw, v1, rof1, rof2);

	delay(d2/2.0);

	zgradpulse(gzlvl1,gt1);
	delay(gstab);
	delay((0.25/sw1) - gt1 - gstab - 2*pw/PI - rof2 - 2*GRADIENT_DELAY - pw - rof1-essoftpw/2.0-2.0e-6);
        obspower(essoftpwr+6); obspwrf(essoftpwrf);
        shaped_pulse(esshape,essoftpw,v2,2.0e-6,2.0e-6);
        obspower(tpwr); obspwrf(4095.0);
	rgpulse(2.0*pw,v3,rof1,rof1);
	zgradpulse(gzlvl1,gt1);
	delay(gstab);
	delay((0.25/sw1) - gt1 - gstab - 2*GRADIENT_DELAY - pw - rof1 - essoftpw/2.0-2.0e-6);

	delay(gstab);
	zgradpulse(gzlvl2,gt2);
	delay(gstab);
        obspower(essoftpwr+6); obspwrf(essoftpwrf);
        shaped_pulse(esshape,essoftpw,v4,2.0e-6,2.0e-6);
	obspower(selpwrPS); obspwrf(4095.0) ;
	rgradient('z',gzlvlPS);
	shaped_pulse(selshapePS,selpwPS,v5,rof1,rof1);
	rgradient('z',0.0);
	delay(gstab);
	obspower(tpwr);
	zgradpulse(gzlvl2,gt2);
	delay(gstab - droppts/sw);
	delay(d2/2.0);
        obspower(tpwr); obspwrf(4095.0);

   status(C);
}
Esempio n. 27
0
void MCButton::GetAutoArm(MCExecContext& ctxt, bool& r_setting)
{
	r_setting = getflag(F_AUTO_ARM);
}
Esempio n. 28
0
int
main(int argc, char *argv[])
{
#ifdef __linux__
	const char *ifname = "wifi0";
#else
	const char *ifname = "ath0";
#endif
	const char *cp, *tp;
	const char *sep;
	int c, op, i;
	u_int32_t debug, ndebug;
	size_t debuglen;
	char oid[256];

	progname = argv[0];
	if (argc > 1) {
		if (strcmp(argv[1], "-i") == 0) {
			if (argc < 2)
				errx(1, "missing interface name for -i option");
			ifname = argv[2];
			argc -= 2, argv += 2;
		} else if (strcmp(argv[1], "-?") == 0)
			usage();
	}

#ifdef __linux__
	snprintf(oid, sizeof(oid), "dev.%s.debug", ifname);
#else
	snprintf(oid, sizeof(oid), "dev.ath.%s.debug", ifname+3);
#endif
	debuglen = sizeof(debug);
	if (sysctlbyname(oid, &debug, &debuglen, NULL, 0) < 0)
		err(1, "sysctl-get(%s)", oid);
	ndebug = debug;
	for (; argc > 1; argc--, argv++) {
		cp = argv[1];
		do {
			u_int bit;

			if (*cp == '-') {
				cp++;
				op = -1;
			} else if (*cp == '+') {
				cp++;
				op = 1;
			} else
				op = 0;
			for (tp = cp; *tp != '\0' && *tp != '+' && *tp != '-';)
				tp++;
			bit = getflag(cp, tp-cp);
			if (op < 0)
				ndebug &= ~bit;
			else if (op > 0)
				ndebug |= bit;
			else {
				if (bit == 0) {
					if (isdigit(*cp))
						bit = strtoul(cp, NULL, 0);
					else
						errx(1, "unknown flag %.*s",
							tp-cp, cp);
				}
				ndebug = bit;
			}
		} while (*(cp = tp) != '\0');
	}
	if (debug != ndebug) {
		printf("%s: 0x%x => ", oid, debug);
		if (sysctlbyname(oid, NULL, NULL, &ndebug, sizeof(ndebug)) < 0)
			err(1, "sysctl-set(%s)", oid);
		printf("0x%x", ndebug);
		debug = ndebug;
	} else
		printf("%s: 0x%x", oid, debug);
	sep = "<";
	for (i = 0; i < N(flags); i++)
		if (debug & flags[i].bit) {
			printf("%s%s", sep, flags[i].name);
			sep = ",";
		}
	printf("%s\n", *sep != '<' ? ">" : "");
	return 0;
}
Esempio n. 29
0
void MCButton::GetArmBorder(MCExecContext& ctxt, bool& r_setting)
{
	r_setting = getflag(F_ARM_BORDER);
}
Esempio n. 30
0
int AgiEngine::selectSlot() {
	int i, key, active = 0;
	int rc = -1;
	int hm = 1, vm = 3;	// box margins
	int xmin, xmax, slotClicked;
	char desc[NUM_VISIBLE_SLOTS][40];
	int textCenter, buttonLength, buttonX[2], buttonY;
	const char *buttonText[] = { "  OK  ", "Cancel", NULL };

	_noSaveLoadAllowed = true;

	for (i = 0; i < NUM_VISIBLE_SLOTS; i++) {
		getSavegameDescription(_firstSlot + i, desc[i]);
	}

	textCenter = GFX_WIDTH / CHAR_LINES / 2;
	buttonLength = 6;
	buttonX[0] = (textCenter - 3 * buttonLength / 2) * CHAR_COLS;
	buttonX[1] = (textCenter + buttonLength / 2) * CHAR_COLS;
	buttonY = (vm + 17) * CHAR_LINES;

	for (i = 0; i < 2; i++)
		_gfx->drawCurrentStyleButton(buttonX[i], buttonY, buttonText[i], false, false, i == 0);

	AllowSyntheticEvents on(this);
	int oldFirstSlot = _firstSlot + 1;
	int oldActive = active + 1;

	while (!(shouldQuit() || _restartGame)) {
		int sbPos = 0;

		// Use the extreme scrollbar positions only if the extreme
		// slots are in sight. (We have to calculate this even if we
		// don't redraw the save slots, because it's also used for
		// clicking in the scrollbar.

		if (_firstSlot == 0)
			sbPos = 1;
		else if (_firstSlot == NUM_SLOTS - NUM_VISIBLE_SLOTS)
			sbPos = NUM_VISIBLE_SLOTS - 2;
		else {
			sbPos = 2 + (_firstSlot * (NUM_VISIBLE_SLOTS - 4)) / (NUM_SLOTS - NUM_VISIBLE_SLOTS - 1);
			if (sbPos >= NUM_VISIBLE_SLOTS - 3)
				sbPos = NUM_VISIBLE_SLOTS - 3;
		}

		if (oldFirstSlot != _firstSlot || oldActive != active) {
			char dstr[64];
			for (i = 0; i < NUM_VISIBLE_SLOTS; i++) {
				sprintf(dstr, "[%2d. %-28.28s]", i + _firstSlot, desc[i]);
				printText(dstr, 0, hm + 1, vm + 4 + i,
						(40 - 2 * hm) - 1, i == active ? MSG_BOX_COLOR : MSG_BOX_TEXT,
						i == active ? MSG_BOX_TEXT : MSG_BOX_COLOR);
			}

			char upArrow[] = "^";
			char downArrow[] = "v";
			char scrollBar[] = " ";

			for (i = 1; i < NUM_VISIBLE_SLOTS - 1; i++)
				printText(scrollBar, 35, hm + 1, vm + 4 + i, 1, MSG_BOX_COLOR, 7, true);

			printText(upArrow, 35, hm + 1, vm + 4, 1, 8, 7);
			printText(downArrow, 35, hm + 1, vm + 4 + NUM_VISIBLE_SLOTS - 1, 1, 8, 7);
			printText(scrollBar, 35, hm + 1, vm + 4 + sbPos, 1, MSG_BOX_COLOR, MSG_BOX_TEXT);

			oldActive = active;
			oldFirstSlot = _firstSlot;
		}

		pollTimer();
		key = doPollKeyboard();

		// It may happen that somebody will open GMM while
		// this dialog is open, and load a game
		// We are processing it here, effectively jumping
		// out of the dead loop
		if (getflag(fRestoreJustRan)) {
			rc = -2;
			goto getout;
		}

		switch (key) {
		case KEY_ENTER:
			rc = active;
			strncpy(_game.strings[MAX_STRINGS], desc[i], MAX_STRINGLEN);
			goto press;
		case KEY_ESCAPE:
			rc = -1;
			goto getout;
		case BUTTON_LEFT:
			if (_gfx->testButton(buttonX[0], buttonY, buttonText[0])) {
				rc = active;
				strncpy(_game.strings[MAX_STRINGS], desc[i], MAX_STRINGLEN);
				goto press;
			}
			if (_gfx->testButton(buttonX[1], buttonY, buttonText[1])) {
				rc = -1;
				goto getout;
			}
			slotClicked = ((int)_mouse.y - 1) / CHAR_COLS - (vm + 4);
			xmin = (hm + 1) * CHAR_COLS;
			xmax = xmin + CHAR_COLS * 34;
			if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) {
				if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS)
					active = slotClicked;
			}
			xmin = (hm + 36) * CHAR_COLS;
			xmax = xmin + CHAR_COLS;
			if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) {
				if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) {
					if (slotClicked == 0)
						keyEnqueue(KEY_UP);
					else if (slotClicked == NUM_VISIBLE_SLOTS - 1)
						keyEnqueue(KEY_DOWN);
					else if (slotClicked < sbPos)
						keyEnqueue(KEY_UP_RIGHT);
					else if (slotClicked > sbPos)
						keyEnqueue(KEY_DOWN_RIGHT);
				}
			}
			break;
		case KEY_DOWN:
			active++;
			if (active >= NUM_VISIBLE_SLOTS) {
				if (_firstSlot + NUM_VISIBLE_SLOTS < NUM_SLOTS) {
					_firstSlot++;
					for (i = 1; i < NUM_VISIBLE_SLOTS; i++)
						memcpy(desc[i - 1], desc[i], sizeof(desc[0]));
					getSavegameDescription(_firstSlot + NUM_VISIBLE_SLOTS - 1, desc[NUM_VISIBLE_SLOTS - 1]);
				}
				active = NUM_VISIBLE_SLOTS - 1;
			}
			break;
		case KEY_UP:
			active--;
			if (active < 0) {
				active = 0;
				if (_firstSlot > 0) {
					_firstSlot--;
					for (i = NUM_VISIBLE_SLOTS - 1; i > 0; i--)
						memcpy(desc[i], desc[i - 1], sizeof(desc[0]));
					getSavegameDescription(_firstSlot, desc[0]);
				}
			}
			break;

		// Page Up/Down and mouse wheel scrolling all leave 'active'
		// unchanged so that a visible slot will remain selected.

		case WHEEL_DOWN:
			if (_firstSlot < NUM_SLOTS - NUM_VISIBLE_SLOTS) {
				_firstSlot++;
				for (i = 1; i < NUM_VISIBLE_SLOTS; i++)
					memcpy(desc[i - 1], desc[i], sizeof(desc[0]));
				getSavegameDescription(_firstSlot + NUM_VISIBLE_SLOTS - 1, desc[NUM_VISIBLE_SLOTS - 1]);
			}
			break;
		case WHEEL_UP:
			if (_firstSlot > 0) {
				_firstSlot--;
				for (i = NUM_VISIBLE_SLOTS - 1; i > 0; i--)
					memcpy(desc[i], desc[i - 1], sizeof(desc[0]));
				getSavegameDescription(_firstSlot, desc[0]);
			}
			break;
		case KEY_DOWN_RIGHT:
			// This is probably triggered by Page Down.
			_firstSlot += NUM_VISIBLE_SLOTS;
			if (_firstSlot > NUM_SLOTS - NUM_VISIBLE_SLOTS) {
				_firstSlot = NUM_SLOTS - NUM_VISIBLE_SLOTS;
			}
			for (i = 0; i < NUM_VISIBLE_SLOTS; i++)
				getSavegameDescription(_firstSlot + i, desc[i]);
			break;
		case KEY_UP_RIGHT:
			// This is probably triggered by Page Up.
			_firstSlot -= NUM_VISIBLE_SLOTS;
			if (_firstSlot < 0) {
				_firstSlot = 0;
			}
			for (i = 0; i < NUM_VISIBLE_SLOTS; i++)
				getSavegameDescription(_firstSlot + i, desc[i]);
			break;
		}
		_gfx->doUpdate();
	}

press:
	debugC(8, kDebugLevelMain | kDebugLevelInput, "Button pressed: %d", rc);

getout:
	closeWindow();

	_noSaveLoadAllowed = false;

	return rc;
}