log.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. #include "log.h"
  2. #include "rtc.h"
  3. #include "ringfs.h"
  4. #include "spi_flash.h"
  5. #include "FreeRTOS.h"
  6. #include "task.h"
  7. #include "semphr.h"
  8. #include "rtc.h"
  9. #include <string.h>
  10. #include <stdio.h>
  11. #include <inttypes.h>
  12. #undef DBG
  13. #define DBG if(1)
  14. static struct ringfs fs_log;
  15. struct ringfs fs_archive;
  16. SemaphoreHandle_t log_mutex;
  17. //
  18. static int op_sector_erase(struct ringfs_flash_partition *flash, int address) {
  19. (void)flash;
  20. int ret;
  21. ret = spi_flash_erase_sector(address, 0);
  22. return ret;
  23. }
  24. //
  25. static ssize_t op_program(struct ringfs_flash_partition *flash, int address, const void *data, size_t size) {
  26. (void)flash;
  27. int ret;
  28. ret = spi_flash_write(address, data, size, 0);
  29. return ret;
  30. }
  31. //
  32. static ssize_t op_read(struct ringfs_flash_partition *flash, int address, void *data, size_t size) {
  33. (void)flash;
  34. int ret;
  35. ret = spi_flash_read(address, data, size, 0);
  36. return ret;
  37. }
  38. //
  39. static struct ringfs_flash_partition ringfs_flash_log =
  40. {
  41. .sector_offset = LOG_FLASH_SECTOR_OFFSET,
  42. .sector_erase = op_sector_erase,
  43. .program = op_program,
  44. .read = op_read,
  45. };
  46. //
  47. static struct ringfs_flash_partition ringfs_flash_archive =
  48. {
  49. .sector_offset = ARCHIVE_FLASH_SECTOR_OFFSET,
  50. .sector_erase = op_sector_erase,
  51. .program = op_program,
  52. .read = op_read,
  53. };
  54. //
  55. void log_init(bool format)
  56. {
  57. DBG printf("[LOG] Init...\r\n");
  58. if (!spi_flash_desc.present)
  59. return;
  60. // ---------------------------------------------------------------------- //
  61. // Журнал
  62. ringfs_flash_log.sector_size = spi_flash_desc.sector_size;
  63. ringfs_flash_log.sector_count = LOG_FLASH_SECTOR_COUNT;
  64. ringfs_init(&fs_log, &ringfs_flash_log, LOG_ENTRY_VERSION, sizeof(log_entry_t));
  65. if (format || ringfs_scan(&fs_log) != 0) {
  66. DBG printf("FAT1 false\r\n");
  67. ringfs_format(&fs_log);
  68. }
  69. DBG printf("FAT1 true\r\n");
  70. // ---------------------------------------------------------------------- //
  71. // Архив
  72. ringfs_flash_archive.sector_size = spi_flash_desc.sector_size;
  73. ringfs_flash_archive.sector_count = 4; //ARCHIVE_FLASH_SECTOR_COUNT;
  74. ringfs_init(&fs_archive, &ringfs_flash_archive, ARCHIV_ENTRY_VERSION, sizeof(archive_entry_t));
  75. if (format || ringfs_scan(&fs_archive) != 0) {
  76. DBG printf("FAT2 false\r\n");
  77. ringfs_format(&fs_archive);
  78. }
  79. DBG printf("FAT2 true\r\n");
  80. // ---------------------------------------------------------------------- //
  81. //fLogInit = true;
  82. log_mutex = xSemaphoreCreateMutex();
  83. //xTaskCreate(log_task, ( char * ) "log_task", configMINIMAL_STACK_SIZE * 2, NULL, tskIDLE_PRIORITY, NULL);
  84. }
  85. //
  86. int log_fetch(void *entry, entry_type_t entry_type, uint32_t timeout)
  87. {
  88. int ret;
  89. ret = xSemaphoreTake(log_mutex, (TickType_t)timeout);
  90. if (ret == pdFALSE)
  91. return ret;
  92. if (entry_type == LOG_ENTRY)
  93. ret = ringfs_fetch(&fs_log, entry);
  94. else if (entry_type == ARCHIVE_ENTRY)
  95. ret = ringfs_fetch(&fs_archive, entry);
  96. else ret = -1;
  97. xSemaphoreGive(log_mutex);
  98. return ret;
  99. }
  100. //
  101. int log_discard(void *entry, entry_type_t entry_type, uint32_t timeout)
  102. {
  103. int ret;
  104. ret = xSemaphoreTake(log_mutex, (TickType_t)timeout);
  105. if (ret == pdFALSE)
  106. return ret;
  107. if (entry_type == LOG_ENTRY)
  108. ret = ringfs_discard(&fs_log);
  109. else if (entry_type == ARCHIVE_ENTRY)
  110. ret = ringfs_discard(&fs_archive);
  111. else ret = -1;
  112. xSemaphoreGive(log_mutex);
  113. return ret;
  114. }
  115. //
  116. int log_append(void *entry, entry_type_t entry_type)
  117. {
  118. int ret;
  119. TM_RTC_t time;
  120. common_entry_t *entry_ptr = entry;
  121. log_entry_t *log_etnry_ptr;
  122. archive_entry_t *archive_etnry_ptr;
  123. ret = xSemaphoreTake(log_mutex, portMAX_DELAY);
  124. if (ret == pdFALSE)
  125. return ret;
  126. entry_ptr->timestamp = rtc_get_ms();
  127. if (entry_type == LOG_ENTRY)
  128. {
  129. log_etnry_ptr = entry;
  130. log_etnry_ptr->crc = crc_8(entry, sizeof(log_entry_t) - 1);
  131. ret = ringfs_append(&fs_log, entry);
  132. }
  133. else if (entry_type == ARCHIVE_ENTRY)
  134. {
  135. archive_etnry_ptr = entry;
  136. archive_etnry_ptr->crc = crc_8(entry, sizeof(archive_entry_t) - 1);
  137. ret = ringfs_append(&fs_archive, entry);
  138. }
  139. else ret = -1;
  140. xSemaphoreGive(log_mutex);
  141. return ret;
  142. }
  143. // -------------------------------------------------------------------------- //
  144. // misc
  145. uint8_t crc_8(uint8_t *data, int length)
  146. {
  147. uint8_t crc = 0x00;
  148. uint8_t extract;
  149. uint8_t sum;
  150. for (int i = 0; i < length; i++) {
  151. extract = *data;
  152. for (uint8_t tmp = 8; tmp; tmp--) {
  153. sum = (crc ^ extract) & 0x01;
  154. crc >>= 1;
  155. if (sum)
  156. crc ^= 0x8C;
  157. extract >>= 1;
  158. }
  159. data++;
  160. }
  161. return crc;
  162. }
  163. // -------------------------------------------------------------------------- //
  164. // Tests
  165. #if 0
  166. // fs_log
  167. int log_test(void)
  168. {
  169. int ret;
  170. }
  171. #endif
  172. // fs_archive
  173. int test_archive(void)
  174. {
  175. int ret;
  176. archive_entry_t entry;
  177. int capacity_flash = 0;
  178. int count_flash = 0;
  179. capacity_flash = ringfs_capacity(&fs_archive);
  180. count_flash = ringfs_count_exact(&fs_archive);
  181. DBG printf("Fetching...\r\n");
  182. if (log_fetch(&entry, ARCHIVE_ENTRY, portMAX_DELAY))
  183. {
  184. printf("%" PRId64 "\n", entry.timestamp);
  185. }
  186. else
  187. {
  188. DBG printf("fail\r\n");
  189. }
  190. #if 0
  191. DBG printf("Discarding\r\n");
  192. if (log_discard)
  193. #endif
  194. return 0;
  195. }
  196. // Добавить n архивных записей
  197. int test_add_random_archive_entry(uint32_t cnt_entry)
  198. {
  199. int ret;
  200. archive_entry_t entry = {0};
  201. static uint32_t index = 0;
  202. DBG printf("Try append %u archive entry\r\n", cnt_entry);
  203. for (uint32_t i = 0; i < cnt_entry; i++)
  204. {
  205. //entry.input_value = ringfs_count_exact(&fs_archive);
  206. entry.input_value = index++;
  207. ret = log_append(&entry, ARCHIVE_ENTRY);
  208. }
  209. return ret;
  210. }
  211. //
  212. void test_fetch(void)
  213. {
  214. archive_entry_t entry = {0};
  215. log_fetch(&entry, ARCHIVE_ENTRY, portMAX_DELAY);
  216. //printf("\r\n%" PRId64 " [ms]\r\n", rtc_get_ms());
  217. printf("[entry] timestamp = % " PRId64 ", value = %u, crc = %u\r\n", entry.timestamp, entry.input_value, entry.crc);
  218. }
  219. //
  220. void test_archive_info(void)
  221. {
  222. int capacity_flash = 0;
  223. int count_flash = 0;
  224. int count_estimate = 0;
  225. capacity_flash = ringfs_capacity(&fs_archive);
  226. count_flash = ringfs_count_exact(&fs_archive);
  227. count_estimate = ringfs_count_estimate(&fs_archive);
  228. printf("Archive partition capasity: %u\r\n", capacity_flash);
  229. printf("Count archive entry: %u\r\n", count_flash);
  230. printf("Estimate count: %u\r\n", count_estimate);
  231. }
  232. //
  233. void test_archive_format(void)
  234. {
  235. ringfs_format(&fs_archive);
  236. }
  237. //
  238. void test_print_all_archive(void)
  239. {
  240. test_archive_info();
  241. }
  242. #if 0
  243. char logFileBuf[FILE_BUF_MAX_LEN];
  244. char name_login[50];
  245. extern const char* logsStrShortRu[];
  246. bool flUpdateLog = false;
  247. static bool fLogInit = false; // Флаг инициализации журнала
  248. #define LOG_TIME 1000*60*10
  249. static int op_sector_erase(struct ringfs_flash_partition *flash, int address) {
  250. (void)flash;
  251. int ret;
  252. ret = spi_flash_erase_sector(address, 0);
  253. return ret;
  254. }
  255. static ssize_t op_program(struct ringfs_flash_partition *flash, int address, const void *data, size_t size) {
  256. (void)flash;
  257. int ret;
  258. ret = spi_flash_write(address, data, size, 0);
  259. return ret;
  260. }
  261. static ssize_t op_read(struct ringfs_flash_partition *flash, int address, void *data, size_t size) {
  262. (void)flash;
  263. int ret;
  264. ret = spi_flash_read(address, data, size, 0);
  265. return ret;
  266. }
  267. static struct ringfs_flash_partition ringfs_flash = {
  268. .sector_offset = LOG_FLASH_SECTOR_OFFSET,
  269. .sector_erase = op_sector_erase,
  270. .program = op_program,
  271. .read = op_read,
  272. };
  273. static struct ringfs fs;
  274. static struct ringfs_flash_partition ringfs_flash2 = {
  275. .sector_offset = ALARM_LOG_FLASH_SECTOR_OFFSET,
  276. .sector_erase = op_sector_erase,
  277. .program = op_program,
  278. .read = op_read,
  279. };
  280. static struct ringfs fs2;
  281. static SemaphoreHandle_t log_mutex;
  282. /**
  283. * @brief Отключает журнал для безопасной перезагрузки
  284. */
  285. bool LOG_Disable(void)
  286. {
  287. if (fLogInit) {
  288. /* Ожидаем завершения работы с журнал */
  289. if ( xSemaphoreTake(log_mutex, 10000) == pdTRUE ) {
  290. //fLogInit = false;
  291. //xSemaphoreGive(logMutex);
  292. return true;
  293. }
  294. else {
  295. return false;
  296. }
  297. }
  298. else {
  299. return true;
  300. }
  301. }
  302. void log_task(void* params)
  303. {
  304. for(;;){
  305. flUpdateLog = true;
  306. vTaskDelay(LOG_TIME);
  307. /*vTaskDelay(50);
  308. log_event_data(LOG_SYSTEM_BOOT, "Администратор");
  309. log_add(")215.7;215.7;220.5;000;50.1;2.30;25.0;00000001;");*/
  310. }
  311. }
  312. void log_init(bool format) {
  313. DBG printf(">>> Event log\n");
  314. if (!spi_flash_desc.present)
  315. return;
  316. ringfs_flash.sector_size = spi_flash_desc.sector_size;
  317. ringfs_flash.sector_count = SECTOR_COUNT;
  318. ringfs_init(&fs, &ringfs_flash, LOG_ENTRY_VERSION, sizeof(log_entry_t));
  319. if (format || ringfs_scan(&fs) != 0){
  320. DBG printf("FAT1 false\r\n");
  321. ringfs_format(&fs);
  322. }
  323. DBG printf("FAT1 true\r\n");
  324. ringfs_flash2.sector_size = spi_flash_desc.sector_size;
  325. ringfs_flash2.sector_count = SECTOR_COUNT;
  326. ringfs_init(&fs2, &ringfs_flash2, LOG_ENTRY_VERSION, sizeof(log_entry_t));
  327. if (format || ringfs_scan(&fs2) != 0){
  328. DBG printf("FAT2 false\r\n");
  329. ringfs_format(&fs2);
  330. }
  331. DBG printf("FAT2 true\r\n");
  332. fLogInit = true;
  333. log_mutex = xSemaphoreCreateMutex();
  334. xTaskCreate(log_task, ( char * ) "log_task", configMINIMAL_STACK_SIZE * 2, NULL, tskIDLE_PRIORITY, NULL);
  335. }
  336. int capacity_flash = 0;
  337. int count_flash = 0;
  338. int log_test(void) {
  339. int ret;
  340. log_entry_t entry;
  341. log_init(false);
  342. capacity_flash = ringfs_capacity(&fs);
  343. count_flash = ringfs_count_exact(&fs);
  344. DBG printf("\tCapacity: %d\n", capacity_flash);
  345. DBG printf("\tCount: %d\n", count_flash);
  346. DBG printf("\tAppending ");
  347. // ret = log_event(LOG_SYSTEM_DEFCONFIG, 0, 0);
  348. DBG printf("%s\n", ret == 0 ? "ok" : "error");
  349. if (ret == 0)
  350. return -1;
  351. // ret = log_event(LOG_SYSTEM_DEFCONFIG, 0, 512);
  352. entry.timestamp = 0;
  353. entry.type = 0;
  354. DBG printf("\tFetching ");
  355. if (log_fetch(&entry, portMAX_DELAY) == 0){
  356. DBG printf("ok, time=%d, type=%d\n", entry.timestamp, entry.type);
  357. log_fetch(&entry, portMAX_DELAY);
  358. entry.timestamp = 0;
  359. entry.type = 0;
  360. log_fetch(&entry, portMAX_DELAY);
  361. entry.timestamp = 0;
  362. entry.type = 0;
  363. log_fetch(&entry, portMAX_DELAY);
  364. entry.timestamp = 0;
  365. entry.type = 0;
  366. log_fetch(&entry, portMAX_DELAY);
  367. return 0;
  368. }
  369. else {
  370. DBG printf("fail\n");
  371. return -1;
  372. }
  373. DBG printf("\tDiscarding ");
  374. if (log_discard(&entry,portMAX_DELAY) == 0)
  375. DBG printf("ok\n");
  376. else {
  377. DBG printf("fail\n");
  378. return -1;
  379. }
  380. return 0;
  381. }
  382. int log_append(log_entry_t *entry) {
  383. int ret;
  384. TM_RTC_t data;
  385. ret = xSemaphoreTake( log_mutex, portMAX_DELAY );
  386. if (ret == pdFALSE)
  387. return ret;
  388. if (!entry->timestamp){
  389. TM_RTC_GetDateTime(&data, TM_RTC_Format_BIN);
  390. entry->timestamp = data.unix;
  391. }
  392. if(entry->type == LOG_VALUE)
  393. ringfs_append(&fs, entry);
  394. else
  395. ringfs_append(&fs2, entry);
  396. xSemaphoreGive(log_mutex);
  397. return ret;
  398. }
  399. int log_fetch(log_entry_t *entry, uint32_t timeout) {
  400. int ret;
  401. ret = xSemaphoreTake( log_mutex, (TickType_t)timeout );
  402. if (ret == pdFALSE)
  403. return ret;
  404. if(entry->type == LOG_VALUE)
  405. ret = ringfs_fetch(&fs, entry);
  406. else
  407. ret = ringfs_fetch(&fs2, entry);
  408. xSemaphoreGive(log_mutex);
  409. return ret;
  410. }
  411. int log_rewind(log_entry_t *entry, uint32_t timeout) {
  412. int ret;
  413. ret = xSemaphoreTake( log_mutex, (TickType_t)timeout );
  414. if (ret == pdFALSE)
  415. return ret;
  416. if(entry->type == LOG_VALUE)
  417. ret = ringfs_rewind(&fs);
  418. else
  419. ret = ringfs_rewind(&fs2);
  420. xSemaphoreGive(log_mutex);
  421. return ret;
  422. }
  423. int log_discard(log_entry_t *entry, uint32_t timeout) {
  424. int ret;
  425. ret = xSemaphoreTake( log_mutex, (TickType_t)timeout );
  426. if (ret == pdFALSE)
  427. return ret;
  428. if(entry->type == LOG_VALUE)
  429. ret = ringfs_discard(&fs);
  430. else
  431. ret = ringfs_discard(&fs2);
  432. xSemaphoreGive(log_mutex);
  433. return ret;
  434. }
  435. void log_event_data(log_type_t type, char *data)
  436. {
  437. log_entry_t entry_data;
  438. entry_data.timestamp = 0;
  439. entry_data.type = type;
  440. strncpy(entry_data.data, data, 49);
  441. if (fLogInit)
  442. log_append(&entry_data);
  443. }
  444. void log_add(char *log_data)
  445. {
  446. char buf_value[50];
  447. uint8_t i, len;
  448. memset(buf_value, 0, 50);
  449. len = strlen(log_data);
  450. if (len != UPS_DATA_STRING_SIZE) {
  451. //len = UPS_DATA_STRING_SIZE;
  452. return;
  453. }
  454. strncpy(buf_value, log_data, len);
  455. DBG printf("UPS log data: %s\r\n", log_data);
  456. buf_value[0] = '\"';
  457. for(i = 0; i < len; i++)
  458. {
  459. if(buf_value[i] == ' ')
  460. buf_value[i] = ';';
  461. }
  462. buf_value[len - 1] = ';';
  463. if(fLogInit){
  464. if(fs.write.slot>67)
  465. {
  466. log_entry_t entry_data;
  467. entry_data.timestamp = 0;
  468. log_event_data(LOG_VALUE, buf_value);
  469. }
  470. else
  471. log_event_data(LOG_VALUE, buf_value);
  472. }
  473. }
  474. /**
  475. * @brief Возвращает true если журнал проинициализирован
  476. */
  477. bool LOG_IsInit()
  478. {
  479. return fLogInit;
  480. }
  481. /**
  482. * @brief Возвращает общее количество страниц
  483. */
  484. uint32_t LOG_GetPageCount(void)
  485. {
  486. return (((ringfs_count_estimate(&fs)) / 10) + 1);
  487. }
  488. uint32_t LOG_GetTotalSTRCount(void)
  489. {
  490. return ringfs_count_estimate(&fs);
  491. }
  492. void LOG_GetPage_tabs(char *str, uint32_t page)
  493. {
  494. TM_RTC_t rtc_data;
  495. log_entry_t entry;
  496. char buf[20];
  497. uint8_t i;
  498. int start =LOG_GetTotalSTRCount();//(fs.write.sector*fs.slots_per_sector + fs.write.slot);
  499. memset(buf, 0, 20);
  500. for(i=0; i < 10; i++){
  501. fs.cursor_position = start - 10*(page-1) - 1 - i;
  502. if(fs.cursor_position < 0)
  503. break;
  504. else{
  505. fs.cursor.sector = (fs.read.sector + fs.cursor_position/fs.slots_per_sector)%fs.flash->sector_count;
  506. fs.cursor.slot = fs.cursor_position%fs.slots_per_sector;
  507. }
  508. entry.type = LOG_VALUE;
  509. log_fetch(&entry, portMAX_DELAY);
  510. entry.data[49] = 0;
  511. strncat(str, entry.data, strlen(entry.data));
  512. TM_RTC_GetDateTimeFromUnix(&rtc_data, entry.timestamp);
  513. sprintf(buf, "%02i.%02i.%02i %02i:%02i:%02i", rtc_data.date, rtc_data.month,
  514. rtc_data.year, rtc_data.hours, rtc_data.minutes, rtc_data.seconds);
  515. strcat(str, buf);
  516. strcat(str, "\",");
  517. strcat(str, "\r\n");
  518. }
  519. }
  520. void LOG_GetPage(char *str, uint32_t page)
  521. {
  522. TM_RTC_t rtc_data;
  523. log_entry_t entry;
  524. char buf[20];
  525. uint8_t i;
  526. int start =LOG_GetTotalSTRCount();//(fs.write.sector*fs.slots_per_sector + fs.write.slot);
  527. memset(buf, 0, 20);
  528. for(i=0; i < 10; i++){
  529. fs.cursor_position = start - 10*(page-1) - 1 - i;
  530. if(fs.cursor_position < 0)
  531. break;
  532. else{
  533. fs.cursor.sector = (fs.read.sector + fs.cursor_position/fs.slots_per_sector)%fs.flash->sector_count;
  534. fs.cursor.slot = fs.cursor_position%fs.slots_per_sector;
  535. }
  536. entry.type = LOG_VALUE;
  537. log_fetch(&entry, portMAX_DELAY);
  538. entry.data[49] = 0;
  539. strncat(str, entry.data, strlen(entry.data));
  540. TM_RTC_GetDateTimeFromUnix(&rtc_data, entry.timestamp);
  541. sprintf(buf, "%02i.%02i.%02i %02i:%02i:%02i", rtc_data.date, rtc_data.month,
  542. rtc_data.year, rtc_data.hours, rtc_data.minutes, rtc_data.seconds);
  543. strcat(str, buf);
  544. strcat(str, "\",");
  545. }
  546. }
  547. uint32_t LOG_GetData(int ptr, char *str, uint32_t size, bool start)
  548. {
  549. TM_RTC_t rtc_data;
  550. log_entry_t entry;
  551. char buf[20];
  552. uint8_t i;
  553. entry.type = LOG_VALUE;
  554. if(start)
  555. log_rewind(&entry, portMAX_DELAY);
  556. fs.cursor_position = ptr/STRING_SIZE;
  557. fs.cursor.sector = (fs.read.sector + fs.cursor_position/fs.slots_per_sector)%fs.flash->sector_count;
  558. fs.cursor.slot = fs.cursor_position%fs.slots_per_sector;
  559. for(i = 0; i < size/STRING_SIZE; i++)
  560. {
  561. entry.type = LOG_VALUE;
  562. log_fetch(&entry, portMAX_DELAY);
  563. entry.data[49] = 0;
  564. strncat(str, &entry.data[1], (strlen(entry.data) - 1));
  565. TM_RTC_GetDateTimeFromUnix(&rtc_data, entry.timestamp);
  566. sprintf(buf, "%02i.%02i.%02i %02i:%02i:%02i", rtc_data.date, rtc_data.month,
  567. rtc_data.year, rtc_data.hours, rtc_data.minutes, rtc_data.seconds);
  568. strcat(str, buf);
  569. strcat(str, "\n");
  570. }
  571. return strlen(str);
  572. }
  573. #endif