Beispiel #1
0
void ReadIR(void)
{
    WORD t;
    BYTE hilo;
    BYTE exit;
    WORD byteOrWord; // 0:未設定
    WORD pos;

    if (enableReadIR==0)
        return;

    if (IR_PORT == 1)
        return;

    // なにか信号があった

    WriteTimer0(0);
    INTCONbits.TMR0IF = 0;
    hilo = 0;

    pos = 0;
    byteOrWord = 0;
    exit = 0;
    while (exit==0) {
        LED1_PORT = !hilo;
        do {
            t = ReadTimer0();
            if (INTCONbits.TMR0IF || (t > MAX_WAIT_CYCLE)) {
                t = MAX_WAIT_CYCLE;
                INTCONbits.TMR0IF = 0;
                exit=1;
                break;
            }
        } while (IR_PORT == hilo);
        WriteTimer0(0);
        exit += WriteBuffer(t,&pos,&byteOrWord);
        hilo = !hilo;
    }
    LED1_PORT = 0;
    WriteEOF(pos);

    if (!WaitToReadySerial())
        return;
    PrintIRBuffer("received,");
}
Beispiel #2
0
static afs_int32
WriteTapeBlock(struct butm_tapeInfo *info,
	       char *buffer,     /* assumed to be 16384 bytes with data in it */
	       afs_int32 length, /* amount data in buffer */
	       afs_int32 blockType)
{
    afs_int32 code = 0, rc = 0;
    afs_uint32 wsize;
    struct tapeLabel *label;
    struct fileMark *fmark;
    struct blockMark *bmark;
    struct progress *p;
    afs_int32 error = 0;

    p = (struct progress *)info->tmRock;

    if (blockType == BLOCK_DATA) {	/* Data Block */
	if (length == 0)
	    ERROR_EXIT(0);
	bmark = (struct blockMark *)buffer;
	memset(bmark, 0, sizeof(struct blockMark));
	bmark->magic = htonl(BLOCK_MAGIC);
	bmark->count = htonl(length);
    } else if (blockType == BLOCK_FMBEGIN) {	/* Filemark - begin */
	fmark = (struct fileMark *)buffer;
	fmark->magic = htonl(FILE_MAGIC);
	fmark->nBytes = htonl(FILE_BEGIN);
    } else if (blockType == BLOCK_FMEND) {	/* Filemark - end */
	fmark = (struct fileMark *)buffer;
	fmark->magic = htonl(FILE_MAGIC);
	fmark->nBytes = htonl(FILE_FMEND);
    } else if (blockType == BLOCK_LABEL) {	/* Label */
	label = (struct tapeLabel *)buffer;
	label->magic = htonl(TAPE_MAGIC);
    } else if (blockType == BLOCK_EOD) {	/* Filemark - EOD mark */
	fmark = (struct fileMark *)buffer;
	fmark->magic = htonl(FILE_MAGIC);
	fmark->nBytes = htonl(FILE_EOD);
    }

    /* Write the tape block */
    /* -------------------- */
    rc = USD_WRITE(p->fid, buffer, BUTM_BLOCKSIZE, &wsize);
    if ((rc == 0) && (wsize > 0)) {
	incPosition(info, p->fid, wsize);	/* record whats written */
	p->writing++;
    }

    if (wsize != BUTM_BLOCKSIZE) {
	info->status |= BUTM_STATUS_WRITEERROR;
	if (rc != 0) {
	    error = rc;
	    ERROR_EXIT(BUTM_IO);
	} else
	    ERROR_EXIT(BUTM_EOT);
    }
    if (isafile)
	info->position++;

    /* Write trailing EOF marker for some block types */
    /* ---------------------------------------------- */
    if ((blockType == BLOCK_FMEND) || (blockType == BLOCK_LABEL)
	|| (blockType == BLOCK_EOD)) {

	POLL();
	error = WriteEOF(p->fid, 1);
	POLL();
	if (error) {
	    info->status |= BUTM_STATUS_WRITEERROR;
	    ERROR_EXIT(BUTM_IOCTL);
	}

	incSize(info, config.fileMarkSize);
	if (!isafile)
	    info->position++;
	p->writing = 0;
    }

  error_exit:
    if (error)
	info->error = error;
    return (code);
}
Beispiel #3
0
void WriteOutputEOF() {
	WriteEOF();
}
Beispiel #4
0
void SerialProc(void)
{
    WORD numBytesRead;
    BYTE i;
    char buff[10];
    char *buffPtr;
    BYTE *readPtr;
    char state; // 0:readed ',' 1:readed number
    BYTE exit;
    WORD byteOrWord; // 0:未設定
    WORD pos;
    WORD v;
    WORD bpos;

    // check whether data is recieved from uart
    if (!DataRdyUSART())
        return;

    bpos = 0;
    // read data from uart
    numBytesRead = ReadSerial(uartInBuffer, sizeof(uartInBuffer));
    if (numBytesRead == 0 || numBytesRead == 0xFFFF)
        return;

    state = 0;
    buffPtr = buff;
    readPtr = uartInBuffer;
    pos = 0;
    byteOrWord = 0;
    exit = 0;
loop:
    for(i=0;i<numBytesRead;i++) {
        if (readPtr[i]=='\r' || readPtr[i]=='\n'){
            if (pos>0) {
                if (buffPtr==buff) {
                    sprintf(uartOutBuffer,
                            (far rom char*)"parse error. need number. [%d,%c]\r\n",
                            bpos+i,readPtr[i]);
                    PutsStringCPtr(uartOutBuffer);
                    return;
                }
                *buffPtr++ = '\0';
                v = atoi(buff);
                exit += WriteBuffer(v,&pos,&byteOrWord);
                buffPtr = buff;

                WriteEOF(pos);
                SendIRImpl();
                PrintIRBuffer("echo,");
            }
            return;
        } else if (state==0) {
            if(readPtr[i] != 'H' && readPtr[i] != 'L') {
                sprintf(uartOutBuffer,
                        (far rom char*)"parse error. need 'H' or 'L'. [%d,%c]\r\n",
                        bpos+i,readPtr[i]);
                PutsStringCPtr(uartOutBuffer);

                WriteEOF(pos);
                PrintIRBuffer("echo,");
                return;
            }
            state = 1;
        } else if (state==1) {
            if (readPtr[i] == ',') {
                state = 0;
                if (buffPtr==buff) {
                    sprintf(uartOutBuffer,
                            (far rom char*)"parse error. need number. [%d,%c]\r\n",
                            bpos+i,readPtr[i]);
                    PutsStringCPtr(uartOutBuffer);
                    WriteEOF(pos);
                    PrintIRBuffer("echo,");
                    return;
                }
                *buffPtr++ = '\0';
                v = atoi(buff);
                exit += WriteBuffer(v,&pos,&byteOrWord);
                buffPtr = buff;
            } else if ('0' <= readPtr[i] && readPtr[i] <= '9') {
                *buffPtr++ = readPtr[i];
            } else {
                sprintf(uartOutBuffer,
                        (far rom char*)"parse error. need ',' or number. [%d,%c]\r\n",
                        bpos+i,readPtr[i]);
                PutsStringCPtr(uartOutBuffer);
                WriteEOF(pos);
                PrintIRBuffer("echo,");
                return;
            }
        }
    }
    bpos += numBytesRead;
    numBytesRead = ReadSerial(uartInBuffer, sizeof(uartInBuffer));
    if (numBytesRead == 0xFFFF)
        return;
    goto loop;
}