dev progress

This commit is contained in:
Nigel Dokter 2017-01-08 11:28:15 +01:00
parent 663024239f
commit 87a5a2d2fa
4 changed files with 10 additions and 25 deletions

View File

@ -9,8 +9,7 @@ from serial_asyncio import create_serial_connection
from . import telegram_specifications from . import telegram_specifications
from .exceptions import ParseError from .exceptions import ParseError
from .parsers import TelegramParserV2_2, TelegramParserV4 from .parsers import TelegramParserV2_2, TelegramParserV4
from .serial import (SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4, from .serial import (SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4,TelegramBuffer)
is_end_of_telegram, is_start_of_telegram, TelegramBuffer)
def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None): def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None):
@ -81,7 +80,9 @@ class DSMRProtocol(asyncio.Protocol):
data = data.decode('ascii') data = data.decode('ascii')
self.log.debug('received data: %s', data) self.log.debug('received data: %s', data)
self.telegram_buffer.put(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): def connection_lost(self, exc):
"""Stop when connection is lost.""" """Stop when connection is lost."""

View File

@ -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): class SerialReader(object):
PORT_KEY = 'port' PORT_KEY = 'port'
@ -123,8 +107,8 @@ class AsyncSerialReader(SerialReader):
class TelegramBuffer(object): class TelegramBuffer(object):
""" """
Used as a buffer for a stream or telegram data. Returns telegram from buffer Used as a buffer for a stream of telegram data. Constructs full telegram
when complete. strings from the buffered data and returns it.
""" """
def __init__(self): def __init__(self):
@ -132,7 +116,7 @@ class TelegramBuffer(object):
def get_all(self): def get_all(self):
""" """
Remove complete telegrams from buffer and yield them Remove complete telegrams from buffer and yield them.
:rtype generator: :rtype generator:
""" """
for telegram in self._find_telegrams(): for telegram in self._find_telegrams():
@ -160,7 +144,7 @@ class TelegramBuffer(object):
def _find_telegrams(self): 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'). checksum ('!AB12\r\n').
:rtype: list :rtype: list
""" """

View File

@ -1,6 +1,6 @@
import unittest 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.parsers import TelegramParserV2_2
from dsmr_parser import telegram_specifications from dsmr_parser import telegram_specifications
from dsmr_parser import obis_references as obis from dsmr_parser import obis_references as obis

View File

@ -4,7 +4,7 @@ import unittest
import pytz 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 obis_references as obis
from dsmr_parser import telegram_specifications from dsmr_parser import telegram_specifications
from dsmr_parser.exceptions import InvalidChecksumError, ParseError from dsmr_parser.exceptions import InvalidChecksumError, ParseError