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

📄 file_name_gen.c

📁 dm270 source code
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------\
@ModuleName  :: file_name_gen.c

@Description :: Routines to Generate file names for a camera system

    Directory Structure for a camera system

    / ( Device Root )
	|
    + - DCIM    ( Base Directory )
          |
          + - DM270_00  ( Manufacturer Directories )
          |       |
          |       + - IMG_0000.JPG or MVI_0000.MOV  ( Image or Movie Files )
          |       ...           ...
          |       + - IMG_0099.JPG or MVI_0099.MOV
          |
          |
          + - DM270_01
          |       |
          |       + - IMG_0100.JPG or MVI_0100.MOV
          |       ...           ...
          |       + - IMG_0199.JPG or MVI_0199.MOV
          |
          ...   ...
          |
          + - DM270_99
                  |
                  + - IMG_9900.JPG or MVI_9900.MOV
                  ...           ...
                  + - IMG_9999.JPG or MVI_9999.MOV



@Copyright   :: Copyright 2001- Texas Instruments, Inc.

@History     ::
-------------------------------------------------------------------------------

    Dec.  26, 2001  Kedar C (kedarc@ti.com) Start


\-----------------------------------------------------------------------------*/


/*  include files   */

#include <system/uart270.h>
#include <demo/ui.h>

#include <util/file_name_gen.h>

#include <demo_gui/demo_gui.h>

#include <fileio/fileio.h>
#include <fileio/ata_init.h>

#include <appl/still.h>
#include <appl/movie_main.h>
#include <appl/mp3_play.h>

BOOL FS_FILE_IO=FALSE;

static char BasePath[32];       /*  CFC:/DCIM   */

static int curIndex = -1;       /* last generated file name index   */

char FileDevice[8]="SDRAM";




/*-----------------------------------------------------------------------------\
@RoutineName :: FileNameGenInit

@Description ::
    Check device for directory structure.
    If no dir structure found create it.
    Initialize 'curIndex' to last generated file name index

    Should be called each time device ( disks ) are changed.

@Parameters  ::
    NONE

@Return      ::
    E_PASS,     success
    E_DEVICE,  failure
\-----------------------------------------------------------------------------*/
STATUS FileNameGenInit() {
    AtaChar unicodeName[40]; 
	char	name[40];
	int		stat;
	AtaFile  fileInfo, *pCurFile;


	pCurFile = &fileInfo;

	// name contains drive name, get drive info and switch to root dir
	stat = FILE_gotoRootDir( pCurFile, FileDevice);
	
	if(stat!=E_PASS)
		return E_DEVICE;

	stat = FILE_searchDir( pCurFile, ROOT_DIR);

	if(stat!=E_PASS) {
		// root directory not found, create it.
		charToUnicode( ROOT_DIR, unicodeName );

		if( ATA_setLongDirectoryName(pCurFile, unicodeName) != ATA_ERROR_NONE )
			return E_DEVICE;

		if( ATA_createDirectoryLong(pCurFile, unicodeName ) != ATA_ERROR_NONE )
			return E_DEVICE;

		stat = FILE_searchDir(pCurFile, ROOT_DIR);
		if(stat!=E_PASS)
			return E_DEVICE;
	} 

	// change to root directory
	if( ATA_cd( pCurFile ) != ATA_ERROR_NONE )
		return E_DEVICE;
	
    {
        int len;
        int num, maxnum=-1;

        len = strlen( DIR_PREFIX );

		
		stat = ATA_findFirst( pCurFile );
        while( stat == ATA_ERROR_NONE ) {

			if( ATA_isDir(pCurFile) ) {
	          	ATA_getLongName( pCurFile, unicodeName, 0, 20 );
				unicodeToChar( unicodeName, name);

				sprintf( UART_outBuff, "\r\n  %s", name);
				UART_sendString( UART0, UART_outBuff );

				if( memcmp(name, DIR_PREFIX, len) == 0 ) {
					num = atoi( name + len );
					if( num > maxnum )
						maxnum=num;
				}
			}
			stat = ATA_findNext( pCurFile );
        }

        if( maxnum == -1 ) {
            sprintf(name,"%s\\%s\\%s%d%d", FileDevice, ROOT_DIR, DIR_PREFIX, 0/10, 0%10);
            
            sprintf( UART_outBuff, "\r\n   Creating %s\n", name);
			UART_sendString( UART0, UART_outBuff );

			sprintf(name,"%s%d%d", DIR_PREFIX, 0/10, 0%10);

			// No directories found, create it. "DM270_00".
			charToUnicode( name, unicodeName );

			if( ATA_setLongDirectoryName(pCurFile, unicodeName) != ATA_ERROR_NONE )
				return E_DEVICE;

			if( ATA_createDirectoryLong(pCurFile, unicodeName ) != ATA_ERROR_NONE )
				return E_DEVICE;			
            
			FILE_driveFlush(pCurFile);

            curIndex = -1;
            return E_PASS;
        }

        sprintf( name, "%s%d%d", DIR_PREFIX, maxnum/10, maxnum%10);
        stat = FILE_searchDir( pCurFile, name );

        if( stat != E_PASS )
            return E_DEVICE;

		// change to root directory
		if( ATA_cd( pCurFile ) != ATA_ERROR_NONE )
			return E_DEVICE;

        curIndex = ( maxnum*100 ) - 1;
        maxnum = -1;
        len = strlen( IMG_PREFIX );

		stat = ATA_findFirst( pCurFile );
        while( stat == ATA_ERROR_NONE ) {
			
			if( !ATA_isDir(pCurFile) ) {
	          	ATA_getLongName( pCurFile, unicodeName, 0, 20 );
				unicodeToChar( unicodeName, name);

				sprintf( UART_outBuff, "\r\n  %s", name);
				UART_sendString( UART0, UART_outBuff );

				if(     memcmp(name, IMG_PREFIX, len) == 0
					||  memcmp(name, MJPEG_PREFIX, len) == 0
					||  memcmp(name, H263_PREFIX, len) == 0
					||  memcmp(name, MPEG4_PREFIX, len) == 0
					) {
					num = atoi( name + len );
					if( num > maxnum )
						maxnum=num;
				}
			}
			stat = ATA_findNext( pCurFile );
        }
        if( maxnum != -1 )
            curIndex = maxnum;
    }

    /*  */
    return E_PASS;
}

/*-----------------------------------------------------------------------------\
@RoutineName :: NewFileName

@Description ::
    Generate a new file name and update 'curIndex'

@Parameters  ::
    char *fname     ::  The new file name generated
    int *index      ::  *index is set to the new curIndex value
    FILE_TYPE type  ::  The type of file name to be generated i.e IMG_XXYY.JPG or MVI_XXYY.MOV

@Return      ::
    E_PASS,     success
    E_DEVICE,  failure
\-----------------------------------------------------------------------------*/
STATUS NewFileName( char *fname, int *index, FILE_TYPE type) {
	AtaChar unicodeName[40]; 
	char	name[40];
	AtaFile  fileInfo;
    int dirnum;
    char prefix[20];
	int stat;
	
    curIndex++;
    dirnum=curIndex/100;

    switch( type ) {
        case MPEG4_FILE :
            strcpy(prefix, MPEG4_PREFIX);
            break;
        case H263_FILE :
            strcpy(prefix, H263_PREFIX);
            break;
        case IMG_FILE :
            strcpy(prefix, IMG_PREFIX);
            break;
        case MJPEG_FILE :
            strcpy(prefix, MJPEG_PREFIX);
            break;
    }

    /* check if dir is present, if not create   */
	stat = FILE_gotoRootDir( &fileInfo, FileDevice );
	if(stat!=E_PASS)
		return E_DEVICE;
    
	stat = FILE_searchDir( &fileInfo, ROOT_DIR );
	if(stat!=E_PASS)
		return E_DEVICE;

	// change to root directory
	if( ATA_cd( &fileInfo ) != ATA_ERROR_NONE )
		return E_DEVICE;

	sprintf(name,"%s%d%d", DIR_PREFIX, dirnum/10, dirnum%10);
	stat = FILE_searchDir( &fileInfo, name );
    if( stat != E_PASS ) {
		charToUnicode( name, unicodeName );

		if( ATA_setLongDirectoryName(&fileInfo, unicodeName) != ATA_ERROR_NONE )
			return E_DEVICE;

		if( ATA_createDirectoryLong(&fileInfo, unicodeName ) != ATA_ERROR_NONE )
			return E_DEVICE;			
    }

    /*  */
    if( GenFileName( fname, curIndex , type ) != E_PASS )
        return E_DEVICE;

    *index = curIndex;
    return E_PASS;
}

/*-----------------------------------------------------------------------------\
@RoutineName :: GetNextIndex

@Description ::
    Gets the next index for a given file type relative to a given current index
    Used to iterate through the files in the directory structure for a particular file type

@Parameters  ::
    int *index      ::  the given current index is passed as input , the prev file index is returned
    FILE_TYPE type  ::  the file type ( see FileNameGen.h )

@Return      ::
    E_PASS,     success
    E_DEVICE,  failure
\-----------------------------------------------------------------------------*/


STATUS GetNextIndex(int *index, FILE_TYPE type ) {
	char path[50];
    int i;
	FILE_ID	*fp;

    i=*index;
    while(1) {
        i++;
        if( i > curIndex )
            return E_DEVICE;
        GenFileName(path, i, type);
		fp = FILE_open(path, "rb", 0);
		if(fp!=NULL) {
			FILE_close(fp, 0);
			break;
		}
    }

    *index = i;

    return E_PASS;
}

/*-----------------------------------------------------------------------------\
@RoutineName :: GetPrevIndex

@Description ::
    Gets the previous index for a given file type relative to a given current index
    Used to iterate through the files in the directory structure for a particular file type

@Parameters  ::
    int *index      ::  the given current index is passed as input , the previous file index is returned
    FILE_TYPE type  ::  the file type ( see FileNameGen.h )

@Return      ::
    E_PASS,     success
    E_DEVICE,  failure
\-----------------------------------------------------------------------------*/
STATUS GetPrevIndex(int *index, FILE_TYPE type ) {
    char path[50];
    int i;
	FILE_ID *fp;

    i=*index;
    while(1) {
        i--;
        if( i < 0 )
            return E_DEVICE;

        GenFileName(path, i, type);
		fp = FILE_open(path, "rb", 0);
		if(fp!=NULL) {
			FILE_close(fp, 0);
			break;

⌨️ 快捷键说明

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