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

Add Wouxun KG-UV950P support #832

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add Wouxun KG-UV950P support #832

wants to merge 1 commit into from

Conversation

mrtjr1
Copy link
Contributor

@mrtjr1 mrtjr1 commented Nov 30, 2023

Add support for Wouxun KG-UV950P
Fixes #10498

CHIRP PR Checklist

The following must be true before PRs can be merged:

  • All tests must be passing.
  • Commits should be squashed into logical units.
  • Commits should be rebased (or simply rebase-able in the web UI) on current master. Do not put merge commits in a PR.
  • Commits in a single PR should be related.
  • Major new features or bug fixes should reference a CHIRP issue.
  • New drivers should be accompanied by a test image in tests/images (except for thin aliases where the driver is sufficiently tested already).
  • All files must be GPLv3 licensed or contain no license verbiage. No additional restrictions can be placed on the usage (i.e. such as noncommercial).

Please also follow these guidelines:

  • Keep cleanups in separate commits from functional changes.
  • Please write a reasonable commit message, especially if making some change that isn't totally obvious (such as adding a new model, adding a feature, etc).
  • The first line of every commit is emailed to the users' list after each build. It should be short, but meaningful for regular users (examples: "thd74: Fixed tone decoding" or "uv5r: Added settings support").
  • Do not add new py2-compatibility code (No new uses of six, future, etc).
  • All new drivers should set NEEDS_COMPAT_SERIAL=False and use MemoryMapBytes.
  • New drivers and radio models will affect the Python3 test matrix. You should regenerate this file with tox -emakesupported and include it in your commit.

@mrtjr1 mrtjr1 changed the title Add Wouxun KG-950P support Add Wouxun KG-UV950P support Nov 30, 2023
Add support for Wouxun KG-UV950P
Fixes: #10498
out_str = ''
for c in in_str:
if c > 95:
out_str += ''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not free but has no effect. Just replace this line with pass

elif c >= 80:
out_str += chr(c-48)
else:
out_str += chr(c+48)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what you're doing here? It kinda looks like maybe you're just needing to mask out 0x80 from each of these characters, but I'm not sure what you're trying to accomplish here. Is the character set in the radio just starting at zero (for the character 0)? Maybe 0x80 is just a flag for "capitals" or something? Either way, doing this with magic decimal numbers doesn't make this very understandable by other people with no comments.

else:
out_str += chr(int(ord(c) - 48))
while len(out_str) < 8:
out_str += chr(0x50)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This while loop can be replaced by this:

out_str = out_str.ljust(8, chr(0x50))

out_str += chr(int(ord(c) - 48))
while len(out_str) < 8:
out_str += chr(0x50)
if out_str == " " or out_str == "":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this can be:

if not out_str.strip():

The next person that comes along will have to count how many spaces in that string trigger this special behavior, but the above makes it clear that it's "if it's all spaces, use this special thing".

mem.name = _str_decode(self._memobj.names[number].name)
# Remove trailing whitespaces from the name
mem.name = mem.name.rstrip()
if self.MODEL != "KG-UV950P":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just override _str_decode() on the classes, and make the 950 subclass to do the thing for the 950. That's the reason for the class structure - if you subclass something, everything is inherited unless it is overridden and this is exactly the sort of thing that should be done that way. We honestly have too much of this if self.MODEL stuff in CHIRP. It's quicker to just do it that way in the middle of a complex function (like get_settings()) but for something like this that is a small unit of work that can be overridden, we should do that.

Looking around in this file, it looks like we've collected a lot of this exact pattern, so I think we need to clean that up here and not make it worse.

else:
mem.name = _str_decode_950(self._memobj.names[number].name)
# Remove trailing whitespaces from the name
mem.name = mem.name.rstrip()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do this once at the end instead of repeating the comment and the rstrip() :)

@@ -1249,7 +1287,8 @@ def _get_settings(self):
vfo_grp.append(vfob_grp)
vfoa_grp.append(vfo150_grp)
vfoa_grp.append(vfo450_grp)
if self.MODEL == "KG-UV980P":
if (self.MODEL == "KG-UV980P" or
self.MODEL == "KG-UV950P"):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the sort of thing where I'm willing to go along with the use of the model thing, because it's in the middle of a larger block of stuff that's not easy to swap out. But for the str encode/decode you've already got those as separate methods, so you should use the class hierarchy to do the thing for you.

else:
temp = c + 48
if chr(temp) in chirp_common.CHARSET_ASCII:
_str += chr(temp)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just repeated from str_decode() or one of the many other variants you have in this file? Even if it's not, why put it here instead of with all the others?

if self.MODEL != "KG-UV950P":
_str = _decode(eval("_settings.scanname"+x))
else:
_str = _decode_950(eval("_settings.scanname"+x))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here again, this should be just self._decode() and override it on the subclasses that need it.

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

Successfully merging this pull request may close these issues.

2 participants