From 87a512556f19515e1286e4bbd23232c3f542f54f Mon Sep 17 00:00:00 2001 From: Vladimir Ermakov Date: Fri, 1 Dec 2023 12:12:27 +0100 Subject: [PATCH] add support for more gas meters --- docs/protocol.md | 5 +++- make_flags.py | 71 +++++++++++++++++++++++++----------------------- src/ble.cpp | 5 +++- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/docs/protocol.md b/docs/protocol.md index 3a90de1..780d95b 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -72,7 +72,7 @@ Always same for one device. Расшифровка протокола газового счетчика Элехант СГБД-4 ====================================================== -Смотри [тему #8](https://github.com/vooon/elehant-to-mqtt/issues/8). +Смотри [тему #8](https://github.com/vooon/elehant-to-mqtt/issues/8) и [тему #14](https://github.com/vooon/elehant-to-mqtt/issues/14). Сообщение очень похоже на водяной счетчик. Интересующее нас число находится по тому-же смещению, и также в декалитрах. @@ -81,7 +81,10 @@ MAC адреса приборов: - `B0:10:01` - СГБД-1,8 - `B0:11:01` - СГБД-3,2 - `B0:12:01` - СГБД-4,0 +- `B0:30:01` - СГБД-1,8ТК +- `B0:31:01` - СГБД-3,2ТК - `B0:32:01` - СГБД-4,0ТК +- `B0:22:01` - Соник-G4 Mfg Data at B0 diff --git a/make_flags.py b/make_flags.py index c2a2b89..27b306d 100755 --- a/make_flags.py +++ b/make_flags.py @@ -1,30 +1,31 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import re -import pathlib import argparse -import tempfile +import pathlib +import re import subprocess - +import tempfile defines = { - #'DEBUG_ESP_HTTP_UPDATE': 1, - #'DEBUG_ESP_WIFI': 1, - #'DEBUG_ESP_PORT': 'Serial', - 'PIO_FRAMEWORK_ESP_IDF_ENABLE_EXCEPTIONS': None, - 'ARDUINOJSON_ENABLE_PROGMEM': 0, - 'ARDUINOJSON_ENABLE_STD_STRING': 1, - 'ARDUINOJSON_USE_LONG_LONG': 1, + # "DEBUG_ESP_HTTP_UPDATE": 1, + # "DEBUG_ESP_WIFI": 1, + # "DEBUG_ESP_PORT": "Serial", + "PIO_FRAMEWORK_ESP_IDF_ENABLE_EXCEPTIONS": None, + "ARDUINOJSON_ENABLE_PROGMEM": 0, + "ARDUINOJSON_ENABLE_STD_STRING": 1, + "ARDUINOJSON_USE_LONG_LONG": 1, } parser = argparse.ArgumentParser() -parser.add_argument('-D', '--define', action='append') +parser.add_argument("-D", "--define", action="append") args = parser.parse_args() -git_desc = subprocess.check_output(['git', 'describe', '--dirty']).strip() +git_desc = ( + subprocess.check_output(["git", "describe", "--dirty"]).decode("utf-8").strip() +) VER_TPL = """ @@ -33,6 +34,7 @@ const char* cfg::msgs::FW_VERSION = "{git_desc}"; """ + def replace_content(fd, new_content): content = fd.read() if content != new_content: @@ -43,56 +45,57 @@ def replace_content(fd, new_content): ver_content = VER_TPL.format(**locals()) -with open('./src/version.cpp', 'a+') as fd: +with open("./src/version.cpp", "a+") as fd: replace_content(fd, ver_content) # Embed all files if 0: - ddir = pathlib.Path('./data') - defines['COMPONENT_EMBED_TXTFILES'] = ':'.join(str(f) for f in ddir.iterdir()) + ddir = pathlib.Path("./data") + defines["COMPONENT_EMBED_TXTFILES"] = ":".join(str(f) for f in ddir.iterdir()) - with open('./src/embedded_data.h', 'a+') as fd: + with open("./src/embedded_data.h", "a+") as fd: edata_content = "#pragma once\n" for f in ddir.iterdir(): - name = re.sub(r'[/,\.\ ]', '_', str(f)) + name = re.sub(r"[/,\.\ ]", "_", str(f)) - TPL = '''extern const uint8_t {name}_{label}[] asm("_binary_{name}_{label}");\n''' + TPL = """extern const uint8_t {name}_{label}[] asm("_binary_{name}_{label}");\n""" - edata_content += TPL.format(name=name, label='start') - edata_content += TPL.format(name=name, label='end') + edata_content += TPL.format(name=name, label="start") + edata_content += TPL.format(name=name, label="end") replace_content(fd, edata_content) # Embed icons if 1: - ddir = pathlib.Path('./icons') + ddir = pathlib.Path("./icons") xbm_content = "" - for f in sorted(ddir.glob('*.bmp')): - tf = f.with_suffix('.xbm') - #tf = pathlib.Path(tempfile.mktemp(suffix='.xbm')) + for f in sorted(ddir.glob("*.bmp")): + tf = f.with_suffix(".xbm") + # tf = pathlib.Path(tempfile.mktemp(suffix='.xbm')) if not tf.exists(): - subprocess.check_output(['convert', str(f), str(tf)]) + subprocess.check_output(["convert", str(f), str(tf)]) - with tf.open('r') as fd: + with tf.open("r") as fd: xbm = fd.read() - xbm_content += xbm.replace('char ', 'const uint8_t icon_').replace('#define ', '#define icon_') + xbm_content += xbm.replace("char ", "const uint8_t icon_").replace( + "#define ", "#define icon_" + ) tf.unlink() - with open('./src/icons_xbm.h', 'a+') as fd: + with open("./src/icons_xbm.h", "a+") as fd: replace_content(fd, xbm_content) - if args.define: for d in args.define: - if '=' in d: - k, v = d.split('=', 1) + if "=" in d: + k, v = d.split("=", 1) else: k, v = d, None @@ -101,9 +104,9 @@ def replace_content(fd, new_content): def format_def(k, v): if v is None: - return '-D' + k + return "-D" + k - return '-D{k}={v}'.format(**locals()) + return "-D{k}={v}".format(**locals()) print(" ".join(sorted((format_def(k, v) for k, v in defines.items())))) diff --git a/src/ble.cpp b/src/ble.cpp index 37ac05a..1db8441 100644 --- a/src/ble.cpp +++ b/src/ble.cpp @@ -122,7 +122,10 @@ class ElehantGasMeterAdvertismentB0 : public ElehanDataB0 { memcmp(esp_addr, "\xb0\x10\x01", 3) != 0 && memcmp(esp_addr, "\xb0\x11\x01", 3) != 0 && memcmp(esp_addr, "\xb0\x12\x01", 3) != 0 && - memcmp(esp_addr, "\xb0\x32\x01", 3) != 0) + memcmp(esp_addr, "\xb0\x30\x01", 3) != 0 && + memcmp(esp_addr, "\xb0\x31\x01", 3) != 0 && + memcmp(esp_addr, "\xb0\x32\x01", 3) != 0 && + memcmp(esp_addr, "\xb0\x22\x01", 3) != 0) return false; if (!dev.haveManufacturerData())