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

waiter() function #3

Open
qurm opened this issue Feb 17, 2019 · 3 comments
Open

waiter() function #3

qurm opened this issue Feb 17, 2019 · 3 comments

Comments

@qurm
Copy link

qurm commented Feb 17, 2019

Hi,

I came across this project while looking for a fully Python-based SMA inverter tool, that would be easier to maintain & modify than the various C language sbfspot projects. It looks like a well structured code base - thanks for your efforts!

I have spent some hours understanding and commenting, but there's one area that puzzles me still. Can you explain the decorator function below, and how it works with the various tx & rx functions & the @waiter decorator? What is the purpose of creating the various _waitcond attributes and the waitvar ?

def waiter(fn):
    """ Adds wait conditions to itself, used with connection.wait() to wait for packets
    :param fn: like rx_raw, rx_outer, rx_ppp from the connection class
    :return: waitfn()
    """
    def waitfn(self, *args):
        fn(self, *args)
        if hasattr(self, '__waitcond_' + fn.__name__):
            wc = getattr(self, '__waitcond_' + fn.__name__)
            if wc is None:
                self.waitvar = args
            else:
                self.waitvar = wc(*args)
    return waitfn

Thanks, Andy

@dgibson
Copy link
Owner

dgibson commented Feb 19, 2019 via email

@qurm
Copy link
Author

qurm commented Feb 21, 2019

Thanks, and that all makes sense! I could not really identify the pattern, though could see it was a like a stack.

There is a line in waitfn(), where you save the args, self.waitvar = args. Would that not get overwritten if there were async packets being received out of order?

Anyway, it seems to work, so I'll leave it alone!!

BTW I did see a different response to a "HELLO" to the one in your code, and was easily fixed, but I guess this may be dependent on the specific inverter model & firmware. I have a SMA 5000TL, about 5 years old.

I am also getting Error responses from the inverter when using the sma2-explore tool and trying various send2 commands from your protocol.txt file. Possibly another small difference, but I should be able to work it out.

Thanks for the response, Andy

@dgibson
Copy link
Owner

dgibson commented Mar 4, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants