skuep / AIOC

Ham Radio All-in-one-Cable
MIT License
747 stars 59 forks source link

AIOC and AllStarLink with simple_usb Module #61

Open Murf opened 8 months ago

Murf commented 8 months ago

More of a question than an Issue, I am trying to get my AIOC working with a 'feng UV-5R for an AllStarLink node. I recompiled the chan_simpleusb module with the correct vendor and product ID's, and was surprised when the PTT came on during the simpleusb-tune-menu utility option to flash the PTT. I know I have a long way to go, especially with COR. How is COR currently handled by default? is it a code sent on the serial port? Thanks, Murf.

Murf commented 8 months ago

Oh wow I just found the solution already, I was on the right track. https://www.youtube.com/watch?v=dMoZEgm2ULo&ab_channel=chcmedia FYI

skuep commented 8 months ago

Nice! So this is a first confirmed use for All-star link for me 🙂 Did you end up using the Virtual COS function of the AIOC?

Murf commented 8 months ago

Well I tried to do what they did in that video and did not get the same results. I assume Virtual-COS is a serial code to watch for instead of a hardware line? The problem with the AllStarLink usbradio module is it only looks at the soundcard, not the serial port, I have left a comment asking him how he does it. Ideally I would want to be using serial and sound, like any normal ham radio application would :) For that I will need to add code to the module to do that as well. Murf.

skuep commented 8 months ago

Virtual COS essentially listens to the audio from the radio and tries to determine if there is a carrier (squelch disengaged). Currently this is done using very simple thresholding. It asserts the volume down (iirc) key of the cm108 emulation, no serial codes required.

Murf commented 8 months ago

Ah yes I saw that option in the ASL module code, cool I will see if I can get it to work!

Murf commented 8 months ago

Oh.. I think I should be using v 1.3 RC1 not 1.2, correct Simon?

skuep commented 8 months ago

Ooops, you are correct! My bad. It looks like the COS feature was introduced in the v1.3 version.

Shopstream204 commented 8 months ago

Murf, is it possible to share your modified version of Allstarlink? I would love to test it with my AOIC.

Murf commented 8 months ago

All I modified in chan_usbradio.c was the product and vendor ID to match the 1.2 ones.So reversing this, if you can set these to CM108 in 1.3 you are already good to try it.I plan to try this today and will let you know the outcome.

Murf commented 8 months ago

Simon rather than rebuild v1.3 rc1 with the CM108 Vendor and product ID , here is the changes to the ASL asterisk module : https://github.com/Murf/ASL-Asterisk/commit/91b621e45c8ade2592f2a5e41bfa3558272de0bd

Only chan_usbradio.c needs changes

Murf commented 8 months ago

Ok I see no difference with V1.3 :(

Murf commented 8 months ago

UPDATE: and facepalm... I was using a Quansheng UV-K6, and have now swapped to a 'feng UV-5R and am progressing.

Murf commented 8 months ago

And now OPERATIONAL :) TL;DR Use a Baofeng UV-5R, make sure you either 1) Set the Vendor/Product ID of the AIOC to 0d8c:000c OR Modify AllStarLink asterisk module chan_usbradio.c to use the normal AIOC IDs of 1209:7388.

skuep commented 8 months ago

UPDATE: and facepalm... I was using a Quansheng UV-K6, and have now swapped to a 'feng UV-5R and am progressing.

What exactly didn't work? I think those should be very similar 🤔

And now OPERATIONAL :)

Nice! With virtual COS? Or are you using another way of detecting incoming voice?

Modify AllStarLink asterisk module chan_usbradio.c to use the normal AIOC IDs of 1209:7388.

Just curious, how did you do it? Using the python script? Note that the next time you use the script, you need to adjust the VID/PID to the new one, or it doesn't find the AIOC.

Murf commented 8 months ago

For the Quansheng, when I run the radio-tune-menu option "F" which is supposed to turn on PTT, emit a tone, then turn off PTT, which it does for the Baofeng UV-5R, but for the Quansheng UV-K6 the PTT stays on and never goes off, and no tone is emitted.

For the Vendor/Product ID detection I didnt use the script as I could not get it to run. Modifying the ASL chan_usbradio module itself to look for AIOC IDs rather than CM108 IDs is what I did. So no serial port involved at all, just pure CM108 emulation.

For COS I didnt really do anything to the AllStarLink config other than what the Youtube I linked suggested, which is basically just set carrierfrom=VOX in usbradio.conf

May I ask, what exactly did you base the CM108 emulation on? Was it the PDF that ASL use for modifying the CM108 hardware?

Shopstream204 commented 8 months ago

Has anyone been able to successfully use the script? I have tried on both a linux and windows machine and each time it fails.

Murf commented 8 months ago

Has anyone been able to successfully use the script? I have tried on both a linux and windows machine and each time it fails.

Which script?

Shopstream204 commented 8 months ago

The script for v1.3 RC1 that allows the vid and pid to be changed

Murf commented 8 months ago

The script for v1.3 RC1 that allows the vid and pid to be changed

No I could not get it to run either, errors in the file. I just recompiled chan_usbradio.c with correct IDs

Shopstream204 commented 8 months ago

What all is involved in recompiling the file? Once the file is compiled is it as easy as placing the file on your existing Allstarlink install or do you need to do a complete reinstall of Allstarlink?

Murf commented 8 months ago

What all is involved in recompiling the file? Once the file is compiled is it as easy as placing the file on your existing Allstarlink install or do you need to do a complete reinstall of Allstarlink?

You will need to install build tools on the computer that you have ASL installed on, what OS is it? and distribution? Then you will need to download the version of ASL you are using (for example I am using ASL V2 beta) Once you can confirm you can build it (not install it) then edit the chan_usbradio.c file to make the changes, as shown above in previous posts. then just copy the module "chan_usbradio.so" to /usr/lib/asterisk/modules/, and restart asterisk or reboot

Shopstream204 commented 7 months ago

@Murf I am using the ASL Beta 2 ISO. I believe it's based on Debian 10.

Murf commented 7 months ago

@Murf I am using the ASL Beta 2 ISO. I believe it's based on Debian 10.

Perfect, thats what I am using.

Hadgee commented 7 months ago

Hi, @Murf Brett,

Is the modified 'chan_usbradio.c' (chan_usbradio.so) file available?. I have been struggling and only running Raspberry Pi on Linux and would like to try it. I have no major knowledge but can get the file to the correct directory. I would love to get my AIOC working on AllStar. Thanks in advance, or more information (laymans terms) on how to do it. Ellis

Murf commented 7 months ago

@Hadgee The file is available in my github, but you need to be able to build it. If you are not familiar with this process then it is probably not the best option for you.

On Mon, 25 Mar 2024 at 07:38, Hadgee @.***> wrote:

Hi, @Murf https://github.com/Murf Brett,

Is the modified 'chan_usbradio.c' (chan_usbradio.so) file available?. I have been struggling and only running Raspberry Pi on Linux and would like to try it. I have no major knowledge but can get the file to the correct directory. I would love to get my AIOC working on AllStar. Thanks in advance, or more information (laymans terms) on how to do it. Ellis

— Reply to this email directly, view it on GitHub https://github.com/skuep/AIOC/issues/61#issuecomment-2016936090, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG72OOEAQ4LCIQMOIJCMATYZ42UJAVCNFSM6AAAAABECYDKOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJWHEZTMMBZGA . You are receiving this because you were mentioned.Message ID: @.***>

Hadgee commented 7 months ago

@Murf No problem. I will investigate further.

Hadgee commented 7 months ago

@Murf In the interest of my sanity....after losing far too many hours with permission errors and getting nowhere would it be possible to have a copy of your 'chan_usbradio.so' file as I believe it is only the equivalent of a library file.? I will try anything before assigning my AIOC cable to chirp and APRS and moving on from AllStarLink home repeater. Yours Hopingly Ellis de M5AEI

Murf commented 7 months ago

@Murf In the interest of my sanity....after losing far too many hours with permission errors and getting nowhere would it be possible to have a copy of your 'chan_usbradio.so' file as I believe it is only the equivalent of a library file.? I will try anything before assigning my AIOC cable to chirp and APRS and moving on from AllStarLink home repeater. Yours Hopingly Ellis de M5AEI

Assuming you are using a Pi, here you go chan_usbradio.zip Also here: https://archive.org/download/chan_usbradio/chan_usbradio.zip

Hadgee commented 7 months ago

@Murf Thank you, yes Pi. I will let you know how it goes.

Hadgee commented 7 months ago

@Murf Thanks again. All good first contact through to Hubnet today. AIOC V1.3. Pi4 8gb running ASL 2.0Beta. I am using Baofeng UV-82. I have a bit of tweaking but works a treat. :-)

Murf commented 7 months ago

Glad to help!

On Tue, 2 Apr 2024 at 01:33, Hadgee @.***> wrote:

@Murf https://github.com/Murf Thanks again. All good first contact through to Hubnet today. AIOC V1.3. Pi4 8gb running ASL 2.0Beta. I am using Baofeng UV-82. I have a bit of tweaking but works a treat. :-)

— Reply to this email directly, view it on GitHub https://github.com/skuep/AIOC/issues/61#issuecomment-2029852499, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG72ONT442O2E4XOK6NRTDY3FV4NAVCNFSM6AAAAABECYDKOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRZHA2TENBZHE . You are receiving this because you were mentioned.Message ID: @.***>

G1LRO commented 7 months ago

Hi @Murf do you know if the SimpleUSB option been accomplished using the change in USB IDs and @skuep's virtual-COS? So just using a reconfiguration of the AIOC? It would be good to achieve this as SimpleUSB is much easier for novice users to do on AllStarLink. It's not clear from the above thread, but it looks like USBRadio is the only config that's been made to work. Cheers Mark

Murf commented 7 months ago

Hi @Murf do you know if the SimpleUSB option been accomplished using the change in USB IDs and @skuep's virtual-COS? So just using a reconfiguration of the AIOC? It would be good to achieve this as SimpleUSB is much easier for novice users to do on AllStarLink. It's not clear from the above thread, but it looks like USBRadio is the only config that's been made to work. Cheers Mark

I think it is best to wait for the ability to change the ID's on the AIOC firmware itself, then no code changes will be needed for asterisk. @skuep do you have an ETA on a working python script to set AIOC USB Vendor/Device IDs please?

G1LRO commented 7 months ago

Hi @Murf I think the USB ID manipulation was delivered and closed on https://github.com/skuep/AIOC/issues/46

So hopefully we are nearly there. I'm not skilled in the manipulation of the AIOC registers so it would be nice to have a canned script to perform the AIOC register mods to make it SimpleUSB compatible. (setting USB ID and Virtual COS)

Murf commented 7 months ago

Yes, that was the plan via python script

On Thu, 4 Apr 2024 at 09:56, G1LRO @.***> wrote:

Hi @Murf https://github.com/Murf I think the USB ID manipulation was delivered and closed on #46 https://github.com/skuep/AIOC/issues/46

So hopefully we are nearly there. I'm not skilled in the manipulation of the AIOC registers so it would be nice to have a canned script to perform the AIOC register mods to make it SimpleUSB compatible. (setting USB ID and Virtual COS)

— Reply to this email directly, view it on GitHub https://github.com/skuep/AIOC/issues/61#issuecomment-2035744099, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG72OI3KEOEAOELCXXP4TDY3SCIRAVCNFSM6AAAAABECYDKOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZVG42DIMBZHE . You are receiving this because you were mentioned.Message ID: @.***>

Shopstream204 commented 7 months ago

There was a script provided for RC1.3 but I have not had success using it. That said I have no python knowledge and I am relatively green with Linux.

Murf commented 7 months ago

Yes I believe that script was incomplete. I could be wrong, but I expect its functionality will be something like: ./scriptname.py V_ID=0x0123 H_ID=0xABCD pretty straightforward...

On Thu, 4 Apr 2024 at 11:57, Shopstream204 @.***> wrote:

There was a script provided for RC1.3 but I have not had success using it. That said I have no python knowledge and I am relatively green with Linux.

— Reply to this email directly, view it on GitHub https://github.com/skuep/AIOC/issues/61#issuecomment-2035889637, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG72OIBUMAWVYEFXVMGYK3Y3SQNZAVCNFSM6AAAAABECYDKOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZVHA4DSNRTG4 . You are receiving this because you were mentioned.Message ID: @.***>

G1LRO commented 7 months ago

Hi @skuep , please do you have a moment to draft a script to configure the AIOC for AllStarLink as described above?

Hadgee commented 7 months ago

@G1LRO Thank you for your firmware update script. I flashed my AIOC to v1.3 using it.

skuep commented 7 months ago

You are correct. It's a pretty advanced feature with some caveats, that's why there is no canned script available yet.

import sys
import hid
from struct import Struct
from enum import IntEnum, IntFlag

class Register(IntEnum):
    MAGIC = 0x00
    USBID = 0x08
    AIOC_IOMUX0 = 0x24
    AIOC_IOMUX1 = 0x25
    CM108_IOMUX0 = 0x44
    CM108_IOMUX1 = 0x45
    CM108_IOMUX2 = 0x46
    CM108_IOMUX3 = 0x47
    SERIAL_CTRL = 0x60
    SERIAL_IOMUX0 = 0x64
    SERIAL_IOMUX1 = 0x65
    SERIAL_IOMUX2 = 0x66
    SERIAL_IOMUX3 = 0x67
    VPTT_LVLCTRL = 0x82
    VPTT_TIMCTRL = 0x84
    VCOS_LVLCTRL = 0x92
    VCOS_TIMCTRL = 0x94

class Command(IntFlag):
    DEFAULTS = 0x10
    RECALL = 0x40
    STORE = 0x80

def read(device, address):
    data = device.get_feature_report(int(address), 5)
    address, value = Struct('<BL').unpack(data)
    return value

def write(device, address, value):
    data = Struct('<BL').pack(address, value)
    device.send_feature_report(data)

# AIOC is searched for on the system using these values
aioc = hid.Device(vid=0x1209, pid=0x7388)

magic = Struct("<L").pack(read(aioc, Register.MAGIC))

if (magic != b'AIOC'):
    sys.exit(-1)

print(f'Manufacturer: {aioc.manufacturer}')
print(f'Product: {aioc.product}')
print(f'Serial No: {aioc.serial}')
print(f'Magic: {magic}')

if True:
    # Load the hardware defaults
    print(f'Loading Defaults...')
    write(aioc, 0, Command.DEFAULTS)

if True:
    # Set USB VID and PID (use with caution. Will need changes above to be able to re-configure the AIOC)
    vid = 0x1209 # Set VID here
    pid = 0x7388 # Set PID here
    write(aioc, Register.USBID, (vid << 0) | (pid << 16))
    print(f'Now USBID: {read(aioc, Register.USBID):08x}')

if True:
    # Store settings into flash
    print(f'Storing...')
    write(aioc, 0, Command.STORE)

This should do the trick. You can set the VID/PID to whatever values you like in the commented lines. After the script has stored the settings on the AIOC, you need to disconnect and reconnect it to your computer. Note that this requires the v1.3.0 pre-release firmware flashed to the AIOC beforehand.

One important thing: If, for some reason you want to run the script again (e.g. reverting back the AIOC to defaults), you need to change the VID/PID to the new values in the commented line at the top. Otherwise the script will not find the AIOC (because it expects it to be at 0x1209/0x7388). In addition, you should remove all other CM108 devices, that could have the same VID/PID in order for the script not to confuse it with an AIOC.

Second thing: In another issue, we found some problems in conjunction with running the script on Windows. This has to do with Windows being a bit more accurate with what commands it can send to the AIOC (or any HID device). I hope I can find a nice solution for this in the future. For now, you need to use Linux or a Raspberry Pi.

G1LRO commented 7 months ago

Thanks for this @skuep it's really helpful. Can we confirm that the script also enables the Virtual-COS function at the same time?

skuep commented 7 months ago

Sorry, I forgot to include it, I will update it later

skuep commented 7 months ago

I was wrong, I think virtual COS should be enabled by default on the CM108 volume up or down button.

G1LRO commented 7 months ago

Thanks @skuep it does appear the virtual COS is on by default following my initial testing. So far so good.

To help others trying to configure, I have set these in the SimpleUSB tune menu.:

COSFROM Mode (currently "usbinvert") PTT Mode (currently active LOW)

I found the radio went into PTT on boot up of the AllStarLink so had to change the PTT mode. The COS mode in SimpleUSB is also inverted by default.

I think there are other settings to change to optimize performance, this is just a get-you-going.

Murf commented 7 months ago

I have finally managed to get the python script to run (hint for when using the ASL2 pi image, command is python3 scriptfilename.py, and I needed pip3 install hid==1.0.4)

Unfortunately it does not work:

root@asl2-46471:/home/repeater# python3 aioc_params.py Traceback (most recent call last): File "aioc_params.py", line 42, in aioc = hid.Device(vid=0x1209, pid=0x7388) File "/usr/local/lib/python3.7/dist-packages/hid/init.py", line 130, in init raise HIDException('unable to open device') hid.HIDException: unable to open device

root@asl2-46471:/home/repeater# lsusb Bus 001 Device 005: ID 1209:7388 Generic

Murf commented 7 months ago

UPDATE: I got the python script to work, I had to: yum install hidapi as well as do it on another linux box

skuep commented 7 months ago

That's odd.. it should work on the raspberry pi. Did they do some fundamental changes to the ASL image? Is "root" really the root user (uid 0) or is it a regular user just named root? You could try using sudo with the python3 command, just to be sure...

Murf commented 7 months ago

Its strange, after I change the IDs to CM108 it now lets me use the script (once I updated the ID's to open of course)

On Sun, 7 Apr 2024 at 18:59, Simon Küppers @.***> wrote:

That's odd.. it should work on the raspberry pi. Did they do some fundamental changes to the ASL image? Is "root" really the root user (und 0) or is it a regular user just makes root? You could try using sudo with the python3 command, just to be sure...

— Reply to this email directly, view it on GitHub https://github.com/skuep/AIOC/issues/61#issuecomment-2041375652, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG72OMO6X4SI3ONYACQKY3Y4EDFJAVCNFSM6AAAAABECYDKOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGM3TKNRVGI . You are receiving this because you were mentioned.Message ID: @.***>

skuep commented 7 months ago

So you changed the USB IDs on your other Linux system and now it works on the ASL image? Hmmm.. still smells a bit like permission problems.

Murf commented 7 months ago

Agreed :)

On Sun, 7 Apr 2024 at 20:17, Simon Küppers @.***> wrote:

So you changed the USB IDs on your other Linux system and now it works on the ASL image? Hmmm.. still smells a bit like permission problems.

— Reply to this email directly, view it on GitHub https://github.com/skuep/AIOC/issues/61#issuecomment-2041407025, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG72OMP5VVHVBJKVARCKP3Y4EMLHAVCNFSM6AAAAABECYDKOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGQYDOMBSGU . You are receiving this because you were mentioned.Message ID: @.***>