Ejemplo n.º 1
0
void main()
{
	int i;
	//OSCCON = 0x6C; // Para usar el oscilador interno PIC16F88 4 Mhz
	//OSCCON = 0x7C; // Para usar el oscilador interno PIC16F88 8 Mhz
	ANSEL = 0x00; // Configuracion de canales analogicos en PIC16F88

	io_mode(8, OUTPUT);
	io_mode(9, OUTPUT);
	io_mode(10, OUTPUT);
	io_mode(11, OUTPUT);
	io_mode(12, OUTPUT);
	io_mode(13, OUTPUT);
	io_mode(14, OUTPUT);
	io_mode(15, OUTPUT);

	for (;;) {
		for (i = 8; i < 16; i++) {
			io_write(i, HIGH);
			delay_ms(100);
			io_write(i, LOW);
		}

	}

}
Ejemplo n.º 2
0
void MIDI_IO_RAW::open(void)
{
  int flags = 0;

  switch(io_mode()) {
  case io_read:
    {
      flags = O_RDONLY;
      break;
    }
  case io_write: 
    {
      flags = O_WRONLY;
      break;
    }
  case io_readwrite: 
    {
      flags = O_RDWR;
      break;
    }
  }
  if (nonblocking_mode() == true) flags |= O_NONBLOCK;

  ECA_LOG_MSG(ECA_LOGGER::system_objects, "Opening midi device \"" + device_name_rep + "\".");
  fd_rep = ::open(device_name_rep.c_str(), flags);
  if (fd_rep < 0) {
    toggle_open_state(false);
  }
  else {
    toggle_open_state(true);
  }

  finished_rep = false;
}
Ejemplo n.º 3
0
/*
 * Receive files with Zmodem, Ymodem or Xmodem.
 * This receiver will figure out what to do, you should
 * be able to send anything.
 */
int zmrcvfiles(int want1k, int wantg)
{
    int	    rc;

    Syslog('+', "%s: start receive", protname());

    get_frame_buffer();

    Rxtimeout = 10;
    if (secbuf == NULL) 
	secbuf = malloc(MAXBLOCK+1);
    tryzhdrtype = ZRINIT;

    if ((rc = tryz()) < 0) {
	Syslog('+', "%s: could not initiate receive, rc=%d", protname(), rc);
    } else {
	if (rc == 0) {
	    if (protocol == ZM_ZMODEM) {
		Syslog('+', "%s: switching to Ymodem", protname());
		protocol = ZM_YMODEM;
	    }
	    rc = ymrcvfiles(want1k, wantg);
	    goto fubar;
	}

	/*
	 * Zmodem receiver
	 */
	switch (rc) {
	    case ZCOMPL:    rc = 0; 
			    break;
	    case ZFILE:	    rc = rzfiles(); 
			    break;
	}
    }
    
fubar:
    if (fout) {
	if (closeit(0)) {
	    WriteError("%s: Error closing file", protname);
	}
    }

    if (secbuf)
	free(secbuf);
    secbuf = NULL;

    io_mode(0, 1);  /* Normal raw mode */
    /*
     * Some programs send some garbage after the transfer, eat these.
     * This also introduces a pause after the transfer, some clients
     * need this.
     */
    purgeline(200);
    
    Syslog('+', "%s: end receive rc=%d", protname(), rc);
    return abs(rc);
}
Ejemplo n.º 4
0
/* called by signal interrupt or terminate to clean things up */
void bibi(int n)
{
    canit(0);
    oflush();
    io_mode(io_mode_fd, 0);
    if (n == SIGQUIT)
        abort();
    exit(128 + n);
}
Ejemplo n.º 5
0
static int wcs(const char *oname, const char *remotename)
{
#if !defined(S_ISDIR)
    int c;
#endif
    struct stat f;
    char *name;
    struct zm_fileinfo zi;

#ifdef HAVE_MMAP
    int dont_mmap_this = 0;
#endif


    if (Restricted) {
        /* restrict pathnames to current tree or uucppublic */
        if (strstr(oname, "../")
#ifdef PUBDIR
            || (oname[0] == '/' && strncmp(oname, MK_STRING(PUBDIR), strlen(MK_STRING(PUBDIR))))
#endif
            ) {
            canit(0);
            zmodem_error(1, 0, "security violation: not allowed to upload from %s", oname);
        }
    }

    if (0 == strcmp(oname, "-")) {
        char *p = getenv("ONAME");

        name = (char *)malloc(PATH_MAX + 1);
        if (p) {
            strcpy(name, p);
        } else {
            sprintf(name, "s%lu.lsz", (unsigned long) getpid());
        }
        input_f = stdin;
#ifdef HAVE_MMAP
        dont_mmap_this = 1;
#endif
    } else if ((input_f = fopen(oname, "r")) == NULL) {
        ++errcnt;
        return OK;              /* pass over it, there may be others */
    } else {
        name = (char *)malloc(PATH_MAX + 1);
        strcpy(name, oname);
    }
#ifdef HAVE_MMAP
    if (!use_mmap || dont_mmap_this)
#endif
    {
        static char *s = NULL;
        static size_t last_length = 0;
        struct stat st;

        if (fstat(fileno(input_f), &st) == -1)
            st.st_size = 1024 * 1024;
        if (buffersize == (size_t) - 1 && s) {
            if ((size_t) st.st_size > last_length) {
                free(s);
                s = NULL;
                last_length = 0;
            }
        }
        if (!s && buffersize) {
            last_length = 16384;
            if (buffersize == (size_t) - 1) {
                if (st.st_size > 0)
                    last_length = st.st_size;
            } else
                last_length = buffersize;
            /* buffer whole pages */
            last_length = (last_length + 4095) & 0xfffff000;
            s = malloc(last_length);
            if (!s) {
                exit(1);
            }
        }
        if (s) {
#ifdef SETVBUF_REVERSED
            setvbuf(input_f, _IOFBF, s, last_length);
#else
            setvbuf(input_f, s, _IOFBF, last_length);
#endif
        }
    }
    vpos = 0;
    /* Check for directory or block special files */
    fstat(fileno(input_f), &f);
#if defined(S_ISDIR)
    if (S_ISDIR(f.st_mode) || S_ISBLK(f.st_mode)) {
#else
    c = f.st_mode & S_IFMT;
    if (c == S_IFDIR || c == S_IFBLK) {
#endif
        fclose(input_f);
	free(name);
        return OK;
    }

    if (remotename) {
        /* disqualify const */
        union {
            const char *c;
            char *s;
        } cheat;

        cheat.c = remotename;
        zi.fname = cheat.s;
    } else
        zi.fname = name;
    zi.modtime = f.st_mtime;
    zi.mode = f.st_mode;
#if defined(S_ISFIFO)
    zi.bytes_total = (S_ISFIFO(f.st_mode)) ? DEFBYTL : f.st_size;
#else
    zi.bytes_total = c == S_IFIFO ? DEFBYTL : f.st_size;
#endif
    zi.bytes_sent = 0;
    zi.bytes_received = 0;
    zi.bytes_skipped = 0;
    zi.eof_seen = 0;

    ++Filcnt;
    free(name);
    switch (wctxpn(&zi)) {
    case ERROR:
        return ERROR;
    case ZSKIP:
        return OK;
    }
    if (!zmodem_requested && wctx(&zi) == ERROR) {
        return ERROR;
    }
    if (Unlinkafter)
        unlink(oname);

    return 0;
}

/*
 * generate and transmit pathname block consisting of
 *  pathname (null terminated),
 *  file length, mode time and file mode in octal
 *  as provided by the Unix fstat call.
 *  N.B.: modifies the passed name, may extend it!
 */
static int wctxpn(struct zm_fileinfo *zi)
{
    register char *p, *q;
    char *name2;
    struct stat f;

    name2 = (char *)malloc(PATH_MAX + 1);

    if (protocol == ZM_XMODEM) {
        free(name2);
        return OK;
    }
    if (!zmodem_requested)
        if (getnak()) {
            free(name2);
            return ERROR;
        }

    q = (char *) 0;
#if 0
    if (Dottoslash) {           /* change . to . */
        for (p = zi->fname; *p; ++p) {
            if (*p == '/')
                q = p;
            else if (*p == '.')
                *(q = p) = '/';
        }
        if (q && strlen(++q) > 8) {     /* If name>8 chars */
            q += 8;             /*   make it .ext */
            strcpy(name2, q);   /* save excess of name */
            *q = '.';
            strcpy(++q, name2); /* add it back */
        }
    }
#endif
    for (p = zi->fname, q = txbuf; *p;)
        if ((*q++ = *p++) == '/' && !Fullname)
            q = txbuf;
    *q++ = 0;
    p = q;
    while (q < (txbuf + MAX_BLOCK))
        *q++ = 0;
    /* note that we may lose some information here in case mode_t is wider than an 
     * int. But i believe sending %lo instead of %o _could_ break compatability
     */
    if (!Ascii && (input_f != stdin) && *zi->fname && fstat(fileno(input_f), &f) != -1)
        sprintf(p, "%lu %lo %o 0 %d %ld", (long) f.st_size, f.st_mtime, (unsigned int) ((no_unixmode) ? 0 : f.st_mode), Filesleft, Totalleft);
    Totalleft -= f.st_size;
    if (--Filesleft <= 0)
        Totalleft = 0;
    if (Totalleft < 0)
        Totalleft = 0;

    /* force 1k blocks if name won't fit in 128 byte block */
    if (txbuf[125])
        blklen = 1024;
    else {                      /* A little goodie for IMP/KMD */
        txbuf[127] = (f.st_size + 127) >> 7;
        txbuf[126] = (f.st_size + 127) >> 15;
    }
    if (zmodem_requested)
        free(name2);
        return zsendfile(zi, txbuf, 1 + strlen(p) + (p - txbuf));

	/*
    if (wcputsec(txbuf, 0, 128) == ERROR) {
        free(name2);
        return ERROR;
    }
    free(name2);
    return OK;
	*/
}

static int getnak(void)
{
    int firstch;
    int tries = 0;

    Lastrx = 0;
    for (;;) {
        tries++;
        switch (firstch = READLINE_PF(100)) {
        case ZPAD:
            if (getzrxinit())
                return ERROR;
            Ascii = 0;          /* Receiver does the conversion */
            return FALSE;
        case TIMEOUT:
            /* 30 seconds are enough */
            if (tries == 3) {
                return TRUE;
            }
            /* don't send a second ZRQINIT _directly_ after the
             * first one. Never send more then 4 ZRQINIT, because
             * omen rz stops if it saw 5 of them */
            if ((zrqinits_sent > 1 || tries > 1) && zrqinits_sent < 4) {
                /* if we already sent a ZRQINIT we are using zmodem
                 * protocol and may send further ZRQINITs 
                 */
                stohdr(0L);
                zshhdr(ZRQINIT, Txhdr);
                zrqinits_sent++;
            }
            continue;
        case WANTG:
            io_mode(io_mode_fd, 2);     /* Set cbreak, XON/XOFF, etc. */
            Optiong = TRUE;
            blklen = 1024;
        case WANTCRC:
            Crcflg = TRUE;
        case NAK:
            return FALSE;
        case CAN:
            if ((firstch = READLINE_PF(20)) == CAN && Lastrx == CAN)
                return TRUE;
        default:
            break;
        }
        Lastrx = firstch;
    }
}
Ejemplo n.º 6
0
int bbs_zsendfile(char *filename, char *remote)
{
    struct stat f;

    if (stat(filename, &f) != 0)
        return ERROR;
    Totalleft = f.st_size;
    Filesleft = 1;
    calc_blklen(Totalleft);
    protocol = ZM_ZMODEM;
    io_mode_fd = 1;
    blklen = start_blklen = 1024;
    if (setjmp(zmodemjmp) == 0) {
        zsendline_init();
        io_mode(io_mode_fd, 1);
        readline_setup(io_mode_fd, 128, 256);
        raw_write(0, "rz\r", 3);

        /*   TODO : throw away received input */

        purgeline(io_mode_fd);
        stohdr(0L);
        zshhdr(ZRQINIT, Txhdr);
        zrqinits_sent++;
        oflush();

        Crcflg = FALSE;
        firstsec = TRUE;
        bytcnt = (size_t) - 1;
        Totsecs = 0;

        if (wcs(filename, remote) == ERROR) {
            readline_clean();
            return ERROR;
        }
        if (zmodem_requested)
            saybibi();
        else if (protocol != ZM_XMODEM) {
            struct zm_fileinfo zi;
            char *pa;

            pa = (char *)malloc(PATH_MAX + 1);
            *pa = '\0';
            zi.fname = pa;
            zi.modtime = 0;
            zi.mode = 0;
            zi.bytes_total = 0;
            zi.bytes_sent = 0;
            zi.bytes_received = 0;
            zi.bytes_skipped = 0;
            wctxpn(&zi);
            free(pa);
        }

        oflush();
        /* here needs a oflush */
        /* eat avalible input */
        /* better to eat some input here */
        io_mode(io_mode_fd, 0);
        readline_clean();
    } else {
        oflush();
        signal(SIGALRM, SIG_IGN);
        alarm(0);
        return ERROR;
    }
    return OK;
}
Ejemplo n.º 7
0
/*
 * Initialize for Zmodem receive attempt, try to activate Zmodem sender
 *  Handles ZSINIT frame
 *  Return ZFILE if Zmodem filename received, -1 on error,
 *   ZCOMPL if transaction finished,  else 0: can be ymodem.
 */
int tryz(void)
{
    int	    c, n;
    int	    cmdzack1flg;

    if (protocol != ZM_ZMODEM)
	return 0;

    for (n = zmodem_requested ?15:10; --n >= 0; ) {
	/*
	 * Set buffer length (0) and capability flags
	 */
	Syslog('z', "tryz attempt %d", n);
	stohdr(0L);
	Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO;
	if (Zctlesc)
	    Txhdr[ZF0] |= TESCCTL;
	zshhdr(tryzhdrtype, Txhdr);
	if (tryzhdrtype == ZSKIP)       /* Don't skip too far */
	    tryzhdrtype = ZRINIT;	/* CAF 8-21-87 */
again:
	switch (zgethdr(Rxhdr)) {
	    case ZRQINIT:   continue;
	    case ZEOF:	    continue;
	    case TIMEOUT:   Syslog('z', "Zmodem: tryz() timeout attempt %d", n);
			    continue;
	    case ZFILE:	    zconv = Rxhdr[ZF0];
			    if (!zconv) {
				Syslog('z', "*** !zconv %d", zconv);
				zconv = ZCBIN;
			    }
			    zmanag = Rxhdr[ZF1];
			    ztrans = Rxhdr[ZF2];
			    tryzhdrtype = ZRINIT;
			    c = zrdata(secbuf, MAXBLOCK);
			    io_mode(0, 3);
			    if (c == GOTCRCW) {
				Syslog('z', "tryz return ZFILE");
				return ZFILE;
			    }
			    zshhdr(ZNAK, Txhdr);
			    goto again;
	    case ZSINIT:    /* this once was:
			     * Zctlesc = TESCCTL & Rxhdr[ZF0];
			     * trouble: if rz get --escape flag:
			     * - it sends TESCCTL to sz, 
			     *   get a ZSINIT _without_ TESCCTL (yeah - sender didn't know), 
			     *   overwrites Zctlesc flag ...
			     * - sender receives TESCCTL and uses "|=..."
			     * so: sz escapes, but rz doesn't unescape ... not good.
			     */
			    Zctlesc |= TESCCTL & Rxhdr[ZF0];
			    if (zrdata(Attn, ZATTNLEN) == GOTCRCW) {
				stohdr(1L);
				zshhdr(ZACK, Txhdr);
				goto again;
			    }
			    zshhdr(ZNAK, Txhdr);
			    goto again;
	    case ZFREECNT:  stohdr(getfree());
			    zshhdr(ZACK, Txhdr);
			    goto again;
	    case ZCOMMAND:  cmdzack1flg = Rxhdr[ZF0];
			    if (zrdata(secbuf, MAXBLOCK) == GOTCRCW) {
				if (cmdzack1flg & ZCACK1)
				    stohdr(0L);
				else
				    Syslog('+', "Zmodem: request for command \"%s\" ignored", printable(secbuf,-32));
				stohdr(0L);
				do {
				    zshhdr(ZCOMPL, Txhdr);
				} while (++errors<20 && zgethdr(Rxhdr) != ZFIN);
				return ackbibi();
			    }
			    zshhdr(ZNAK, Txhdr); 
			    goto again;
	    case ZCOMPL:    goto again;
	    case ZRINIT:    Syslog('z', "tryz: got ZRINIT");
			    return TERROR;
	    case ZFIN:	    /* do not beleive in first ZFIN */
			    ackbibi(); 
			    return ZCOMPL;
	    case TERROR:
	    case HANGUP:
	    case ZCAN:	    return TERROR;
	    default:	    continue;
	}
    }
    return 0;
}