Ejemplo n.º 1
0
/*
 * FTP - send single character
 *  wait for echo & handle timeout
 */
static void
send(char c)
{
	char cc;
	int retry = 0;

	cc = c;
	xpwrite(FD, &cc, 1);
	if (number(value(CDELAY)) > 0 && c != '\r')
		nap(number(value(CDELAY)));
	if (!boolean(value(ECHOCHECK))) {
		if (number(value(LDELAY)) > 0 && c == '\r')
			nap(number(value(LDELAY)));
		return;
	}
tryagain:
	timedout = 0;
	alarm(number(value(ETIMEOUT)));
	read(FD, &cc, 1);
	alarm(0);
	if (timedout) {
		printf("\r\ntimeout error (%s)\r\n", ctrl(c));
		if (retry++ > 3)
			return;
		xpwrite(FD, &null, 1); /* poke it */
		goto tryagain;
	}
}
Ejemplo n.º 2
0
int solvefrom(int x, int y) {
    int i;
    static int solved=0;
    static int solvedepth=0;
    if(solved) return(1);
    solvedepth++;
    if(solvedepth>h) h=solvedepth;
    pset(x,y,fg);
    sprintf(status," %d,%d Depth:%d  ",x,y,solvedepth);
    showstatus(1);
    if(x>=(width-4)) {
        solved=1;
        sprintf(status,"Solved! Depth:%d ",solvedepth);
        showstatus(0);
        return(1);
    }
    for(i=0; i<4; i++) {
        if(ppoint(x+sx[i]/2,y+sy[i]/2)==(fg^31)) {
            if(solvefrom(x+sx[i]/2,y+sy[i]/2)) {
                if(button==0 && solved==0) nap(delay);
                solvedepth--;
                return(1);
            }
        }
    }
    pset(x,y,fg^31);
    if(button==0) nap(delay);
    solvedepth--;
    return(0);
}
Ejemplo n.º 3
0
static void
prepare_test (struct stat *statinfo, struct timespec *modtimes)
{
  int i;

  create_file ("t-stt-stamp1");
  nap ();
  create_file ("t-stt-testfile");
  nap ();
  create_file ("t-stt-stamp2");
  nap ();
  ASSERT (chmod ("t-stt-testfile", 0400) == 0);
  nap ();
  create_file ("t-stt-stamp3");

  do_stat ("t-stt-stamp1",  &statinfo[0]);
  do_stat ("t-stt-testfile", &statinfo[1]);
  do_stat ("t-stt-stamp2",  &statinfo[2]);
  do_stat ("t-stt-stamp3",  &statinfo[3]);

  /* Now use our access functions. */
  for (i = 0; i < NFILES; ++i)
    {
      modtimes[i] = get_stat_mtime (&statinfo[i]);
    }
}
Ejemplo n.º 4
0
/*
 * FTP - send single character
 *  wait for echo & handle timeout
 */
void
send(char c)
{
	char cc;
	int retry = 0;

	cc = c;
	parwrite(FD, (unsigned char *)&cc, 1);
#ifdef notdef
	if (number(value(CDELAY)) > 0 && c != '\r')
		nap(number(value(CDELAY)));
#endif
	if (!boolean(value(ECHOCHECK))) {
#ifdef notdef
		if (number(value(LDELAY)) > 0 && c == '\r')
			nap(number(value(LDELAY)));
#endif
		return;
	}
tryagain:
	timedout = 0;
	if (sigsetjmp(intbuf, 1) && timedout) {
		(void) printf("\r\ntimeout error (%s)\r\n", ctrl(c));
		if (retry++ > 3)
			return;
		parwrite(FD, (unsigned char *)&null, 1); /* poke it */
		goto tryagain;
	}
	(void) alarm(number(value(ETIMEOUT)));
	(void) read(FD, &cc, 1);
	(void) alarm(0);
}
Ejemplo n.º 5
0
void oelevator(int dir)
{
	if (dir==1) { 
		if (level == 0) {
			lprcat(",\nunfortunately, it is out of order.");
			return;
		}
		playerx = rnd(MAXX-2);	
		playery = rnd(MAXY-2);
		nap(2000);
		newcavelevel(rund(level));
	}
	else {
		if (level==DBOTTOM || level==VBOTTOM) {
			nap(2000);
			lprcat("\nand it leads straight to HELL!");
			beep();
			lflush();
			nap(3000);
			died(287);
		}
		playerx = rnd(MAXX-2);	
		playery = rnd(MAXY-2);
		nap(2000);
	    	newcavelevel(level + rnd(DBOTTOM - level));
	}
	positionplayer();
	draws(0,MAXX,0,MAXY); 
	bot_linex();
}
Ejemplo n.º 6
0
  void put_down_all() {
    Servos s;
    lower_hand();
    nap();

    open_hand();
    nap();
  }
Ejemplo n.º 7
0
void usersolve() {
    x=5;
    y=6;
    ox=x;
    oy=y;
    steps=0;
    r=1;
    m=0;
    while((x!=width-3) && (button==0)) {
        expose();
        XQueryPointer(display,main_win,&root,&win,&root_x,&root_y,&win_x,&win_y,&mask);
        while(ox!=x || oy!=y) {
            steps++;
            pset(ox,oy,7);
            px[m]=ox;
            py[m]=oy;
            if(m<maxdepth) m++;
            sprintf(status," Steps: %d",steps);
            showstatus(0);
            if(ox!=x) ox=x;
            else oy=y;
        }
        pset(ox,oy,7);
        ox=x;
        oy=y;
        pset(x,y,(fg+1)&31);
        if((x>win_x/mag) && (ppoint(x-1,y)!=bg)) x--;
        if((x<win_x/mag) && (ppoint(x+1,y)!=bg)) x++;
        if((y>win_y/mag) && (ppoint(x,y-1)!=bg)) y--;
        if((y<win_y/mag) && (ppoint(x,y+1)!=bg)) y++;
        nap(50);
    }
    if(x==width-3) {
        code=rand();
        sprintf(status," %d Steps! Code:%04X ",steps,code);
        showstatus(0);
        i=0;
        c=1;
        button=0;
        while(button==0) {
            pset(ox,oy,c);
            ox=px[i];
            oy=py[i];
            pset(ox,oy,0);
            i++;
            if(i>=m) {
                i=0;
                c=(c+1)&31;
                if(c==bg) c=(c+1)&31;
            }
            expose();
            nap(20);
        }
    }
    waitnobutton();
}
Ejemplo n.º 8
0
  void pick_up_all() {
    Servos s;
    open_hand();
    nap();
    nap();

    lower_hand();
    nap();

    close_hand();
    nap();
  }
Ejemplo n.º 9
0
Archivo: devtty.c Proyecto: Abioy/FUZIX
void nc100_tty_init(void)
{
  /* Reset the 8251 */
  mod_control(0x00, 0x08);
  nap();
  mod_control(0x08, 0x00);
  nap();
  uartb = SER_INIT;
  nap();
  uartb = SER_RXTX;
  nap();
  uarta;
  uarta;
}
Ejemplo n.º 10
0
static void
outofstock()
{
	lprcat("\nSorry, but we are out of that item.");
	lflush();
	nap(2200);
}
Ejemplo n.º 11
0
static void
bootstrap_from_name( const char *name, tr_port port, int af )
{
    struct addrinfo hints, *info, *infop;
    char pp[10];
    int rc;

    memset(&hints, 0, sizeof(hints));
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_family = af;
    /* No, just passing p + 1 to gai won't work. */
    tr_snprintf(pp, sizeof(pp), "%d", (int)port);

    rc = getaddrinfo(name, pp, &hints, &info);
    if(rc != 0) {
        tr_nerr("DHT", "%s:%s: %s", name, pp, gai_strerror(rc));
        return;
    }

    infop = info;
    while(infop) {
        dht_ping_node(infop->ai_addr, infop->ai_addrlen);

        nap(15);

        if(bootstrap_done(session, af))
            break;
        infop = infop->ai_next;
    }
    freeaddrinfo(info);
}
Ejemplo n.º 12
0
void
FindNamedNode::apply( osg::Node& node )
{
    bool match = (
        ( ( _method == EXACT_MATCH ) &&
            ( node.getName() == _name ) ) ||
        ( ( _method == CONTAINS ) &&
            ( node.getName().find( _name ) != std::string::npos ) ) );

    if( match )
    {
        // Copy the NodePath, so we can alter it if necessary.
        osg::NodePath np = getNodePath();

        if( !_includeTargetNode )
            // Calling code has requested that the target node
            // be removed from the node paths.
            np.pop_back();

        NodeAndPath nap( &node, np );
        _napl.push_back( nap );
    }

    traverse( node );
}
Ejemplo n.º 13
0
static void
handsfull()
{
	lprcat("\nYou can't carry anything more!");
	lflush();
	nap(2200);
}
Ejemplo n.º 14
0
void opit()
{
	int i;
	if (rnd(101)>81)
		return;
	if (rnd(70) > 9*c[DEXTERITY]-packweight() || rnd(101)<5) {
		for (i=0;i<IVENSIZE;i++)
		  if (iven[i]==OWWAND) {
			lprcat("\nYou float right over the pit.");
			return;
		  }
		if (level==DBOTTOM || level == VBOTTOM)
			obottomless(); 
		else {
			if (rnd(101)<20) {
				i=0;
				lprcat("\nYou fell ino a pit!  "
					   "A poor monster cushions your fall!\n");
			} else {
				i = rnd(level*3+3);
				if (i > c[HP]) i = c[HP];
				lprintf("\nYou fell into a pit!  "
						"You suffer %d hit point%s damage.",(long)i,
						(i==1)?"":"s");
				lastnum=261; 
				/* if he dies scoreboard will say so */
			}
			losehp(i); 
			lflush();
			nap(2000);  
			newcavelevel(level+1);  
			draws(0,MAXX,0,MAXY);
		}
	}
}
Ejemplo n.º 15
0
void obottomless()
{
	lprcat("\nYou fell into a pit leading straight to HELL!");  
	beep(); 
	lflush();
	nap(3000);  
	died(262);
}
Ejemplo n.º 16
0
 void put_down_one() {
   Servos s;
   lower_hand();
   nap();
   open_hand();
   position_hand(10);
   close_hand();
 }
Ejemplo n.º 17
0
 		inline bool operator()( NodeType & dest, SerializableT const & src ) const
 		{
			typedef node_traits<NodeType> NTR;
			std::auto_ptr<NodeType> nap( NTR::create( this->name ) );
 			return this->functor( *nap, src )
				? (NTR::children(dest).push_back( nap.release() ),true)
				: false;
 		}
Ejemplo n.º 18
0
 		bool operator()( SerializableT const & src ) const
 		{
			typedef node_traits<NodeType> NTR;
			std::auto_ptr<NodeType> nap( NTR::create( this->name ) );
 			if( this->functor( *nap, src ) )
			{
				NTR::children(this->node()).push_back( nap.release() );
			}
			return 0 == nap.get();
 		}
Ejemplo n.º 19
0
static void *thr_fn(void *arg)
{
	int *t;

	t = (int *)arg;
	fprintf(stderr, "Thread %d starting\n", *t);
	(void)nap(*t);
	fprintf(stderr, "Thread %d woke up\n", *t);
	return (void *)0;
}
Ejemplo n.º 20
0
  /* Remove piece from board - i.e. jumping */
  void remove_piece(const iPair& capture) {
    std::cout << "Taking ";
    board_move(capture);
    pick_up_all();

    move_to( iPair(3,0) );
    put_down_all();
    nap();
    reset();
  }
Ejemplo n.º 21
0
dndstore()
  {
  register int i;
  dnditm = 0;
  nosignal = 1; /* disable signals */
  clear();  dnd_2hed();
  if (outstanding_taxes>0)
	{
	lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n"); beep();
	lprintf("They have also told us that you owe %d gp in back taxes, and as we must\n",(long)outstanding_taxes);
	lprcat("comply with the law, we cannot serve you at this time.  Soo Sorry.\n");
	cursors();	
	lprcat("\nPress "); standout("escape"); lprcat(" to leave: "); lflush();
	i=0;
	while (i!='\33') i=getchar();
	drawscreen();  nosignal = 0; /* enable signals */ return;
	}

  dnd_hed();
  while (1)
	{
	cursor(59,18); lprintf("%d gold pieces",(long)c[GOLD]);
	cltoeoln(); cl_dn(1,20);	/* erase to eod */
	lprcat("\nEnter your transaction ["); standout("space");
	lprcat(" for more, "); standout("escape");
	lprcat(" to leave]? ");
	i=0;
	while ((i<'a' || i>'z') && (i!=' ') && (i!='\33') && (i!=12))  i=getchar();
	if (i==12) { clear();  dnd_2hed();  dnd_hed(); }
	else if (i=='\33')
		{ drawscreen();  nosignal = 0; /* enable signals */ return; }
	else if (i==' ')
		{
		cl_dn(1,4);
		if ((dnditm += 26) >= maxitm) dnditm=0; dnd_hed();
		}
	else
		{  /* buy something */
		lprc(i);	/* echo the byte */
		i += dnditm - 'a';
		if (i>=maxitm) outofstock(); else
		if (itm[i].qty <= 0) outofstock(); else
		if (pocketfull()) handsfull(); else
		if (c[GOLD] < itm[i].price*10) nogold(); else
			{
			if (itm[i].mem != 0) *itm[i].mem[itm[i].arg] = ' ';
			c[GOLD] -= itm[i].price*10;
			itm[i].qty--;  take(itm[i].obj,itm[i].arg);
			if (itm[i].qty==0) dnditem(i);  nap(1001);
			}
		}

	}
  }
Ejemplo n.º 22
0
int ttflsh()
{
    if(obufp)
    {
        write(fileno(term),obuf,obufp);
        if(baud<38400) if(obufp*upc/1000) nap(obufp*upc/1000);
        obufp=0;
    }
    if(!have && !leave) if(rdchk(fileno(term))>0) have=1;
    return 0;
}
Ejemplo n.º 23
0
void
usysdep_pause (void)
{
#if HAVE_NAPMS
  napms (500);
#endif /* HAVE_NAPMS */
#if HAVE_NAP
#if HAVE_HUNDREDTHS_NAP
  nap (50L);
#else
  nap (500L);
#endif /* ! HAVE_HUNDREDTHS_NAP */
#endif /* HAVE_NAP */
#if HAVE_USLEEP
  usleep (500 * (long) 1000);
#endif /* HAVE_USLEEP */
#if HAVE_POLL
  struct pollfd sdummy;

  /* We need to pass an unused pollfd structure because poll checks
     the address before checking the number of elements.  */
  memset (&sdummy, 0, sizeof sdummy);
  poll (&sdummy, 0, 500);
#endif /* HAVE_POLL */
#if HAVE_SELECT
  struct timeval s;

  s.tv_sec = 0;
  s.tv_usec = 500 * (long) 1000;
  select (0, (pointer) NULL, (pointer) NULL, (pointer) NULL, &s);
#endif /* HAVE_SELECT */
#if ! HAVE_NAPMS && ! HAVE_NAP && ! HAVE_USLEEP
#if ! HAVE_SELECT && ! HAVE_POLL
  sleep (1);
#endif /* ! HAVE_SELECT && ! HAVE_POLL */
#endif /* ! HAVE_NAPMS && ! HAVE_NAP && ! HAVE_USLEEP */
}
Ejemplo n.º 24
0
Archivo: devtty.c Proyecto: Abioy/FUZIX
int nc100_tty_open(uint8_t minor, uint16_t flag)
{
	int err;
	if (!minor)
		minor = udata.u_ptab->p_tty;

	err = tty_open(minor, flag);
	if (err)
		return err;
	if (minor == 2) {
		mod_control(0, 0x10);	/* turn on the line driver */
		nap();
		mod_control(0x06, 0x01);	/* 9600 baud */
#ifdef CONFIG_NC200
		irqen = 0x1C;
#else
		irqen = 0x0B;			/* Allow serial interrupts */
#endif
	}
	return (0);
}
Ejemplo n.º 25
0
/*
    Code to perform the action of drinking at a fountian.  Assumes that
    cursors() has already been called, and that a check has been made that
    the player is actually standing at a live fountain.
*/
void act_drink_fountain(void)
{
    int x ;

    if (rnd(1501)<2)
        {
        lprcat("\nOops!  You seem to have caught the dreadful sleep!");
        lflush();  
        nap(3000);  
        died(280); 
        return;
        }

    x = rnd(100);
    if (x<7)
        {
        c[HALFDAM] += 200 + rnd(200);
        lprcat("\nYou feel a sickness coming on");
        }

    else if (x < 13)
        quaffpotion(23, FALSE ); /* see invisible,but don't know the potion */

    else if (x < 45)
        lprcat("\nnothing seems to have happened");

    else if (rnd(3) != 2)
        fntchange(1);   /*  change char levels upward   */

    else
        fntchange(-1);  /*  change char levels downward */

    if (rnd(12)<3)
        {
        lprcat("\nThe fountains bubbling slowly quiets");
        item[playerx][playery]=ODEADFOUNTAIN; /* dead fountain */
        know[playerx][playery]=0;
        }
    return;
}
Ejemplo n.º 26
0
// Measure and return the current ambient temperature in units of 1/16th C.
// This may contain up to 4 bits of information to the right of the fixed binary point.
// This may consume significant power and time.
// Probably no need to do this more than (say) once per minute.
// The first read will initialise the device as necessary and leave it in a low-power mode afterwards.
int Sensor_SHT21_readTemperatureC16()
  {
  const bool neededPowerUp = powerUpTWIIfDisabled();

  // Initialise/config if necessary.
  if(!initialised) { SHT21_init(); }
    
  // Max RH measurement time:
  //   * 14-bit: 85ms
  //   * 12-bit: 22ms
  //   * 11-bit: 11ms
  // Use blocking data fetch for now.
  Wire.beginTransmission(SHT21_I2C_ADDR);
  Wire.write((byte) SHT21_I2C_CMD_TEMP_HOLD); // Select control register.
#if defined(SHT21_USE_REDUCED_PRECISION)
  nap(WDTO_30MS); // Should cover 12-bit conversion (22ms).
#else
  sleepLowPowerMs(90); // Should be plenty for slowest (14-bit) conversion (85ms).
#endif
  //delay(100);
  Wire.endTransmission();
  Wire.requestFrom(SHT21_I2C_ADDR, 3);
  while(Wire.available() < 3)
    {
    // Wait for data, but avoid rolling over the end of a minor cycle...
    if(getSubCycleTime() >= GSCT_MAX-2)
      {
      return(0); // Failure value: may be able to to better.
      }
    }
  uint16_t rawTemp = (Wire.read() << 8);
  rawTemp |= (Wire.read() & 0xfc); // Clear status ls bits.
  // Nominal formula: C = -46.85 + ((175.72*raw) / (1L << 16));
  const int c16 = -750 + ((5623L * rawTemp) >> 17); // FIXME: find a faster approximation...

  if(neededPowerUp) { powerDownTWI(); }

  return(c16);
  }
Ejemplo n.º 27
0
//work for student thread
void *StartStudent(void * student)
{
	
	struct student * std = student;
	studentZ++;
	
	while(std->numQuestions > std->questionNum)
	{
			sem_wait(&readyForQuestion);
			pthread_mutex_lock(&question_lock);
			identification = std->id;
			//sem_wait(&readyForQuestion);
			QuestionStart();
			
			//semaphore answer question (post)
			sem_post(&questionWait);
			
			//sem wait for answer
			sem_wait(&answerWait);
			
			//pthread_mutex_unlock(&lock);  //professor starts answering
			//pthread_mutex_lock(&lock2);	//professor done answering
			
			QuestionDone();
			
			pthread_mutex_unlock(&question_lock);
			
			std->questionNum++;
			//printf("%d %d %d\n ", std->questionNum,std->numQuestions, inOffice);
			if(std->questionNum == std->numQuestions)
			{
				LeaveOffice();
				studentZ--;
				
				if(studentZ == 0) //this is new here
				nap();
			}
	}
}
Ejemplo n.º 28
0
int
send_packet(int sock, int ifindex, struct in6_addr *to,
            unsigned char *body, unsigned char bodylen)
{
    struct sockaddr_in6 sin6;
    unsigned char header[4];

    header[0] = 42;
    header[1] = 2;
    DO_HTONS(header + 2, bodylen);

    /* Additional jitter never harms. */
    nap(10);

    memset(&sin6, 0, sizeof(sin6));
    sin6.sin6_family = AF_INET6;
    memcpy(&sin6.sin6_addr, &babel_group, 16);
    sin6.sin6_port = htons(babel_port);
    sin6.sin6_scope_id = ifindex;
    return babel_send(sock, header, 4, body, bodylen,
                      (struct sockaddr*)&sin6, sizeof(sin6));
}
Ejemplo n.º 29
0
void RFM22RawStatsTX(const bool isBinary, uint8_t * const buf, const bool doubleTX)
  {
  // Write in the preamble/sync bytes.
  uint8_t *bptr = buf;
  // Start with RFM23-friendly preamble which ends with with the aacccccc sync word.
  memset(bptr, RFM22_PREAMBLE_BYTE, RFM22_PREAMBLE_BYTES);
  bptr += RFM22_PREAMBLE_BYTES;
  memset(bptr, RFM22_SYNC_BYTE, RFM22_SYNC_MIN_BYTES);
  bptr += RFM22_SYNC_MIN_BYTES;

  // TODO: put in listen before TX to reduce collisions (CSMA).
  // Send message starting will preamble.
  // Assume RFM22/23 support for now.
  RFM22QueueCmdToFF(buf);
  RFM22TXFIFO(); // Send it!  Approx 1.6ms/byte.
  if(doubleTX)
    {
    nap(WDTO_15MS);
    RFM22TXFIFO(); // Re-send it!
    }
  //DEBUG_SERIAL_PRINTLN_FLASHSTRING("RS");
  }
Ejemplo n.º 30
0
demux(){
#define demux Vdemux
  int count = 6;
  unsigned char c, temp;

      while(!rebootflag)
	{
		while(hostops->rcvq->c_cc==0) sw(0);	/* nothing for us to do */
		if (!ENCODE_ENABLE) precv((char)qgetc(hostops->rcvq)); /* read packet */
	 	 else
		   if ((c = (char)qgetc(hostops->rcvq)) == -1) precv((char) c);
		       else
			 if ((c & 0xe0) == 0x20 || (count+=2) == 8)
			   {
				count = 0;
				temp = c;
			     }
			  else precv((char)((c & 0x3f) | ((temp << count) & 0xc0)));
	}
       nap(60);        /* let output queue drain */
       reboot();
}