⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mavcmd.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_Read reads data from the opened file.
//
//****************************************************************************
unsigned long
Maverick_Read(void *pvBuffer, unsigned long ulNumBytes)
{
    unsigned long ulReturn;

    //
    // Read from the file.
    //
    ReadFile(hFile, pvBuffer, ulNumBytes, &ulReturn, NULL);

    //
    // Return the number of bytes read.
    //
    return(ulReturn);
}

//****************************************************************************
//
// Maverick_Write writes data to the opened file.
//
//****************************************************************************
unsigned long
Maverick_Write(void *pvBuffer, unsigned long ulNumBytes)
{
    unsigned long ulReturn;

    //
    // Write to the file.
    //
    WriteFile(hFile, pvBuffer, ulNumBytes, &ulReturn, NULL);

    //
    // Return the number of bytes written.
    //
    return(ulReturn);
}

//****************************************************************************
//
// Maverick_Seek moves the read/write pointer for the opened file to the
// specified position.
//
//****************************************************************************
unsigned long
Maverick_Seek(unsigned long ulPos)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "seek" request.
    //
    sParam.ulRequestCode = REQUEST_SEEK;
    sParam.uParams.sSeek.ulPosition = ulPos;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_Tell returns the current read/write for the opened file.
//
//****************************************************************************
unsigned long
Maverick_Tell(void)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "tell" request.
    //
    sParam.ulRequestCode = REQUEST_TELL;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return the current file
    // position.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return the current file position.
        //
        return(sResult.uResults.sTell.ulPosition);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_Length returns the length of the currently opened file.
//
//****************************************************************************
unsigned long
Maverick_Length(void)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "length" request.
    //
    sParam.ulRequestCode = REQUEST_LENGTH;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return the file length.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return the file length.
        //
        return(sResult.uResults.sLength.ulLength);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_GetDate returns the modification date/time of the currently opened
// file.
//
//****************************************************************************
unsigned long
Maverick_GetDate(void)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "get date" request.
    //
    sParam.ulRequestCode = REQUEST_GETDATE;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return the file length.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return the modification date/time of the file..
        //
        return(sResult.uResults.sGetDate.ulDate);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_Close closes the currently opened file.
//
//****************************************************************************
unsigned long
Maverick_Close(void)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "close" request.
    //
    sParam.ulRequestCode = REQUEST_CLOSE;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_Delete removes the specified file from the file system.
//
//****************************************************************************
unsigned long
Maverick_Delete(unsigned long ulDrive, const unsigned short *pusFileName)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "delete" request.
    //
    sParam.ulRequestCode = REQUEST_DELETE;
    sParam.uParams.sDelete.ulDriveNum = ulDrive;
    memcpy(sParam.uParams.sDelete.pusFileName, pusFileName, 256);

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_OpenDir opens the specified directory on the specified drive.
//
//****************************************************************************
unsigned long
Maverick_OpenDir(unsigned long ulDrive, const unsigned short *pusDirName)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "opendir" request.
    //
    sParam.ulRequestCode = REQUEST_OPENDIR;
    sParam.uParams.sOpenDir.ulDriveNum = ulDrive;
    memcpy(sParam.uParams.sOpenDir.pusDirName, pusDirName, 256);

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_ReadDir reads the next directory entry from the currently opened
// directory.
//
//****************************************************************************
unsigned long
Maverick_ReadDir(unsigned short *pusFileName, unsigned long ulType)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "readdir" request.
    //
    sParam.ulRequestCode = REQUEST_READDIR;
    sParam.uParams.sReadDir.ulType = ulType;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return the file name.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return the name of the file found.
        //
        memcpy(pusFileName, sResult.uResults.sReadDir.pusName, 256);

        //
        // Return success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_CloseDir closes the currently opened directory.
//
//****************************************************************************
unsigned long

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -