Support PM67 voltage fields in UMP logger v3
This commit is contained in:
@@ -63,6 +63,8 @@ FIELDS = (
|
||||
('adc1', 'АЦП канал 1', 37, None),
|
||||
('adc2', 'АЦП канал 2', 38, None),
|
||||
('adc3', 'АЦП канал 3', 39, None),
|
||||
('zpt1', 'ЗПТ1: U1 + U2 (ПМ67, рег. 306)', 40, None),
|
||||
('zpt2', 'ЗПТ2: U3 + U4 (ПМ67, рег. 9)', 41, None),
|
||||
)
|
||||
|
||||
|
||||
@@ -71,7 +73,7 @@ def request(controller: int, function: int, address: int, value: int) -> bytes:
|
||||
raise ValueError('Недопустимый адрес контроллера или значение')
|
||||
if function == 3:
|
||||
valid = ((address == BASE and value == 16) or
|
||||
(address == DATA and 1 <= value <= 120 and value % WORDS == 0) or (address == LIVE and value == 124) or (address == EMU_CONTROL and value == 4)
|
||||
(address == DATA and 1 <= value <= 120 and (value % WORDS == 0 or value in (42, 84))) or (address == LIVE and value == 124) or (address == EMU_CONTROL and value == 4)
|
||||
or (address == FAST_CAPABILITY and value == 4)
|
||||
or (FAST_DATA <= address < FAST_DATA + CAPACITY * WORDS
|
||||
and (address - FAST_DATA) % WORDS == 0
|
||||
@@ -96,25 +98,27 @@ class Status:
|
||||
archive_count: int
|
||||
post_ms: int
|
||||
live_state: int
|
||||
words: int = 40
|
||||
capacity: int = 800
|
||||
|
||||
@classmethod
|
||||
def decode(cls, words):
|
||||
if (len(words) != 16 or words[0:2] != (0x554D, 2) or
|
||||
words[4] != WORDS or words[5] != CAPACITY):
|
||||
raise ValueError('Прошивка не поддерживает логгер УМП v2')
|
||||
if (len(words) != 16 or words[0] != 0x554D or
|
||||
(words[1], words[4], words[5]) not in ((2, 40, 800), (3, 42, 760))):
|
||||
raise ValueError('Прошивка не поддерживает логгер УМП v2/v3')
|
||||
if words[9] != 6:
|
||||
raise ValueError('Логгер УМП доступен только на плате нагрузки dsk_LOAD')
|
||||
if words[2] not in (0, 1, 2, 3) or words[3] > CAPACITY or not 1 <= words[6] <= 1000 or words[11] != 1000 or words[13] > CAPACITY or words[14] > 1000 or words[15] not in (0, 1, 3):
|
||||
if words[2] not in (0, 1, 2, 3) or words[3] > words[5] or not 1 <= words[6] <= 1000 or words[11] != 1000 or words[13] > words[5] or words[14] > 1000 or words[15] not in (0, 1, 3):
|
||||
raise ValueError('Повреждён статус логгера')
|
||||
return cls(words[2], words[3], words[6], words[10], words[11], *words[12:16])
|
||||
return cls(words[2], words[3], words[6], words[10], words[11], *words[12:16], words[4], words[5])
|
||||
|
||||
|
||||
def sample(words, frequency=1000):
|
||||
if len(words) != WORDS or frequency <= 0:
|
||||
if len(words) not in (40, 42) or frequency <= 0:
|
||||
raise ValueError('Неверная запись логгера')
|
||||
result = {'time_ms': (words[0] | words[1] << 16) * 1000 / frequency, 'event': words[2]}
|
||||
for key, _label, index, bit in FIELDS:
|
||||
value = words[index]
|
||||
value = words[index] if index < len(words) else float('nan')
|
||||
if bit is not None:
|
||||
value = (value >> bit) & 1
|
||||
elif 10 <= index <= 13 and value >= 32768:
|
||||
|
||||
@@ -23,7 +23,7 @@ def build_request(mode, token, function, address, value):
|
||||
if not 1 <= token <= 255:
|
||||
raise ValueError('Неверный номер CAN-запроса')
|
||||
valid = ((function == 3 and ((address == BASE and value == 16) or
|
||||
(address == DATA and value in (40, 80, 120)) or
|
||||
(address == DATA and value in (40, 80, 120, 42, 84)) or
|
||||
(address == LIVE and value == MAX_WORDS) or (address == EMU_CONTROL and value == 4))) or
|
||||
(function == 6 and ((BASE <= address <= BASE+3 and 0 <= value <= 65535) or
|
||||
(address == EMU_CONTROL+2 and value in (0, 1)))))
|
||||
|
||||
Reference in New Issue
Block a user