|
@@ -91,7 +91,7 @@ void log_init(bool format)
|
|
// Архив
|
|
// Архив
|
|
|
|
|
|
ringfs_flash_archive.sector_size = spi_flash_desc.sector_size;
|
|
ringfs_flash_archive.sector_size = spi_flash_desc.sector_size;
|
|
- ringfs_flash_archive.sector_count = ARCHIVE_FLASH_SECTOR_COUNT;
|
|
|
|
|
|
+ ringfs_flash_archive.sector_count = 2; //ARCHIVE_FLASH_SECTOR_COUNT;
|
|
|
|
|
|
ringfs_init(&fs_archive, &ringfs_flash_archive, ARCHIV_ENTRY_VERSION, sizeof(archive_entry_t));
|
|
ringfs_init(&fs_archive, &ringfs_flash_archive, ARCHIV_ENTRY_VERSION, sizeof(archive_entry_t));
|
|
|
|
|
|
@@ -148,25 +148,34 @@ int log_discard(void *entry, entry_type_t entry_type, uint32_t timeout)
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-// TODO unixtime ms
|
|
|
|
|
|
+//
|
|
int log_append(void *entry, entry_type_t entry_type)
|
|
int log_append(void *entry, entry_type_t entry_type)
|
|
{
|
|
{
|
|
int ret;
|
|
int ret;
|
|
TM_RTC_t time;
|
|
TM_RTC_t time;
|
|
common_entry_t *entry_ptr = entry;
|
|
common_entry_t *entry_ptr = entry;
|
|
|
|
+ log_entry_t *log_etnry_ptr;
|
|
|
|
+ archive_entry_t *archive_etnry_ptr;
|
|
|
|
|
|
ret = xSemaphoreTake(log_mutex, portMAX_DELAY);
|
|
ret = xSemaphoreTake(log_mutex, portMAX_DELAY);
|
|
|
|
|
|
if (ret == pdFALSE)
|
|
if (ret == pdFALSE)
|
|
return ret;
|
|
return ret;
|
|
- if (!entry_ptr->timestamp) {
|
|
|
|
- TM_RTC_GetDateTime(&time, TM_RTC_Format_BIN);
|
|
|
|
- entry_ptr->timestamp = time.unix;
|
|
|
|
- }
|
|
|
|
- if (entry_type == LOG_ENTRY)
|
|
|
|
|
|
+
|
|
|
|
+ entry_ptr->timestamp = rtc_get_ms();
|
|
|
|
+
|
|
|
|
+ if (entry_type == LOG_ENTRY)
|
|
|
|
+ {
|
|
|
|
+ log_etnry_ptr = entry;
|
|
|
|
+ log_etnry_ptr->crc = crc_8(entry, sizeof(log_entry_t) - 1);
|
|
ret = ringfs_append(&fs_log, entry);
|
|
ret = ringfs_append(&fs_log, entry);
|
|
- else if (entry_type == ARCHIVE_ENTRY)
|
|
|
|
|
|
+ }
|
|
|
|
+ else if (entry_type == ARCHIVE_ENTRY)
|
|
|
|
+ {
|
|
|
|
+ archive_etnry_ptr = entry;
|
|
|
|
+ archive_etnry_ptr->crc = crc_8(entry, sizeof(archive_entry_t) - 1);
|
|
ret = ringfs_append(&fs_archive, entry);
|
|
ret = ringfs_append(&fs_archive, entry);
|
|
|
|
+ }
|
|
else ret = -1;
|
|
else ret = -1;
|
|
|
|
|
|
xSemaphoreGive(log_mutex);
|
|
xSemaphoreGive(log_mutex);
|
|
@@ -174,6 +183,29 @@ int log_append(void *entry, entry_type_t entry_type)
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// -------------------------------------------------------------------------- //
|
|
|
|
+// misc
|
|
|
|
+
|
|
|
|
+uint8_t crc_8(uint8_t *data, int length)
|
|
|
|
+{
|
|
|
|
+ uint8_t crc = 0x00;
|
|
|
|
+ uint8_t extract;
|
|
|
|
+ uint8_t sum;
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
|
+ extract = *data;
|
|
|
|
+ for (uint8_t tmp = 8; tmp; tmp--) {
|
|
|
|
+ sum = (crc ^ extract) & 0x01;
|
|
|
|
+ crc >>= 1;
|
|
|
|
+ if (sum)
|
|
|
|
+ crc ^= 0x8C;
|
|
|
|
+ extract >>= 1;
|
|
|
|
+ }
|
|
|
|
+ data++;
|
|
|
|
+ }
|
|
|
|
+ return crc;
|
|
|
|
+}
|
|
|
|
+
|
|
// -------------------------------------------------------------------------- //
|
|
// -------------------------------------------------------------------------- //
|
|
// Tests
|
|
// Tests
|
|
|
|
|
|
@@ -223,14 +255,13 @@ int test_archive(void)
|
|
int test_add_random_archive_entry(uint32_t cnt_entry)
|
|
int test_add_random_archive_entry(uint32_t cnt_entry)
|
|
{
|
|
{
|
|
int ret;
|
|
int ret;
|
|
- archive_entry_t entry;
|
|
|
|
|
|
+ archive_entry_t entry= {0};
|
|
|
|
|
|
DBG printf("Try append %u archive entry\r\n", cnt_entry);
|
|
DBG printf("Try append %u archive entry\r\n", cnt_entry);
|
|
|
|
|
|
for (uint32_t i = 0; i < cnt_entry; i++)
|
|
for (uint32_t i = 0; i < cnt_entry; i++)
|
|
{
|
|
{
|
|
entry.input_value = ringfs_count_exact(&fs_archive);
|
|
entry.input_value = ringfs_count_exact(&fs_archive);
|
|
- entry.crc = 0xAB;
|
|
|
|
|
|
|
|
ret = log_append(&entry, ARCHIVE_ENTRY);
|
|
ret = log_append(&entry, ARCHIVE_ENTRY);
|
|
}
|
|
}
|
|
@@ -244,7 +275,8 @@ void test_fetch(void)
|
|
{
|
|
{
|
|
archive_entry_t entry = {0};
|
|
archive_entry_t entry = {0};
|
|
log_fetch(&entry, ARCHIVE_ENTRY, portMAX_DELAY);
|
|
log_fetch(&entry, ARCHIVE_ENTRY, portMAX_DELAY);
|
|
- printf("[entry] timestamp = %u, value = %u, crc = %u\r\n", (uint32_t)entry.timestamp, entry.input_value, entry.crc);
|
|
|
|
|
|
+ //printf("\r\n%" PRId64 " [ms]\r\n", rtc_get_ms());
|
|
|
|
+ printf("[entry] timestamp = % " PRId64 ", value = %u, crc = %u\r\n", entry.timestamp, entry.input_value, entry.crc);
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
//
|
|
@@ -269,7 +301,11 @@ void test_archive_format(void)
|
|
ringfs_format(&fs_archive);
|
|
ringfs_format(&fs_archive);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+//
|
|
|
|
+void test_print_all_archive(void)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
|
|