log.c 17 KB

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