فهرست منبع

Тесты, скрипты.

TelenkovDmitry 8 ماه پیش
والد
کامیت
0bfab2ba8d

+ 8 - 13
fw/modules/log/log_api.c

@@ -15,7 +15,7 @@
 #define DBG if(1)
 
 extern struct ringfs fs_log;
-extern struct ringfs fs_archive;
+extern struct ringfs fs_ch_arch[];
 
 extern SemaphoreHandle_t log_mutex;
 
@@ -23,14 +23,6 @@ static archive_entry_t archive_entry;
 static log_entry_t log_entry;
 
 
-//
-void log_get_entry_count(void)
-{
-    int count_flash = 0;
-    
-    count_flash = ringfs_count_exact(&fs_archive);
-    printf("Count archive entry: %u\r\n", count_flash);
-}
 
 //
 int log_get_archive_entry(uint32_t index, struct ringfs *fs, void *entry)
@@ -76,7 +68,7 @@ int log_get_log_entry(uint32_t index, struct ringfs *fs, void *entry)
     
     log_fetch(entry, LOG_ENTRY, 0, portMAX_DELAY);
    
-#if 0
+#if 1
 /*
     printf("[log entry] timestamp = % " PRId64 ", code_type = %u, code_state = %u, \
            channel_number = %u, value = %f, crc = %u\r\n", ent->timestamp, \
@@ -94,16 +86,19 @@ int log_get_log_entry(uint32_t index, struct ringfs *fs, void *entry)
 }
 
 //
-int mb_archive_get_entry(uint8_t *buf, uint16_t entry_index)
+int mb_archive_get_entry(uint8_t *buf, uint8_t ch, uint16_t entry_index)
 {
     uint8_t pack_len = 3;
     buf[2] = MB_ARCHIVE_ENTRY;  // Reference type
+        
+    if (log_get_archive_entry(entry_index, &fs_ch_arch[ch], &archive_entry) == -1)
+        return 0;
     
-    log_get_archive_entry(entry_index, &fs_archive, &archive_entry);
 #if 0    
     printf("[entry] timestamp = % " PRId64 ", value = %u, crc = %u\r\n", 
            archive_entry.timestamp, archive_entry.input_value, archive_entry.crc);
-#endif    
+#endif
+    
     memcpy(&buf[3], &archive_entry, sizeof(archive_entry_t));
     pack_len += sizeof(archive_entry_t);
     

+ 3 - 3
fw/modules/log/log_api.h

@@ -6,15 +6,15 @@
 #include <stdbool.h>
 
 
-//
-void log_get_entry_count(void);
-
 //
 int log_get_archive_entry(uint32_t index, struct ringfs *fs, void *entry);
 
 //
 int log_get_log_entry(uint32_t index, struct ringfs *fs, void *entry);
 
+//
+int mb_archive_get_entry(uint8_t *buf, uint8_t ch, uint16_t entry_index);
+
 //
 int mb_log_get_entry(uint8_t *buf, uint16_t entry_index);
 

+ 13 - 5
fw/modules/modbus/modbus.c

@@ -477,6 +477,7 @@ eMBFuncReadFileRecordCB( UCHAR * pucFrame, USHORT * usLen )
 {
     uint8_t byte_count;
     uint8_t reference_type;
+    uint8_t archive_channel;
     uint16_t record_index = 0;
     uint16_t record_num = 0;
   
@@ -496,24 +497,31 @@ eMBFuncReadFileRecordCB( UCHAR * pucFrame, USHORT * usLen )
     record_index = pucFrame[3] << 8;
     record_index |= pucFrame[4];
     
+    archive_channel = pucFrame[5] << 8;
+    archive_channel |= pucFrame[6];
+    
     record_num = pucFrame[7] << 8;
     record_num |= pucFrame[8];
     
-#if 0    
+#if 1
     DBG printf("Byte count: %u, reference_type: %u, \r\n",
                 byte_count, reference_type);
     
-    DBG printf("Record index: %u, record num: %u\r\n", 
-                record_index, record_num);
+    DBG printf("Record index: %u, channel: %u, record num: %u\r\n", 
+                record_index, archive_channel, record_num);
+   
 #endif    
     
+#if 1    
     if (reference_type == MB_ARCHIVE_ENTRY) {
-        *usLen = 1 + mb_archive_get_entry((uint8_t*)&pucFrame[1], record_index);
+        *usLen = 1 + mb_archive_get_entry((uint8_t*)&pucFrame[1], 
+                                          archive_channel, record_index);
     }
     else if (reference_type == MB_LOG_ENTRY) {
         *usLen = 1 + mb_log_get_entry((uint8_t*)&pucFrame[1], record_index);
     }
-        
+#endif        
+    
     return MB_EX_NONE;
 }
 

+ 7 - 5
fw/modules/terminal/terminal_sbs.cpp

@@ -14,7 +14,7 @@ extern "C" {
 }
 
 extern struct ringfs fs_log;
-extern struct ringfs fs_archive;
+extern struct ringfs fs_ch_arch[];
 
 SbsTerminal sbsTerminal;
 Terminal* pTerminal; //Глобальный указатель на терминал
@@ -112,7 +112,8 @@ int SbsTerminal::execute(int argc, const char * const *argv)
     }
     // 
     if (strcmp(argv[0], "aget") == 0) {
-        log_get_archive_entry(atoi(argv[1]), &fs_archive, &archive_entry);
+        if (argc > 2)
+            log_get_archive_entry(atoi(argv[1]), &fs_ch_arch[atoi(argv[2])], &archive_entry);
         return 0;
     }
     //
@@ -173,11 +174,12 @@ int SbsTerminal::help(int argc, const char * const *argv)
     printl ("  add_lentry                       Add N log entries");
     printl ("  add_aentry [entries] [channel]   Add N archive entries to channel");
     printl ("  linfo                            Print log info");
-    printl ("  ainfo                            Print archive info");
+    printl ("  ainfo [channel]                  Print archive info");
     printl ("  afetch                           Fetch archive entry");
-    printl ("  aentry                           Get archive entry [position] [sector] [slot]");
     printl ("  lformat                          Format log partition");
-    printl ("  aformat                          Format archive partition");
+    printl ("  aformat [channel 0..7]           Format archive partition");
+    printl ("  aget [entry index] [channel]     Get archive entry");
+    printl ("  lget [entry index]               Get log entry");
     printl ("  lstate                           log enable/disable");
     printl ("  astate                           archive enable/disable");
     printl ("  mstime                           gurrnet rtc in ms");

BIN
output/fw.bin


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 420 - 418
project/ewarm/iap/iap.dep


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1039 - 1042
project/ewarm/module_universal_io.dep


BIN
tools/__pycache__/log_reader.cpython-310.pyc


BIN
tools/__pycache__/modbus.cpython-310.pyc


+ 7 - 0
tools/digital_io.py

@@ -114,6 +114,13 @@ def main():
     # dev.log.log_clear()
     # dev.log.archive_clear()
 
+    '''Лог'''
+    # dev.log.get_all_log()
+
+    '''Архив'''
+    dev.log.get_all_archive()
+    # print(dev.log.get_archive_entry(0, 1))
+
     '''Сохранение настроек'''
     # dev.sys.save_sattings()
 

+ 35 - 17
tools/log_reader.py

@@ -12,8 +12,17 @@ ARCHIVE_ENTRY = 0x06
 LOG_ENTRY = 0x07
 
 
+class Parser:
+
+    utc_offset = 10800
+
+    def __init__(self) -> None:
+        t = datetime.now(timezone.utc).astimezone()
+        self.utc_offset = t.utcoffset() // timedelta(seconds=1)
 
-class LogParser:
+
+
+class LogParser(Parser):
 
     events = {1: 'Включение питания/перезагрузка  ',
               2: 'Перевод времени                 ',
@@ -25,13 +34,6 @@ class LogParser:
               8: 'Переход в безопасный режим      ',
               9: 'Очистка журнала/архива          '}
 
-    utc_offset = 10800
-
-    def __init__(self) -> None:
-        t = datetime.now(timezone.utc).astimezone()
-        self.utc_offset = t.utcoffset() // timedelta(seconds=1)
-        
-
     @staticmethod
     def print_entry(entry: tuple, index: int):
         timestamp = time.ctime(entry[0]/1000 - LogParser.utc_offset)
@@ -39,6 +41,14 @@ class LogParser:
         print(Fore.CYAN + ans)
 
 
+class ArchiveParser(Parser):
+
+    @staticmethod
+    def print_entry(entry: tuple, index: int):
+        timestamp = time.ctime(entry[0]/1000 - LogParser.utc_offset)
+        ans = f"[ARCHIVE] {index}: {timestamp}, value: {entry[1]}"
+        print(Fore.CYAN + ans)
+
 
 
 class LogReader:
@@ -92,25 +102,28 @@ class DigitalLogReader(LogReader):
     def get_archive(self):
         print("DigitalLogReader")
 
-    def get_archive_entry(self, index):
-        data = self.modbus.read_file_record(ARCHIVE_ENTRY, index, 1)        
+    def get_archive_entry(self, channel, index):
+        data = self.modbus.read_file_record(ARCHIVE_ENTRY, channel, index, 1)        
         return struct.unpack('<QBB', data[5:15])
         
     def get_random_archive_entry(self):
-        data = self.modbus.read_file_record(ARCHIVE_ENTRY, randint(1, self.archive_entries_number), 1)
+        data = self.modbus.read_file_record(ARCHIVE_ENTRY, randint(0, 8), randint(1, self.archive_entries_number), 1)
         entry = struct.unpack('<QBB', data[5:15])
         print(Fore.CYAN + str(entry))
 
     def get_log_entry(self, index):
-        data = self.modbus.read_file_record(LOG_ENTRY, index, 1)
+        data = self.modbus.read_file_record(LOG_ENTRY, 0, index, 1)
         return struct.unpack('<QBBBfB', data[5:21])
 
     def print_log_entry(self, index):
-        data = self.modbus.read_file_record(LOG_ENTRY, index, 1)
+        data = self.modbus.read_file_record(LOG_ENTRY, 0, index, 1)
         LogParser.print_entry(struct.unpack('<QBBBfB', data[5:21]), index)
 
+    # def print_archive_entry(self, index):
+
+
     def get_random_log_entry(self):
-        data = self.modbus.read_file_record(LOG_ENTRY, randint(1, self.log_entries_number), 1)
+        data = self.modbus.read_file_record(LOG_ENTRY, 0, randint(1, self.log_entries_number), 1)
         entry = struct.unpack('<QBBBfB', data[5:21])
         print(Fore.CYAN + str(entry))
 
@@ -125,9 +138,14 @@ class DigitalLogReader(LogReader):
 
     def get_all_archive(self):
         self.get_log_info()
-        
-        for i in range(1, self.archive_entries_number + 1):
-            print(self.get_archive_entry(i))
+        # print(self.archive_entries_number)
+        for channel in range(0, len(self.archive_entries_number)):
+            # print(f"Archive channel {channel} {self.archive_entries_number[channel]}")
+            # print(self.archive_entries_number[channel])
+            if (self.archive_entries_number[channel]):
+                print(f"Archive channel {channel}")
+                for i in range(0, self.archive_entries_number[channel]):
+                    print(self.get_archive_entry(channel, i+1))
 
     def get_all_log(self):
         self.get_log_info()

+ 3 - 2
tools/modbus.py

@@ -173,15 +173,16 @@ class Modbus(ModbusMixin):
             raise MBError('Incorrect response payload')
 
     # 0x14
-    def read_file_record(self, rec_type: int, rec_index: int, rec_num: int):
+    def read_file_record(self, rec_type: int, channel_number: int, rec_index: int, rec_num: int):
         """Read file record
         rec_type - код записи, 0x06 - архив, 0x07 - журнал
+        channel_number - номер канала архива (0 если это журнал)
         rec_index - порядковый номер (индекс) записи
         rec_num - количество записей
         """
         request = bytearray((self.address,  0x14, 7, rec_type))
         request += rec_index.to_bytes(2, 'big')
-        request += int(0).to_bytes(2, 'big')
+        request += channel_number.to_bytes(2, 'big')
         request += rec_num.to_bytes(2, 'big')
         return self.raw_communicate(request + self._crc(request))
 

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است