Ejemplo n.º 1
0
//! @brief This function displays the disk space of current drive
//!
void ushell_cmd_space( void )
{
   uint32_t u32_space;
   // Display drive letter name (a, b...)
   fputs( mem_name(nav_drive_get()), stdout);
   putchar(' ');
   putchar( nav_drive_get()+'a');
   // Otherwise use fast command
   u32_space = nav_partition_space();
   if( 1024 >(u32_space % (2*1024)) )
   {
      u32_space = u32_space/(2*1024);
   }else{
      u32_space = (u32_space/(2*1024))+1;
   }
   printf(": space: %luMB \n\r", u32_space );
}
static __inline__ uint8_t navauto_mov_ok_loop(bool b_direction, navauto_mov_options_t options)
{
  bool b_ok_loop = false;

  // If mode Disks, it should go to the next/previous disk
  if (g_navauto_exp_mode == NAVAUTO_MODE_DISKS)
  {
    // Mount the next/previous disk
    do
    {
      if (b_direction == FS_FIND_NEXT)
      {
        // Go to the next drive
        if (!nav_drive_set(nav_drive_get() + 1))
        {
          nav_drive_set(0);
          b_ok_loop = true;
        }
      }
      else // direction PREVIOUS
      {
        // Go to the previous drive
        if (!nav_drive_set(nav_drive_get() - 1))
        {
          nav_drive_set(nav_drive_nb() - 1);
          b_ok_loop = true;
        }
      }
    }while(!nav_partition_mount());

    // If it reached a limit
    if (b_ok_loop)
    {
      navauto_mov_explorer_rec(b_direction, options);
      return NAVAUTO_MOV_OK_LOOP;
    }

    // Else return the result of the recursive function
    return navauto_mov_explorer_rec(b_direction, options);
  }

  return NAVAUTO_MOV_OK_LOOP;
}
Ejemplo n.º 3
0
//! @brief This function manages the ls command
//!
//! @param  b_more  enable the '|more' management when true otherwise no '|more' management
//!
void ushell_cmd_ls( bool b_more )
{
   uint8_t str_char[MAX_FILE_PATH_LENGTH];
   uint16_t u16_i,u16_nb_file,u16_nb_dir,last_i;
   uint8_t ext_filter=false;

   //** Print drive name
   printf("%c: volume is %s\r\n", 'a'+nav_drive_get(), mem_name(nav_drive_get()) );
   printf("Drive uses ");
   switch (nav_partition_type())
   {
      case FS_TYPE_FAT_12:
      printf("FAT12\n\r");
      break;

      case FS_TYPE_FAT_16:
      printf("FAT16\n\r");
      break;

      case FS_TYPE_FAT_32:
      printf("FAT32\n\r");
      break;

      default:
      printf("an unknown partition type\r\n");
      return;
   }

   //** Print directory name
   if( !nav_dir_name( (FS_STRING)str_char, MAX_FILE_PATH_LENGTH ) )
      return;
   printf("Dir name is %s\n\r",str_char);

   //** Check extension filter in extra parameters
   if(g_s_arg[0][0]!=0)
   {
      if(g_s_arg[0][0] == '*' && g_s_arg[0][1]=='.')
      {
         ext_filter=true;
         for(u16_i=2; u16_i<USHELL_SIZE_CMD_LINE; u16_i++)
         {
            g_s_arg[0][u16_i-2]=g_s_arg[0][u16_i];
         }
      }
   }

   //** Print files list
   printf("          Size  Name\n\r");
   // Init loop at the beginning of directory
   nav_filelist_reset();
   u16_nb_file=0;
   u16_nb_dir=0;
   last_i=0;
   // For each file in list
   while( nav_filelist_set(0,FS_FIND_NEXT) )
   {
      if(!ext_filter)
      {
         // No extension filter
         if( nav_file_isdir() )
         {
            printf("Dir ");
            u16_nb_dir++;              // count the number of directory
         }else{
            printf("    ");
         }
      }
      else
      {
         // If extension filter then ignore directories
         if(nav_file_isdir())
            continue;
         // Check extension
         if(!nav_file_checkext((FS_STRING)g_s_arg[0]))
            continue;
      }
      u16_nb_file++;                   // count the total of files (directories and files)

      // Check 'more' step
      if( b_more && ((u16_nb_file%USHELL_NB_LINE)==0) && (u16_nb_file!=0) && (last_i != u16_nb_file) )
      {
         last_i=u16_nb_file;
         if( !ushell_more_wait() )
            return;  // Exit LS command
      }

      // Display file
      nav_file_name((FS_STRING)str_char, MAX_FILE_PATH_LENGTH, FS_NAME_GET, true);
      printf("%10lu  %s\n\r", nav_file_lgt(), str_char);
   }
   // Display total number
   printf(" %4i Files\r\n", u16_nb_file-u16_nb_dir );
   printf(" %4i Dir\r\n", u16_nb_dir );
}
Ejemplo n.º 4
0
//! @brief Perform transfer between two devices
//!
void ushell_cmd_perform( void )
{
   Fs_index sav_index;
   Fs_file_segment seg1, seg2;

   if( g_s_arg[0][0] == 0 )
      return;

   sav_index = nav_getindex();   // Save the position

   // Alloc a file on each devices
   printf("Alloc a file on each devices\n\r");
   seg1 = ushell_cmd_perform_alloc( (g_s_arg[0][0]-'a') , FILE_ALLOC_SIZE );
   if( seg1.u16_size == 0 )
   {
      printf("!!!Error allocation on device 1\n\r");
      // Restore the position
      nav_gotoindex(&sav_index);
      return;
   }
   if( g_s_arg[1][0] != 0 )
   {
      nav_select( FS_NAV_ID_COPYFILE );
      seg2 = ushell_cmd_perform_alloc( (g_s_arg[1][0]-'a') , FILE_ALLOC_SIZE );
      if( seg2.u16_size == 0 )
      {
         nav_select( FS_NAV_ID_USHELL_CMD );
         file_close();
         nav_file_del(false);
         printf("!!!Error allocation on device 2\n\r");
         // Restore the position
         nav_gotoindex(&sav_index);
         return;
      }

      // Transfer data from device 1 to device 2
      printf("Transfer data from device 1 to device 2\r\n");
      ushell_cmd_perform_transfer(seg1,seg2);
      printf("Transfer data from device 2 to device 1\r\n");
      ushell_cmd_perform_transfer(seg2,seg1);
      // Delete files allocated
      nav_select( FS_NAV_ID_COPYFILE );
      file_close();
      nav_file_del(false);
      nav_select( FS_NAV_ID_USHELL_CMD );
   }
   else
   {
      ushell_cmd_perform_access( false, seg1 );
      ushell_cmd_perform_access( true, seg1 );
      if( LUN_ID_USB <= nav_drive_get() )
      {
         printf("Transfer large buffer on USB\r\n");
         ushell_cmd_perform_extaccess( false, seg1 );
         ushell_cmd_perform_extaccess( true, seg1 );
      }

   }

   file_close();
   nav_file_del(false);
   // Restore the position
   nav_gotoindex(&sav_index);
   printf("End of test\n\r");
   return;
}