Example #1
0
unsigned char init_print() {  /* 初始化USB打印机,完成打印机枚举 */
#define	p_dev_descr		((PUSB_DEV_DESCR)buffer)
#define	p_cfg_descr		((PUSB_CFG_DESCR_LONG)buffer)
	unsigned char status, len, c;
	status=get_descr(1);  /* 获取设备描述符 */
	if ( status==USB_INT_SUCCESS ) {
		len=rd_usb_data( buffer );  /* 将获取的描述符数据从CH375中读出到单片机的RAM缓冲区中,返回描述符长度 */
		if ( len<18 || p_dev_descr->bDescriptorType!=1 ) return( UNKNOWN_USB_DEVICE );  /* 意外错误:描述符长度错误或者类型错误 */
		if ( p_dev_descr->bDeviceClass!=0 ) return( UNKNOWN_USB_DEVICE );  /* 连接的USB设备不是USB打印机,或者不符合USB规范 */
		status=set_addr(3);  /* 设置打印机的USB地址 */
		if ( status==USB_INT_SUCCESS ) {
			status=get_descr(2);  /* 获取配置描述符 */
			if ( status==USB_INT_SUCCESS ) {  /* 操作成功则读出描述符并分析 */
				len=rd_usb_data( buffer );  /* 将获取的描述符数据从CH375中读出到单片机的RAM缓冲区中,返回描述符长度 */
				if ( p_cfg_descr->itf_descr.bInterfaceClass!=7 || p_cfg_descr->itf_descr.bInterfaceSubClass!=1 ) return( UNKNOWN_USB_PRINT );  /* 不是USB打印机或者不符合USB规范 */
				endp_out_addr=endp_in_addr=0;
				c=p_cfg_descr->endp_descr[0].bEndpointAddress;  /* 第一个端点的地址 */
				if ( c&0x80 ) endp_in_addr=c&0x0f;  /* IN端点的地址 */
				else {  /* OUT端点 */
					endp_out_addr=c&0x0f;
					endp_out_size=p_cfg_descr->endp_descr[0].wMaxPacketSize;  /* 数据接收端点的最大包长度 */
				}
				if ( p_cfg_descr->itf_descr.bNumEndpoints>=2 ) {  /* 接口有两个以上的端点 */
					if ( p_cfg_descr->endp_descr[1].bDescriptorType==5 ) {  /* 端点描述符 */
						c=p_cfg_descr->endp_descr[1].bEndpointAddress;  /* 第二个端点的地址 */
						if ( c&0x80 ) endp_in_addr=c&0x0f;  /* IN端点 */
						else {  /* OUT端点 */
							endp_out_addr=c&0x0f;
							endp_out_size=p_cfg_descr->endp_descr[1].wMaxPacketSize;
						}
					}
				}
				if ( p_cfg_descr->itf_descr.bInterfaceProtocol<=1 ) endp_in_addr=0;  /* 单向接口不需要IN端点 */
				if ( endp_out_addr==0 ) return( UNKNOWN_USB_PRINT );  /* 不是USB打印机或者不符合USB规范 */
				status=set_config( p_cfg_descr->cfg_descr.bConfigurationValue );  /* 加载USB配置值 */
				if ( status==USB_INT_SUCCESS ) {
					CH375_WR_CMD_PORT( CMD_SET_RETRY );  /* 设置USB事务操作的重试次数 */
					CH375_WR_DAT_PORT( 0x25 );
					CH375_WR_DAT_PORT( 0x89 );  /* 位7为1则收到NAK时无限重试, 位3~位0为超时后的重试次数 */
/* 如果单片机在打印机忙时并无事可做,建议设置位7为1,使CH375在收到NAK时自动重试直到操作成功或者失败 */
/* 如果希望单片机在打印机忙时能够做其它事,那么应该设置位7为0,使CH375在收到NAK时不重试,
   所以在下面的USB通讯过程中,如果USB打印机正忙,issue_token等子程序将得到状态码USB_INT_RET_NAK */
				}
			}
		}
	}
	return(status);
}
Example #2
0
void free_code(Code* code)
{
    int i;
    Tstat* pstat = code->head;
    while (pstat)
    {
        Tstat* pstat_next = pstat->next;
        // Controllo se gli arg erano un puntatore a char.
        for (i = 0; i < MAXARGS; i++)
        {
            Opdescr *pdescr = get_descr(pstat->op);
            char tipo = pdescr->format[i];
            if (tipo == '\0') break;

            if (tipo == 's')
                if (pstat->op == T_FPRINT ||
                    pstat->op == T_PRINT ||
                    pstat->op == T_FGET ||
                    pstat->op == T_GET)
                    freemem(pstat->args[i].sval, sizeof(char*));
        }
        freemem(pstat, sizeof(Tstat));
        pstat = pstat_next;
    }
}
void Produto::imprime() {
	cout << "Nome do produto: " << get_nome() << endl;
	cout << "Código: " << get_cod() << endl;
	cout << "Descrição do produto: " << get_descr() << endl;
	cout << "Quantidade de produtos disponiveis: " << get_quant_disp() << endl;
	cout << "Nº dias desde que o produto foi embalado: " << get_dias_embalado()
			<< endl;
	cout << "Preço de compra ao fornecedor: " << get_preco_cmp() << endl;
	cout << "Preço de venda ao cliente: " << get_preco_vnd() << endl;
}
Example #4
0
void codeprint(Code code, int indent)
{
    Tstat *pstat;
    Opdescr *pdescr;
    char pformat[MAXPFORMAT], *pchar;
    int i;


    for (pstat = code.head; pstat; pstat = pstat->next)
    {
        pdescr = get_descr(pstat->op);
        if (pdescr->indent < 0)
            indent += pdescr->indent;
        for (i = 0; i < indent; i++)
        {
            printf("  ");
        }
        printf("%s", pdescr->name);
        int contatore = 0;
        for (*pformat = '\0', pchar = pdescr->format; *pchar != '\0'; pchar++)
        {
            switch(*pchar)
            {
                case 'i':
                    printf(" %d", (pstat->args[contatore]).ival);
                    //sprintf(&pformat[strlen(pformat)], " %%d");
                    break;
                case 's':
                    printf(" \"%s\"", (pstat->args[contatore]).sval);
                    //sprintf(&pformat[strlen(pformat)], " \"%%s\"");
                    break;
                default: syserror("codeprint()");
            }
            contatore++;
        }
        //sprintf(&pformat[strlen(pformat)], "\n");
        //printf(pformat, *pstat->args[0], pstat->args[1], pstat->args[2]);
        printf("\n");
        if (pdescr->indent > 0)
            indent += pdescr->indent;
    }
}
Example #5
0
char const * param_descrs::get_descr(char const * name) const {
    return get_descr(symbol(name));
}