Compare commits
10
Commits
development
...
v0.11
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41381f1705 | ||
|
|
e3203a5334 | ||
|
|
c78ebe3e2d | ||
|
|
d6e28db116 | ||
|
|
5f1afeb1f8 | ||
|
|
dcb59fddb1 | ||
|
|
9b0a85e84b | ||
|
|
1dca6ab396 | ||
|
|
efc09df71f | ||
|
|
de5c884d8d |
@@ -1,6 +1,16 @@
|
|||||||
Change Log
|
Change Log
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
**0.10** (2017-06-05)
|
||||||
|
|
||||||
|
- bugix: don't force full telegram signatures (`pull request #25 <https://github.com/ndokter/dsmr_parser/pull/25>`_)
|
||||||
|
- removed unused code for automatic telegram detection as this needs reworking after the fix mentioned above
|
||||||
|
- InvalidChecksumError's are logged as warning instead of error
|
||||||
|
|
||||||
|
**0.9** (2017-05-12)
|
||||||
|
|
||||||
|
- added DSMR v5 serial settings
|
||||||
|
|
||||||
**0.8** (2017-01-26)
|
**0.8** (2017-01-26)
|
||||||
|
|
||||||
- added support for DSMR v3
|
- added support for DSMR v3
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ into a dictionary.
|
|||||||
from dsmr_parser import telegram_specifications
|
from dsmr_parser import telegram_specifications
|
||||||
from dsmr_parser.parsers import TelegramParser
|
from dsmr_parser.parsers import TelegramParser
|
||||||
|
|
||||||
|
# String is formatted in separate lines for readability.
|
||||||
telegram_str = (
|
telegram_str = (
|
||||||
'/ISk5\2MT382-1000\r\n'
|
'/ISk5\2MT382-1000\r\n'
|
||||||
'\r\n'
|
'\r\n'
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from serial_asyncio import create_serial_connection
|
|||||||
|
|
||||||
from dsmr_parser import telegram_specifications
|
from dsmr_parser import telegram_specifications
|
||||||
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
|
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
|
||||||
from dsmr_parser.exceptions import ParseError
|
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
|
||||||
from dsmr_parser.parsers import TelegramParser
|
from dsmr_parser.parsers import TelegramParser
|
||||||
from dsmr_parser.clients.settings import SERIAL_SETTINGS_V2_2, \
|
from dsmr_parser.clients.settings import SERIAL_SETTINGS_V2_2, \
|
||||||
SERIAL_SETTINGS_V4
|
SERIAL_SETTINGS_V4
|
||||||
@@ -23,6 +23,9 @@ def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None):
|
|||||||
elif dsmr_version == '4':
|
elif dsmr_version == '4':
|
||||||
specification = telegram_specifications.V4
|
specification = telegram_specifications.V4
|
||||||
serial_settings = SERIAL_SETTINGS_V4
|
serial_settings = SERIAL_SETTINGS_V4
|
||||||
|
elif dsmr_version == '5':
|
||||||
|
specification = telegram_specifications.V5
|
||||||
|
serial_settings = SERIAL_SETTINGS_V4
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("No telegram parser found for version: %s",
|
raise NotImplementedError("No telegram parser found for version: %s",
|
||||||
dsmr_version)
|
dsmr_version)
|
||||||
@@ -98,6 +101,8 @@ class DSMRProtocol(asyncio.Protocol):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
parsed_telegram = self.telegram_parser.parse(telegram)
|
parsed_telegram = self.telegram_parser.parse(telegram)
|
||||||
|
except InvalidChecksumError as e:
|
||||||
|
self.log.warning(str(e))
|
||||||
except ParseError:
|
except ParseError:
|
||||||
self.log.exception("failed to parse telegram")
|
self.log.exception("failed to parse telegram")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import serial
|
|||||||
import serial_asyncio
|
import serial_asyncio
|
||||||
|
|
||||||
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
|
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
|
||||||
from dsmr_parser.exceptions import ParseError
|
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
|
||||||
from dsmr_parser.parsers import TelegramParser
|
from dsmr_parser.parsers import TelegramParser
|
||||||
|
|
||||||
|
|
||||||
@@ -36,6 +36,8 @@ class SerialReader(object):
|
|||||||
for telegram in self.telegram_buffer.get_all():
|
for telegram in self.telegram_buffer.get_all():
|
||||||
try:
|
try:
|
||||||
yield self.telegram_parser.parse(telegram)
|
yield self.telegram_parser.parse(telegram)
|
||||||
|
except InvalidChecksumError as e:
|
||||||
|
logger.warning(str(e))
|
||||||
except ParseError as e:
|
except ParseError as e:
|
||||||
logger.error('Failed to parse telegram: %s', e)
|
logger.error('Failed to parse telegram: %s', e)
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class TelegramBuffer(object):
|
|||||||
# - The checksum is optional '{0,4}' because not all telegram versions
|
# - The checksum is optional '{0,4}' because not all telegram versions
|
||||||
# support it.
|
# support it.
|
||||||
return re.findall(
|
return re.findall(
|
||||||
r'\/[^\/]+?\![A-F0-9]{0,4}\r\n',
|
r'\/[^\/]+?\![A-F0-9]{0,4}\0?\r\n',
|
||||||
self._buffer,
|
self._buffer,
|
||||||
re.DOTALL
|
re.DOTALL
|
||||||
)
|
)
|
||||||
|
|||||||
+8
-34
@@ -51,12 +51,10 @@ class TelegramParser(object):
|
|||||||
for signature, parser in self.telegram_specification['objects'].items():
|
for signature, parser in self.telegram_specification['objects'].items():
|
||||||
match = re.search(signature, telegram_data, re.DOTALL)
|
match = re.search(signature, telegram_data, re.DOTALL)
|
||||||
|
|
||||||
# All telegram specification lines/signatures are expected to be
|
# Some signatures are optional and may not be present,
|
||||||
# present.
|
# so only parse lines that match
|
||||||
if not match:
|
if match:
|
||||||
raise ParseError('Telegram specification does not match '
|
telegram[signature] = parser.parse(match.group(0))
|
||||||
'telegram data')
|
|
||||||
telegram[signature] = parser.parse(match.group(0))
|
|
||||||
|
|
||||||
return telegram
|
return telegram
|
||||||
|
|
||||||
@@ -94,31 +92,6 @@ class TelegramParser(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def match_telegram_specification(telegram_data):
|
|
||||||
"""
|
|
||||||
Find telegram specification that matches the telegram data by trying all
|
|
||||||
specifications.
|
|
||||||
|
|
||||||
Could be further optimized to check the actual 0.2.8 OBIS reference which
|
|
||||||
is available for DSMR version 4 and up.
|
|
||||||
|
|
||||||
:param str telegram_data: full telegram from start ('/') to checksum
|
|
||||||
('!ABCD') including line endings in between the telegram's lines
|
|
||||||
:return: telegram specification
|
|
||||||
:rtype: dict
|
|
||||||
"""
|
|
||||||
# Prevent circular import
|
|
||||||
from dsmr_parser import telegram_specifications
|
|
||||||
|
|
||||||
for specification in telegram_specifications.ALL:
|
|
||||||
try:
|
|
||||||
TelegramParser(specification).parse(telegram_data)
|
|
||||||
except ParseError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return specification
|
|
||||||
|
|
||||||
|
|
||||||
class DSMRObjectParser(object):
|
class DSMRObjectParser(object):
|
||||||
"""
|
"""
|
||||||
Parses an object (can also be see as a 'line') from a telegram.
|
Parses an object (can also be see as a 'line') from a telegram.
|
||||||
@@ -176,10 +149,11 @@ class CosemParser(DSMRObjectParser):
|
|||||||
1 23 45
|
1 23 45
|
||||||
|
|
||||||
1) OBIS Reduced ID-code
|
1) OBIS Reduced ID-code
|
||||||
2) Separator “(“, ASCII 28h
|
2) Separator "(", ASCII 28h
|
||||||
3) COSEM object attribute value
|
3) COSEM object attribute value
|
||||||
4) Unit of measurement values (Unit of capture objects attribute) – only if applicable
|
4) Unit of measurement values (Unit of capture objects attribute) - only if
|
||||||
5) Separator “)”, ASCII 29h
|
applicable
|
||||||
|
5) Separator ")", ASCII 29h
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def parse(self, line):
|
def parse(self, line):
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ setup(
|
|||||||
author='Nigel Dokter',
|
author='Nigel Dokter',
|
||||||
author_email='nigeldokter@gmail.com',
|
author_email='nigeldokter@gmail.com',
|
||||||
url='https://github.com/ndokter/dsmr_parser',
|
url='https://github.com/ndokter/dsmr_parser',
|
||||||
version='0.8',
|
version='0.10',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'pyserial>=3,<4',
|
'pyserial>=3,<4',
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
import unittest
|
|
||||||
|
|
||||||
from dsmr_parser.parsers import match_telegram_specification
|
|
||||||
from dsmr_parser import telegram_specifications
|
|
||||||
from test import example_telegrams
|
|
||||||
|
|
||||||
|
|
||||||
class MatchTelegramSpecificationTest(unittest.TestCase):
|
|
||||||
|
|
||||||
def test_v2_2(self):
|
|
||||||
assert match_telegram_specification(example_telegrams.TELEGRAM_V2_2) \
|
|
||||||
== telegram_specifications.V2_2
|
|
||||||
|
|
||||||
def test_v3(self):
|
|
||||||
assert match_telegram_specification(example_telegrams.TELEGRAM_V3) \
|
|
||||||
== telegram_specifications.V3
|
|
||||||
|
|
||||||
def test_v4_2(self):
|
|
||||||
assert match_telegram_specification(example_telegrams.TELEGRAM_V4_2) \
|
|
||||||
== telegram_specifications.V4
|
|
||||||
|
|
||||||
def test_v5(self):
|
|
||||||
assert match_telegram_specification(example_telegrams.TELEGRAM_V5) \
|
|
||||||
== telegram_specifications.V5
|
|
||||||
Reference in New Issue
Block a user