Rammbock
Rammbock copied to clipboard
Error when using _Freelength pdu
When I use the pdu length as a free length while defining the protocol.
...
...
self.pdu('*')
self.end_protocol()
I get a python error saying
"""
pydev debugger: starting
Traceback (most recent call last):
File "...\eclipse\plugins\org.python.pydev_2.7.3.2013031601\pysrc\pydevd.py", line 1397, in
File "...\eclipse\plugins\org.python.pydev_2.7.3.2013031601\pysrc\pydevd.py", line 1090, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "...py", line 55, in
"""
Hi,
You cannot use '*' for pdu length. You must either define a static length or refer to some field in protocol header:
"""Defines the message in protocol template.
Length must be the name of a previous field in template definition or a
static value for fixed length protocols.
Examples:
| pdu | 5 |
| u8 | length |
| pdu | length - 1 |
"""
-Janne
2013/7/16 harshm [email protected]
When I use the pdu length as a free length while defining the protocol.
... ... self.pdu('*') self.end_protocol()
I get a python error saying
""" pydev debugger: starting Traceback (most recent call last): File "...\eclipse\plugins\org.python.pydev_2.7.3.2013031601\pysrc\pydevd.py", line 1397, in debugger.run(setup['file'], None, None)
File "...\eclipse\plugins\org.python.pydev_2.7.3.2013031601\pysrc\pydevd.py", line 1090, in run pydev_imports.execfile(file, globals, locals) #execute the script File "...py", line 55, in msg = myObject.server_receives_without_validation() File "C:\Python27\lib\site-packages\Rammbock\core.py", line 478, in server_receives_without_validation with self._receive(self._servers, _parameters) as (msg, *): File "C:\Python27\lib\contextlib.py", line 17, in enter return self.gen.next() File "C:\Python27\lib\site-packages\Rammbock\core.py", line 503, in _receive msg = node.get_message(self._get_message_template(), **configs) File "C:\Python27\lib\site-packages\Rammbock\networking.py", line 73, in get_message return self._get_from_stream(message_template, self._message_stream, timeout=timeout, header_filter=header_filter) File "C:\Python27\lib\site-packages\Rammbock\networking.py", line 76, in _get_from_stream return stream.get(message_template, timeout=timeout, header_filter=header_filter) File "C:\Python27\lib\site-packages\Rammbock\templates\message_stream.py", line 34, in get header, pdu_bytes = self._protocol.read(self._stream, timeout=timeout) File "C:\Python27\lib\site-packages\Rammbock\templates\containers.py", line 165, in read length_param = header[self.pdu_length.field].int AttributeError: '_FreeLength' object has no attribute 'field'
"""
— Reply to this email directly or view it on GitHubhttps://github.com/robotframework/Rammbock/issues/14 .
Hello,
Thank you for your response.
Referring to a field in the protocol has worked correctly, but when I try using the Static Length, it gives me an error saying,
File "C:\Python27\lib\site-packages\Rammbock\templates\containers.py", line 165, in read
length_param = header[self.pdu_length.field].int
AttributeError: '_StaticLength ' object has no attribute 'field'
I have modify some code. it seems Ok for this issue. do you need it?
Yes, I'd be interested to see the changes.
Thanks, Harsh
On Mon, Sep 9, 2013 at 9:32 AM, johnbearzhao [email protected]:
I have modify some code. it seems Ok for this issue. do you need it?
— Reply to this email directly or view it on GitHubhttps://github.com/robotframework/Rammbock/issues/14#issuecomment-24073897 .
Harsh Hitesh Mehta Master of Sciencehttp://www.seas.upenn.edu/prospective-students/graduate/masters/index.php | Telecommunication & Networking http://www.seas.upenn.edu/profprog/tcom/, University of Pennsylvania http://www.upenn.edu. Senior Project Electrical Engineer - Embeddedhttp://www.linkedin.com/in/harshmehta1111/ Lutron Electronics Inc. http://www.lutron.com
i modified src/Rammbock/templates/containers.py file, below is diff
20c20
< from primitives import Length, Binary, TBCD
---
> from primitives import Length, Binary, TBCD ,_StaticLength
169,170c169,174
< length_param = header[self.pdu_length.field].int
< pdu_bytes = stream.read(self.pdu_length.calc_value(length_param))
---
> if isinstance(self.pdu_length, _StaticLength):
> len1 = self.pdu_length.value
> else :
> length_param = header[self.pdu_length.field].int
> len1= self.pdu_length.calc_value(length_param)
> pdu_bytes = stream.read(len1)
Thanks for the help.
It's interesting how you check the instance of the pdu_length for _StaticLength class, because a similar error also occurs when you use a _FreeLength (wildcard *).
Nevertheless, thanks once again.
Best, Harsh
On Mon, Sep 9, 2013 at 10:21 AM, johnbearzhao [email protected]:
i modified src/Rammbock/templates/containers.py file, below is diff
20c20 < from primitives import Length, Binary, TBCD
from primitives import Length, Binary, TBCD ,_StaticLength 169,170c169,174
< length_param = header[self.pdu_length.field].int
< pdu_bytes = stream.read(self.pdu_length.calc_value(length_param))
if isinstance(self.pdu_length, _StaticLength): len1 = self.pdu_length.value else : length_param = header[self.pdu_length.field].int len1= self.pdu_length.calc_value(length_param) pdu_bytes = stream.read(len1)
— Reply to this email directly or view it on GitHubhttps://github.com/robotframework/Rammbock/issues/14#issuecomment-24079591 .
Harsh Hitesh Mehta Master of Sciencehttp://www.seas.upenn.edu/prospective-students/graduate/masters/index.php | Telecommunication & Networking http://www.seas.upenn.edu/profprog/tcom/, University of Pennsylvania http://www.upenn.edu. Senior Project Electrical Engineer - Embeddedhttp://www.linkedin.com/in/harshmehta1111/ Lutron Electronics Inc. http://www.lutron.com
Hi!
Sorry for the delay.. I have now again some time to work on this project.
Could you provide an example test that explains what goes wrong?
We already have an acceptance test where we use a pdu with a fixed length:
Define simple protocol New protocol Example uint 1 field 16 pdu 4 End protocol