Exemplo n.º 1
0
int uget(int ndev, DEV_NAME devnames[], float setp[], float rdbk[])
{
  int       i, setp_cnts[N_MAX], rdbk_cnts[N_MAX], status;
  float     gain[N_MAX], offset[N_MAX];

  if (ndev < 1) {
    printf("*** No of devices = %d\n", ndev); exit(0);
  }
  for(i = 0; i < ndev; i++) {
    ugddr_getcalib_data(devnames[i], &gain[i], &offset[i]);
  }

  if (uidopen("Ctest")) {
    ucdperror(); exit(1);
  }
  status = ureadsetp(ndev, devnames, setp_cnts) ||
           ureadmag(ndev, devnames, rdbk_cnts);
  if (status) {
    fprintf(stderr, "*** ");
    ucdperror();
  } else {
    for(i = 0; i < ndev; i++) {
      setp[i] = setp_cnts[i]*gain[i]; rdbk[i] = rdbk_cnts[i]*gain[i];
    }
  }
  uclose();
  return(status);
}
Exemplo n.º 2
0
main(int argc, char *argv[])
{
  int       k, stpt[N_MAX], ndev, status;
  DEV_NAME  devnames[N_MAX];
  float     gain[N_MAX], offs[N_MAX], val;

  ndev = argc/2;
  if((argc < 2) || (argc % 2 == 0)) {
    printf("*** Incorrect number of args\n"); exit(0);
  } else {
    for(k=0; k < ndev; k++) {
      sscanf(argv[2*k+1], "%s", devnames[k]);
      sscanf(argv[2*k+2], "%f", &val);      
      ugddr_getcalib_data(devnames[k], &gain[k], &offs[k]);
      stpt[k] = (int)(val/gain[k]+sgn(val)*0.5);
      printf("name=%s, value=%d gain=%e\n", devnames[k], stpt[k], gain[k]) ;
    }
  }

  if(uidopen("Ctest")) {
    ucdperror(); exit(1);
  }
  status = usetmag(argc/2, devnames, stpt); 
  printf("%d\n", status);
  uclose();
}
Exemplo n.º 3
0
void
consinit(int dev, int speed)
{
	struct linux_termios termios;
	int fd;

	switch (dev) {
	case CONSDEV_COM0:
		iodev = dev;
		break;

	case CONSDEV_GLASS:
	default:
 glass_console:
		iodev = CONSDEV_GLASS;
		break;
	}

	if (infd >= 0 && infd == outfd) {
		uclose(infd);
		infd = 0;
		outfd = 1;
	}

	if (iodev == CONSDEV_GLASS) {
		infd = 0;
		outfd = 1;

		strlcpy(bi_cons.devname, "glass", sizeof(bi_cons.devname));
		bi_cons.addr = -1;
		bi_cons.speed = -1;
	} else {
		fd = uopen(comdevname[iodev - CONSDEV_COM0], LINUX_O_RDWR);
		if (fd < 0)
			goto glass_console;
		infd = outfd = fd;

		/* set speed */
		linux_tcgetattr(fd, &termios);
		if (linux_cfsetspeed(&termios, speed) < 0) {
			speed = 9600;
			if (linux_cfsetspeed(&termios, speed) < 0)
				goto glass_console;
		}
		if (linux_tcsetattr(fd, LINUX_TCSETS, &termios) < 0)
			goto glass_console;

		snprintf(bi_cons.devname, sizeof(bi_cons.devname), "com%d",
		    iodev - CONSDEV_COM0);
		bi_cons.addr = -1;
		bi_cons.speed = speed;
	}
	BI_ADD(&bi_cons, BTINFO_CONSDEV, sizeof(bi_cons));
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) { 
	char name[64];
	int pid, cmd;
	int pd[2];

	while(1){

		printf("\n----------------------------------------------\n");
		#ifndef _LAB_3_
			printf("I am proc %d in U mode with ppid %d: running segment=%x\n",getpid(), getppid(), getcs());
		#else
			printf("I am proc "); getpid(); printf(" in U mode: running segment=%x\n", getcs());
		#endif

		#ifdef _SLEEPER_
			while(1) {
				printf("PID: %d PPID: %d\n", getpid(), getppid());
				sleep(5);
				return 0;
			}
		#endif

		show_menu();
		printf("Command? ");
		gets(name);
		printf("\n"); 
		if (name[0]==0) 
		continue;

		cmd = find_cmd(name);
		switch(cmd){
			case 0:		getpid();	break;
			case 1:		ps();		break;
			case 2:		chname();	break;
			case 3:		kswitch();	break;
			case 4:		wait();		break;
			case 5:		ufork();	break;
			case 6:		uexec();	break;
			case 7: 	exit();		break;
			case 8: 	pipe(pd);	break;
			case 9: 	pfd();		break;
			case 10:	uclose();	break;
			case 11:	uread();	break;
			case 12:	uwrite();	break;
			case 13:	usleep();	break;
			default:invalid(name);break;
		}
	}
}
Exemplo n.º 5
0
int uputsp(int ndev, DEV_NAME devnames[], float setp[])
{
  int       k, cnts[N_MAX], status;
  float     gain[N_MAX], offset[N_MAX], val;

  if (ndev < 1) {
    printf("*** No of devices = %d\n", ndev); exit(0);
  } else {
    for (k = 0; k < ndev; k++) {
      ugddr_getcalib_data(devnames[k], &gain[k], &offset[k]);
      cnts[k] = (int)(setp[k]/gain[k]+sgn(setp[k])*0.5);
      printf("name=%s, value=%d gain=%e\n", devnames[k], cnts[k], gain[k]) ;
    }
  }

  if(uidopen("Ctest")) {
    ucdperror(); exit(1);
  }
  status = usetmag(ndev, devnames, cnts); 
  uclose();
  return(status);
}
Exemplo n.º 6
0
void
com_init(struct consdev *cn)
{
	struct termios t;
	int unit = minor(cn->cn_dev);
	
	if (unit >= NCOM)
		return;

	if (com_fd != -1)
		uclose(com_fd);
	
	com_fd = uopen(compath[unit], O_RDWR);
	if (com_fd == -1)
		return;

	if (tcgetattr(com_fd, &t) == 0) {
		cfmakeraw(&t);
		cfsetspeed(&t, (speed_t)com_speed);
		(void)tcsetattr(com_fd, TCSAFLUSH, &t);
	}
}
Exemplo n.º 7
0
static int
zboot_exec(int fd, u_long *marks, int flags)
{
	char buf[512];
	char *p;
	int tofd;
	int sz;
	int i;

	/* XXX cheating here by assuming that Xboot() was called before. */

	tofd = uopen(_PATH_ZBOOT, O_WRONLY);
	if (tofd == -1) {
		printf("%s: can't open (errno %d)\n", _PATH_ZBOOT, errno);
		return 1;
	}

	p = cmd.path;
	for (; *p != '\0'; p++)
		if (*p == ':') {
			strlcpy(buf, p+1, sizeof(buf));
			break;
		}
	if (*p == '\0')
		strlcpy(buf, cmd.path, sizeof(buf));

	p = buf;
	for (; *p == '/'; p++)
		;

	sz = strlen(p);
	if (uwrite(tofd, p, sz) != sz) {
		printf("zboot_exec: argument write error\n");
		goto err;
	}

	buf[0] = ' ';
	buf[1] = '-';
	if (uwrite(tofd, buf, 2) != 2) {
		printf("zboot_exec: argument write error\n");
		goto err;
	}

	i = (cmd.argc > 1 && cmd.argv[1][0] != '-') ? 2 : 1;
	for (; i < cmd.argc; i++) {
		p = cmd.argv[i];
		if (*p == '-')
			p++;
		sz = strlen(p);
		if (uwrite(tofd, p, sz) != sz) {
			printf("zboot_exec: argument write error\n");
			goto err;
		}
	}

	/* Select UART unit for serial console. */
	if (cn_tab && major(cn_tab->cn_dev) == 12) {
		buf[0] = '0' + minor(cn_tab->cn_dev);
		if (uwrite(tofd, buf, 1) != 1) {
			printf("zboot_exec: argument write error\n");
			goto err;
		}
	}

	/* Commit boot arguments. */
	uclose(tofd);

	tofd = uopen(_PATH_ZBOOT, O_WRONLY);
	if (tofd == -1) {
		printf("%s: can't open (errno %d)\n", _PATH_ZBOOT, errno);
		return 1;
	}

	if (lseek(fd, 0, SEEK_SET) != 0) {
		printf("%s: seek error\n", _PATH_ZBOOT);
		goto err;
	}

	while ((sz = read(fd, buf, sizeof(buf))) == sizeof(buf)) {
		if ((sz = uwrite(tofd, buf, sz)) != sizeof(buf)) {
			printf("%s: write error\n", _PATH_ZBOOT);
			goto err;
		}
	}

	if (sz < 0) {
		printf("zboot_exec: read error\n");
		goto err;
	}

	if (sz >= 0 && uwrite(tofd, buf, sz) != sz) {
		printf("zboot_exec: write error\n");
		goto err;
	}

	uclose(tofd);
	return 0;

err:
	uclose(tofd);
	return 1;
}
Exemplo n.º 8
0
int main(int argc, char** argv) {
#if (defined WIN32 || defined _WIN32)
  WSADATA wsadata;
  int rc = WSAStartup(MAKEWORD(2,0), &wsadata); 
  if (rc) return 1;
#endif

  upoll_t* upq = upoll_create(32);
  intptr_t sd1 = usocket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  printf("server: %li\n", sd1);

  printf("bind: %d\n", ubind(sd1, "127.0.0.1", "1976"));
  printf("listen: %d\n", ulisten(sd1, 128));

  upoll_event_t ev1, ev2;
  upoll_event_t events[8];

  ev1.events = UPOLLIN;
  ev1.data.fd = sd1;

  upoll_ctl(upq, UPOLL_CTL_ADD, sd1, &ev1);

  int r = 0, x = 0;
  while (1) {
    int i, e;
    e = upoll_wait(upq, events, 8, -1);
    printf("events: %i\n", e);
    if (x++ == 50) return 0;
    for (i = 0; i < e; i++) {
      char buf[4096];
      if (events[i].events & UPOLLERR) {
        printf("ERROR on %li\n", events[i].data.fd);
        upoll_ctl(upq, UPOLL_CTL_DEL, events[i].data.fd, NULL);
        uclose(events[i].data.fd);
      }
      else if (events[i].events & UPOLLIN) {
        printf("have POLLIN on %li\n", events[i].data.fd);
        if (events[i].data.fd == sd1) {
          int sd2 = uaccept(sd1);
          printf("uaccept: %i\n", sd2);
          ev2.events = UPOLLIN;
          ev2.data.fd = sd2;
          upoll_ctl(upq, UPOLL_CTL_ADD, sd2, &ev2);
        }
        else {
          int cfd = events[i].data.fd;
          memset(buf, 0, 4096);
          printf("client input...\n");
          r = uread(cfd, buf, 4096);
          printf("read %i bytes\n", r);
          if (r == 0) {
            printf("EOF DETECTED\n");
            upoll_ctl(upq, UPOLL_CTL_DEL, events[i].data.fd, NULL);
            uclose(events[i].data.fd);
          }
          else {
            ev2.events = UPOLLOUT;
            upoll_ctl(upq, UPOLL_CTL_MOD, cfd, &ev2);
          }
        }
      }
      else if (events[i].events & UPOLLOUT) {
        printf("client writable...\n");
        int cfd = events[i].data.fd;
        int w = uwrite(cfd, buf, r);
        ev2.events = UPOLLIN;
        printf("wrote %i bytes, mod for UPOLLIN again\n", w);
        upoll_ctl(upq, UPOLL_CTL_MOD, cfd, &ev2);
      }
    }
  }

#if (defined WIN32 || defined _WIN32)
  WSACleanup();
#endif

  return 0;
}
Exemplo n.º 9
0
int autohadr (char *call, int ausgabe)
//*************************************************************************
//
// Search for address in HADR database
//
//*************************************************************************
{
  lastfunc("autohadr");
  int pos;
  int i;
  bitfeld options = b->optplus;
  int which = -1;
  hadr_t *ha = (hadr_t*) t_malloc(sizeof(hadr_t), "hadr");

  if (m.hadrstore)
  {
    strupr(call);
    hadr_tryopen();
    pos = loadhadr(call, ha, 0);
    uclose();
    if (pos)
    {
      which = which_partner(call, ha);
      if (ausgabe && (options & o_a))
      {
        time_t mindelay = ad_time();
        time_t mtime = ad_time();
        putf("Forward data from HADR-entry:\n");
        putf("H-Addr     : %s\n", ha->adr);
        putf("R-Header   : %s\n", ha->lastheader);
        putf("Last BID   : %s\n", ha->lastbid);
        putf("Last Board : %s\n", ha->lastboard);
        putf("Last User  : %s\n", ha->lastuser);
        putf("Header Date: %s\n", datestr(ha->lasthtime, 12));
        if (*ha->sysopcall)
          putf("Sysop:       %s %s\n", ha->sysopcall,
                                       get_name(ha->sysopcall, 1));
        if (*ha->protocol && *ha->hwaddress)
          putf("HW-Address:  %s: %s\n", ha->protocol, ha->hwaddress);
        if (ha->bversion && *ha->bstatus && ha->lastwprcvd)
          putf("BVersion:    %ld %s (%s)\n", ha->bversion, ha->bstatus,
                                             datestr(ha->lastwprcvd, 12));
        putf("Bulletins  : %ld\n", ha->bulletins);
        putf("Usermails  : %ld\n", ha->usermails);
        putf("Neighbour Count Update +Delay Hops\n");
        for (i = 0; i < ADJNUM; i++)
        {
          if (ha->adjacent[i][0])
          {
            if (ha->delay[i] < mindelay) mindelay = ha->delay[i];
          }
        }
        for (i = 0; i < ADJNUM; i++)
        { // Ausgabe HADR-Eintrag
          if (ha->adjacent[i][0])
          {
            putf("%-9s%6d%7s%7s%5d", ha->adjacent[i], ha->rel_mails[i],
                  zeitspanne(mtime - ha->lastupdate[i], zs_seconds),
                  zeitspanne(ha->delay[i] - mindelay, zs_seconds),
                  ha->hops[i]);
            if (i == which) putf(" <");
            if (isforwardpartner(ha->adjacent[i]) == NOTFOUND)
              putf(" fwd terminated");
            putv(LF);
          }
        }
        putv(LF);
      }
    }
  }
  if (which != NOTFOUND) strcpy(b->destboxlist, ha->adjacent[which]);
  t_free(ha);
  if (which == NOTFOUND) return unbekannt;
  return auto_bekannt;
}