示例#1
0
string JSLexer::read_str(char quote) {
    string rtn;
    char t_c = read_ch();
    while(t_c != quote && t_c != NULL) {
        rtn.push_back(t_c);
        t_c = read_ch();
    }
    return rtn;
}
示例#2
0
//***************************************************
//从有子地址器件读多个字节数据
//function:
void read_from_nch(unsigned char ad_main,unsigned char ad_sub,unsigned char *buf,unsigned char num){
	unsigned char i;
	IIC_start();
	send_ch(ad_main);
	send_ch(ad_sub);
	for(i=0;i<num-1;i++){
		*buf=read_ch();
		IIC_ack_main(ack); //主应答<ack=1>
		buf++;
	}
	*buf=read_ch();
	buf++; //本次指针调整无意义,目的是操作后buf指向下一地址
	IIC_ack_main(no_ack); //无需应答<no_ack=0>
	IIC_stop();
}
示例#3
0
//***************************************************
//从无子地址器件读单字节数据
//function:器件地址,所读数据存在接收缓冲区当前字节
void read_from_ch(unsigned char ad_main,unsigned char *buf){
	IIC_start();
	send_ch(ad_main); //发送器件地址
	*buf=read_ch();
	IIC_ack_main(no_ack); //无需应答<no_ack=0>
	IIC_stop();
}
示例#4
0
size_t WRTnode2r_spi_read(char * buf , int is_force)
{
	int fd;

	/* We use the last specified parameters, unless new ones are entered */

	unsigned char status = SPI_STATUS_OK;
	unsigned char i = 0;
	unsigned int len = 0;

	fd = open("/dev/spiS0", O_RDONLY);
	if (fd <= 0) {
		fprintf(stderr, "Please insmod module spi_drv.o!\n");
		return -1;
	}
	if (is_force) {
		status = read_status(fd);
		DEBUG_PRINT("read status = 0x%x\n", status);
		if(!(status & SPI_STATUS_OK)) {
			fprintf(stderr, "stm32 spi read error.\n");
			goto err;
		}
		if(status & SPI_STATUS_7688_READ_FROM_STM32_E) {
			fprintf(stderr, "stm32 read buf empty.\n");
			goto err;
		}
	}
	else {
		do {
			status = read_status(fd);
			DEBUG_PRINT("read status = 0x%x\n", status);
			if(status & (SPI_STATUS_OK) &&
					(!(status & SPI_STATUS_7688_READ_FROM_STM32_E))) {
				break;
			}
			//usleep(SPI_MCU_CHECK_STATUS_DELAY_US);
		}while(1);
	}
	len = read_len(fd);
	DEBUG_PRINT("read len = %d\n", len);

	if(0 == len) {
		fprintf(stderr, "read length is 0.\n");
		goto err;
	}

	for(i=0; i<len; i++) {
		buf[i] = read_ch(fd);
	}
	close(fd);
	return len;
err:
	close(fd);
	return -1;
}
示例#5
0
unsigned char MMA845x_readch(unsigned char address)
{
unsigned char ret = 100;
	IIC_start();		//启动
	send_ch(MMA845x_IIC_ADDRESS);	//写入设备ID及写信号
	send_ch(address);	//X地址
	IIC_start();		//重新发送开始
	send_ch(MMA845x_IIC_ADDRESS+1);	//写入设备ID及读信
	ret = read_ch();	//读取一字节
	IIC_stop();

	return ret;
}
示例#6
0
Token JSLexer::help_get_token(char c1,char c2,char c3) {
    string str;
    str.push_back(c1);
    char t_c = read_ch();
    if(t_c == c2) {
        str.push_back(c2);
    }
    else if(t_c == c3) {
        str.push_back(c3);
    }
    else {
        unread_ch();
    }
    return Token(get_tag(str.c_str()),str);
}
示例#7
0
void int_80(int fd, byte * data)
{
	switch (fd)
	{
		case WRITE:
			write(fd, *data);
			break;
		case WRITE_ON_SCREEN:
			write(fd, *data);
			break;
		case READ:
			*data = read();
			break;
		case READCH:
			*data = read_ch();
			break;
	}
	
	update_cursor(current_shell);
}
示例#8
0
int get_schar(char *p, int fd) {
  char c;
  int notdone=1;
  /* clock_t scnt, tcnt; */
  double scnt, tcnt;
  /* scnt = clock(); */
  scnt = getwholetime();
  while (notdone) {
    if (read_ch(fd, &c) == 1) {
      *p = c; /* pass the character back */
      return(1); /* got a character */
    } else {
      usleep(100);
    }
    tcnt = getwholetime() - scnt;
    if (tcnt > MAXWAITTIME) {
      notdone = 0;
    }
  }
  return(0);
}
示例#9
0
Token JSLexer::scan() {
    while(read_ch() != NULL) {
        if(peek == ' ' || peek == '\t' || peek== '\r')
            continue;
        else if(peek == '\n')
            line++;
        else
            break;
    }
    if(peek ==NULL)
        return Token::END;

    char cur_peek = peek;
    char t_c='\0';
    char t_str[2]= {0};
    switch(peek) {
    case '/':
        t_c=read_ch();
        if(t_c=='/') {
            return Token(get_tag("inlinecomment"),"//"+ read_str('\n'));
            break;
        } else if(t_c=='*') {
            string comment_str="/*"+read_str('*');
            t_c=read_ch();
            while(t_c!=NULL && t_c!='/') {
                comment_str.append(read_str('*'));
                t_c=read_ch();
            }
            comment_str.append("*/");
            return Token(get_tag("comment"),comment_str);
            break;
        } else {
            unread_ch();
        }
    case '+':
    case '-':
    case '&':
    case '|':
        return help_get_token(cur_peek, '=', cur_peek);
        break;
    case '*':
    case '%':
    case '^':
        return help_get_token(cur_peek, '=', NULL);
        break;
    case '=':
        if(read_the_ch('=') == true) {
            if(read_the_ch('=') == true)
                return Token(get_tag("==="),"===");
            else {
                unread_ch();
                return Token(get_tag("=="),"==");
            }
        } else {
            unread_ch();
            return Token(get_tag("="),"=");
        }

        break;
    case '!':
        if(read_the_ch('=') == true) {
            if(read_the_ch('=') == true)
                return Token(get_tag("!=="),"!==");
            else {
                unread_ch();
                return Token(get_tag("!="),"!=");
            }
        } else {
            unread_ch();
            return Token(get_tag("!"),"!");
        }
        break;
    case '<':
        t_c = read_ch();
        if(t_c == '=')
            return Token(get_tag("<="), "<=");
        else if(t_c == '<') {
            if(read_the_ch('=') == true)
                return Token(get_tag("<<="), "<<=");
            else {
                unread_ch();
                return Token(get_tag("<<"), "<<");
            }
        } else {
            unread_ch();
            return Token(get_tag("<"), "<");
        }
        break;
    case '>':
        t_c = read_ch();
        if(t_c == '=')
            return Token(get_tag(">="), ">=");
        else if(t_c == '>') {
            if(read_the_ch('=') == true)
                return Token(get_tag(">>="), ">>=");
            else {
                unread_ch();
                return Token(get_tag(">>"), ">>");
            }
        } else {
            unread_ch();
            return Token(get_tag(">"), ">");
        }
        break;
    case '~':
    case '(':
    case ')':
    case '[':
    case ']':
    case '{':
    case '}':
    case '?':
    case ':':
    case ';':
    case '.':
    case ',':
    case '\\':
        t_str[0]=cur_peek;
        return Token(get_tag(t_str),t_str);
        break;
    case '\'':
    case '\"':
        string r_str;
        r_str.push_back(cur_peek);
        r_str.append(read_str(cur_peek)).push_back(cur_peek);
        return Token(get_tag("string"),r_str);
        break;
    }

    string word;
    word.push_back(peek);

    if(is_digit(peek)==true) {
        while(is_digit(read_ch())==true) {
            word.push_back(peek);
        }
        unread_ch();
        return Token(get_tag("number"),word);
    }

    if(is_id_letter(peek) ==true) {
        while(is_id_letter(read_ch()) == true) {
            word.push_back(peek);
        }
        unread_ch();
        Token t = get_buffer_token(word.c_str());
        if(t==Token::EMPTY) {
            t = Token(get_tag("id"),word);
            save_buffer_token(t);
            return t;
        }
        else {
            return t;
        }
    }

    return Token::WRONG;
}
示例#10
0
bool JSLexer::read_the_ch(char c) {
    return read_ch()==c;
}