-
Notifications
You must be signed in to change notification settings - Fork 433
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
Fix grgsm_scanner -l #646
base: master
Are you sure you want to change the base?
Fix grgsm_scanner -l #646
Conversation
|
||
def get_devices(hint=""): | ||
return osmosdr.device_find(osmosdr.device_t(hint)) | ||
|
||
def device_to_dict(dev): | ||
dev_dict = {} | ||
for k, v in parse_qsl(dev.to_string(), separator=","): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to avoid the import of parse_qsl
, we can also do it this way:
def device_to_dict(dev):
dev_dict = {}
for pair in dev.split(","):
k, v = pair.split("=")
try:
dev_dict[k] = literal_eval(v)
except (ValueError, SyntaxError):
dev_dict[k] = literal_eval(f"'{v}'")
return dev_dict
try: | ||
dev_dict[k] = literal_eval(v) | ||
except (ValueError, SyntaxError): | ||
dev_dict[k] = literal_eval(f"'{v}'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This try/except is required to handle the cases where the values returned by to_string
are strings without quotes or strings without quotes starting with /
like /dev/ttyUSB0
for example.
This PR should also fix #636 |
When running the command
grgsm_scanner -l
, the following exception is raised:By looking at the error we can see the that issue is that
dev
is used as a if it was adict
but it's actually adevice_t
. This pull request adds a helper function to convert adevice_t
to adict
so the existing code can work as expected.The conversion is done by using the
to_string
method which is available on objects of typedevice_t
which can give strings like this:"label='RFSPACE SDR-IQ Receiver',sdr-iq=/dev/ttyUSB0"
or this"default_input=False,default_output=False,device_id=3,driver=audio,label='Monitor of USB Audio',soapy=2"
. Then the string is parsed into pairs of key/value usingparse_qsl
and finally the values, which are still strings at this point, are evaluated withliteral_eval
.