/ src / tests / test_sdcard_read_directories.cpp
test_sdcard_read_directories.cpp
 1  #include "tests.h"
 2  
 3  #if defined(DEBUG)
 4  
 5  #include "nrf_log.h"
 6  #include "nrf_log_ctrl.h"
 7  
 8  #include "app/app_odiin.h"
 9  
10  void readDirectory(const char* dirName, int depth = 0)
11  {
12  	files::Fat32* SDCARD = app::Odiin::GetSdCard();
13  	files::Fat32Directory dir;
14  	if (SDCARD->DirectoryOpen(dir, dirName))
15  	{
16  		NRF_LOG_RAW_INFO("%s\t<dir>\r\n", nrf_log_push((char*)dirName));
17  
18  		files::Fat32FileInfo info;
19  		while (SDCARD->DirectoryRead(dir, info))
20  		{
21  			const char* readOnly = (info.fattrib & AM_RDO) ? "R" : " ";
22  			const char* hidden = (info.fattrib & AM_HID) ? "H" : " ";
23  			const char* system = (info.fattrib & AM_SYS) ? "S" : " ";
24  			bool directory = (info.fattrib & AM_DIR);
25  			const char* archive = (info.fattrib & AM_ARC) ? "A" : " ";
26  
27  			if (directory)
28  			{
29  				char recurseInto[256] = { 0 };
30  				snprintf(recurseInto, 256, "%s/%s", dirName, info.fname);
31  				readDirectory(recurseInto, depth+1);
32  			}
33  			else
34  			{
35  				for (int scan = 0; scan < depth; ++scan)
36  				{
37  					NRF_LOG_RAW_INFO("-");
38  				}
39  
40  				if (depth == 0)
41  				{
42  					NRF_LOG_RAW_INFO("/%s %s%s%s%s\r\n", nrf_log_push(info.fname), readOnly, hidden, system, archive);
43  				}
44  				else
45  				{
46  					NRF_LOG_RAW_INFO("%s/%s %s%s%s%s\r\n", nrf_log_push((char*)dirName), nrf_log_push(info.fname), readOnly, hidden, system, archive);
47  				}
48  			}
49  			NRF_LOG_FLUSH();
50  		}
51  
52  		SDCARD->DirectoryClose(dir);
53  	}
54  }
55  
56  void TEST_ReadDirectories()
57  {
58  	files::Fat32* SDCARD = app::Odiin::GetSdCard();
59  
60  	NRF_LOG_INFO("Starting TEST_ReadDirectories().");
61  	if (SDCARD->Mount())
62  	{
63  		NRF_LOG_RAW_INFO("\r\n\r\n");
64  		readDirectory(SDCARD->GetRootDirectory());
65  		NRF_LOG_RAW_INFO("\r\n\r\n");
66  	}
67  }
68  
69  #endif // DEBUG