Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of malformed MEI responses #47

Closed
Tamarinen opened this issue May 16, 2014 · 0 comments
Closed

Handling of malformed MEI responses #47

Tamarinen opened this issue May 16, 2014 · 0 comments

Comments

@Tamarinen
Copy link

We have a heat pump that manages to confuse pymodbus when asked to identify itself through RTU. When asked for the mandatory information, the response is as follows:

0x01 00x2b 0x0e 0x01 0x01 0x00 0x00 0x01 0x00 0x04 NIBE 0x01 0x08 F1345-60 0x02 0x04 4150 0xab 0x9a

The pump indicate that the MEI response contain only one object, while three are sent, which calculateRtuFrameSize() in mei_message.py doesn't like at all.

I propose this method of verifying the MEI response structure:

@classmethod
def calculateRtuFrameSize(cls, buffer):
    ''' Calculates the size of the message

    :param buffer: A buffer containing the data that have been received.
    :returns: The number of bytes in the response.
    '''
    size = 8 # skip the header information

    while size + 2 < len(buffer):
        _, object_size = struct.unpack('>BB', buffer[size:size+2])
        size += object_size + 2

    return size + 2

Instead of trying to read the specified number of objects, this read objects until the input buffer is exhausted, returning a valid length for a certain class of malformed MEI responses. The same method of parsing the response is used in ReadDeviceInformationResponse.decode().

@dhoomakethu dhoomakethu added this to the 2.0.0 milestone Dec 23, 2017
@dhoomakethu dhoomakethu mentioned this issue Dec 23, 2017
12 tasks
@dhoomakethu dhoomakethu modified the milestones: 2.0.0, 1.5.1 May 3, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants