Thanks for the feedback Dan. I'm going to opt for named formatters but I'll keep it as straightforward as possible. I thought about overloaded fixed-string names but that would still mean I'd have to add more conditionals or class-based overloads of get_memory(). By using formatters I can keep the decoded memory attribute names the same between 2 models, and the parent class function can be used without any overload in the inherited class.
-- Brian
On Thu, Sep 1, 2016 at 7:10 AM, Dan Smith dsmith@danplanet.com wrote:
I'm working on adding Leixen VV-898S support. They decided to take what used to be 1 bit for Power and 1 bit for Mode and instead use both bits for Power, and move Mode to a previously unused bit. I could work around this by parameterizing the map, so it would look sorta like this:
u8 %s:1, foo1:1, foo2:1, foo3:1, foo4:1, foo5:1, %s;
The first radio would format it as:
MEM_FORMAT % ( 'unknown' , 'mode:1,power:1' )
while the second would format it as:
MEM_FORMAT % ( 'mode' , 'power:2' )
Any fundamental objections to this approach? Should I just suck it up and combine the bits at read time on the second radio instead of parameterizing?
We've done this before in places. I do think we should use it sparingly as it's confusing. The places we've used it before have mostly been around setting an offset for a "#seekto %i" kind of thing.
So, if it's massively harder to do it without the parameter bit then it's probably worth it. If not, I'd rather just do something like:
u8 powerormode:1 ... newpower:1;
and just handle the switch in code depending on the model. I just figure it's easier to read and debug later for someone that doesn't know what is going on. Just MHO though.
If you're going to do something like what you describe, it would probably be good to use named parameters so that it's easier to figure out which one is which, instead of just by counting:
MEM_FORMAT = """ u8 %(powerormode)s:1, ... %(newpower)s:1; my_format = MEM_FORMAT % {'powerormode': 'power', 'newpower': 'unknown'}
...or something.
--Dan