softerhardware / Hermes-Lite2

A second generation low-cost amateur HF software defined radio transceiver.
http://www.hermeslite.com
227 stars 80 forks source link

hermeslite.py: discover HL2s on all interfaces #160

Closed RDPowerz closed 3 years ago

RDPowerz commented 3 years ago

I refactored the discovery code in hermeslite.py to do discovery on all network interfaces.

There were some complications so please read the following before deciding if you want the code or not.

One pain point is that it uses the netifaces module which is not a core module, so users will have to use 'pip' or their linux distro's installer to install it. I suppose that could be a show-stopper since it's been pretty challenging to get people to install python correctly to begin with, but OTOH it's just one more step during install that we could document. I looked at a lot of different things and every approach other than using netifaces was an inferior choice.

My install of netifaces on Windows from the command prompt looked like:

$ python -m pip install netifaces Collecting netifaces Downloading netifaces-0.11.0-cp38-cp38-win_amd64.whl (16 kB) Installing collected packages: netifaces Successfully installed netifaces-0.11.0

I kept all the existing methods the same, in one case added an optional argument. The semantics are different because it is running discovery on all network interfaces. I think this is a benefit because it's not guaranteed that the HL2 is attached to the first/primary network interface, which is the semantics of the current code. I can't think of a case where this is a problem, and if it is, you can either bypass discovery by calling HermesLite's constructor or you can provide the optional ifaddr argument I added to discover().

I left in all the original print statements and added more because it was hard to track what it was doing otherwise, the failure messages for port 1025 didn't make sense unless you knew it was trying an interface that doesn't have any HL2s on it.

I tested with two HL2s on Linux and on Windows 7. I tested the case with two HL2s on two different network interfaces on Linux and tested the case with two HL2s on one wifi interface from Windows and Linux.

If you don't want the code because it needs a non-core module or because the print statements are confusing or it's all just too much added complexity, that's fine by me. I just wanted to offer it up in case it is of use.

Regards, RDP

softerhardware commented 3 years ago

Thanks for the updates!