Skip to content

Commit

Permalink
add support for more gas meters
Browse files Browse the repository at this point in the history
  • Loading branch information
vooon committed Dec 1, 2023
1 parent 01bcfe9 commit 87a5125
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
5 changes: 4 additions & 1 deletion docs/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Сообщение очень похоже на водяной счетчик. Интересующее нас число находится по тому-же смещению, и также в декалитрах.

Expand All @@ -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
Expand Down
71 changes: 37 additions & 34 deletions make_flags.py
Original file line number Diff line number Diff line change
@@ -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 = """
Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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()))))
5 changes: 4 additions & 1 deletion src/ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 87a5125

Please sign in to comment.