?? fmschedule.c
字號:
/*
********************************************************************************
* 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 + -