//----------------------------------------------------------------------------
///
///
///
//----------------------------------------------------------------------------


#include <fosh/command.h>
#include <biwak/sd.hpp>


class CCommandSd: public CCommand
{
   private:
      CSd &m_sd;
      enum ESubCommands
      {
         erase = 1,
         write,
         write2,
         read,
         info,
         scan,
      };

      static constexpr struct SSubCommands
      {
         const char *string;
         int id;
         int minArgs;
         int maxArgs;
         const char *argumentsHelpString;
         const char *helpString;
      }m_subCommands[]=
      {
         { "erase", (int)ESubCommands::erase, 0, 1, "[block]", "erase single block"},
         { "write", (int)ESubCommands::write, 0, 1, "[block]", "write single block"},
         { "w2", (int)ESubCommands::write2, 0, 1, "[block]", "write single block"},
         { "read" , (int)ESubCommands::read, 0, 1, "[block]", "read single block"},
         { "info" , (int)ESubCommands::info, 0, 0, "", "Show sd card info"},
         { "scan" , (int)ESubCommands::scan, 0, 0, "", "Scan whole card"},
      };

      static uint8_t m_data[0x200];

   public:
      CCommandSd( CSd &sd )
         :CCommand( "sd", "access sd card" )
         ,m_sd(sd)
      {}
      virtual int exec(int argc, const char *argv[]) const;
      virtual int execSubCommand(int id, int argc, const char *argv[]) const;
      int commandErase( int block ) const;
      int commandWrite( int block ) const;
      int commandWrite2( int block ) const;
      int commandRead( int block, bool dump=true ) const;
      int commandInfo(  ) const;
      int commandScan(  ) const;
      int optArg(int &dest, int argPos, int argc, const char *argv[]) const;
      virtual void printHelp() const;
};


//---fin----------------------------------------------------------------------
