From 803e8f2bff1515918de6ec3ae46bd7c7e1e04e9a Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 13:11:11 +0200 Subject: [PATCH 1/9] Add SD Card Info to info.html --- code/components/jomjol_helper/CMakeLists.txt | 2 +- code/components/jomjol_helper/Helper.cpp | 235 ++++++++++++++++++- code/components/jomjol_helper/Helper.h | 12 +- code/main/main.cpp | 1 + code/main/server_main.cpp | 67 ++++++ sd-card/html/info.html | 78 ++++++ 6 files changed, 391 insertions(+), 4 deletions(-) diff --git a/code/components/jomjol_helper/CMakeLists.txt b/code/components/jomjol_helper/CMakeLists.txt index c57b54d3..8d9580d5 100644 --- a/code/components/jomjol_helper/CMakeLists.txt +++ b/code/components/jomjol_helper/CMakeLists.txt @@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "." - REQUIRES tflite-lib jomjol_logfile) + REQUIRES tflite-lib jomjol_logfile fatfs sdmmc) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 1c826430..57f97950 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -20,7 +20,8 @@ extern "C" { #include "ClassLogFile.h" -//#include "ClassLogFile.h" + +#include "esp_vfs_fat.h" static const char* TAG = "helper"; @@ -29,6 +30,9 @@ static const char* TAG = "helper"; using namespace std; +sdmmc_cid_t SDCardCid; +sdmmc_csd_t SDCardCsd; + ///////////////////////////////////////////////////////////////////////////////////////////// string getESPHeapInfo(){ string espInfoResultStr = ""; @@ -75,8 +79,100 @@ size_t getInternalESPHeapSize() { return aFreeInternalHeapSize; } +string getSDCardPartitionSize(){ + FATFS *fs; + uint32_t fre_clust, tot_sect; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + tot_sect = ((fs->n_fatent - 2) * fs->csize) /1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + + printf("%d MB total drive space (Sector size [bytes]: %d)\n", (int)tot_sect, (int)fs->csize*512); + + return std::to_string(tot_sect); +} + +string getSDCardFreeParitionSpace(){ + FATFS *fs; + uint32_t fre_clust, fre_sect; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + + printf("%d MB free drive space (Sector size [bytes]: %d)\n", (int)fre_sect, (int)fs->ssize); + + return std::to_string(fre_sect); +} + +string getSDCardParitionAllocationSize(){ + FATFS *fs; + uint32_t fre_clust, allocation_size; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + allocation_size = fs->ssize; + + printf("SD Card Parition Allocation Size (bytes): %d)\n", allocation_size); + + return std::to_string(allocation_size); +} +void SaveSDCardInfo(sdmmc_card_t* card) { + SDCardCid = card->cid; + SDCardCsd = card->csd; +} + +string getSDCardManufacturer(){ + string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id); + printf("SD Card Manufactuer: %s\n", SDCardManufacturer.c_str()); + + return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")"); +} + +string getSDCardName(){ + char *SDCardName = SDCardCid.name; + printf("SD Card Name: %s\n", SDCardName); + + return std::string(SDCardName); +} + +string getSDCardCapacity(){ + int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) + printf("SD Card Capacity: %s\n", std::to_string(SDCardCapacity).c_str()); + + return std::to_string(SDCardCapacity); +} + +string getSDCardSectorSize(){ + int SDCardSectorSize = SDCardCsd.sector_size; + printf("SD Card Sector Size: %s\n", std::to_string(SDCardSectorSize).c_str()); + + return std::to_string(SDCardSectorSize); +} + +/* + int SDCardManu = card->cid.mfg_id; + printf("SD Manu: %s\n", std::to_string(SDCardManu).c_str()); + + printf("SD Manu (ASCII): %s\n", SDCardParseManufacturerIDs(card->cid.mfg_id).c_str()); + + int SDCardOEM = card->cid.oem_id; + printf("SD OEM: %s\n", std::to_string(SDCardOEM).c_str()); + + int SDCardRev = card->cid.revision; + printf("SD Rev: %s\n", std::to_string(SDCardRev).c_str()); + + char *SDCardName = card->cid.name; + printf("SD Name: %s\n", SDCardName); + + int SDCardCSize = card->csd.sector_size; + printf("SD C-Size: %s\n", std::to_string(SDCardCSize).c_str()); + + int SDCardCapa = card->csd.capacity / (1024/card->csd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) + printf("SD Capa: %s\n", std::to_string(SDCardCapa).c_str()); +*/ /////////////////////////////////////////////////////////////////////////////////////////////// @@ -462,7 +558,6 @@ int removeFolder(const char* folderPath, const char* logTag) { } - std::vector HelperZerlegeZeile(std::string input, std::string _delimiter = "") { std::vector Output; @@ -487,3 +582,139 @@ std::vector HelperZerlegeZeile(std::string input, std::string _delimiter return Output; } + +/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ +/* SD Card Manufacturer Database */ +struct SDCard_Manufacturer_database { + string type; + int id; + string manufacturer; +}; + +/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ +/* SD Card Manufacturer Database */ +struct SDCard_Manufacturer_database database[] = { + { + .type = "sd", + .id = 0x01, + .manufacturer = "Panasonic", + }, + { + .type = "sd", + .id = 0x02, + .manufacturer = "Toshiba/Kingston/Viking", + }, + { + .type = "sd", + .id = 0x03, + .manufacturer = "SanDisk", + }, + { + .type = "sd", + .id = 0x08, + .manufacturer = "Silicon Power", + }, + { + .type = "sd", + .id = 0x18, + .manufacturer = "Infineon", + }, + { + .type = "sd", + .id = 0x1b, + .manufacturer = "Transcend/Samsung", + }, + { + .type = "sd", + .id = 0x1c, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x1d, + .manufacturer = "Corsair/AData", + }, + { + .type = "sd", + .id = 0x1e, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x1f, + .manufacturer = "Kingston", + }, + { + .type = "sd", + .id = 0x27, + .manufacturer = "Delkin/Phison", + }, + { + .type = "sd", + .id = 0x28, + .manufacturer = "Lexar", + }, + { + .type = "sd", + .id = 0x30, + .manufacturer = "SanDisk", + }, + { + .type = "sd", + .id = 0x31, + .manufacturer = "Silicon Power", + }, + { + .type = "sd", + .id = 0x33, + .manufacturer = "STMicroelectronics", + }, + { + .type = "sd", + .id = 0x41, + .manufacturer = "Kingston", + }, + { + .type = "sd", + .id = 0x6f, + .manufacturer = "STMicroelectronics", + }, + { + .type = "sd", + .id = 0x74, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x76, + .manufacturer = "Patriot", + }, + { + .type = "sd", + .id = 0x82, + .manufacturer = "Gobe/Sony", + }, + { + .type = "sd", + .id = 0x89, + .manufacturer = "Unknown", + } +}; + +/* Parse SD Card Manufacturer Database */ +string SDCardParseManufacturerIDs(int id) +{ + unsigned int id_cnt = sizeof(database) / sizeof(struct SDCard_Manufacturer_database); + string ret_val = ""; + + for (int i = 0; i < id_cnt; i++) { + if (database[i].id == id) { + return database[i].manufacturer; + } + else { + ret_val = "ID unknown (not in DB)"; + } + } + return ret_val; +} + diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index a84fe8d1..b530f446 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -2,7 +2,7 @@ #include #include #include - +#include "sdmmc_cmd.h" using namespace std; @@ -47,3 +47,13 @@ size_t getESPHeapSize(); string getESPHeapInfo(); ///////////////////////////// +string getSDCardPartitionSize(); +string getSDCardFreeParitionSpace(); +string getSDCardParitionAllocationSize(); + +void SaveSDCardInfo(sdmmc_card_t* card); +string SDCardParseManufacturerIDs(int); +string getSDCardManufacturer(); +string getSDCardName(); +string getSDCardCapacity(); +string getSDCardSectorSize(); diff --git a/code/main/main.cpp b/code/main/main.cpp index 01be3146..5436c7c6 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -112,6 +112,7 @@ bool Init_NVS_SDCard() return false; } sdmmc_card_print_info(stdout, card); + SaveSDCardInfo(card); return true; } diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index d60b2aa1..555089ee 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -17,6 +17,8 @@ #include "esp_log.h" +#include "helper.h" + //#define DEBUG_DETAIL_ON @@ -136,6 +138,71 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } + if (_task.compare("SDCardPartitionSize") == 0) + { + std::string zw; + zw = getSDCardPartitionSize(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardFreeParitionSpace") == 0) + { + std::string zw; + zw = getSDCardFreeParitionSpace(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardPartitionSectorSize") == 0) + { + std::string zw; + zw = getSDCardParitionAllocationSize(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardManufacturer") == 0) + { + std::string zw; + zw = getSDCardManufacturer(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardName") == 0) + { + std::string zw; + zw = getSDCardName(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardCapacity") == 0) + { + std::string zw; + zw = getSDCardCapacity(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardSectorSize") == 0) + { + std::string zw; + zw = getSDCardSectorSize(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + + return ESP_OK; } diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 2ad7c351..ffcfad3c 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -77,6 +77,84 @@ div { + + +

SD Card Info

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ SD Card Manufacturer: + +
+ +
+
+ SD Card Name: + +
+ +
+
+ SD Card Size [MB]: + +
+ +
+
+ SD Card Sector Size [byte]: + +
+ +
+
+ Partition Size [MB]: + +
+ +
+
+ Partition Free Space [MB]: + +
+ +
+
+ Partition Allocation Size [byte]: + +
+ +
+
+ + +

Version Info

From 4150c31b984c71d5de99f2edcf98c7cfe403b425 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 13:17:02 +0200 Subject: [PATCH 2/9] Add SD Card Info to info.html --- code/components/jomjol_helper/Helper.cpp | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 57f97950..334444dd 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -152,28 +152,6 @@ string getSDCardSectorSize(){ return std::to_string(SDCardSectorSize); } -/* - int SDCardManu = card->cid.mfg_id; - printf("SD Manu: %s\n", std::to_string(SDCardManu).c_str()); - - printf("SD Manu (ASCII): %s\n", SDCardParseManufacturerIDs(card->cid.mfg_id).c_str()); - - int SDCardOEM = card->cid.oem_id; - printf("SD OEM: %s\n", std::to_string(SDCardOEM).c_str()); - - int SDCardRev = card->cid.revision; - printf("SD Rev: %s\n", std::to_string(SDCardRev).c_str()); - - char *SDCardName = card->cid.name; - printf("SD Name: %s\n", SDCardName); - - int SDCardCSize = card->csd.sector_size; - printf("SD C-Size: %s\n", std::to_string(SDCardCSize).c_str()); - - int SDCardCapa = card->csd.capacity / (1024/card->csd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) - printf("SD Capa: %s\n", std::to_string(SDCardCapa).c_str()); -*/ - /////////////////////////////////////////////////////////////////////////////////////////////// void memCopyGen(uint8_t* _source, uint8_t* _target, int _size) From 2a54d9b8891d39db7d477c4708cb99f989a6dd7a Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 19:30:37 +0200 Subject: [PATCH 3/9] Name adjustment --- code/main/server_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 555089ee..abb8626d 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -156,7 +156,7 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardPartitionSectorSize") == 0) + if (_task.compare("SDCardParitionAllocationSize") == 0) { std::string zw; zw = getSDCardParitionAllocationSize(); From 0adfc45d36e300a054ef22a0eb5e5590b38cd3e3 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 19:35:51 +0200 Subject: [PATCH 4/9] Name adjustment --- sd-card/html/info.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/info.html b/sd-card/html/info.html index ffcfad3c..4beda452 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -146,7 +146,7 @@ div { Partition Allocation Size [byte]: From 2b810ca32d77d07e8f1af66c33f497aabb311c57 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 20:27:21 +0200 Subject: [PATCH 5/9] Name adjustment --- code/components/jomjol_helper/Helper.cpp | 6 +++--- code/components/jomjol_helper/Helper.h | 4 ++-- code/main/server_main.cpp | 6 +++--- sd-card/html/info.html | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 334444dd..cf7b4d5e 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -92,7 +92,7 @@ string getSDCardPartitionSize(){ return std::to_string(tot_sect); } -string getSDCardFreeParitionSpace(){ +string getSDCardFreePartitionSpace(){ FATFS *fs; uint32_t fre_clust, fre_sect; @@ -105,7 +105,7 @@ string getSDCardFreeParitionSpace(){ return std::to_string(fre_sect); } -string getSDCardParitionAllocationSize(){ +string getSDCardPartitionAllocationSize(){ FATFS *fs; uint32_t fre_clust, allocation_size; @@ -113,7 +113,7 @@ string getSDCardParitionAllocationSize(){ f_getfree("0:", (DWORD *)&fre_clust, &fs); allocation_size = fs->ssize; - printf("SD Card Parition Allocation Size (bytes): %d)\n", allocation_size); + printf("SD Card Partition Allocation Size (bytes): %d)\n", allocation_size); return std::to_string(allocation_size); } diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index b530f446..8d7c2cf0 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -48,8 +48,8 @@ string getESPHeapInfo(); ///////////////////////////// string getSDCardPartitionSize(); -string getSDCardFreeParitionSpace(); -string getSDCardParitionAllocationSize(); +string getSDCardFreePartitionSpace(); +string getSDCardPartitionAllocationSize(); void SaveSDCardInfo(sdmmc_card_t* card); string SDCardParseManufacturerIDs(int); diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index abb8626d..bb519093 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -147,7 +147,7 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardFreeParitionSpace") == 0) + if (_task.compare("SDCardFreePartitionSpace") == 0) { std::string zw; zw = getSDCardFreeParitionSpace(); @@ -156,10 +156,10 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardParitionAllocationSize") == 0) + if (_task.compare("SDCardPartitionAllocationSize") == 0) { std::string zw; - zw = getSDCardParitionAllocationSize(); + zw = getSDCardPartitionAllocationSize(); httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr_chunk(req, NULL); return ESP_OK; diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 4beda452..7dbd7ee1 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -137,7 +137,7 @@ div { From dbf8e634d9a4a1242082edeff0f1c198395ec47c Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 20:29:32 +0200 Subject: [PATCH 6/9] Name adjustment --- code/main/server_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index bb519093..9f679a6f 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -150,7 +150,7 @@ esp_err_t info_get_handler(httpd_req_t *req) if (_task.compare("SDCardFreePartitionSpace") == 0) { std::string zw; - zw = getSDCardFreeParitionSpace(); + zw = getSDCardFreePartitionSpace(); httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr_chunk(req, NULL); return ESP_OK; From d3e195df9fa590d4d08ad4a356c8e5bbc5222e90 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 20:31:17 +0200 Subject: [PATCH 7/9] Name adjustment --- sd-card/html/info.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 7dbd7ee1..afd87843 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -136,7 +136,7 @@ div { Partition Free Space [MB]: From 3a999358b90e3e497f61552950bee5e130e03c0d Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 23:14:44 +0200 Subject: [PATCH 8/9] correct case sensitivity of include --- code/main/server_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 9f679a6f..64a82e65 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -17,7 +17,7 @@ #include "esp_log.h" -#include "helper.h" +#include "Helper.h" //#define DEBUG_DETAIL_ON From f65b2850a22cc19ac075e389dd4f6387ab51f7c5 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 23:14:44 +0200 Subject: [PATCH 9/9] correct case sensitivity of include --- code/main/server_main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 64a82e65..b2a38307 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -16,7 +16,6 @@ #include "server_tflite.h" #include "esp_log.h" - #include "Helper.h" //#define DEBUG_DETAIL_ON
-
+
- +
-
+