Helper.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. //#pragma warning(disable : 4996)
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "Helper.h"
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include <dirent.h>
  11. #ifdef __cplusplus
  12. }
  13. #endif
  14. #include <string.h>
  15. #include <esp_log.h>
  16. #include "ClassLogFile.h"
  17. #include "esp_vfs_fat.h"
  18. static const char* TAG = "helper";
  19. //#define ISWINDOWS_TRUE
  20. #define PATH_MAX_STRING_SIZE 256
  21. using namespace std;
  22. sdmmc_cid_t SDCardCid;
  23. sdmmc_csd_t SDCardCsd;
  24. /////////////////////////////////////////////////////////////////////////////////////////////
  25. string getESPHeapInfo(){
  26. string espInfoResultStr = "";
  27. char aMsgBuf[80];
  28. multi_heap_info_t aMultiHead_info ;
  29. heap_caps_get_info (&aMultiHead_info,MALLOC_CAP_8BIT);
  30. size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT);
  31. size_t aMinFreeHeadSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT);
  32. size_t aMinFreeHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT);
  33. size_t aHeapLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
  34. sprintf(aMsgBuf," Free Heap Size: %ld", (long) aFreeHeapSize);
  35. size_t aFreeSPIHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_SPIRAM);
  36. size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
  37. size_t aMinFreeInternalHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
  38. sprintf(aMsgBuf," Heap: %ld", (long) aFreeHeapSize);
  39. espInfoResultStr += string(aMsgBuf);
  40. sprintf(aMsgBuf," Min Free: %ld", (long) aMinFreeHeapSize);
  41. espInfoResultStr += string(aMsgBuf);
  42. sprintf(aMsgBuf," larg. Block: %ld", (long) aHeapLargestFreeBlockSize);
  43. espInfoResultStr += string(aMsgBuf);
  44. sprintf(aMsgBuf," SPI Heap: %ld", (long) aFreeSPIHeapSize);
  45. espInfoResultStr += string(aMsgBuf);
  46. sprintf(aMsgBuf," Min Free Heap Size: %ld", (long) aMinFreeHeadSize);
  47. sprintf(aMsgBuf," NOT_SPI Heap: %ld", (long) (aFreeHeapSize - aFreeSPIHeapSize));
  48. espInfoResultStr += string(aMsgBuf);
  49. sprintf(aMsgBuf," largest Block Size: %ld", (long) aHeapLargestFreeBlockSize);
  50. sprintf(aMsgBuf," Internal Heap: %ld", (long) (aFreeInternalHeapSize));
  51. espInfoResultStr += string(aMsgBuf);
  52. sprintf(aMsgBuf," Internal Min Heap free: %ld", (long) (aMinFreeInternalHeapSize));
  53. espInfoResultStr += string(aMsgBuf);
  54. return espInfoResultStr;
  55. }
  56. size_t getESPHeapSize(){
  57. size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT);
  58. return aFreeHeapSize;
  59. }
  60. size_t getInternalESPHeapSize() {
  61. size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
  62. return aFreeInternalHeapSize;
  63. }
  64. string getSDCardPartitionSize(){
  65. FATFS *fs;
  66. uint32_t fre_clust, tot_sect;
  67. /* Get volume information and free clusters of drive 0 */
  68. f_getfree("0:", (DWORD *)&fre_clust, &fs);
  69. 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
  70. printf("%d MB total drive space (Sector size [bytes]: %d)\n", (int)tot_sect, (int)fs->csize*512);
  71. return std::to_string(tot_sect);
  72. }
  73. string getSDCardFreeParitionSpace(){
  74. FATFS *fs;
  75. uint32_t fre_clust, fre_sect;
  76. /* Get volume information and free clusters of drive 0 */
  77. f_getfree("0:", (DWORD *)&fre_clust, &fs);
  78. fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB
  79. printf("%d MB free drive space (Sector size [bytes]: %d)\n", (int)fre_sect, (int)fs->ssize);
  80. return std::to_string(fre_sect);
  81. }
  82. string getSDCardParitionAllocationSize(){
  83. FATFS *fs;
  84. uint32_t fre_clust, allocation_size;
  85. /* Get volume information and free clusters of drive 0 */
  86. f_getfree("0:", (DWORD *)&fre_clust, &fs);
  87. allocation_size = fs->ssize;
  88. printf("SD Card Parition Allocation Size (bytes): %d)\n", allocation_size);
  89. return std::to_string(allocation_size);
  90. }
  91. void SaveSDCardInfo(sdmmc_card_t* card) {
  92. SDCardCid = card->cid;
  93. SDCardCsd = card->csd;
  94. }
  95. string getSDCardManufacturer(){
  96. string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id);
  97. printf("SD Card Manufactuer: %s\n", SDCardManufacturer.c_str());
  98. return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")");
  99. }
  100. string getSDCardName(){
  101. char *SDCardName = SDCardCid.name;
  102. printf("SD Card Name: %s\n", SDCardName);
  103. return std::string(SDCardName);
  104. }
  105. string getSDCardCapacity(){
  106. int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024)
  107. printf("SD Card Capacity: %s\n", std::to_string(SDCardCapacity).c_str());
  108. return std::to_string(SDCardCapacity);
  109. }
  110. string getSDCardSectorSize(){
  111. int SDCardSectorSize = SDCardCsd.sector_size;
  112. printf("SD Card Sector Size: %s\n", std::to_string(SDCardSectorSize).c_str());
  113. return std::to_string(SDCardSectorSize);
  114. }
  115. /*
  116. int SDCardManu = card->cid.mfg_id;
  117. printf("SD Manu: %s\n", std::to_string(SDCardManu).c_str());
  118. printf("SD Manu (ASCII): %s\n", SDCardParseManufacturerIDs(card->cid.mfg_id).c_str());
  119. int SDCardOEM = card->cid.oem_id;
  120. printf("SD OEM: %s\n", std::to_string(SDCardOEM).c_str());
  121. int SDCardRev = card->cid.revision;
  122. printf("SD Rev: %s\n", std::to_string(SDCardRev).c_str());
  123. char *SDCardName = card->cid.name;
  124. printf("SD Name: %s\n", SDCardName);
  125. int SDCardCSize = card->csd.sector_size;
  126. printf("SD C-Size: %s\n", std::to_string(SDCardCSize).c_str());
  127. int SDCardCapa = card->csd.capacity / (1024/card->csd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024)
  128. printf("SD Capa: %s\n", std::to_string(SDCardCapa).c_str());
  129. */
  130. ///////////////////////////////////////////////////////////////////////////////////////////////
  131. void memCopyGen(uint8_t* _source, uint8_t* _target, int _size)
  132. {
  133. for (int i = 0; i < _size; ++i)
  134. *(_target + i) = *(_source + i);
  135. }
  136. FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec)
  137. {
  138. FILE *pfile;
  139. ESP_LOGD(TAG, "open file %s in mode %s", nm, _mode);
  140. if ((pfile = fopen(nm, _mode)) != NULL) {
  141. ESP_LOGD(TAG, "File %s successfully opened", nm);
  142. }
  143. else {
  144. ESP_LOGD(TAG, "Error: file %s does not exist!", nm);
  145. return NULL;
  146. }
  147. /*
  148. if (pfile == NULL)
  149. {
  150. TickType_t xDelay;
  151. xDelay = _waitsec * 1000 / portTICK_PERIOD_MS;
  152. std::string zw = "File is locked: " + std::string(nm) + " - wait for " + std::to_string(_waitsec) + " seconds";
  153. LogFile.WriteToFile(zw);
  154. vTaskDelay( xDelay );
  155. pfile = fopen(nm, _mode);
  156. }
  157. */
  158. return pfile;
  159. }
  160. std::string FormatFileName(std::string input)
  161. {
  162. #ifdef ISWINDOWS_TRUE
  163. input.erase(0, 1);
  164. std::string os = "/";
  165. std::string ns = "\\";
  166. FindReplace(input, os, ns);
  167. #endif
  168. return input;
  169. }
  170. void FindReplace(std::string& line, std::string& oldString, std::string& newString) {
  171. const size_t oldSize = oldString.length();
  172. // do nothing if line is shorter than the string to find
  173. if (oldSize > line.length()) return;
  174. const size_t newSize = newString.length();
  175. for (size_t pos = 0; ; pos += newSize) {
  176. // Locate the substring to replace
  177. pos = line.find(oldString, pos);
  178. if (pos == std::string::npos) return;
  179. if (oldSize == newSize) {
  180. // if they're same size, use std::string::replace
  181. line.replace(pos, oldSize, newString);
  182. }
  183. else {
  184. // if not same size, replace by erasing and inserting
  185. line.erase(pos, oldSize);
  186. line.insert(pos, newString);
  187. }
  188. }
  189. }
  190. void MakeDir(std::string _what)
  191. {
  192. // chdir(_where.c_str());
  193. if (mkdir(_what.c_str(), S_IRWXU|S_IRWXG|S_IROTH))
  194. ESP_LOGD(TAG, "Problem with MakeDir: %s", _what.c_str());
  195. }
  196. bool ctype_space(const char c, string adddelimiter)
  197. {
  198. if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == 11)
  199. {
  200. return true;
  201. }
  202. if (adddelimiter.find(c) != string::npos)
  203. return true;
  204. return false;
  205. }
  206. string trim(string istring, string adddelimiter)
  207. {
  208. bool trimmed = false;
  209. if (ctype_space(istring[istring.length() - 1], adddelimiter))
  210. {
  211. istring.erase(istring.length() - 1);
  212. trimmed = true;
  213. }
  214. if (ctype_space(istring[0], adddelimiter))
  215. {
  216. istring.erase(0, 1);
  217. trimmed = true;
  218. }
  219. if ((trimmed == false) || (istring.size() == 0))
  220. {
  221. return istring;
  222. }
  223. else
  224. {
  225. return trim(istring, adddelimiter);
  226. }
  227. }
  228. size_t findDelimiterPos(string input, string delimiter)
  229. {
  230. size_t pos = std::string::npos;
  231. size_t zw;
  232. string akt_del;
  233. for (int anz = 0; anz < delimiter.length(); ++anz)
  234. {
  235. akt_del = delimiter[anz];
  236. if ((zw = input.find(akt_del)) != std::string::npos)
  237. {
  238. if (pos != std::string::npos)
  239. {
  240. if (zw < pos)
  241. pos = zw;
  242. }
  243. else
  244. pos = zw;
  245. }
  246. }
  247. return pos;
  248. }
  249. void RenameFile(string from, string to)
  250. {
  251. // ESP_LOGI(logTag, "Deleting file : %s", fn.c_str());
  252. /* Delete file */
  253. FILE* fpSourceFile = OpenFileAndWait(from.c_str(), "rb");
  254. if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
  255. {
  256. ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", from.c_str());
  257. return;
  258. }
  259. fclose(fpSourceFile);
  260. rename(from.c_str(), to.c_str());
  261. }
  262. void DeleteFile(string fn)
  263. {
  264. // ESP_LOGI(logTag, "Deleting file : %s", fn.c_str());
  265. /* Delete file */
  266. FILE* fpSourceFile = OpenFileAndWait(fn.c_str(), "rb");
  267. if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
  268. {
  269. ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", fn.c_str());
  270. return;
  271. }
  272. fclose(fpSourceFile);
  273. unlink(fn.c_str());
  274. }
  275. void CopyFile(string input, string output)
  276. {
  277. input = FormatFileName(input);
  278. output = FormatFileName(output);
  279. if (toUpper(input).compare("/SDCARD/WLAN.INI") == 0)
  280. {
  281. ESP_LOGD(TAG, "wlan.ini kann nicht kopiert werden!");
  282. return;
  283. }
  284. char cTemp;
  285. FILE* fpSourceFile = OpenFileAndWait(input.c_str(), "rb");
  286. if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
  287. {
  288. ESP_LOGD(TAG, "File %s existiert nicht!", input.c_str());
  289. return;
  290. }
  291. FILE* fpTargetFile = OpenFileAndWait(output.c_str(), "wb");
  292. // Code Section
  293. // Read From The Source File - "Copy"
  294. while (fread(&cTemp, 1, 1, fpSourceFile) == 1)
  295. {
  296. // Write To The Target File - "Paste"
  297. fwrite(&cTemp, 1, 1, fpTargetFile);
  298. }
  299. // Close The Files
  300. fclose(fpSourceFile);
  301. fclose(fpTargetFile);
  302. ESP_LOGD(TAG, "File copied: %s to %s", input.c_str(), output.c_str());
  303. }
  304. string getFileFullFileName(string filename)
  305. {
  306. size_t lastpos = filename.find_last_of('/');
  307. if (lastpos == string::npos)
  308. return "";
  309. // ESP_LOGD(TAG, "Last position: %d", lastpos);
  310. string zw = filename.substr(lastpos + 1, filename.size() - lastpos);
  311. return zw;
  312. }
  313. string getDirectory(string filename)
  314. {
  315. size_t lastpos = filename.find('/');
  316. if (lastpos == string::npos)
  317. lastpos = filename.find('\\');
  318. if (lastpos == string::npos)
  319. return "";
  320. // ESP_LOGD(TAG, "Directory: %d", lastpos);
  321. string zw = filename.substr(0, lastpos - 1);
  322. return zw;
  323. }
  324. string getFileType(string filename)
  325. {
  326. size_t lastpos = filename.rfind(".", filename.length());
  327. size_t neu_pos;
  328. while ((neu_pos = filename.find(".", lastpos + 1)) > -1)
  329. {
  330. lastpos = neu_pos;
  331. }
  332. if (lastpos == string::npos)
  333. return "";
  334. string zw = filename.substr(lastpos + 1, filename.size() - lastpos);
  335. zw = toUpper(zw);
  336. return zw;
  337. }
  338. /* recursive mkdir */
  339. int mkdir_r(const char *dir, const mode_t mode) {
  340. char tmp[PATH_MAX_STRING_SIZE];
  341. char *p = NULL;
  342. struct stat sb;
  343. size_t len;
  344. /* copy path */
  345. len = strnlen (dir, PATH_MAX_STRING_SIZE);
  346. if (len == 0 || len == PATH_MAX_STRING_SIZE) {
  347. return -1;
  348. }
  349. memcpy (tmp, dir, len);
  350. tmp[len] = '\0';
  351. /* remove trailing slash */
  352. if(tmp[len - 1] == '/') {
  353. tmp[len - 1] = '\0';
  354. }
  355. /* check if path exists and is a directory */
  356. if (stat (tmp, &sb) == 0) {
  357. if (S_ISDIR (sb.st_mode)) {
  358. return 0;
  359. }
  360. }
  361. /* recursive mkdir */
  362. for(p = tmp + 1; *p; p++) {
  363. if(*p == '/') {
  364. *p = 0;
  365. /* test path */
  366. if (stat(tmp, &sb) != 0) {
  367. /* path does not exist - create directory */
  368. if (mkdir(tmp, mode) < 0) {
  369. return -1;
  370. }
  371. } else if (!S_ISDIR(sb.st_mode)) {
  372. /* not a directory */
  373. return -1;
  374. }
  375. *p = '/';
  376. }
  377. }
  378. /* test path */
  379. if (stat(tmp, &sb) != 0) {
  380. /* path does not exist - create directory */
  381. if (mkdir(tmp, mode) < 0) {
  382. return -1;
  383. }
  384. } else if (!S_ISDIR(sb.st_mode)) {
  385. /* not a directory */
  386. return -1;
  387. }
  388. return 0;
  389. }
  390. string toUpper(string in)
  391. {
  392. for (int i = 0; i < in.length(); ++i)
  393. in[i] = toupper(in[i]);
  394. return in;
  395. }
  396. string toLower(string in)
  397. {
  398. for (int i = 0; i < in.length(); ++i)
  399. in[i] = tolower(in[i]);
  400. return in;
  401. }
  402. // CPU Temp
  403. extern "C" uint8_t temprature_sens_read();
  404. float temperatureRead()
  405. {
  406. return (temprature_sens_read() - 32) / 1.8;
  407. }
  408. time_t addDays(time_t startTime, int days) {
  409. struct tm* tm = localtime(&startTime);
  410. tm->tm_mday += days;
  411. return mktime(tm);
  412. }
  413. int removeFolder(const char* folderPath, const char* logTag) {
  414. ESP_LOGI(logTag, "Delete folder %s", folderPath);
  415. DIR *dir = opendir(folderPath);
  416. if (!dir) {
  417. ESP_LOGI(logTag, "Failed to stat dir : %s", folderPath);
  418. return -1;
  419. }
  420. struct dirent *entry;
  421. int deleted = 0;
  422. while ((entry = readdir(dir)) != NULL) {
  423. std::string path = string(folderPath) + "/" + entry->d_name;
  424. if (entry->d_type == DT_REG) {
  425. if (unlink(path.c_str()) == 0) {
  426. deleted ++;
  427. } else {
  428. ESP_LOGE(logTag, "can't delete file : %s", path.c_str());
  429. }
  430. } else if (entry->d_type == DT_DIR) {
  431. deleted += removeFolder(path.c_str(), logTag);
  432. }
  433. }
  434. closedir(dir);
  435. if (rmdir(folderPath) != 0) {
  436. ESP_LOGE(logTag, "can't delete file : %s", folderPath);
  437. }
  438. ESP_LOGI(logTag, "%d older log files in folder %s deleted.", deleted, folderPath);
  439. return deleted;
  440. }
  441. std::vector<string> HelperZerlegeZeile(std::string input, std::string _delimiter = "")
  442. {
  443. std::vector<string> Output;
  444. std::string delimiter = " =,";
  445. if (_delimiter.length() > 0){
  446. delimiter = _delimiter;
  447. }
  448. input = trim(input, delimiter);
  449. size_t pos = findDelimiterPos(input, delimiter);
  450. std::string token;
  451. while (pos != std::string::npos) {
  452. token = input.substr(0, pos);
  453. token = trim(token, delimiter);
  454. Output.push_back(token);
  455. input.erase(0, pos + 1);
  456. input = trim(input, delimiter);
  457. pos = findDelimiterPos(input, delimiter);
  458. }
  459. Output.push_back(input);
  460. return Output;
  461. }
  462. /* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */
  463. /* SD Card Manufacturer Database */
  464. struct SDCard_Manufacturer_database {
  465. string type;
  466. int id;
  467. string manufacturer;
  468. };
  469. /* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */
  470. /* SD Card Manufacturer Database */
  471. struct SDCard_Manufacturer_database database[] = {
  472. {
  473. .type = "sd",
  474. .id = 0x01,
  475. .manufacturer = "Panasonic",
  476. },
  477. {
  478. .type = "sd",
  479. .id = 0x02,
  480. .manufacturer = "Toshiba/Kingston/Viking",
  481. },
  482. {
  483. .type = "sd",
  484. .id = 0x03,
  485. .manufacturer = "SanDisk",
  486. },
  487. {
  488. .type = "sd",
  489. .id = 0x08,
  490. .manufacturer = "Silicon Power",
  491. },
  492. {
  493. .type = "sd",
  494. .id = 0x18,
  495. .manufacturer = "Infineon",
  496. },
  497. {
  498. .type = "sd",
  499. .id = 0x1b,
  500. .manufacturer = "Transcend/Samsung",
  501. },
  502. {
  503. .type = "sd",
  504. .id = 0x1c,
  505. .manufacturer = "Transcend",
  506. },
  507. {
  508. .type = "sd",
  509. .id = 0x1d,
  510. .manufacturer = "Corsair/AData",
  511. },
  512. {
  513. .type = "sd",
  514. .id = 0x1e,
  515. .manufacturer = "Transcend",
  516. },
  517. {
  518. .type = "sd",
  519. .id = 0x1f,
  520. .manufacturer = "Kingston",
  521. },
  522. {
  523. .type = "sd",
  524. .id = 0x27,
  525. .manufacturer = "Delkin/Phison",
  526. },
  527. {
  528. .type = "sd",
  529. .id = 0x28,
  530. .manufacturer = "Lexar",
  531. },
  532. {
  533. .type = "sd",
  534. .id = 0x30,
  535. .manufacturer = "SanDisk",
  536. },
  537. {
  538. .type = "sd",
  539. .id = 0x31,
  540. .manufacturer = "Silicon Power",
  541. },
  542. {
  543. .type = "sd",
  544. .id = 0x33,
  545. .manufacturer = "STMicroelectronics",
  546. },
  547. {
  548. .type = "sd",
  549. .id = 0x41,
  550. .manufacturer = "Kingston",
  551. },
  552. {
  553. .type = "sd",
  554. .id = 0x6f,
  555. .manufacturer = "STMicroelectronics",
  556. },
  557. {
  558. .type = "sd",
  559. .id = 0x74,
  560. .manufacturer = "Transcend",
  561. },
  562. {
  563. .type = "sd",
  564. .id = 0x76,
  565. .manufacturer = "Patriot",
  566. },
  567. {
  568. .type = "sd",
  569. .id = 0x82,
  570. .manufacturer = "Gobe/Sony",
  571. },
  572. {
  573. .type = "sd",
  574. .id = 0x89,
  575. .manufacturer = "Unknown",
  576. }
  577. };
  578. /* Parse SD Card Manufacturer Database */
  579. string SDCardParseManufacturerIDs(int id)
  580. {
  581. unsigned int id_cnt = sizeof(database) / sizeof(struct SDCard_Manufacturer_database);
  582. string ret_val = "";
  583. for (int i = 0; i < id_cnt; i++) {
  584. if (database[i].id == id) {
  585. return database[i].manufacturer;
  586. }
  587. else {
  588. ret_val = "ID unknown (not in DB)";
  589. }
  590. }
  591. return ret_val;
  592. }