DMR on the Fly -Shell Script


Mike KB8JNM
 
Edited

Do read the whole of this thread for additions  / problems / fixes  questions

Here is a rough framework for you to improve on to change your DMR TG via system command.
I have been using and working on a deluxe version of this but long way to go for the time that I have.
So, it is a stripped down version for you to customize and improve.

Be advised this is crude but effective. And easy enough for you to customize and learn from.

Quick theory of operation.

We set a command in rpt.conf to make a silent phone patch (allows you to send all dtmf in your string for other commands as well)
The context is set here as dmrmenu

97=autopatchup,context=dmrmenu,noct=1,farenddisconnect=1,dialtime=90000,quiet=1

We set a extension that matches the command we gave the silent phone patch (extentsions.conf) to run our shell script.
On completion of the ' *97 xxx ' command, it will run the shell script DMRontheFly.sh and pass the extra digits to the script.
which is expected to be in the /opt/Analog_Bridge directory

extensions.conf (edited to include a missing line)

[dmrmenu]
exten = _X.,1,Wait,1
exten = _X.,n,System(asterisk -rx "rpt fun 29283 *21999")
exten = _X.,n,SayAlpha(dmr,${EXTEN})
exten = _X.,n,Wait,3  ; this gives you a chance (3sec) to cancel by hitting the '#' key if incorrect.
exten = _X.,n,System(/opt/Analog_Bridge/DMRonthefly.sh ${EXTEN})
exten = _X.,n,Hangup

Here is the shell script DMRontheFly.sh (don't forget to set proper permissions and/or ownership)

####################################################
#!/bin/bash

# DMR on the Fly !  - KB8JNM
# This is a stripped down version of a larger code segment for folks to build on
# So you can look at the framework of how it works and build to suite
# and/or make it better. Please publish your improvements for others to build on.
# No, sorry, this is not a one size fits all solution but I am working on one. Slowly.
# note that 1999 is my dmr usrp channel private node and the node I am commanding from is 29283
# change to your info as needed

# Your original Analog_Bridge.ini 'needs to be renamed' Analog_Bridge.bk
# It reads the .bk file and writes the .ini file. Manual changes to edit in the .bk file.
# script assumes that the TG number follows the script command
# DMRontheFly xxx

# I placed my script in the /opt/Analog_Bridge directory and call it from there for ease of use.

cd /opt/Analog_Bridge/

sed 's/^txTg =.*/txTg = '"$1"'/g' Analog_Bridge.bk > Analog_Bridge.ini &

wait !$

# Turn off link to dmr node so Allison will not blow through if system is active

asterisk -rx "rpt fun 29283 *11999"

# sleep 1  # you might need to un/comment this pause

systemctl restart analog_bridge

sleep .5

# This is the easiest way thus far to bump start the TG but it has its problems.
# Not always needed. Node sensitive & Mode sensitive. You may get away without the next 4 lines ?
asterisk -rx "rpt fun 29283 *30"
# sleep .5 # you might need to uncomment this ?
asterisk -rx "rpt fun 29283 *20"
asterisk -rx "rpt playback 29283 /var/lib/asterisk/sounds/rpt/monitor"

# you are left with your 'dmr node' connected to the commanding node as 'MONITOR' / RX
# *30 will quickly change that to TX

# This is not going to fit everyone's need as is.
# Take some time to think about the implications of what you are doing with changes.
# Test your revisions somewhere where you will not create a ruckus !
# If you just have a dmr private node commanding from some other single node,
# just change the node numbers. Many changes required for commanding from many nodes.
# But you can see how I did it and make it fit your need/purpose with other methods.
# I have been reluctant to put this out there for all the 'OPPS' that will likely happen.
# So....   Be careful and thoughtful. When I finish what I started in a more foolproof version, I will post it @groups.io.
# EOF ################################################

Do read the rest of this thread for additions  / problems / fixes  questions


Mike Zingman - N4IRR
 

Please be aware that you do NOT have to restart Analog_Bridge.  It has a remote control set of commands built in that allow you to change TG on the fly.  It acts on the command and then passes the very same on to the bridge (MB) for additional processing.


Mike KB8JNM
 

For the lack of the publish framework of operation, this is what I came up with 5 months ago.

Sorry to mislead anyone. Not intended. Thanks.

It acts on what 'command' ?    Could you share the spec  in built-in 'remote control commands'  usage ?

I'm certainly lost as I have never seen such a animal. A link would do. Thanks.


On 11/14/2018 1:41 PM, Mike Zingman - N4IRR wrote:
Please be aware that you do NOT have to restart Analog_Bridge.  It has a remote control set of commands built in that allow you to change TG on the fly.  It acts on the command and then passes the very same on to the bridge (MB) for additional processing.


Steve N4IRS
 

Mike,
You are correct, we are behind in documenting a LOT of what the different programs will do. mea culpa

Here is a shell script for changing TGs on the fly when using Analog_Bridge and MMDVM bridge connected to BM.

#!/bin/bash

# /*
#  * Copyright (C) 2018 N4IRR
#  *
#  * Permission to use, copy, modify, and/or distribute this software for any
#  * purpose with or without fee is hereby granted, provided that the above
#  * copyright notice and this permission notice appear in all copies.
#  *
#  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
#  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
#  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
#  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
#  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
#  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
#  * PERFORMANCE OF THIS SOFTWARE.
#  */

function tune() {
python - <<END
#!/usr/bin/env python

import sys
import socket
import struct

cmd = "txTg=$1"
_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
cmd = struct.pack("BB", 0x05, len(cmd))[0:2] + cmd
# Set the second value below to match the rxPort in the [AMBE_AUDIO] stanza of Analog_Bridge.ini
_sock.sendto(cmd, ('127.0.0.1', 31100))
_sock.close()

END
}

tune $1

Assuming the script is named tune.sh and the rxPort is set to 31100 in Analog_bridge.ini start the program with:
./tune.sh 1234
Where the desired TG is 1234
Send a quick PTT on the analog side and you will be tuned to TG 1234

There is quite a list of possible commands available. Some are dependent on the mode. Along with the other 1001 things we need to do we will try to get the info out.

Steve N4IRS


Mike KB8JNM
 

Thanks Steve for putting that out there.

When I get the time, I will look at this and experiment more to make best use of it through asterisk.

I'll post a good example of use. But it looks like I can just substitute my file re-write with a call to the script.

Just needs some window dressing. Thank You

On 11/14/2018 2:45 PM, Steve N4IRS wrote:
Mike,
You are correct, we are behind in documenting a LOT of what the different programs will do. mea culpa

Here is a shell script for changing TGs on the fly when using Analog_Bridge and MMDVM bridge connected to BM.

#!/bin/bash

# /*
#  * Copyright (C) 2018 N4IRR
#  *
#  * Permission to use, copy, modify, and/or distribute this software for any
#  * purpose with or without fee is hereby granted, provided that the above
#  * copyright notice and this permission notice appear in all copies.
#  *
#  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
#  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
#  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
#  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
#  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
#  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
#  * PERFORMANCE OF THIS SOFTWARE.
#  */

function tune() {
python - <<END
#!/usr/bin/env python

import sys
import socket
import struct

cmd = "txTg=$1"
_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
cmd = struct.pack("BB", 0x05, len(cmd))[0:2] + cmd
# Set the second value below to match the rxPort in the [AMBE_AUDIO] stanza of Analog_Bridge.ini
_sock.sendto(cmd, ('127.0.0.1', 31100))
_sock.close()

END
}

tune $1

Assuming the script is named tune.sh and the rxPort is set to 31100 in Analog_bridge.ini start the program with:
./tune.sh 1234
Where the desired TG is 1234
Send a quick PTT on the analog side and you will be tuned to TG 1234

There is quite a list of possible commands available. Some are dependent on the mode. Along with the other 1001 things we need to do we will try to get the info out.

Steve N4IRS


va3dxv
 

Sorry to bring back an old topic like this, but wanted to thank you both for publishing the script.

I used Steve's shell script and it works a treat. I used Mike's method in extensions.conf and it works great also, except I just realized that this line: 

exten = _X.,n,SayAlpha(dmr,${EXTEN})
Is actually sending the voice telemetry to the currently connected DMR talk group. I was informed by someone else that it was happening but I didn't put 2 and 2 together to realize why until playing with it again just now. I inadvertently spammed TG91 with it for a while a few nights back. :( In order to keep myself out of trouble I'll do further testing on private TG's until I know for sure it's not doing this.

I can comment out that line of course but I really would like the voice confirmation. The other issue is the DTMF from the RF end is making it through to the connected TG as well.

I was just wondering if anyone could point me to which part of the config I need to look at to stop this from happening, as well as mask the DTMF from going across the connected TG.

The entry under [functions] in rpt.conf is the same as Mikes, above, and I also have my nodes set to 0 for all the telemetry options in rpt.conf. Thanks!


va3dxv
 

So I solved the Allison problem by doing this under my [dmrmenu] context in extensions.conf:

exten => _X.,1,Wait,1
exten => _X.,n,System(asterisk -rx "rpt fun 12345 *11999") ; replace 12345 with your node number
exten => _X.,n,Wait,1
exten => _X.,n,SayAlpha(dmr,${EXTEN})
exten => _X.,n,Wait,1
exten => _X.,n,System(/opt/Analog_Bridge/dmrtune.sh ${EXTEN})
exten => _X.,n,Wait,1
exten => _X.,n,System(asterisk -rx "rpt fun 12345 *31999") ; replace 12345 with your node number
exten => _X.,n,Hangup
 
I don't think that's the way Asterisk would want it done but it works. Does anyone see a major issue with this?

If I could figure out why DTMF isn't being masked from going over the network I think this could be working.


Mike KB8JNM
 
Edited

It should be said I had not considered everything someone might do.
But I did try to cover the basics.
You should not change TG's while Node is in TX but Rx/Mon or not use allison at all !

The method I used was to allow a readback of the TG from the file and I doubt I ever release that script.

SO there is a missing instruction to return the node to 'RX/MON" in stanza before making a change which is in my personal stanza but not in my instruction.
I edited the original post to include it.

I also strongly do NOT recommend any dmr bridge be left in TX 'unattended' unless you have 'specific permission' to do so.
If you can't think of a good reason to not do this, I will state ONE.
If someone connects to your node and they do the same in tx, and their squelch opens from interference,
...what a mess ! who will stop it ? perhaps in a hour after emails, phone calls, text msgs if that is even possible.

It's up to everyone to think about what they are doing 'in use' and test your config somewhere not affecting traffic.
You may find 'we all' will not be welcome to other networks.


va3dxv
 

I understand I made a poor choice by using it in active TG's. I tested it in our own TG's first and was excited to try it out, and I did so before fully realizing what was happening, that was my mistake. I'm trying to do it right in a way that doesn't interfere, that's why I'm here and asking questions.