예제 #1
0
파일: snapfs.c 프로젝트: dancrossnyc/harvey
void
fsread(Req *r)
{
	char *e;
	PD *pd;
	Fid *fid;
	void *data;
	int64_t offset;
	int32_t count;

	fid = r->fid;
	data = r->ofcall.data;
	offset = r->ifcall.offset;
	count = r->ifcall.count;
	pd = fid->file->aux;

	if(pd->isproc)
		e = memread(pd->p, fid->file, data, &count, offset);
	else
		e = dataread(pd->d, data, &count, offset);

	if(e == nil)
		r->ofcall.count = count;
	respond(r, e);
}
예제 #2
0
파일: fs.c 프로젝트: rminnich/harvey
static void
fsread(Req *r)
{
	char e[ERRMAX], *s;
	uint32_t path;

	path = r->fid->qid.path;
	switch(TYPE(path)){
	default:
		snprint(e, sizeof e, "bug in execnet path=%lx", path);
		respond(r, e);
		break;

	case Qroot:
		dirread9p(r, rootgen, nil);
		respond(r, nil);
		break;

	case Qexec:
		dirread9p(r, execgen, nil);
		respond(r, nil);
		break;

	case Qn:
		dirread9p(r, conngen, client[NUM(path)]);
		respond(r, nil);
		break;

	case Qctl:
		snprint(e, sizeof e, "%u", NUM(path));
		readstr(r, e);
		respond(r, nil);
		break;

	case Qdata:
		dataread(r, client[NUM(path)]);
		break;

	case Qlocal:
		snprint(e, sizeof e, "%d", client[NUM(path)]->pid);
		readstr(r, e);
		respond(r, nil);
		break;

	case Qremote:
		s = client[NUM(path)]->cmd;
		if(strlen(s) >= 5)	/* "exec " */
			readstr(r, s+5);
		else
			readstr(r, s);
		respond(r, nil);
		break;

	case Qstatus:
		readstr(r, statusstr[client[NUM(path)]->status]);
		respond(r, nil);
		break;
	}
}
예제 #3
0
파일: fgettr.c 프로젝트: gganssle/stripper
static
int fgettr_internal(FILE *fp, segy *tp, cwp_Bool fixed_length) {
   int nread;  /* bytes seen by fread calls  */
   unsigned char buf[240];  /* buffer for test for line header */

   /* search linked list for possible alternative */
   if(fp != lastfp)  searchlist(fp);

   if (infoptr == ((struct insegyinfo *) NULL)) {
	/* initialize new segy input stream */
	unsigned int databytes; /* bytes from nsfirst   */

	/* allocate new segy input information table */
	*oldinfoptr = (struct insegyinfo *)
	 malloc(sizeof(struct insegyinfo));
	infoptr = *oldinfoptr;
	infoptr->nextinfo = (struct insegyinfo *) NULL;
	infoptr->infp = fp;  /* save FILE * ptr */
	infoptr->itr = 0;
	infoptr->ntr = -1;
	
	switch (infoptr->ftype = filestat(fileno(fp))) {
	 case DIRECTORY:
	    err("%s: segy input can't be a directory", __FILE__);

	 case TTY:
	    err("%s: segy input can't be tty", __FILE__);

	 default:
	    /* all others are ok */
	    break;
	}

/*--------------------------------------------------------------------*\
   Check for the presence of a line header and set a flag if one is
   found. The decision of what to do will be delayed until the call
   to fputtr(). This allows us to accept data w/ or w/o a line
   header.

   Reginald H. Beardsley [email protected]
\*--------------------------------------------------------------------*/

	/* Attempt to get a text header */

	nread=efread(buf ,1 ,HDRBYTES ,infoptr->infp);

	switch( nread ){

	 case 0:   
	    return 0; /* no traces; trap in mains */

	 default:  

	    if (nread < HDRBYTES ){
		return 0; 

	    }else if( isascii_txt( buf ,HDRBYTES  )
		  || isebcdic_txt( buf ,HDRBYTES  ) ){
		in_line_hdr = 1;
		memcpy( su_text_hdr ,buf ,HDRBYTES );
		nread += efread(&(su_text_hdr[HDRBYTES]) ,1 
			,3200-HDRBYTES ,infoptr->infp);

	    }else{
		in_line_hdr=0;
		memcpy( tp ,buf ,HDRBYTES );

	    }
	}		

	
	if( in_line_hdr ){

	 /* Get the binary header */
	 nread = efread(&su_binary_hdr, 1, sizeof(bhed), infoptr->infp);
	 switch( nread ){
	    case 0:   
		return 0; /* no traces; trap in mains */

		default:  
		 if (nread != sizeof(su_binary_hdr)){
		    err("%s:%d bad binary header" , __FILE__ ,__LINE__ );
		 }
	 }	 

	 /* Get the first trace header */
	 nread = efread(tp, 1, HDRBYTES, infoptr->infp);
	 switch( nread ){
	    case 0:   
		return 0; /* no traces; trap in mains */

	    default:  
		if (nread != HDRBYTES){ 
		  err("%s: bad first header", __FILE__);
		}
	 }	 


	}

	/* Have the header, now for the data */
	infoptr->nsfirst = tp->ns;
	if (infoptr->nsfirst > SU_NFLTS){
	 err("%s: unable to handle %d > %d samples per trace",
		__FILE__, infoptr->nsfirst, SU_NFLTS);
	}

	switch (tp->trid) {
	 case CHARPACK:
	    infoptr->bytesper = sizeof(char); break;
	 case SHORTPACK:
	    infoptr->bytesper = 2*sizeof(char); break;
	 default:
	    infoptr->bytesper = sizeof(float); break;
	}

	databytes = infoptr->bytesper * tp->ns;

	infoptr->nsegy = HDRBYTES + databytes;


	/* Inconvenient to bump nread here; do it in the switch */
	nread = dataread(tp, infoptr, fixed_length);
	
	switch (nread) {
	 case 0:   
	    err("%s: no data on first trace", __FILE__);

	 default:  
	    if (nread != databytes){
		err("%s: first trace: " "read only %d bytes of %u",
		  __FILE__, nread, databytes);

	    }else{
		nread += HDRBYTES;
	    }
	}
	
	
	if (infoptr->ftype == DISK) { /* compute ntr */
	 efseeko(fp, (off_t) 0LL,SEEK_END);

	 if( in_line_hdr ){
	    infoptr->ntr = (eftello(fp)-3600)/infoptr->nsegy;
	    efseeko(fp, (off_t) 3600+infoptr->nsegy,SEEK_SET);

	 }else{
	    infoptr->ntr = eftello(fp)/infoptr->nsegy;
	    efseeko(fp, (off_t) infoptr->nsegy ,SEEK_SET);

	 }
	 
	}

   }else{

	/* not first trace */

/*--------------------------------------------------------------------*\
   A number of programs seek on the input file using either fseek(3c)
   or rewind(3c) and then expect to read trace data.  As a consequence
   we need to check and offset the filepointer if needed.
\*--------------------------------------------------------------------*/

	if( in_line_hdr && ftello( infoptr->infp ) == 0 ){

	 fseeko( infoptr->infp ,(off_t)3600L ,SEEK_SET );

	}

	nread = (int) efread(tp, 1, HDRBYTES, infoptr->infp);

	switch( nread ){

	 case 0: 
	    lastfp = infoptr->infp;
	    return 0; /* finished */

	 default:  
	    if (nread != HDRBYTES){
		err("%s: on trace #%ld read %d bytes expected %d bytes",
		  __FILE__,(infoptr->itr)+1,nread,HDRBYTES);
	    }
	}

	nread += dataread(tp, infoptr, fixed_length);

	if (fixed_length && (tp->ns != infoptr->nsfirst)){
	 err("%s: on trace #%ld number of samples in header (%d) differs from number for first trace (%d)"
		,__FILE__, (infoptr->itr)+1, tp->ns,

		infoptr->nsfirst);
	}
   }

   ++(infoptr->itr);
   lastfp = infoptr->infp;
   return (nread);
}
예제 #4
0
파일: fgettr.c 프로젝트: gganssle/stripper
static
int fgettr_internal(FILE *fp, segy *tp, cwp_Bool fixed_length)
{
	int nread;		/* bytes seen by fread calls	*/
	off_t curoff;

	if(fp != lastfp)  /* search linked list for possible alternative */
			    searchlist(fp);

	if (infoptr == ((struct insegyinfo *) NULL)) {
	/* initialize new segy input stream */
		unsigned int databytes;	/* bytes from nsfirst		*/

		/* allocate new segy input information table */
		*oldinfoptr = (struct insegyinfo *)
			malloc(sizeof(struct insegyinfo));
		infoptr = *oldinfoptr;
		infoptr->nextinfo = (struct insegyinfo *) NULL;
		/* save FILE * ptr */
		infoptr->infp = fp;
		infoptr->itr = 0;
		infoptr->ntr = -1;
		/* allocate XDR struct and associate FILE * ptr */
		infoptr->segy_xdr = (XDR *) malloc(sizeof(XDR));

		switch (infoptr->ftype = filestat(fileno(fp))) {
		case DIRECTORY:
			err("%s: segy input can't be a directory", __FILE__);
		case TTY:
			err("%s: segy input can't be tty", __FILE__);
		break;
		default: /* the rest are ok */
		break;
		}
		/* xdrstdio_create(infoptr->segy_xdr,fp,XDR_DECODE); */
		infoptr->buf = ealloc1(sizeof(segy),sizeof(char));
		xdrmem_create(infoptr->segy_xdr, infoptr->buf, sizeof(segy), XDR_DECODE);
		infoptr->bufstart = xdr_getpos(infoptr->segy_xdr);

		/* retrieve segy trace header */
		nread = efread(infoptr->buf ,1 ,HDRBYTES ,infoptr->infp);

		if(nread != HDRBYTES || FALSE == xdrhdrsub(infoptr->segy_xdr,tp))
			err("%s: bad first header", __FILE__);
		
		/* Have the header, now for the data */
		infoptr->nsfirst = tp->ns;
		if (infoptr->nsfirst > SU_NFLTS)
			err("%s: unable to handle %d > %d samples per trace",
				    __FILE__, infoptr->nsfirst, SU_NFLTS);

		switch(tp->trid) {
		case CHARPACK:
		   infoptr->bytesper = sizeof(char); break;
		case SHORTPACK:
		   infoptr->bytesper = 2*sizeof(char); break;
		default:
		   infoptr->bytesper = BYTES_PER_XDR_UNIT; break;
		}

		databytes = infoptr->bytesper * tp->ns;

		infoptr->nsegy = databytes + HDRBYTES;

		nread = dataread(infoptr, tp, fixed_length);


		switch (nread) {
		case 0:   err("%s: no data on first trace", __FILE__);
		default:  if (nread != databytes)
				 err("%s: first trace: tried to read %d bytes "
				     "read %d bytes",
					__FILE__, databytes, nread);
			else nread += HDRBYTES;
		}

		if(infoptr->ftype == DISK) { /* compute ntr */
		    curoff = eftello(fp); 
		    efseeko(fp,(off_t) 0,SEEK_END);
		    infoptr->ntr = eftello(fp)/infoptr->nsegy;
		    efseeko(fp, curoff, SEEK_SET); /* restore location */
		    }


	} else { /* Not first entry */

		  xdr_setpos(infoptr->segy_xdr, infoptr->bufstart);
		  nread = efread(infoptr->buf ,1 ,HDRBYTES ,infoptr->infp);
		  if ( nread != HDRBYTES || FALSE == xdrhdrsub(infoptr->segy_xdr,tp)) nread=0;
		  if(nread == HDRBYTES)
			nread += dataread(infoptr, tp, fixed_length);
		  if (nread <= 0) {
			   lastfp = infoptr->infp;
			   return 0;
		  }



		if (fixed_length && (tp->ns != infoptr->nsfirst))
			err("%s: on trace #%ld, "
			    "number of samples in header (%d) "
			    "differs from number for first trace (%d)", 
			     __FILE__, infoptr->itr, tp->ns, infoptr->nsfirst);
	}

	++(infoptr->itr);
	lastfp = infoptr->infp;
	return (nread);
}
/* Hauptprogramm des Controllers                                           **
** Dieses Programm wird beim Starten des Controllers aufgerufen und        **
** abgearbeitet. Die Endlosschleife ist der zyklische Teil des Programms   */
int main(void)
{
	init();													//Aufruf der init Funktion
	
    while(1)												//zyklischer Teil des Programms
    {			
		if(controller == 0 && dataint)	
		{
			receive = dataread(1);
			switch(receive)
			{
				case 1:										//falls die Klemme 1 angesprochen werden soll
				{
					setBit(DDRC, Klemme1);
					setBit(PORTC, Klemme1);					//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 2:										//falls die Klemme 2 angesprochen werden soll
				{
					setBit(DDRC, Klemme2);
					setBit(PORTC, Klemme2);					//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 3:										//falls die Klemme 3 angesprochen werden soll
				{
					setBit(DDRC, Klemme3);
					setBit(PORTC, Klemme3);					//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					
					break;
				}
				case 4:										//falls die Klemme 4 angesprochen werden soll
				{
					setBit(DDRC, Klemme4);
					setBit(PORTC, Klemme4);					//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 5:										//falls die Klemme 5 angesprochen werden soll
				{
					setBit(DDRC, Klemme5);
					setBit(PORTC, Klemme5);					//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 6:										//falls die Klemme 6 angesprochen werden soll
				{
					setBit(DDRC, Klemme6);
					setBit(PORTC, Klemme6);					//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 7:										//falls die Klemme 7 angesprochen werden soll
				{
					setBit(DDRB, Klemme7);
					setBit(PORTB, Klemme7);					//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}	
				case 8:										//falls die Klemme 8 angesprochen werden soll
				{
					setBit(DDRD, Klemme8);
					setBit(PORTD, Klemme8);					//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 9:										//falls die Klemme 9 angesprochen werden soll
				{
					setBit(DDRB, Klemme9);
					setBit(PORTB, Klemme9);					//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 10:									//falls die Klemme 10 angesprochen werden soll
				{
					setBit(DDRD, Klemme10);
					setBit(PORTD, Klemme10);				//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 11:									//falls die Klemme 11 angesprochen werden soll
				{
					setBit(DDRB, Klemme11);
					setBit(PORTB, Klemme11);				//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 12:									//falls die Klemme 12 angesprochen werden soll
				{
					setBit(DDRD, Klemme12);
					setBit(PORTD, Klemme12);				//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 13:									//falls die Klemme 13 angesprochen werden soll
				{
					setBit(DDRB, Klemme13);
					setBit(PORTB, Klemme13);				//setzen der Klemme
					datawrite(Datenrichtig, Sthaupt);
					break;
				}
				case 31:									//falls ein Platinentest durchgeführt werden soll
				{
					_delay_ms(100);
					datawrite(Platinentest, Sthaupt);
					break;
				}
				default:
				{
					datawrite(Datennichtrichtig, Sthaupt);
					break;
				}	
			}
			dataint = 0;
			controller = -1;
			receive = 0;
			datareadinit();
		}
		else if(controller == 1 && dataint)
		{
			receive = dataread(1);
			switch(receive)
			{
				case 0:
				{
					
					break;
				}
			}
			dataint = 0;
			controller = -1;
			receive = 0;
			datareadinit();
		}																								
    }
}