1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

make it a little easier to create application encoded integer tags

This commit is contained in:
Joel Bender 2015-08-24 13:39:11 -04:00
parent 1dcbddeca8
commit 46f9b19fbf

View File

@ -16,8 +16,6 @@ from bacpypes.primitivedata import Tag, ApplicationTag, ContextTag, \
DecodingError DecodingError
from bacpypes.pdu import PDUData from bacpypes.pdu import PDUData
from test_integer import integer_tag
from test_unsigned import unsigned_tag
# some debugging # some debugging
_debug = 0 _debug = 0
@ -29,6 +27,16 @@ def tag_tuple(tag):
return (tag.tagClass, tag.tagNumber, tag.tagLVT, tag.tagData) return (tag.tagClass, tag.tagNumber, tag.tagLVT, tag.tagData)
@bacpypes_debugging
def IntegerTag(v):
"""Return an application encoded integer tag with the appropriate value.
"""
obj = Integer(v)
tag = Tag()
obj.encode(tag)
return tag
@bacpypes_debugging @bacpypes_debugging
def obj_decode(blob): def obj_decode(blob):
"""Build PDU from the string, decode the tag, convert to an object.""" """Build PDU from the string, decode the tag, convert to an object."""
@ -472,7 +480,7 @@ class TestTagList(unittest.TestCase):
def test_peek(self): def test_peek(self):
if _debug: TestTagList._debug("test_peek") if _debug: TestTagList._debug("test_peek")
tag0 = integer_tag('00') tag0 = IntegerTag(0)
taglist = TagList([tag0]) taglist = TagList([tag0])
# peek at the first tag # peek at the first tag
@ -495,9 +503,9 @@ class TestTagList(unittest.TestCase):
ContextTag(0, xtob('00')), ContextTag(0, xtob('00')),
ContextTag(1, xtob('01')), ContextTag(1, xtob('01')),
OpeningTag(2), OpeningTag(2),
integer_tag('03'), IntegerTag(3),
OpeningTag(0), OpeningTag(0),
integer_tag('04'), IntegerTag(4),
ClosingTag(0), ClosingTag(0),
ClosingTag(2), ClosingTag(2),
] ]
@ -538,8 +546,8 @@ class TestTagList(unittest.TestCase):
""" """
if _debug: TestTagList._debug("test_endec_1") if _debug: TestTagList._debug("test_endec_1")
tag0 = integer_tag('00') tag0 = IntegerTag(0x00)
tag1 = integer_tag('01') tag1 = IntegerTag(0x01)
taglist = TagList([tag0, tag1]) taglist = TagList([tag0, tag1])
data = PDUData() data = PDUData()
@ -572,7 +580,7 @@ class TestTagList(unittest.TestCase):
if _debug: TestTagList._debug("test_endec_2") if _debug: TestTagList._debug("test_endec_2")
tag0 = OpeningTag(0) tag0 = OpeningTag(0)
tag1 = integer_tag('0102') tag1 = IntegerTag(0x0102)
tag2 = ClosingTag(0) tag2 = ClosingTag(0)
taglist = TagList([tag0, tag1, tag2]) taglist = TagList([tag0, tag1, tag2])