[chirp_devel] Parameterized memory maps

Dan Smith
Thu Sep 1 07:10:49 PDT 2016


> 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



More information about the chirp_devel mailing list