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