Esempio n. 1
0
static void
identstmt(void)
{
	struct iobuf *ob = NULL;
	struct symtab *sp;
	usch *bp;
	int ch;

	if (ISID0(ch = fastspc())) {
		bp = readid(ch);
		if ((sp = lookup(bp, FIND)))
			ob = kfind(sp);
		if (ob->buf[0] != '\"')
			goto bad;
		if (ob)
			bufree(ob);
	} else if (ch == '\"') {
		bufree(faststr(ch, NULL));
		
	} else
		goto bad;
	chknl(1);
	return;
bad:
	error("bad #ident directive");
}
Esempio n. 2
0
void ll_mail_free(struct ll_mail *p)
{
	char myid[IDBUFSIZE];
	char idbuf[IDBUFSIZE];

	getid(myid);

	if (p->cclientfd >= 0)
	{
		if (lseek(p->cclientfd, 0L, SEEK_SET) == 0 &&
		    readid(idbuf, p->cclientfd) == 0 &&
		    strcmp(myid, idbuf) == 0)
		{
			if (ftruncate(p->cclientfd, 0) >= 0)
				unlink(p->cclientfile);
		}
		close(p->cclientfd);
		free(p->cclientfile);
	}

	if (p->dotlock)
	{
		int fd=open(p->dotlock, O_RDONLY);

		if (fd >= 0)
		{
			if (readid(idbuf, fd) == 0 &&
			    strcmp(myid, idbuf) == 0)
			{
				close(fd);
				unlink(p->dotlock);
				free(p->dotlock);
				free(p->file);
				free(p);
				return;
			}
			close(fd);
		}

		free(p->dotlock);
	}
	free(p->file);
	free(p);
}
Esempio n. 3
0
/*
 * Handle a preprocessor directive.
 * # is already found.
 */
void
ppdir(void)
{
	int ch, i, oldC;
	usch *bp;

	oldC = Cflag;
redo:	Cflag = 0;
	if ((ch = fastspc()) == '\n') { /* empty directive */
		unch(ch);
		Cflag = oldC;
		return;
	}
	Cflag = oldC;
	if ((spechr[ch] & C_ID0) == 0)
		goto out;
	bp = readid(ch);

	/* got some keyword */
	for (i = 0; i < NPPD; i++) {
		if (bp[0] == ppd[i].name[0] &&
		    strcmp((char *)bp, ppd[i].name) == 0) {
			if (flslvl == 0) {
				(*ppd[i].fun)();
				if (flslvl == 0)
					return;
			} else {
				if (ppd[i].flags & DIR_FLSLVL) {
					(*ppd[i].fun)();
					if (flslvl == 0)
						return;
				} else if (ppd[i].flags & DIR_FLSINC)
					flslvl++;
			}
			flscan();
			goto redo;
		}
	}
	if (flslvl == 0) {
		if (Aflag)
			skpln();
		return;
	}
	flscan();
	goto redo;

out:
	if (flslvl == 0 && Aflag == 0)
		error("invalid preprocessor directive");

	unch(ch);
	skpln();
}
Esempio n. 4
0
static void
undefstmt(void)
{
	struct symtab *np;
	usch *bp;
	int ch;

	if (!ISID0(ch = fastspc()))
		error("bad #undef");
	bp = readid(ch);
	if ((np = lookup(bp, FIND)) != NULL)
		np->valoff = 0;
	chknl(0);
}
Esempio n. 5
0
static void
ifndefstmt(void)
{
	usch *bp;
	int ch;

	if (!ISID0(ch = fastspc()))
		error("bad #ifndef");
	bp = readid(ch);
	if (lookup(bp, FIND) != NULL)
		flslvl++;
	else
		trulvl++;
	chknl(0);
}
Esempio n. 6
0
static void dotlock_exists(const char *dotlock, char *myidbuf,
			   int timeout)
{
	char idbuf[IDBUFSIZE];
	struct stat stat_buf;
	int fd;

	if ((fd=open(dotlock, O_RDONLY)) >= 0)
	{
		pid_t p;

		/*
		** Where the locking process is on the same server,
		** the decision is easy: does the process still exist,
		** or not?
		*/

		if (readid(idbuf, fd) == 0 && (p=getpidid(idbuf, myidbuf)))
		{
			if (p == getpid() /* Possibly recycled PID */
			    || (kill(p, 0) < 0 && errno == ESRCH))
			{
				close(fd);
				if (unlink(dotlock) == 0)
					errno=EAGAIN;
				else
					errno=EEXIST;
				return;
			}
		}
		else if (timeout > 0 && fstat(fd, &stat_buf) >= 0 &&
			 stat_buf.st_mtime < time(NULL) - timeout)
		{
			close(fd);

			if (unlink(dotlock) == 0)
				errno=EAGAIN;
			else
				errno=EEXIST;
			return;
		}

		close(fd);
	}

	errno=EEXIST;
}
Esempio n. 7
0
Token cp_token (ParseState *ps) {
    for (; curchar(ps); ) {
        char c = ps->str[ps->pos++];
        if (c == ',') return deftoken(T_COMMA);
        if (c == '.') return deftoken(T_DOT);
        if (isdigit(c)) {
            NumType num = readnum(ps);
            return numtoken(num);
        }
        if (c == '"') {
            char *s = readstr(ps);
            return strtoken(s);
        }
        if (isidstr(c)) {
            char *s = readid(ps);
            return idtoken(s);
        }
    }
    return deftoken(T_EOF);
}
Esempio n. 8
0
int ll_mail_lock(struct ll_mail *p)
{
	struct stat stat_buf;
	char idbuf[IDBUFSIZE];
	char idbuf2[IDBUFSIZE];

	char fn[NUMBUFSIZE*2 + 20];
	char *f;
	int fd;

	getid(idbuf);

	if (p->cclientfd >= 0)
		return 0;

	if (stat(p->file, &stat_buf) < 0)
		return -1;

	if (snprintf(fn, sizeof(fn), "/tmp/.%lx.%lx",
		     (unsigned long)stat_buf.st_dev,
		     (unsigned long)stat_buf.st_ino) < 0)
	{
		errno=ENOSPC;
		return (-1);
	}

	if ((f=strdup(fn)) == NULL)
		return (-1);

	/* We do things a bit differently.  First, try O_EXCL */

	if ((fd=open(f, O_RDWR|O_CREAT|O_EXCL, 0644)) >= 0)
	{
		struct stat stat_buf2;

		if (ll_lockfd(fd, ll_writelock, ll_whence_start, 0) < 0 ||
		    fcntl(fd, F_SETFD, FD_CLOEXEC) < 0 ||
		    writeid(idbuf, fd) < 0)
		{
			/* This shouldn't happen */

			close(fd);
			free(f);
			return (-1);
		}

		/* Rare race condition: */

		if (fstat(fd, &stat_buf) < 0 ||
		    lstat(f, &stat_buf2) < 0 ||
		    stat_buf.st_dev != stat_buf2.st_dev ||
		    stat_buf.st_ino != stat_buf2.st_ino)
		{
			errno=EAGAIN;
			close(fd);
			free(f);
			return (-1);
		}

		p->cclientfd=fd;
		p->cclientfile=f;
		return 0;
	}

	/*
	** An existing lockfile.  See if it's tagged with another
	** pid on this server, which no longer exists.
	*/

	if ((fd=open(f, O_RDONLY)) >= 0)
	{
		pid_t p=-1;

		if (readid(idbuf2, fd) == 0 &&
		    (p=getpidid(idbuf2, idbuf)) != 0 &&
		    kill(p, 0) < 0 && errno == ESRCH)
		{
			errno=EAGAIN;
			close(fd);
			unlink(f); /* Don't try again right away */
			free(f);
			return (-1);
		}

		/* If we can't lock, someone must have it open, game over. */

		if (p == getpid() /* It's us! */

		    || ll_lockfd(fd, ll_readlock, ll_whence_start, 0) < 0)
		{
			errno=EEXIST;
			close(fd);
			free(f);
			return (-1);
		}

		close(fd);
	}

	/* Stale 0-length lockfiles are blown away after 5 mins */

	if (lstat(f, &stat_buf) == 0 && stat_buf.st_size == 0 &&
	    stat_buf.st_mtime + 300 < time(NULL))
	{
		errno=EAGAIN;
		unlink(f);
		free(f);
		return (-1);
	}

	errno=EAGAIN;
	free(f);
	return (-1);
}
Esempio n. 9
0
int main()
{


/*
    DECLARE LOCAL DATA AREAS:
*/

    char cmd_buff[80];		/* command line input buffer */
    unsigned finished, finished1; /* flag to exit program */
    int hstatus;		/* returned status of routines */
    int item;			/* menu item selection variable */
    float ideal_volt_span;	/* storage span info */
    float f_data;
    long addr;			/* board address */
    int flag;			/* general flag for exiting loops */
    int i,j;			/* loop index */
    int temp;
    struct conf_blk c_block;	/* configuration block */
    int hflag;                  /* interrupt handler installed flag */
    struct handler_data hdata;  /* interrupt data structure (see exception.h) */
    float fb[MAXSIZE];		/* storage buffer for floats */
    float fs, zs, slope, ge;

/*
    ENTRY POINT OF ROUTINE:
    INITIALIZATION
*/

    flag = 0;		/* indicate board address not yet assigned */
    finished = 0;	/* indicate not finished with program */
    hflag = 0;          /* indicate interrupt handler not installed yet */

    for(j = 0; j < MAXSIZE; j++)	/* clear float buffer */
    	fb[j] = 0.0;
    
    for(i = 0; i < NUM_CHAN;i++)
    {
      for(j = 0; j < MAXSIZE; j++)
      {
	c_block.ideal_data[i][j] = 0;	/* clear ideal data buffer */
	c_block.cor_data[i][j] = 0;	/* clear corrected data buffer */
      }
      c_block.coef_bufu10[i][0] = c_block.coef_bufu10[i][1] = 0;
      c_block.coef_bufb10[i][0] = c_block.coef_bufb10[i][1] = 0;
      c_block.coef_bufb5[i][0]  = c_block.coef_bufb5[i][1] = 0;

      /* Initialize the Configuration Parameter Block to default values */

      c_block.mode[i] = 0;		/* mode */
      c_block.trigger[i] = 0;		/* default triggering */
      c_block.interrupt_enable[i] = 0;	/* interrupt enable */
      c_block.threshold[i] = 0;	/* empty threshold */
      c_block.range[i] = BIPOLAR_10;/* channel range storage */
      c_block.prescaler[i] = 53;	/* timer prescaler */
      c_block.counter[i] = 1;		/* conversion counter */
      c_block.write_size[i] = 1;
    }
    c_block.interrupt_flag = 0;	/* default to no interrupts */
    c_block.current_channel = 0;	/* default channel */

    c_block.interrupt_vector = VECTOR;	/* default interrupt vector */
    c_block.bCarrier = FALSE;		/* indicate no carrier initialized and set up yet */
    c_block.bInitialized = FALSE;	/* indicate not ready to talk to IP */
    c_block.slotLetter = SLOT_A;
    c_block.nHandle = 0;		/* make handle to a closed carrier board */

    hdata.h_pid = getpid();		/* save it in the interrupt handler data structure */
    hdata.hd_ptr = (char *)&c_block;/* put in address of c_block structure also */

/*
	Initialize the Carrier library
*/
    if(InitCarrierLib() != S_OK)
    {
	printf("\nUnable to initialize the carrier library. Exiting program.\n");
	exit(0);
    }

/*
	Open an instance of a carrier device 
*/
    if(CarrierOpen(0, &c_block.nHandle) != S_OK)
    {
	printf("\nUnable to Open instance of carrier.\n");
	finished = 1;	 /* indicate finished with program */
    }
    else
	flag = 1;


/* Enter main loop */

    while(!finished)
    {
      printf("\nIP236 Library Demonstration  Rev. A \n\n");
      printf(" 1. Exit this Program\n");
      printf(" 2. Set Board Base Address\n");
      printf(" 3. Set IP Slot Letter\n");
      printf(" 4. Read Module I.D./Display Event Status\n");
      printf(" 5. Read Calibration Coefficients\n");
      printf(" 6. Set/Change Channel Number\n");
      printf(" 7. Issue Software Reset to Board\n");
      printf(" 8. Set Up Configuration Parameters\n");
      printf(" 9. Configure Channel\n");
      printf("10. Enter/Change Output Values\n");
      printf("11. Correct Output Values\n");
      printf("12. Write Values to Output FIFO\n");
      printf("13. N/A\n");
      printf("14. Start/Stop Conversions\n");
      printf("15. View Data Buffers & Offset/Gain Coefficients\n");
      printf("16. Clear All Data Buffers\n");
      printf("17. Modify Offset/Gain Coefficients\n");
      printf("18. N/A\n\n");
      printf("Select: ");
      scanf("%d",&item);

/*
    perform the menu item selected.
*/  

      switch(item)
      {
       case 1: /* exit program command */
            printf("Exit program(y/n)?: ");
            scanf("%s",cmd_buff);
            if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
                finished++;
            break;
        

	case 2: /* set board address command */
	    do 
	    {
		if(flag == 0)
		{
		  printf("\n\nenter base address of carrier board in hex: ");
		  scanf("%lx",&addr);
		  /* Set Carrier Address for Open Carrier Device */
		  SetCarrierAddress(c_block.nHandle, addr);	/* Set Carrier Address */
		}
		GetCarrierAddress(c_block.nHandle, &addr);	/* Read back carrier address */
		printf("address: %lX\n",addr);
		printf("is this value correct(y/n)?: ");
		scanf("%s",cmd_buff);
		if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
		{
          SetCarrierAddress(c_block.nHandle, addr);	/* Set Carrier Address */
		  if(CarrierInitialize(c_block.nHandle) == S_OK)/* Initialize Carrier */
		  {
		        c_block.bCarrier = TRUE;
			SetInterruptLevel(c_block.nHandle, INTERRUPT_LEVEL);/* Set carrier interrupt level */
		  }
		  flag = 1;
		}
		else
		  flag = 0;

            }while( cmd_buff[0] != 'y' && cmd_buff[0] != 'Y' );
        break;


	  case 3: /* set IP Slot Letter */
		if(flag == 0 || c_block.bCarrier == FALSE)
			printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
		else
		{
			printf("\n\nEnter IP slot letter (A, B etc...): ");
			scanf("%s",cmd_buff);
			cmd_buff[0] = toupper(cmd_buff[0]);
			if(cmd_buff[0] < 'A' || cmd_buff[0] > GetLastSlotLetter())
			{
				printf("\nInvalid Slot Letter!\n");
				c_block.bCarrier = FALSE;
			}
			else
			{
				c_block.slotLetter = cmd_buff[0];
																					
/*
	Get the IPACK's base address based on the Slot letter,
        and initialize the IPACK's data structure with the returned address
*/
				if(GetIpackAddress(c_block.nHandle, c_block.slotLetter, &addr) != S_OK)
				{
					printf("\nUnable to Get Ipack Address.\n");
					c_block.bInitialized = FALSE;
				}
				else	              
				{	
			            c_block.brd_ptr = (struct map236 *)addr;
					c_block.bInitialized = TRUE;
				}
			}
		}
	  break;


        case 4: /* Read ID Prom */
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
		 readid(&c_block);
        break;

        case 5: /* Read calibration coeficients*/
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	      {
	       for( i = 0; i < NUM_CHAN; i++ )
	       {
		  c_block.coef_bufu10[i][0] = (word)ReadOffsetError( &c_block, i, UNIPOLAR_10 );
                  c_block.coef_bufu10[i][1] = (word)ReadGainError( &c_block, i, UNIPOLAR_10 );

                  c_block.coef_bufb5[i][0]  = (word)ReadOffsetError( &c_block, i, BIPOLAR_5 );
                  c_block.coef_bufb5[i][1]  = (word)ReadGainError( &c_block, i, BIPOLAR_5 );

                  c_block.coef_bufb10[i][0] = (word)ReadOffsetError( &c_block, i, BIPOLAR_10 );
                  c_block.coef_bufb10[i][1] = (word)ReadGainError( &c_block, i, BIPOLAR_10 );
	       }
	    }
            break;    

        case 6: /* channel number */
	    finished1 = 0;
	    while(!finished1)
	    {
 	       printf("\n\nChannel: %x\n\n",c_block.current_channel);
	       printf(" 1. Return to Previous Menu\n");
	       printf(" 2. Change Channel Number\n");
	       printf("\nSelect: ");
	       scanf("%d",&temp);
	       switch(temp)
	       {
		 case 1: /* return to previous menu */
		    finished1++;
		 break;

		 case 2: /* Select channel */
		     printf("New Channel Number (0 - %d)\n",(NUM_CHAN - 1));
		     c_block.current_channel = (int)get_param();
		 break;
	       }
	    }
	    break;

        case 7: /* Reset channel */
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
		    reset_board(&c_block);
        break;

        case 8: /* set up configuration block parameters */
	      setconf236(&c_block);
        break;

        case 9: /* configure */
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	          cnfg236(&c_block);
        break;

        case 10: /* Enter Ideal Data */
	    finished1 = 0;
	    while(!finished1)
	    {
	 	printf("\n\nChannel: %x\n\n",c_block.current_channel);
		printf(" 1. Return to Previous Menu\n");
		printf(" 2. Enter Value(s)\n");
		printf("\nSelect: ");
		scanf("%d",&temp);
		switch(temp)
		{
			case 1: /* return to previous menu */
			    finished1++;
			break;

			case 2: /* enter channel values */
	 		    printf("\nEnter desired voltage: ie: 1.25, follow each with CR %d max)",MAXSIZE);
			    printf("\n  CR alone moves to next value,");
       			    printf("\n  SPACE CR moves to previous value,");
	       		    printf("\n  Q CR quits:\n\n");
			    gets( &cmd_buff[0] );	      /* purge input stream */
         	 	    for( j = 0; j < MAXSIZE; j++ )
           	            {
              		      printf("[%02X]: %f ",j,fb[j]);
              		      gets( &cmd_buff[0] );

	                      if(( cmd_buff[0] == 'Q') || ( cmd_buff[0] == 'q'))
	                           break;
	                      else
	                      {
	                        if( cmd_buff[0] == ' ' )      /* check for space */
 	                            j -= 2; 	   	      /* back up if so */

	                        if( cmd_buff[0] != 0 && cmd_buff[0] != ' ' ) /* check for CR */
	                            sscanf( &cmd_buff[0], "%f", &fb[j]);  /* save */
 	                      }
  	                    }

                            for( i = 0; i < j; i++ )	/* convert data */
                            {
			      if(c_block.range[c_block.current_channel] == BIPOLAR_10)
 			         ideal_volt_span = VOLT_SPAN_B10;
			      else	
			         ideal_volt_span = VOLT_SPAN;

			      f_data = (((float)65536 * fb[i]) / ideal_volt_span);

			      if( c_block.range[c_block.current_channel] == UNIPOLAR_10 )
			    	f_data -= 32768.0;

			      if( f_data < 0.0)		/* round */
		 		f_data -= 0.5;
		 	      else
				f_data += 0.5;

			      if( f_data > 32767.0 )	/* clip high */
				f_data = 32767.0;

			      if( f_data < -32768.0 )	/* clip low */
				f_data = -32768.0;

			      c_block.ideal_data[c_block.current_channel][i] = (short)f_data;
			    }

			    c_block.write_size[c_block.current_channel] = j;
			break;
		}
	    }
        break;

        case 11: /* Correct Data */
	    cd236(&c_block);		/* correct data */ 
        break;

        case 12: /* Write Data to output */
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	      {
	      finished1 = 0;
	      while(!finished1)
	      {

 	        printf("\n\nChannel: %x\n\n",c_block.current_channel);
	        printf(" 1. Return to Previous Menu\n");
	        printf(" 2. Write Ideal Data Values\n");
	        printf(" 3. Write Corrected Data Values\n");
	        printf("\nSelect: ");
	        scanf("%d",&temp);
	        switch(temp)
	       { 
		      case 1: /* return to previous menu */
			    finished1++;
	   	      break;
		      case 2: /* Ideal */
			    c_block.current_ptr[c_block.current_channel] =
			    c_block.head_ptr[c_block.current_channel] = &c_block.ideal_data[c_block.current_channel][0];
			    c_block.tail_ptr[c_block.current_channel] = &c_block.ideal_data[c_block.current_channel][0] + c_block.write_size[c_block.current_channel];
			    wro236(&c_block, c_block.current_channel);
		      break;
		      case 3: /* Corrected */
			    c_block.current_ptr[c_block.current_channel] =
			    c_block.head_ptr[c_block.current_channel] = &c_block.cor_data[c_block.current_channel][0];
			    c_block.tail_ptr[c_block.current_channel] = &c_block.cor_data[c_block.current_channel][0] + c_block.write_size[c_block.current_channel];
			    wro236(&c_block, c_block.current_channel);
		      break;
	       }
	      }
	    }
	break;

        case 13:     /* attach exception handler */

            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
        break;

        case 14:  /* Start Conversion */
	    finished1 = 0;
	    while(!finished1)
	    {
 	       printf("\n\nChannel: %x\n\n",c_block.current_channel);
	       printf(" 1. Return to Previous Menu\n");
	       printf(" 2. Start Current Channel\n");
	       printf(" 3. Start Multiple Channels\n");
	       printf(" 4. Stop/Reset Current Channel\n");
	       printf(" 5. Stop/Reset Multiple Channels\n");
	       printf("\nSelect: ");
	       scanf("%d",&temp);
	       switch(temp)
	       { 
		      case 1: /* return to previous menu */
			    finished1++;
	   	      break;
		      case 2: /* Current channel */
		           start_single(&c_block);
		      break;
		      case 3: /* multiple channels */
		          printf("8 Bit Channel Mask to Start\n");
		          start_multiple(&c_block,(byte)get_param());
		      break;
		      case 4: /* Current channel */
			   reset_channel(&c_block);
		      break;
		      case 5: /* stop multiple channels */
		          printf("8 Bit Channel Mask to Stop\n");
		          stop_multiple(&c_block,(byte)get_param());
		      break;
	       }
	    }
           break;

        case 15:	/* Display Ideal/Corrected Data, Offset/Gain Coefficients */
previous:
	    printf("\n\nChannel: %1d  Range: ",c_block.current_channel);

	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("Bipolar 5  ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("Bipolar 10 ");
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("Unipolar 10");

	    printf("  Coefficients: Offset ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("%04X",(c_block.coef_bufb5[c_block.current_channel][0] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("%04X",(c_block.coef_bufb10[c_block.current_channel][0] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("%04X",(c_block.coef_bufu10[c_block.current_channel][0] & 0xFFFF));

	    printf("  Gain ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("%04X",(c_block.coef_bufb5[c_block.current_channel][1] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("%04X",(c_block.coef_bufb10[c_block.current_channel][1] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("%04X",(c_block.coef_bufu10[c_block.current_channel][1] & 0xFFFF));

	    printf("\n\nIdeal Data");
	    for( j = 0; j < 8; j++)
	    {
		printf("\n[%02X]",j*8);
		for(i = 0; i < 8; i++)
		      printf("    %04x",c_block.ideal_data[c_block.current_channel][j*8+i] & 0xFFFF);
	    }

	    printf("\n\nCorrected Data ");
	    for( j = 0; j < 8; j++)
	    {
		printf("\n[%02X]",j*8);
		for(i = 0; i < 8; i++)
		      printf("    %04x",c_block.cor_data[c_block.current_channel][j*8+i] & 0xFFFF);
	    }

	    printf("\n 1. Return to Previous Menu");
	    printf("\n 2. View Next Data Block");
	    printf("\nSelect: ");
	    scanf("%d",&temp);
	    if(temp == 1)
		break;

	    printf("\n\nChannel: %1d  Range: ",c_block.current_channel);

	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("Bipolar 5  ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("Bipolar 10 ");
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("Unipolar 10");

	    printf("  Coefficients: Offset ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("%04X",(c_block.coef_bufb5[c_block.current_channel][0] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("%04X",(c_block.coef_bufb10[c_block.current_channel][0] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("%04X",(c_block.coef_bufu10[c_block.current_channel][0] & 0xFFFF));

	    printf("  Gain ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("%04X",(c_block.coef_bufb5[c_block.current_channel][1] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("%04X",(c_block.coef_bufb10[c_block.current_channel][1] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("%04X",(c_block.coef_bufu10[c_block.current_channel][1] & 0xFFFF));

	    printf("\n\nIdeal Data");
	    for( j = 8; j < 16; j++)
	    {
		printf("\n[%02X]",j*8);
		for(i = 0; i < 8; i++)
		      printf("    %04x",c_block.ideal_data[c_block.current_channel][j*8+i] & 0xFFFF);
	    }

	    printf("\n\nCorrected Data ");
	    for( j = 8; j < 16; j++)
	    {
		printf("\n[%02X]",j*8);
		for(i = 0; i < 8; i++)
		      printf("    %04x",c_block.cor_data[c_block.current_channel][j*8+i] & 0xFFFF);
	    }

	    printf("\n 1. Return to Previous Menu");
	    printf("\n 2. View Previous Data Block");
	    printf("\nSelect: ");
	    scanf("%d",&temp);
	    if( temp == 2)
		goto previous;
	 break;


        case 16:        /* clear all data buffers */
	    for(i = 0; i < NUM_CHAN; i++)
	    {
	      for(j = 0; j < MAXSIZE; j++)
	      {
		c_block.ideal_data[i][j] = 0;	/* clear ideal data buffer */
		c_block.cor_data[i][j] = 0;	/* clear corrected data buffer */
	      }
	      c_block.coef_bufu10[i][0] = c_block.coef_bufu10[i][1] = 0;
	      c_block.coef_bufb10[i][0] = c_block.coef_bufb10[i][1] = 0;
	      c_block.coef_bufb5[i][0]  = c_block.coef_bufb5[i][1] = 0;
	    }
            break;

  
        case 17: /* modify gain & offset coefficients for a channel */
         if(flag == 0)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
         else
	 {
	    finished1 = 0;
	    while(!finished1)
	    {
 	       printf("\n\nChannel: %x\n\n",c_block.current_channel);
	       printf(" 1. Return to Previous Menu\n");
	       printf(" 2. Change Channel Number\n");
	       printf(" 3. Change Bipolar   5 Offset & Gain\n");
	       printf(" 4. Change Bipolar  10 Offset & Gain\n");
	       printf(" 5. Change Unipolar 10 Offset & Gain\n");
	       printf(" 6. Calculate Offset & Gain from End Points\n");
	       printf(" 7. Write All Current Channel Coefficients to EEPROM\n");
	       printf("\nSelect: ");
	       scanf("%d",&temp);
	       switch(temp)
	       {
		 case 1: /* return to previous menu */
		    finished1++;
		 break;

		 case 2: /* Select channel */
		     printf("New Channel Number (0 - %d)\n",(NUM_CHAN - 1));
		     c_block.current_channel = (int)get_param();
		 break;

		 case 3: /* Select Bipolar   5 */
		     printf("New Offset Value\n");
		     c_block.coef_bufb5[c_block.current_channel][0] = (short)get_param();
		     printf("New Gain Value\n");
		     c_block.coef_bufb5[c_block.current_channel][1] = (short)get_param();
		 break;

		 case 4: /* Select Bipolar  10 */
		     printf("New Offset Value\n");
		     c_block.coef_bufb10[c_block.current_channel][0] = (short)get_param();
		     printf("New Gain Value\n");
		     c_block.coef_bufb10[c_block.current_channel][1] = (short)get_param();
		 break;

		 case 5: /* Select Unipolar  10 */
		     printf("New Offset Value\n");
		     c_block.coef_bufu10[c_block.current_channel][0] = (short)get_param();
		     printf("New Gain Value\n");
		     c_block.coef_bufu10[c_block.current_channel][1] = (short)get_param();
		 break;

		 case 6: /* calculate */
		     printf("\nSpan 10 or 20: ");
		     scanf("%d",&temp);
		     printf("\nFull Scale Value: ");
		     scanf("%f",&fs);
		     printf("\nZero Scale Value: ");
		     scanf("%f",&zs);

		     if((fs - zs) == 0.0)
			break;

		     /* do gain calculation */
		     slope = 65536.0 / (fs - zs);
		     /* gain error */
		     ge = (((float)temp * slope) / 65536.0) - 1.0;
		     printf("\nGain = %X", ((short)((ge * 65536.0 * 4) + 0.5) & 0xFFFF));
 
		     /* do offset calculation */
		     slope *= -1;
		     printf("  Offset = %X",((short)((((slope * zs) - 32768.0) * 4) + 0.5) & 0xFFFF));
		 break;


		 case 7: /* Write values to EEPROM */
		  WriteCoefficients( &c_block, c_block.current_channel, c_block.coef_bufu10[c_block.current_channel][0],
			 c_block.coef_bufu10[c_block.current_channel][1], UNIPOLAR_10 );

		  WriteCoefficients( &c_block, c_block.current_channel, c_block.coef_bufb5[c_block.current_channel][0],
			 c_block.coef_bufb5[c_block.current_channel][1], BIPOLAR_5 );

		  WriteCoefficients( &c_block, c_block.current_channel, c_block.coef_bufb10[c_block.current_channel][0],
			 c_block.coef_bufb10[c_block.current_channel][1], BIPOLAR_10 );

		 break;
	       }
	    }
         }
        break;

      
        case 18: /* detach exception handlers */
		hflag = 0;
		DisableInterrupts(c_block.nHandle);
         break;

        }   /* end of switch */
    }   /* end of while */
/*
    Reset board to disable interrupts from all counters on this IP module
*/
    if(!c_block.bInitialized)    /* module address was set */
       reset_board(&c_block);	  /* reset board */

    DisableInterrupts(c_block.nHandle);
    if(c_block.bCarrier)
	CarrierClose(c_block.nHandle);

    printf("\nEXIT PROGRAM\n");
}   /* end of main */
Esempio n. 10
0
static int
exprline(void)
{
	extern int nbufused;
	struct iobuf *ob, *rb;
	struct symtab *nl;
	int oCflag = Cflag;
	usch *dp;
	int c, d, ifdef;

	rb = getobuf(BNORMAL);
	nbufused--;
	Cflag = ifdef = 0;

	for (;;) {
		c = qcchar();
xloop:		if (c == '\n')
			break;
		if (c == '.') {
			putob(rb, '.');
			if ((spechr[c = qcchar()] & C_DIGIT) == 0)
				goto xloop;
		}
		if (ISDIGIT(c)) {
			c = fastnum(c, rb);
			goto xloop;
		}
		if (c == '\'' || c == '\"') {
			faststr(c, rb);
			continue;
		}
		if (c == 'L' || c == 'u' || c == 'U') {
			unch(d = qcchar());
			if (d == '\'')	/* discard wide designator */
				continue;
		}
		if (ISID0(c)) {
			dp = readid(c);
			nl = lookup(dp, FIND);
			if (nl && nl->type == DEFLOC) {
				ifdef = 1;
			} else if (ifdef) {
				putob(rb, nl ? '1' : '0');
				ifdef = 0;
			} else if (nl != NULL) {
				inexpr = 1;
				if ((ob = kfind(nl))) {
					ob->buf[ob->cptr] = 0;
					strtobuf(ob->buf, rb);
					bufree(ob);
				} else
					putob(rb, '0');
				inexpr = 0;
			} else
				putob(rb, '0');
		} else
			putob(rb, c);
	}
	rb->buf[rb->cptr] = 0;
	unch('\n');
	yyinp = rb->buf;
	c = yyparse();
	bufree(rb);
	nbufused++;
	Cflag = oCflag;
	return c;
}