Skip to content

Commit

Permalink
Add SDCARD_get_file_info
Browse files Browse the repository at this point in the history
  • Loading branch information
bessman committed Dec 4, 2023
1 parent e0e82df commit d6f594a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1
Undefined, Undefined, Undefined, Undefined,
},
{ // 14 SDCARD
// 0 1 READ_FILE 2 WRITE_FILE 3
Undefined, SDCARD_read_file, SDCARD_write_file, Undefined,
// 0 1 READ_FILE 2 WRITE_FILE 3 GET_FILE_INFO
Undefined, SDCARD_read_file, SDCARD_write_file, SDCARD_get_file_info,
// 4 5 6 7
Undefined, Undefined, Undefined, Undefined,
// 8 9 10 11
Expand Down
2 changes: 1 addition & 1 deletion src/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern "C" {
#define NUM_COMMON_CMDS 27
#define NUM_PASSTHRU_CMDS 1
#define NUM_SENSOR_CMDS 9
#define NUM_SDCARD_CMDS 2
#define NUM_SDCARD_CMDS 3
#define NUM_SECONDARY_CMDS_MAX NUM_COMMON_CMDS // Change if necessary.

/**
Expand Down
20 changes: 20 additions & 0 deletions src/sdcard/sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,23 @@ response_t SDCARD_read_file(void) {

return DO_NOT_BOTHER;
}

response_t SDCARD_get_file_info(void) {
TCHAR filename[SFN_MAX + SFN_SUFFIX_LEN + 1]; // +1 is null-terminator.
get_filename(filename, sizeof filename);

FATFS drive;
DEBUG_write_u8(f_mount(&drive, "0:", 1));

FILINFO info = {0, 0, 0, 0, {0}};
DEBUG_write_u8(f_stat(filename, &info));

UART1_write_u32(info.fsize);
UART1_WriteInt(info.fdate);
UART1_WriteInt(info.ftime);
UART1_Write(info.fattrib);

DEBUG_write_u8(f_mount(0, "0:", 0));

return SUCCESS;
}
18 changes: 18 additions & 0 deletions src/sdcard/sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,22 @@ response_t SDCARD_write_file(void);
*/
response_t SDCARD_read_file(void);

/**
* @brief Get metadata of file on SD-card.
*
* @details See documentation of FatFS FILINFO.
UART transaction order:
* Rx[1-12] filename
* <DEBUG> Tx[1] result_mount
* <DEBUG> Tx[1] result_stat
* Tx[4] data_size
* Tx[2] modification_date
* Tx[2] modification_time
* Tx[1] file_attributes
* <DEBUG> Tx[1] result_unmount
*
* @return SUCCESS
*/
response_t SDCARD_get_file_info(void);

#endif // _SDCARD_H

0 comments on commit d6f594a

Please sign in to comment.