Esempio n. 1
0
func (dpf *DPF) scsiWrite(cmd []byte, data []byte) error {
	var err error

	// Write command to device
	if dpf.Debug {
		log.Print("[WRITE] Write command to device")
	}
	_, err = libusb.Bulk_Transfer(dpf.udev, AX206_ENDP_OUT, dpf.scsiCmdPrepare(cmd, len(data), true), scsiTimeout)
	if err != nil {
		return err
	}

	// Write data to device
	if data != nil {
		if dpf.Debug {
			log.Print("[WRITE] Write data to device")
		}
		_, err := libusb.Bulk_Transfer(dpf.udev, AX206_ENDP_OUT, data, scsiTimeout)
		if err != nil {
			return err
		}
	}

	return dpf.scsiGetAck()
}
Esempio n. 2
0
func (dpf *DPF) scsiRead(cmd []byte, blockLen int) ([]byte, error) {
	var err error

	// Write command to device
	if dpf.Debug {
		log.Print("[READ] Write command to device")
	}
	_, err = libusb.Bulk_Transfer(dpf.udev, AX206_ENDP_OUT, dpf.scsiCmdPrepare(cmd, blockLen, false), scsiTimeout)
	if err != nil {
		return nil, err
	}

	if dpf.Debug {
		log.Print("[READ] Read data from device")
	}
	// Read data from device
	data1 := make([]byte, blockLen, blockLen)
	data, err := libusb.Bulk_Transfer(dpf.udev, AX206_ENDP_IN, data1, scsiTimeout)
	if err != nil {
		return nil, err
	}
	if dpf.Debug {
		log.Print("[READ] data ", data)
	}

	err = dpf.scsiGetAck()
	if err != nil {
		return data, err
	}

	return data, nil
}
Esempio n. 3
0
func (dpf *DPF) scsiGetAck() error {
	buf := []byte{
		0, 0, 0, 0,
		0, 0, 0, 0,
		0, 0, 0, 0,
		0,
	}
	// Get ACK
	if dpf.Debug {
		log.Print("[ACK] Read ACK from device")
	}
	ack, err := libusb.Bulk_Transfer(dpf.udev, AX206_ENDP_IN, buf, scsiTimeout)
	if err != nil {
		return err
	}
	if dpf.Debug {
		log.Print("[ACK] data ", ack)
	}

	if string(ack[:4]) != "USBS" {
		return fmt.Errorf("Got invalid reply")
	}
	// pass back return code set by peer:
	// return ansbuf[12];
	return nil
}