📄 fs_shell.c
字号:
{
mprintf( WHITE, CONTINUE, "can't open file \"%s\"\r\n", orig );
return ( 1 );
}
if ( NULL == (fc = fopen( copied, "rb" )) )
{
mprintf( WHITE, CONTINUE, "can't open file \"%s\"\r\n", copied );
fclose( fo );
return ( 1 );
}
// while ( orig_sz = fread( bo, 1, 10240, fo ) )
while ( 0 != (orig_sz = fread( bo, 1, 10240, fo )) )
{
mprintf( FSTS_NORM, CONTINUE, "file checking... %lu\r", proc_sz );
if ( orig_sz != fread( bc, 1, 10240, fc ) )
{
mprintf( FSTS_NORM, CONTINUE, "file size doesn't match\r\n" );
fclose( fo );
fclose( fc );
return ( 1 );
}
for ( i = 0; i < orig_sz; i++ )
{
// if ( *bo++ != *bc++ )
if ( bo[ i ] != bc[ i ] )
{
mprintf( FSTS_NORM, CONTINUE, "file contents doesn't match\r\n" );
fclose( fo );
fclose( fc );
return ( 1 );
}
}
proc_sz += orig_sz;
}
mprintf( FSTS_NORM, CONTINUE, "file checking... %lu\r\n", proc_sz );
fclose( fo );
fclose( fc );
return ( 0 );
}
static void fsts_test1( char *source_name, char *target_name )
{
fs_FILE *fs_fp;
unsigned char bp[ RW_BUFFER_SIZE ];
unsigned short i;
unsigned short size;
unsigned long total = 0;
clock_t t_meas;
if ( NULL == (fs_fp = fs_fopen( source_name, R )) )
{
mprintf( FSTS_NORM, CONTINUE, "\r\nerror : file open @ fs_fopen( \"%s\", R )\r\n", source_name );
return;
}
mprintf( FSTS_NORM, CONTINUE, "\r\nreading file USB:\"%s\" >> local:\"%s\"\r\n", source_name, target_name );
t_meas = clock();
// while ( size = fs_read( fs_fp, bp, RW_BUFFER_SIZE ) )
while ( 0 != (size = fs_read( fs_fp, bp, RW_BUFFER_SIZE )) )
total += size;
t_meas = clock() - t_meas;
if ( t_meas )
mprintf( FSTS_NORM, CONTINUE, "read %ld bytes %.2f sec %.2f B/sec\r", total += size, (double)t_meas / (double)CLK_TCK, (double)total / ((double)t_meas / (double)CLK_TCK) );
fs_fclose( fs_fp );
}
static void fsts_make1mb_local( char *target_name )
{
FILE *fo;
unsigned char bp[ 1024 ];
unsigned short i;
unsigned short size;
for ( i = 0; i < 1024; i++ )
bp[ i ] = (unsigned char)i;
if ( NULL == (fo = fopen( target_name, "wb" )) )
{
mprintf( FSTS_NORM, CONTINUE, "\r\nerror : local file open to write : \"%s\"\r\n", target_name );
return;
}
for ( i = 0; i < 1024; i++ )
fwrite( bp, 1, 1024, fo );
fclose( fo );
}
static void fsts_get( char *source_name, char *target_name )
{
FILE *fo;
fs_FILE *fs_fp;
unsigned char bp[ RW_BUFFER_SIZE ];
unsigned short i;
unsigned short size;
unsigned long total = 0;
clock_t t_meas;
if ( NULL == (fo = fopen( target_name, "wb" )) )
{
mprintf( FSTS_NORM, CONTINUE, "\r\nerror : local file open to write : \"%s\"\r\n", target_name );
return;
}
if ( NULL == (fs_fp = fs_fopen( source_name, R )) )
{
mprintf( FSTS_NORM, CONTINUE, "\r\nerror : file open @ fs_fopen( \"%s\", R )\r\n", source_name );
fclose( fo );
return;
}
mprintf( FSTS_NORM, CONTINUE, "\r\ngetting file USB:\"%s\" >> local:\"%s\"\r\n", source_name, target_name );
t_meas = clock();
// while ( size = fs_read( fs_fp, bp, RW_BUFFER_SIZE ) )
while ( 0 != (size = fs_read( fs_fp, bp, RW_BUFFER_SIZE )) )
{
fwrite( bp, 1, size, fo );
mprintf( FSTS_NORM, CONTINUE, "reading... %ld bytes\r", total += size );
wait_ms( 0 );
}
t_meas = clock() - t_meas;
if ( t_meas )
mprintf( FSTS_NORM, CONTINUE, "read %ld bytes %.2f sec %.2f B/sec\r", total += size, (double)t_meas / (double)CLK_TCK, (double)total / ((double)t_meas / (double)CLK_TCK) );
fclose( fo );
fs_fclose( fs_fp );
}
static void fsts_put( char *source_name, char *target_name )
{
FILE *fi;
fs_FILE *fs_fp;
unsigned char bp[ RW_BUFFER_SIZE ];
unsigned long i;
unsigned short size;
unsigned short written_size;
unsigned long total = 0;
clock_t t_meas;
if ( NULL == (fi = fopen( source_name, "rb" )) )
{
mprintf( FSTS_NORM, CONTINUE, "\r\nerror : local file open to read : \"%s\"\r\n", source_name );
return;
}
if ( NULL == (fs_fp = fs_fopen( target_name, W )) )
{
mprintf( FSTS_NORM, CONTINUE, "\r\nerror : file open @ fs_fopen( \"%s\", W )\r\n", target_name );
fclose( fi );
return;
}
mprintf( FSTS_NORM, CONTINUE, "\r\nputting file local:\"%s\" >> USB:\"%s\"\r\n", source_name, target_name );
t_meas = clock();
// while ( size = fread( bp, 1, RW_BUFFER_SIZE, fi ) )
while ( 0 != (size = fread( bp, 1, RW_BUFFER_SIZE, fi )) )
{
if ( size != (written_size = fs_write( fs_fp, bp, size )) )
{
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nno space for more data. (%u)\r\n", written_size );
debug_error++;
break;
}
mprintf( FSTS_NORM, CONTINUE, "writing... %ld bytes\r", total += size );
wait_ms( 0 );
}
t_meas = clock() - t_meas;
if ( t_meas )
mprintf( FSTS_NORM, CONTINUE, "written %ld bytes %.2f sec %.2f B/sec\r", total += size, (double)t_meas / (double)CLK_TCK, (double)total / ((double)t_meas / (double)CLK_TCK) );
fclose( fi );
fs_fclose( fs_fp );
}
static void fsts_cp( char *source_name, char *target_name )
{
fs_FILE *fi;
fs_FILE *fo;
unsigned char bp[ RW_BUFFER_SIZE ];
unsigned long i;
unsigned short size;
unsigned long total = 0;
clock_t t_meas;
if ( NULL == (fi = fs_fopen( source_name, R )) )
{
mprintf( FSTS_NORM, CONTINUE, "\r\nerror : file open @ fs_fopen( \"%s\", R )\r\n", source_name );
return;
}
if ( NULL == (fo = fs_fopen( target_name, W )) )
{
mprintf( FSTS_NORM, CONTINUE, "\r\nerror : file open @ fs_fopen( \"%s\", W )\r\n", target_name );
fs_fclose( fi );
return;
}
mprintf( FSTS_NORM, CONTINUE, "\r\ncopying file \"%s\" >> \"%s\"\r\n", source_name, target_name );
t_meas = clock();
// while ( size = fs_read( fi, bp, RW_BUFFER_SIZE ) )
while ( 0 != (size = fs_read( fi, bp, RW_BUFFER_SIZE )) )
{
if ( size != fs_write( fo, bp, size ) )
{
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nno space for more data\r\n" );
break;
}
mprintf( FSTS_NORM, CONTINUE, "copying... %ld bytes\r", total += size );
}
t_meas = clock() - t_meas;
if ( t_meas )
mprintf( FSTS_NORM, CONTINUE, "copied %ld bytes %.2f sec %.2f bytes/sec\r", total += size, (double)t_meas / (double)CLK_TCK, (double)total / ((double)t_meas / (double)CLK_TCK) );
fs_fclose( fi );
fs_fclose( fo );
}
static void fsts_cs( char *str )
{
unsigned long s;
unsigned short v;
sscanf( str, "%X", &v );
s = fs_cluster_to_sector( v );
mprintf( FSTS_NORM, CONTINUE, "\r\ncluster : %s ... sector : %lu (0x%08lX)\r\n", str, s, s );
}
static void fsts_fat( char *str )
{
unsigned short start;
unsigned short i;
sscanf( str, "%X", &start );
start /= 8;
mprintf( FSTS_LIGHTGRAY, CONTINUE, "\r\nFAT view from 0x%04X", start );
for ( i = start; i < (start + 64); i++ )
{
if ( !(i % 8) )
mprintf( FSTS_LIGHTGRAY, CONTINUE, "\r\n 0x%04X -", i );
mprintf( FSTS_WHITE, CONTINUE, " %04X", fs_read_FAT( i ) );
}
mprintf( FSTS_LIGHTGRAY, CONTINUE, "\r\n" );
}
static void fsts_format( void )
{
device_instance *dvi_ptr;
storage_instance *si_ptr;
dvi_ptr = storage_device_ready();
si_ptr = (storage_instance *)(dvi_ptr->class_instance_ptr);
if ( si_ptr->volume_instance[ 0 ] )
fs_volume_close( si_ptr->volume_instance[ 0 ] );
si_ptr->volume_instance[ 0 ] = NULL;
mprintf( FSTS_LIGHTGRAY, CONTINUE, "\r\nformatting..." );
fs_format();
mprintf( LIGHTGRAY, CONTINUE, "done\r\n" );
si_ptr->volume_instance[ 0 ] = fs_volume_open();
}
#define hp( x ) mprintf( FSTS_YELLOW, CONTINUE, " %-7s", x )
#define np( x ) mprintf( FSTS_NORM, CONTINUE, ": %-28s", x )
#define br mprintf( FSTS_NORM, CONTINUE, "\r\n" )
static void show_fsts_help( void )
{
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nHelp!\r\n" );
hp( "e" ); np( "exit form shell" ); hp( "?" ); np( "help view" ); br;
hp( "h" ); np( "view command history" ); hp( "i" ); np( "volume information" ); br;
hp( "ls" ); np( "list of directory" ); hp( "cd" ); np( "change directory" ); br;
hp( "pwd" ); np( "print working directory" ); hp( "mkdir" ); np( "make directory" ); br;
hp( "mv" ); np( "move directory/file" ); hp( "rm" ); np( "remove directory/file" ); br;
hp( "df" ); np( "free disk space" ); hp( "cp" ); np( "copy file" ); br;
hp( "put" ); np( "file beam up (to USB)" ); hp( "get" ); np( "file beam dwon (fm USB)" );br;
hp( "play" ); np( "WAV play on USB spkr" ); hp( "format" ); np( "format disk" ); br;
hp( "dump" ); np( "dump sector contents" ); hp( "cs" ); np( "convert cluster->sector" );br;
hp( "up/down arrow keys" ); np( "browse history" );
}
//////////
//////////
////////// Audio play testing
//////////
//////////
#include "class_dr/audio/sing.h"
fs_FILE *g_play_source_file;
unsigned long g_fsts_play_total;
static unsigned short storage_play_fill( short *buffer_ptr )
{
unsigned short read_size;
read_size = fs_read( g_play_source_file, (unsigned char *)buffer_ptr, (MEMORY_FILLING_SIZE_FROM_FILE << 1) );
return ( read_size >> 1 ); // size convert from bytes to short
}
static void storage_play_stop( void )
{
if ( g_play_source_file )
fs_fclose( g_play_source_file );
g_play_source_file = NULL;
mprintf( FSTS_NORM, CONTINUE, " strage play end. audio file closed.\r\n" );
}
void fsts_play( char *path )
{
device_instance *dvi_ptr;
if ( is_audio_active() )
return;
if ( NULL == (g_play_source_file = fs_fopen( path, R )) )
{
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nerror : file open @ fs_fopen( \"%s\", R )\r\n", path );
return;
}
if ( NULL == (dvi_ptr = devep_find_class_interface( AUDIO_CLASS_INTERFACE, 0 )) )
{
mprintf( FSTS_LIGHTRED, CONTINUE, "\r\nerror : audio device is not ready.\r\n", path );
fs_fclose( g_play_source_file );
g_play_source_file = NULL;
return ;
}
if ( 0 != audio_initialize( dvi_ptr, "*", storage_play_fill, storage_play_stop ) )
return;
audio_start();
}
void fsts_stop( void )
{
// if ( !is_audio_active() )
// return;
// audio_start();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -