diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-11-02 14:21:35 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-11-02 14:21:35 +0100 |
commit | bfbb0256057179d2c4bb01a86ceb58bb14ca36b0 (patch) | |
tree | 877348ebc8028f8b743f25bd61dcde61ead2e009 /serialrx.py | |
parent | dac531ddb170c6ad01ad479d5bc1158cfb98be3e (diff) | |
download | glutte-serial-web-bfbb0256057179d2c4bb01a86ceb58bb14ca36b0.tar.gz glutte-serial-web-bfbb0256057179d2c4bb01a86ceb58bb14ca36b0.tar.bz2 glutte-serial-web-bfbb0256057179d2c4bb01a86ceb58bb14ca36b0.zip |
Add logique uptime too
Diffstat (limited to 'serialrx.py')
-rw-r--r-- | serialrx.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/serialrx.py b/serialrx.py index 2d4238a..4e7ccf6 100644 --- a/serialrx.py +++ b/serialrx.py @@ -33,7 +33,7 @@ import config re_cc_capa = re.compile(r"\[\d+\] CC: CAPA,(\d+),(\d+)") re_cc_vbat_plus = re.compile(r"\[\d+\] CC: VBAT\+,\d+,(\d+)") re_num_sv = re.compile(r"\[\d+\] T_GPS.+ (\d+) SV tracked") -re_alim = re.compile(r"\[\d+\] ALIM (\d+) mV") +re_alim = re.compile(r"\[(\d+)\] ALIM (\d+) mV") re_temp = re.compile(r"\[\d+\] TEMP ([+-]?[0-9.]+)") re_relay = re.compile(r"\[\d+\] CC: RELAY,\d+,(On|Off),(On|Off),(On|Off)") @@ -41,8 +41,10 @@ class MessageParser: def __init__(self): self._lock = threading.Lock() - self._last_cc_timestamp_time = 0 + self._last_timestamp = 0 + self._last_timestamp_time = 0 self._last_cc_timestamp = 0 + self._last_cc_timestamp_time = 0 self._last_cc_capa = 0 self._last_cc_capa_time = 0 self._last_vbat_plus = 0 @@ -77,8 +79,11 @@ class MessageParser: match = re_alim.search(message) if match: - self._last_alim = int(match.group(1)) - self._last_alim_time = time.time() + # Convert milliseconds to seconds so that we have consistent units between the two uptimes + self._last_timestamp = int(int(match.group(1)) / 1000) + self._last_alim = int(match.group(2)) + self._last_timestamp_time = \ + self._last_alim_time = time.time() match = re_temp.search(message) if match: @@ -98,7 +103,8 @@ class MessageParser: "num_sv": (self._last_num_sv, self._last_num_sv_time), "temp": (self._last_temp, self._last_temp_time), "relay": (self._last_relay, self._last_relay_time), - "uptime": (self._last_cc_timestamp, self._last_cc_timestamp_time)} + "cc_uptime": (self._last_cc_timestamp, self._last_cc_timestamp_time), + "uptime": (self._last_timestamp, self._last_timestamp_time)} class SerialRX(threading.Thread): def __init__(self): |