Advertisement
Guest User

AtomComments

a guest
Jul 17th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. /*
  2.     LIST: This command LIST directories and FILES.
  3.     Parameters include:
  4.     LIST D... LF
  5.  
  6.     D... = Directory to start at. "/" is root (UP TO 126 BYTES + SPACE)
  7.     LF = LINE FEED (1 BYTE 0x0A)
  8.  
  9.     EXAMPLE: LIST / 0x0A
  10.  
  11.     The above example will return: C [X LF]
  12.     C = Count of directories Found
  13.     X = Directory/File Name
  14.     LF = LINE FEED (0x0A)
  15.  
  16.     Example: If your root has 3 folders [FOLD1]-[FOLD2]-[FOLD3] and 1 file [HELLO.TXT]
  17.     LIST / 0x0A
  18.     Will return:
  19.     0x04 FOLD1 0x0A FOLD2 0x0A FOLD3 0x0A HELLO.TXT 0x0A
  20. */
  21.     if(strncmp(CMD[LIST],RX_CMD,4) == 0)    //Send out directory listing
  22.     {
  23.         res = scan_files(RX_ARG,ALL_T);
  24.         return;
  25.     }
  26. /*
  27.     LIFI: This command list FILES ONLY.
  28.     Parameters include:
  29.     LIFI D... LF
  30.  
  31.     D... = Directory to start at. "/" is root (UP TO 126 BYTES + SPACE)
  32.     LF = LINE FEED (1 BYTE 0x0A)
  33.  
  34.     EXAMPLE: LIFI / 0x0A
  35.  
  36.     The above example will return: C [X LF]
  37.     C = Count of directories Found
  38.     X = File Name
  39.     LF = LINE FEED (0x0A)
  40.  
  41.     Example: If your root has 3 folders [FOLD1]-[FOLD2]-[FOLD3] and 1 file [HELLO.TXT]
  42.     LIFI / 0x0A
  43.     Will return:
  44.     0x01 HELLO.TXT 0x0A
  45. */
  46.     if(strncmp(CMD[LIST_FILES],RX_CMD,4) == 0)  //Send out directory listing
  47.     {
  48.         res = scan_files(RX_ARG,FILE_T);
  49.         return;
  50.     }
  51. /*
  52.     LIDI: This command LIST directories only.
  53.     Parameters include:
  54.     LIDI D... LF
  55.  
  56.     D... = Directory to start at. "/" is root (UP TO 126 BYTES + SPACE)
  57.     LF = LINE FEED (1 BYTE 0x0A)
  58.  
  59.     EXAMPLE: LIDI / 0x0A
  60.  
  61.     The above example will return: C [X LF]
  62.     C = Count of directories Found
  63.     X = Directory Name
  64.     LF = LINE FEED (0x0A)
  65.  
  66.     Example: If your root has 3 folders [FOLD1]-[FOLD2]-[FOLD3] and 1 file [HELLO.TXT]
  67.     LIDI / 0x0A
  68.     Will return:
  69.     0x03 FOLD1 0x0A FOLD2 0x0A FOLD3 0x0A
  70.  
  71. */
  72.     if(strncmp(CMD[LIST_DIRS],RX_CMD,4) == 0)   //Send out directory listing
  73.     {
  74.         res = scan_files(RX_ARG,DIR_T);
  75.         return;
  76.     }
  77. /*
  78.     READ: This command reads a file.
  79.     Parameters include:
  80.     READ SSSS C F... LF
  81.  
  82.     SSSS = Seek Location, where to start when getting data (4 BYTES + SPACE)
  83.     C = Count of bytes to return, MAX 128 (1 BYTE + SPACE)
  84.     F... = FILE NAME (UP TO 120 BYTES + SPACE)
  85.     LF = LINE FEED (1 BYTE 0x0A)
  86.  
  87.     EXAMPLE: READ 0000 10 HELLO.TXT 0x0A
  88.  
  89.     The above example will return the first 10 bytes in the file HELLO.TXT
  90. */
  91.     if(strncmp(CMD[READ],RX_CMD,4) == 0)    //Read data from a file
  92.     {
  93.         SeekPosition = RX_ARG[3] + (RX_ARG[2] << 8)+ (RX_ARG[1] << 16)+ (RX_ARG[0] << 24);
  94.         Bytes2Read = RX_ARG[5];
  95.         res = f_open(&fsrc,(RX_ARG+7),FA_READ);
  96.  
  97.         memset(Buffer,0,128);
  98.  
  99.         res = f_lseek(&fsrc,SeekPosition);
  100.         res = f_read(&fsrc,Buffer, Bytes2Read, &br);    /* Read a chunk of src file */
  101.  
  102.         RWC[0] = br;        //Get how many actual bytes were read.
  103.         UART_TX(RWC[0]);    //inform the user how many bytes to expect after this
  104.         UART_BUFF(Buffer,br);   //Send the buffer.
  105.  
  106.         return;
  107.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement