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

Detect RT95/VOX #1028

Merged
merged 8 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions chirp/bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
import re
import warnings

from builtins import bytes

from chirp import bitwise_grammar

LOG = logging.getLogger(__name__)
Expand Down
28 changes: 21 additions & 7 deletions chirp/chirp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from builtins import bytes

import base64
import json
import inspect
Expand Down Expand Up @@ -1389,9 +1387,11 @@ def load(self, filename):
pass


class DetectableInterface:
DETECTED_MODELS = None
def class_detected_models_attribute(cls):
return 'DETECTED_MODELS_%s' % cls.__name__


class DetectableInterface:
@classmethod
def detect_from_serial(cls, pipe):
"""Communicate with the radio via serial to determine proper class
Expand All @@ -1400,14 +1400,28 @@ def detect_from_serial(cls, pipe):
RadioError if not. If NotImplemented is raised, we assume that no
detection is possible or necessary.
"""
assert cls.DETECTED_MODELS is None, (
detected = getattr(cls, class_detected_models_attribute(cls), None)
assert detected is None, (
'Class has detected models but no detect_from_serial() '
'implementation')
raise NotImplementedError()

@classmethod
def detected_models(cls):
return list(cls.DETECTED_MODELS or [])
def detected_models(cls, include_self=True):
detected = getattr(cls, class_detected_models_attribute(cls), [])
# Only include this class if it is registered
if include_self and hasattr(cls, '_DETECTED_BY'):
extra = [cls]
else:
extra = []
return extra + list(detected)

@classmethod
def detect_model(cls, detected_cls):
detected_attr = class_detected_models_attribute(cls)
if getattr(cls, detected_attr, None) is None:
setattr(cls, detected_attr, [])
getattr(cls, detected_attr).append(detected_cls)


class CloneModeRadio(FileBackedRadio, ExternalMemoryProperties,
Expand Down
10 changes: 4 additions & 6 deletions chirp/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def register(cls):
DRV_TO_RADIO[ident] = cls
RADIO_TO_DRV[cls] = ident

if not hasattr(cls, '_DETECTED_MODEL'):
cls._DETECTED_MODEL = False
if not hasattr(cls, '_DETECTED_BY'):
cls._DETECTED_BY = None

return cls

Expand All @@ -81,10 +81,8 @@ def detected_by(manager_class):
def wrapper(cls):
assert issubclass(cls, chirp_common.CloneModeRadio)

cls._DETECTED_MODEL = True
if manager_class.DETECTED_MODELS is None:
manager_class.DETECTED_MODELS = []
manager_class.DETECTED_MODELS.append(cls)
cls._DETECTED_BY = manager_class
manager_class.detect_model(cls)
return cls

return wrapper
Expand Down
Loading
Loading