dev progress
This commit is contained in:
parent
663024239f
commit
87a5a2d2fa
@ -9,8 +9,7 @@ from serial_asyncio import create_serial_connection
|
||||
from . import telegram_specifications
|
||||
from .exceptions import ParseError
|
||||
from .parsers import TelegramParserV2_2, TelegramParserV4
|
||||
from .serial import (SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4,
|
||||
is_end_of_telegram, is_start_of_telegram, TelegramBuffer)
|
||||
from .serial import (SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4,TelegramBuffer)
|
||||
|
||||
|
||||
def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None):
|
||||
@ -81,7 +80,9 @@ class DSMRProtocol(asyncio.Protocol):
|
||||
data = data.decode('ascii')
|
||||
self.log.debug('received data: %s', data)
|
||||
self.telegram_buffer.put(data)
|
||||
map(self.handle_telegram, self.telegram_buffer.get_all())
|
||||
|
||||
for telegram in self.telegram_buffer.get_all():
|
||||
self.handle_telegram(telegram)
|
||||
|
||||
def connection_lost(self, exc):
|
||||
"""Stop when connection is lost."""
|
||||
|
@ -32,22 +32,6 @@ SERIAL_SETTINGS_V4 = {
|
||||
}
|
||||
|
||||
|
||||
def is_start_of_telegram(line):
|
||||
"""
|
||||
:param bytes line: series of bytes representing a line.
|
||||
Example: b'/KFM5KAIFA-METER\r\n'
|
||||
"""
|
||||
return line.startswith('/')
|
||||
|
||||
|
||||
def is_end_of_telegram(line):
|
||||
"""
|
||||
:param bytes line: series of bytes representing a line.
|
||||
Example: b'!7B05\r\n'
|
||||
"""
|
||||
return line.startswith('!')
|
||||
|
||||
|
||||
class SerialReader(object):
|
||||
PORT_KEY = 'port'
|
||||
|
||||
@ -123,8 +107,8 @@ class AsyncSerialReader(SerialReader):
|
||||
|
||||
class TelegramBuffer(object):
|
||||
"""
|
||||
Used as a buffer for a stream or telegram data. Returns telegram from buffer
|
||||
when complete.
|
||||
Used as a buffer for a stream of telegram data. Constructs full telegram
|
||||
strings from the buffered data and returns it.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
@ -132,7 +116,7 @@ class TelegramBuffer(object):
|
||||
|
||||
def get_all(self):
|
||||
"""
|
||||
Remove complete telegrams from buffer and yield them
|
||||
Remove complete telegrams from buffer and yield them.
|
||||
:rtype generator:
|
||||
"""
|
||||
for telegram in self._find_telegrams():
|
||||
@ -160,7 +144,7 @@ class TelegramBuffer(object):
|
||||
|
||||
def _find_telegrams(self):
|
||||
"""
|
||||
Find complete telegrams from buffer from start ('/') till ending
|
||||
Find complete telegrams in buffer from start ('/') till ending
|
||||
checksum ('!AB12\r\n').
|
||||
:rtype: list
|
||||
"""
|
||||
|
@ -1,6 +1,6 @@
|
||||
import unittest
|
||||
|
||||
from .example_telegrams import TELEGRAM_V2_2
|
||||
from test.example_telegrams import TELEGRAM_V2_2
|
||||
from dsmr_parser.parsers import TelegramParserV2_2
|
||||
from dsmr_parser import telegram_specifications
|
||||
from dsmr_parser import obis_references as obis
|
||||
|
@ -4,7 +4,7 @@ import unittest
|
||||
|
||||
import pytz
|
||||
|
||||
from .example_telegrams import TELEGRAM_V4_2
|
||||
from test.example_telegrams import TELEGRAM_V4_2
|
||||
from dsmr_parser import obis_references as obis
|
||||
from dsmr_parser import telegram_specifications
|
||||
from dsmr_parser.exceptions import InvalidChecksumError, ParseError
|
||||
|
Loading…
Reference in New Issue
Block a user