예제 #1
0
int netmd_send_message(netmd_dev_handle *devh, unsigned char *cmd,
                       const size_t cmdlen)
{
    unsigned char pollbuf[4];
    int	len;
    libusb_device_handle *dev;

    dev = (libusb_device_handle *)devh;

    /* poll to see if we can send data */
    len = netmd_poll(dev, pollbuf, 1);
    if (len != 0) {
        netmd_log(NETMD_LOG_ERROR, "netmd_exch_message: netmd_poll failed\n");
        return (len > 0) ? NETMDERR_NOTREADY : len;
    }

    /* send data */
    netmd_log(NETMD_LOG_DEBUG, "Command:\n");
    netmd_log_hex(NETMD_LOG_DEBUG, cmd, cmdlen);
    if (libusb_control_transfer(dev, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR |
                        LIBUSB_RECIPIENT_INTERFACE, 0x80, 0, 0, cmd, (int)cmdlen,
                        NETMD_SEND_TIMEOUT) < 0) {
        netmd_log(NETMD_LOG_ERROR, "netmd_exch_message: libusb_control_transfer failed\n");
        return NETMDERR_USB;
    }

    return 0;
}
예제 #2
0
int netmd_recv_message(netmd_dev_handle *devh, unsigned char* rsp)
{
    int len;
    unsigned char pollbuf[4];
    libusb_device_handle *dev;

    dev = (libusb_device_handle *)devh;

    /* poll for data that minidisc wants to send */
    len = netmd_poll(dev, pollbuf, NETMD_RECV_TRIES);
    if (len <= 0) {
        netmd_log(NETMD_LOG_ERROR, "netmd_exch_message: netmd_poll failed\n");
        return (len == 0) ? NETMDERR_TIMEOUT : len;
    }

    /* receive data */
    if (libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR |
                        LIBUSB_RECIPIENT_INTERFACE, pollbuf[1], 0, 0, rsp, len,
                        NETMD_RECV_TIMEOUT) < 0) {
        netmd_log(NETMD_LOG_ERROR, "netmd_exch_message: libusb_control_transfer failed\n");
        return NETMDERR_USB;
    }

    netmd_log(NETMD_LOG_DEBUG, "Response:\n");
    netmd_log_hex(NETMD_LOG_DEBUG, rsp, (size_t)len);

    /* return length */
    return len;
}
예제 #3
0
파일: libnetmd.c 프로젝트: bobo1on1/netmd
/*
	exchanges a message with the minidisc
	
	IN	dev		USB device handle
			buf		pointer to buffer to send
			len		length of data to send
	
	Returns >0 on success, <0 on failure
*/
int netmd_exch_message(usb_dev_handle *dev, unsigned char *cmd, int cmdlen,
	unsigned char *rsp)
{
	unsigned char	pollbuf[4];
	int		len;

	/* poll to see if we can send data */
	len = netmd_poll(dev, pollbuf, 1);
	if (len != 0) {
		fprintf(stderr, "netmd_exch_message: netmd_poll failed\n");
		return (len > 0) ? NETMDERR_NOTREADY : len;
	}	
	
	/* send data */
	if (usb_control_msg(dev, USB_ENDPOINT_OUT | USB_TYPE_VENDOR |
			 								USB_RECIP_INTERFACE, 0x80, 0, 0, (char*)cmd, cmdlen,
			 								NETMD_SEND_TIMEOUT) < 0) {
		fprintf(stderr, "netmd_exch_message: usb_control_msg failed\n");
		return NETMDERR_USB;
	}

	do {
		/* poll for data that minidisc wants to send */
		len = netmd_poll(dev, pollbuf, NETMD_RECV_TRIES);
		if (len <= 0) {
			fprintf(stderr, "netmd_exch_message: netmd_poll failed\n");
			return (len == 0) ? NETMDERR_TIMEOUT : len;
		}
		
		/* receive data */
		if (usb_control_msg(dev, USB_ENDPOINT_IN | USB_TYPE_VENDOR |
											 	USB_RECIP_INTERFACE, pollbuf[1], 0, 0, (char*)rsp, len,
											 	NETMD_RECV_TIMEOUT) < 0) {
			fprintf(stderr, "netmd_exch_message: usb_control_msg failed\n");
			return NETMDERR_USB;
		}
		/* get response again if player responds with 0x0F.	*/
	} while (rsp[0] == 0x0F);

	/* return length */
	return len;
}