file_name_gen.c
字号:
}
}
*index = i;
return E_PASS;
}
/*-----------------------------------------------------------------------------\
@RoutineName :: GetFirstIndex
@Description ::
Gets the first index for a given file type
Used to iterate through the files in the directory structure for a particular file type
@Parameters ::
int *index :: the first file index is returned
FILE_TYPE type :: the file type ( see FileNameGen.h )
@Return ::
E_PASS, success
E_DEVICE, failure
\-----------------------------------------------------------------------------*/
STATUS GetFirstIndex(int *index, FILE_TYPE type ) {
*index = -1;
return GetNextIndex(index, type);
}
/*-----------------------------------------------------------------------------\
@RoutineName :: GetLastIndex
@Description ::
Gets the last index for a given file type
Used to iterate through the files in the directory structure for a particular file type
@Parameters ::
int *index :: the last file index is returned
FILE_TYPE type :: the file type ( see FileNameGen.h )
@Return ::
E_PASS, success
E_DEVICE, failure
\-----------------------------------------------------------------------------*/
STATUS GetLastIndex(int *index, FILE_TYPE type ) {
int stat;
*index = curIndex + 1;
stat = GetPrevIndex(index, type);
if( *index == curIndex + 1 )
*index = -1;
return stat;
}
/*-----------------------------------------------------------------------------\
@RoutineName :: GetFileName
@Description ::
Generate a filename given a file index and file type
@Parameters ::
char *fname :: the generated file name
int index :: the file index
FILE_TYPE type :: the file type
@Return ::
E_PASS, success
E_DEVICE, failure
\-----------------------------------------------------------------------------*/
STATUS GenFileName( char *fname, int index, FILE_TYPE type) {
int dirnum = index / 100;
int fnum = index % 100;
if( index < 0 || index > 9999 || index > curIndex )
return E_DEVICE;
/* FS:\DCIM\DM270_XX\MVI_XXYY.MOV or
FS:\DCIM\DM270_XX\MVI_XXYY.MP4 or
FS:\DCIM\DM270_XX\MVI_XXYY.263 or
FS:\DCIM\DM270_XX\IMG_XXYY.JPG
*/
switch( type ) {
case IMG_FILE :
sprintf( fname, "%s\\%s%d%d\\%s%d%d%d%d.%s",
BasePath, /* CFC:\DCIM */
DIR_PREFIX, /* \DM270_ */
dirnum / 10, dirnum % 10, /* XX */
IMG_PREFIX , /* IMG_ */
dirnum/10, dirnum%10, fnum/10, fnum%10, /* XXYY */
IMG_EXT /* .JPG */
);
break;
case MJPEG_FILE :
sprintf( fname, "%s\\%s%d%d\\%s%d%d%d%d.%s",
BasePath, /* CFC:\DCIM */
DIR_PREFIX, /* \DM270_ */
dirnum / 10, dirnum % 10, /* XX */
MJPEG_PREFIX , /* MVI_ */
dirnum/10, dirnum%10, fnum/10, fnum%10, /* XXYY */
MJPEG_EXT /* .MOV */
);
break;
case H263_FILE :
sprintf( fname, "%s\\%s%d%d\\%s%d%d%d%d.%s",
BasePath, /* CFC:\DCIM */
DIR_PREFIX, /* \DM270_ */
dirnum / 10, dirnum % 10, /* XX */
H263_PREFIX , /* MVI_ */
dirnum/10, dirnum%10, fnum/10, fnum%10, /* XXYY */
H263_EXT /* .263 */
);
break;
case MPEG4_FILE :
sprintf( fname, "%s\\%s%d%d\\%s%d%d%d%d.%s",
BasePath, /* CFC:\DCIM */
DIR_PREFIX, /* \DM270_ */
dirnum / 10, dirnum % 10, /* XX */
MPEG4_PREFIX , /* MVI_ */
dirnum/10, dirnum%10, fnum/10, fnum%10, /* XXYY */
MPEG4_EXT /* .MP4 */
);
break;
}
return E_PASS;
}
/*-----------------------------------------------------------------------------\
@RoutineName :: GetCurFileIndex
@Description ::
returns 'curIndex'
@Parameters ::
NONE
@Return ::
curIndex
\-----------------------------------------------------------------------------*/
int GetCurFileIndex() {
return curIndex;
}
/*-----------------------------------------------------------------------------\
@RoutineName :: testFileGen
@Description ::
test routine for FileNameGen Module
@Parameters ::
NONE
@Return ::
NONE
\-----------------------------------------------------------------------------*/
void testFileGen() {
int img=-1;
int mov=-1;
char fname[40];
char ch;
FILE_ID *fp;
FileDeviceSelectionInit();
sprintf( UART_outBuff, "\r\n curIndex = %d", curIndex );
UART_sendString( UART0, UART_outBuff);
do {
sprintf( UART_outBuff, "\r\n c=%d i=%d m=%d > ", curIndex, img, mov);
UART_sendString( UART0, UART_outBuff );
ch = UI_getInput();
switch(ch) {
case 'z' :
NewFileName(fname, &mov, MPEG4_FILE);
fp = FILE_open( fname, "wb", 0 );
if( fp == NULL ) {
sprintf( UART_outBuff, "\r\n E_DEVICE : pf_open()", fname);
} else {
FILE_close( fp, 0 );
sprintf( UART_outBuff, "\r\n %s created", fname);
}
UART_sendString( UART0, UART_outBuff );
break;
case 'x' :
GetNextIndex(&mov, MPEG4_FILE);
GenFileName(fname, mov, MPEG4_FILE);
sprintf( UART_outBuff, "\r\n Here is file %s", fname);
UART_sendString( UART0, UART_outBuff );
break;
case 'c' :
GetPrevIndex(&mov, MPEG4_FILE);
GenFileName(fname, mov, MPEG4_FILE);
sprintf( UART_outBuff, "\r\n Here is file %s", fname);
UART_sendString( UART0, UART_outBuff );
break;
case 'a' :
NewFileName(fname, &img, IMG_FILE);
fp = FILE_open( fname, "wb", 0 );
if( fp == NULL ) {
sprintf( UART_outBuff, "\r\n E_DEVICE : pf_open()", fname);
} else {
FILE_close( fp, 0 );
sprintf( UART_outBuff, "\r\n %s created", fname);
}
UART_sendString( UART0, UART_outBuff );
break;
case 's' :
GetNextIndex(&img, IMG_FILE);
GenFileName(fname, img, IMG_FILE);
sprintf( UART_outBuff, "\r\n Here is file %s", fname);
UART_sendString( UART0, UART_outBuff );
break;
case 'd' :
GetPrevIndex(&img, IMG_FILE);
GenFileName(fname, img, IMG_FILE);
sprintf( UART_outBuff, "\r\n Here is file %s", fname);
UART_sendString( UART0, UART_outBuff );
break;
}
} while( ch != 'q' );
}
STATUS FileDeviceSelectionInit() {
STATUS stat=E_DEVICE;
FileDevice[0]=0;
FS_FILE_IO = FALSE;
if(stat!=E_PASS) {
stat = SelectDevice(DRV_CF);
if(stat==E_PASS) {
GUI_fileInfoPanelSelectMedia(GUI_MEDIA_DRV_A);
}
}
if(stat!=E_PASS) {
stat = SelectDevice(DRV_SM);
if(stat==E_PASS) {
GUI_fileInfoPanelSelectMedia(GUI_MEDIA_DRV_A);
}
}
if(stat!=E_PASS) {
stat = SelectDevice(DRV_SD);
if(stat==E_PASS) {
GUI_fileInfoPanelSelectMedia(GUI_MEDIA_DRV_B);
}
}
if(stat == E_PASS ) {
CheckDirStruct();
FS_FILE_IO = TRUE;
stat = E_PASS;
}
if(FS_FILE_IO == FALSE) {
strcpy( FileDevice, DRV_SDRAM );
GUI_fileInfoPanelSelectMedia(GUI_MEDIA_SDRAM);
UART_sendString( UART0, "\r\n Memory cards not found. Data would be stored in SDRAM itself. " );
}
return stat;
}
STATUS SelectDevice(char *dev_name) {
STATUS stat=E_DEVICE;
sprintf( UART_outBuff, "\r\n Checking Memory Card in drive %s . Please wait ... ", dev_name );
UART_sendString( UART0, UART_outBuff );
if(strcmp(dev_name, DRV_CF)==0)
CF_ataInit();
if(strcmp(dev_name, DRV_SM)==0)
SM_ataInit();
if(strcmp(dev_name, DRV_SD)==0)
MMCSD_ataInit();
if(strcmp(dev_name, DRV_MS)==0)
;
FTBL_init();
if( CheckDevice( dev_name ) == E_PASS )
stat = E_PASS;
else {
sprintf( UART_outBuff, "\r\n WARNING : Drive %s not found.", dev_name );
UART_sendString(UART0, UART_outBuff );
}
return stat;
}
STATUS CheckDirStruct() {
UART_sendString( UART0, "\r\n Checking directory structure. Please wait ... " );
STILL_firstFile();
MOVIE_firstFile(MOVIE_MPEG4_MODE);
MOVIE_firstFile(MOVIE_MJPEG_MODE);
MP3_deviceNameSet(FileDevice);
UART_sendString( UART0, "\r\n Done.");
return E_PASS;
}
STATUS CheckDevice(char *dev_name) {
STATUS stat=E_DEVICE;
char TmpBasePath[32], TmpFileDevice[8];
AtaState *drive;
drive = FILE_getDrive(dev_name);
if(drive!=NULL) {
strcpy(TmpBasePath, BasePath);
strcpy(TmpFileDevice, FileDevice);
strcpy(FileDevice, dev_name);
sprintf(BasePath, "%s\\%s", dev_name, ROOT_DIR);
stat=FileNameGenInit();
if(stat==E_PASS) {
strcpy(FileDevice, dev_name);
sprintf( UART_outBuff, "\r\n Drive %s found. %s free space : %ld B", FileDevice, FileDevice, FS_diskFree(FileDevice) );
UART_sendString( UART0, UART_outBuff );
} else {
strcpy(BasePath, TmpBasePath);
strcpy(FileDevice, TmpFileDevice);
}
}
return stat;
}
Uint32 FS_diskFree(char *dev_name) {
AtaState *drive;
AtaError error;
drive = FILE_getDrive(dev_name);
if(drive!=NULL) {
return ATA_diskFree(drive, &error)*1024;
} else
return 0;
}
int FileIONotSupportedMessage() {
UART_sendString( UART0, "\r\n\n This option is not supported in this version of the Demo. \r\n\n" );
return 0;
}
AtaState *FILE_getDrive(char *name) {
if(strcmp(name, DRV_CF)==0)
return cfDrive;
if(strcmp(name, DRV_SM)==0)
return smDrive;
if(strcmp(name, DRV_SD)==0)
return mmcsdDrive;
if(strcmp(name, DRV_MS)==0)
return NULL;
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -