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

📄 fmschedule.c

📁 SI4702
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
********************************************************************************
*          Copyright (C),2004-2007, Fuzhou Rockchip Electronics Co.,Ltd.
*                             All Rights Reserved
*
*Description: FM Module 系统接口主程序
*
$Header: /cvs_server/mp3_project/RK2608_4G_DEMO/FM/FmSchedule.c,v 1.8 2007/05/14 03:29:52 zyz Exp $
$Author: zyz $
$Date: 2007/05/14 03:29:52 $ 
$Revision: 1.9 Release$
********************************************************************************
*/

#include <Creg.h>
#include "Macro.h"
#include "Memap.h"
#include "MsgDef.h"
#include "Resource.h"
#include "Global.h"
#include "KeyMacro.h"
#include "KeyGlobal.h"
#include "Lcd.h"

#ifdef FM_MODULE

    #define _IN_FMSCHEDULE
    #include "FmMacro.h"
    #include "FmStruct.h"
    #include "FmGlobal.h"
    #include "tuner_drv.h"




void FmCPUInit(void);
void FmModuleInitial(void);
void FmPlayStart(void);
void FmPlay(void);
void FmVariableInit(void);
void FmCodecInit(void);

//--------------------------------------------------FM 电台列表 开始----------------------------------------------------------

#if(FM_LIST_ENABLE == 1)
/************************************************************
Function:       unsigned int* fmlistGetNextLine (unsigned int *str, unsigned int num, HANDLE Handle)
Description:    读一行字符, 该行的字符数不大于 num - 2.
Calls:          
Called by:      
Input:          str         存放读入的字符数组指针
                num         最大允许读入字符数
                Handle      文件指针
Output:         
Return:         成功, 返回 str 指针, 失败返回 NULL.
Others:         如果读取的文件不是 Unicode 编码, 本函数将自动转换成 Unicode 码.
************************************************************/
FM_CODE_SECTION
unsigned int* fmlistGetNextLine (unsigned int *str, unsigned int num, HANDLE Handle)
{
    int             i;
    int             iReadBytes;
    int             iOffset;
    unsigned int    *pstr;
    
    FileSeek(FmListOffset, SEEK_SET, hSlaveFile);
    iReadBytes = FileRead((unsigned char *)str, num - 2, Handle);
    if(iReadBytes > 0)
    {
        // 计算偏移量.
        iOffset = 0;
        for (i = 0; i < iReadBytes; i++)
        {
            iOffset ++;
            if (0x0A == str[i])
            {
                break;
            }
        }
        FmListOffset += iOffset;
        
        str[iOffset] = '\0';
        TxtGbk2Unicode(str, str, iReadBytes);
        
        pstr = str;
    }
    else
    {
        pstr = NULL;
    }
    
    return pstr;
}
#endif

#if(FM_LIST_ENABLE == 1)
/************************************************************
Function:       unsigned int* fmlistWaitChar (unsigned int *str, unsigned int iChar)
Description:    在字符串中, 查找一个字符.
Calls:          
Called by:      
Input:          str         字符串指针
                iChar       要查找的字符, Unicode 码.
Output:         
Return:         成功, 返回 str 指针指向下一个字符;
                失败, 返回 str 指针指向字符串末尾.
Others:         
************************************************************/
FM_CODE_SECTION
unsigned int* fmlistWaitChar (unsigned int *str, unsigned int iChar)
{
    unsigned int    *pstr;
    
    pstr = str;
    
    while ('\0' != (*pstr))
    {
        if (iChar == (*pstr))
        {
            pstr++;
            break;
        }
        
        pstr++;
    }
    
    return pstr;
}
#endif

#if(FM_LIST_ENABLE == 1)
/************************************************************
Function:       void fmlistAnalyseLine (unsigned int *str)
Description:    分析一行字符, 从中提取电台号, 电台频率, 以及 电台名称.
Calls:          
Called by:      
Input:          
Output:         
Return:         成功, 返回 TRUE;
                失败, 返回 FALSE.
Others:         
************************************************************/
FM_CODE_SECTION
int fmlistAnalyseLine (unsigned int *str, unsigned int *iFmStation, unsigned int *iFmFreq, unsigned int **pFmStationName)
{
    unsigned int    *pstr;
    int             iStatus;
    
    pstr        = str;
    iStatus     = TRUE;
    *iFmStation  = 0;
    *iFmFreq     = 0;
    
    // 以 CH 开头.
    if (('\0' != (*pstr)) && (TRUE == iStatus))
    {
        pstr = fmlistWaitChar (pstr, 'C');
    }
    if (('\0' != (*pstr)) && (TRUE == iStatus))
    {
        pstr = fmlistWaitChar (pstr, 'H');
    }
    
    // 计算电台号.
    if (('\0' != (*pstr)) && (TRUE == iStatus))
    {
        *iFmStation =  (pstr[0] - '0') * 10
                    + (pstr[1] - '0') * 1;
        *iFmStation -= 1;
//        if ((*iFmStation >= FREQMAXNUMBLE) || (*iFmStation < 0))
//        {
//            iStatus = FALSE;
//        }
    }
    
    // 检查 = 号
    if (('\0' != (*pstr)) && (TRUE == iStatus))
    {
        pstr = fmlistWaitChar (pstr, '=');
    }
    if (('\0' != (*pstr)) && (TRUE == iStatus))
    {
        while (' ' == (*pstr))
        {
            pstr++;
        }
    }
    
    // 计算频率.
    if (('\0' != (*pstr)) && (TRUE == iStatus))
    {
        *iFmFreq =   (pstr[0] - '0') * 10000
                  + (pstr[1] - '0') * 1000
                  + (pstr[2] - '0') * 100
                  + (pstr[3] - '0') * 10
                  + (pstr[4] - '0') * 1;
                  
        if ((*iFmFreq  < 7600) || (*iFmFreq  > 10800))
        {
            iStatus = FALSE;
        }
    }
    
    // 检查 , 号
    if (('\0' != (*pstr)) && (TRUE == iStatus))
    {
        pstr = fmlistWaitChar (pstr, ',');
    }
    if (('\0' != (*pstr)) && (TRUE == iStatus))
    {
        while (' ' == (*pstr))
        {
            pstr++;
        }
    }
    
    // 取电台名
    *pFmStationName = pstr;
    
    return iStatus;
}
#endif

#if(FM_LIST_ENABLE == 1)
/************************************************************
Function:       int fmlistGetFmFreqList (unsigned int *FmFreqArray)
Description:    从 FM列表文件, 读取 电台频率列表.
Calls:          
Called by:      
Input:          FmFreqArray:    保存 电台频率列表 的数组.
Output:         
Return:         成功, 返回 TRUE;
                失败, 返回 FALSE.
Others:         
************************************************************/
FM_CODE_SECTION
int fmlistGetFmFreqList (unsigned int *FmFreqArray)
{
    int                 iStatus;
    int                 bDone;
    unsigned int        iFmStation;
    unsigned int        iFmFreq;
    unsigned int        *pFmStationName;
    unsigned int        *pstr;
    
    // FM电台列表 文件路径. 
    unsigned char       sFilePath[] = FM_LIST_PATH;
    
    // FM电台列表 文件名
    unsigned char       sFileName[] = FM_LIST_FILE_NAME;
    
    unsigned int        FileBuffer[FILE_BUFFER_LENGTH];
    unsigned int        iIsUnicode;
    
    iStatus     = TRUE;
    bDone       = FALSE;
    
    // 打开列表文件.
    if (TRUE == iStatus)
    {
        if ((hSlaveFile = FileOpen(sFilePath, sFileName, "R")) == NOT_OPEN_FILE) 
        {
            iStatus = FALSE;
        }
    }
    
    // 初始化 文件偏移量.
    if (TRUE == iStatus)
    {
        FmListOffset = 0;
    }
    
    // 检查文件头标志: [FM]
    if (TRUE == iStatus)
    {
        if (NULL != fmlistGetNextLine (FileBuffer, FILE_BUFFER_LENGTH, hSlaveFile))
        {
            pstr = FileBuffer;
            pstr = fmlistWaitChar (pstr, '[');
            if (('F' != pstr[0]) || ('M' != pstr[1]) || (']' != pstr[2]))
            {
                iStatus = FALSE;
            }
        }
        else
        {
            iStatus = FALSE;
        }
    }
    
    // 提取电台.
    if (TRUE == iStatus)
    {
        int iLastStation;
        
        iLastStation    = 0;
        while (FALSE == bDone)
        {
            if (NULL != fmlistGetNextLine (FileBuffer, FILE_BUFFER_LENGTH, hSlaveFile))
            {
                if (TRUE == fmlistAnalyseLine (FileBuffer, &iFmStation, &iFmFreq, &pFmStationName))
                {
                    if (iFmStation < iLastStation)  // 电台应按顺序排列.
                    {
                        break;
                    }
                    
                    if ((iFmStation < FREQMAXNUMBLE) || (iFmStation >= 0))  // 电台号不能超出范围.
                    {
                        FmFreqArray[iFmStation] = iFmFreq;
                        
                        iLastStation = iFmStation;
                    }
                    else
                    {
                        bDone = TRUE;
                    }
                }
            }
            else
            {
                bDone = TRUE;
            }
        }
    }
    
    // 关闭列表文件
    if (NOT_OPEN_FILE != hSlaveFile)
    {
        FileClose(hSlaveFile);
    }
    
    return iStatus;
}
#endif

#if(FM_LIST_ENABLE == 1)
/************************************************************
Function:       int fmlistGetFmStationName (unsigned int FmFreq, unsigned int FmStationName)
Description:    从 FM列表文件, 读取 某一个电台频率 对应的 电台名称.
Calls:          
Called by:      
Input:          FmFreq:         电台频率值.
                FmStationName:  电台名称字符串数组.
Output:         
Return:         成功, 返回 TRUE;
                失败, 返回 FALSE.
Others:         
************************************************************/
FM_CODE_SECTION
int fmlistGetFmStationName (unsigned int FmFreq, unsigned int *FmStationName)
{
    int                 i;
    
    int                 iStatus;
    int                 bDone;
    unsigned int        iFmStation;
    unsigned int        iFmFreq;
    unsigned int        *pFmStationName;
    unsigned int        *pstr;
    
    // FM电台列表 文件路径. 
    unsigned char       sFilePath[] = FM_LIST_PATH;
    
    // FM电台列表 文件名
    unsigned char       sFileName[] = FM_LIST_FILE_NAME;
    
    unsigned int        FileBuffer[FILE_BUFFER_LENGTH];
    unsigned int        iIsUnicode;
    
    iStatus     = TRUE;
    bDone       = FALSE;
    
    // 打开列表文件.
    if (TRUE == iStatus)
    {
        if ((hSlaveFile = FileOpen(sFilePath, sFileName, "R")) == NOT_OPEN_FILE) 
        {
            iStatus = FALSE;
        }
    }
    
    // 初始化 文件偏移量.
    if (TRUE == iStatus)
    {
        FmListOffset = 0;
    }
    
    // 检查文件头标志: [FM]
    if (TRUE == iStatus)
    {
        if (NULL != fmlistGetNextLine (FileBuffer, FILE_BUFFER_LENGTH, hSlaveFile))
        {
            pstr = FileBuffer;
            pstr = fmlistWaitChar (pstr, '[');
            if (('F' != pstr[0]) || ('M' != pstr[1]) || (']' != pstr[2]))
            {
                iStatus = FALSE;
            }
        }
        else
        {
            iStatus = FALSE;
        }
    }
    
    // 提取电台名称.
    if (TRUE == iStatus)
    {
        iStatus = FALSE;
        while (FALSE == bDone)
        {
            if (NULL != fmlistGetNextLine (FileBuffer, FILE_BUFFER_LENGTH, hSlaveFile))
            {
                if (TRUE == fmlistAnalyseLine (FileBuffer, &iFmStation, &iFmFreq, &pFmStationName))
                {
                    if (FmFreq == iFmFreq)
                    {
                        iStatus     = TRUE;
                        bDone       = TRUE;
                    }
                }
            }
            else
            {
                bDone = TRUE;
            }
        }
    }
    
    if (TRUE == iStatus)
    {
        for (i = 0; i < FM_STATION_NAME_LENGTH - 1; i++)
        {
            if (('/' == pFmStationName[i]) && ('/' == pFmStationName[i + 1]))
            {

⌨️ 快捷键说明

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