📄 fs_shell.c
字号:
/*
** WASABI-Hot! version 1.2c
**
**
** -- copyright (c) 2001-2004 by Philips Japan, Ltd. -- All rights reserved --
**
**
** ** This code has been made to check/learn **
** ** the ISP1362/ISP1363 functionalities **
** ** Release 06-Aug-2004 **
**
** OKANO, Akifumi
**
** Application Laboratory, Mobile and Connectivity
** Semiconductors Div, Philips Japan Ltd.
** akifumi.okano@philips.com
** +81-3-3740-4668
*/
/****************************************************************************/
/* includes */
/****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include "general.h"
#include "_hc_core/dev_ep.h"
#include "class_dr/storage/fs.h"
#include "class_dr/storage/fs_shell.h"
#include "class_dr/storage/storage.h"
#include "_hc_cls/cls_hndl.h"
#include "ui.h"
/****************************************************************************/
/* constants */
/****************************************************************************/
#define COMM_STR_BUFFER_SIZE 16
#define MAX_COMMAND_TOKENS 30
#if 0
enum FSTS_COLORS {
FSTS_BLACK = (LIGHTGRAY << 4), // dark colors
FSTS_BLUE,
FSTS_GREEN,
FSTS_CYAN,
FSTS_RED,
FSTS_MAGENTA,
FSTS_BROWN,
FSTS_LIGHTGRAY,
FSTS_DARKGRAY, // light colors
FSTS_LIGHTBLUE,
FSTS_LIGHTGREEN,
FSTS_LIGHTCYAN,
FSTS_LIGHTRED,
FSTS_LIGHTMAGENTA,
FSTS_YELLOW,
FSTS_WHITE
};
#define FSTS_NORM FSTS_BLACK
#else
enum FSTS_COLORS {
FSTS_BLACK = 0, // dark colors
FSTS_BLUE,
FSTS_GREEN,
FSTS_CYAN,
FSTS_RED,
FSTS_MAGENTA,
FSTS_BROWN,
FSTS_LIGHTGRAY,
FSTS_DARKGRAY, // light colors
FSTS_LIGHTBLUE,
FSTS_LIGHTGREEN,
FSTS_LIGHTCYAN,
FSTS_LIGHTRED,
FSTS_LIGHTMAGENTA,
FSTS_YELLOW,
FSTS_WHITE
};
#define FSTS_NORM FSTS_LIGHTGRAY
#endif
/****************************************************************************/
/* global vars */
/****************************************************************************/
unsigned char g_file_system_test_shell_ON = False;
unsigned char g_comm_str_buffer_last = 0;
unsigned char g_comm_str_buffer_start = 0;
unsigned char g_comm_str_buffer_current = 0;
char g_comm_str_buffer[ COMM_STR_BUFFER_SIZE ][ MAX_PATH_STRING_LENGTH ]
= {
"", "", "", "",
"", "", "", "",
"", "", "", "",
"", "", "", ""
};
/****************************************************************************/
/* function prototypes */
/****************************************************************************/
static void go_into_fsts( void );
static void back_from_fsts( void );
static void file_system_test_shell_process( void );
static void fsts_ls( char *path );
static void format_file_name_for_screen( char *str, char *filename, char *suffix );
static unsigned char show_file_entry( directory_entry *entry_ptr );
static void fsts_cd( char *path );
static void fsts_rm( char **path, unsigned short n, unsigned char recursive );
static void fsts_mv( char *from, char *to );
static void fsts_mkdir( char **path, unsigned short n );
static void fsts_df( void );
static unsigned char split_command_string( char **token, char *string );
static void fsts_get( char *source_name, char *target_name );
static void fsts_put( char *source_name, char *target_name );
static void fsts_cp( char *source_name, char *target_name );
static void fsts_cs( char *str );
static void fsts_fat( char *str );
static void fsts_format( void );
static void show_fsts_help( void );
static unsigned short storage_play_fill( short *buffer_ptr );
static void storage_play_stop( void );
void fsts_stop( void );
static void fsts_test( void );
static void fsts_test1( char *source_name, char *target_name );
static void fsts_make1mb_local( char *target_name );
/****************************************************************************/
/* function definitions */
/****************************************************************************/
// FSTS
/*
==============================================================================
==============================================================================
==== Public function for file system access user interface
==== Function for APPLICATION side
==============================================================================
==============================================================================
*/
void fsts_file_system_test_shell( void )
{
storage_mount();
if ( NULL == storage_device_ready() )
{
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nStorage device not ready.\r\n" );
return;
}
if ( NULL == storage_volume_ready() )
{
mprintf( FSTS_LIGHTMAGENTA, CONTINUE, "\r\n Started to mount a volume\r\n" );
return;
}
go_into_fsts();
}
/*
==============================================================================
==============================================================================
==== Private functions for file system access user interface
==== Functions
==============================================================================
==============================================================================
*/
static void go_into_fsts( void )
{
unsigned char i;
gene_install_asynchronous_periodic_process( 6, file_system_test_shell_process );
g_file_system_test_shell_ON = True;
ui_show_current_time( False );
mprintf( (RED<<4) | WHITE, CONTINUE, "\r\nUser interface switched into file system test shell" );
mprintf( BLACK, CONTINUE, "\r\n" );
}
static void back_from_fsts( void )
{
unsigned char i;
gene_install_asynchronous_periodic_process( 6, gene_maintenance_process );
g_file_system_test_shell_ON = False;
ui_show_current_time( True );
mprintf( (RED<<4) | WHITE, CONTINUE, "\r\nUser interface come backed from file system test shell" );
mprintf( BLACK, CONTINUE, "\r\n" );
}
static void file_system_test_shell_process( void )
{
static unsigned short is_in_execution = False;
char comm_str[ MAX_PATH_STRING_LENGTH ] = " ";
char prompt[ MAX_PATH_STRING_LENGTH + 10 ];
char pwd[ MAX_PATH_STRING_LENGTH ];
char *token[ MAX_COMMAND_TOKENS ];
unsigned char n;
unsigned short key;
if ( is_in_execution )
return;
else
is_in_execution = True;
if ( (NULL == storage_device_ready()) || (NULL == storage_volume_ready()) )
back_from_fsts();
if ( ui_key_polling_timing() ) // Get timing to sample keyboard hit
{
// Process user command
//
// Showing prompt
//
mprintf( FSTS_WHITE, CONTINUE, "\r " );
fs_pwd( pwd );
sprintf( prompt, "[%u][%s] fsts% ", storage_device_address(), pwd );
ui_get_string_from_console( comm_str, MAX_PATH_STRING_LENGTH, FSTS_NORM, prompt, FSTS_LIGHTCYAN, 0, g_comm_str_buffer[ g_comm_str_buffer_current ], &key );
if ( (NULL == storage_device_ready()) || (NULL == storage_volume_ready()) )
back_from_fsts();
//
// Browsing history by up/down arrow key
//
if ( !(key & 0x00FF) )
{
if ( key == 0x4800 )
{
if (g_comm_str_buffer_current != g_comm_str_buffer_start)
g_comm_str_buffer_current = --g_comm_str_buffer_current & 0x0F;
mprintf( FSTS_WHITE, CONTINUE, "\r" );
is_in_execution = False;
return;
}
else if ( key == 0x5000 )
{
if (g_comm_str_buffer_current != g_comm_str_buffer_last)
g_comm_str_buffer_current = ++g_comm_str_buffer_current & 0x0F;
mprintf( FSTS_WHITE, CONTINUE, "\r" );
is_in_execution = False;
return;
}
}
//
// Storing command to history
//
if ( *comm_str != 'e' )
{
fs_data_copy( g_comm_str_buffer[ g_comm_str_buffer_last ], comm_str, MAX_PATH_STRING_LENGTH );
g_comm_str_buffer_last = ++g_comm_str_buffer_last & 0x0F;
if ( g_comm_str_buffer_last == g_comm_str_buffer_start )
g_comm_str_buffer_start = ++g_comm_str_buffer_start & 0x0F;
g_comm_str_buffer_current = g_comm_str_buffer_last;
*(g_comm_str_buffer[ g_comm_str_buffer_last ]) = 0;
}
//
// Parsing command
//
if ( *comm_str == 'e' )
back_from_fsts();
else if (*comm_str == '?')
show_fsts_help();
else if (*comm_str == 'i')
storage_info();
else if (*comm_str == 'i')
storage_info();
else if (*comm_str == 'h')
{
unsigned char i = g_comm_str_buffer_start;
while ( i != g_comm_str_buffer_last )
{
mprintf( FSTS_NORM, CONTINUE, "\r\n %s", g_comm_str_buffer[ i ] );
i++;
i &= 0xF;
}
}
else
{
n = split_command_string( token, comm_str );
if ( !strncmp( "ls", token[ 0 ], 2) )
{
if ( n == 1 )
fsts_ls( "" );
else if ( n == 2 )
fsts_ls( token[ 1 ] );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "cd", token[ 0 ], 2) )
{
if ( n == 2 )
fsts_cd( token[ 1 ] );
else if ( n == 1 )
{
mprintf( FSTS_LIGHTRED, CONTINUE, " -> pwd : " );
mprintf( FSTS_WHITE, CONTINUE, "\r\n%s", pwd );
}
else
mprintf( FSTS_LIGHTRED, CONTINUE, "check number of arguments" );
}
else if ( !strncmp( "rmr", token[ 0 ], 3) )
{
fsts_rm( token, n, True );
}
else if ( !strncmp( "rm", token[ 0 ], 2) )
{
fsts_rm( token, n, False );
}
else if ( !strncmp( "mv", token[ 0 ], 2) )
{
if ( n == 3 )
fsts_mv( token[ 1 ], token[ 2 ] );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "mkdir", token[ 0 ], 5) )
{
if ( 1 < n )
fsts_mkdir( token, n );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "df", token[ 0 ], 2) )
{
if ( 1 == n )
fsts_df();
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "pwd", token[ 0 ], 3) )
{
mprintf( FSTS_WHITE, CONTINUE, "\r\n%s\r\n", pwd );
}
else if ( !strncmp( "get", token[ 0 ], 3) )
{
if ( n == 2 )
fsts_get( token[ 1 ], token[ 1 ] );
else if ( n == 3 )
fsts_get( token[ 1 ], token[ 2 ] );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "put", token[ 0 ], 3) )
{
if ( n == 2 )
fsts_put( token[ 1 ], token[ 1 ] );
else if ( n == 3 )
fsts_put( token[ 1 ], token[ 2 ] );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "cp", token[ 0 ], 2) )
{
if ( n == 3 )
fsts_cp( token[ 1 ], token[ 2 ] );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "play", token[ 0 ], 4) )
{
if ( n == 2 )
fsts_play( token[ 1 ] );
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
else if ( !strncmp( "stop", token[ 0 ], 4) )
{
if ( n == 1 )
fsts_stop();
else
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\ncheck number of arguments" );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -