log.c 17 KB

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