Link to D-Star reflectors from the command line

Post your tips and tricks here
Post Reply
User avatar
N7HHI
Posts: 65
Joined: Thu Apr 12, 2018 11:33 pm
Location: Wentzville, MO
Contact:

Link to D-Star reflectors from the command line

Post by N7HHI »

Command Line Reflector Linking

I have written a BASH Shell Script for linking to reflectors via the command line. Below is a screen capture showing the output of the script:
Screen Capture for Command Line Linking
Screen Capture for Command Line Linking
CommandLineLinking.png (32.23 KiB) Viewed 13349 times

The script is shown in the code block below:

Code: Select all

#!/bin/bash
####################################
#
# Script to link to Dstar reflector
#
# Scott Showalter - N7HHI - 10/06/2018
#
####################################

# ${0} is the script name
# $(basename ${0}) strips the first portion of the PATH so that only the script name is returned
# ${1} is the number of the reflector
# ${2} is the port of the reflector
#

if [ $# -ne 2 ]; then
  echo "Usage: $(basename ${0}) [number] [port]"
  echo ""
  echo "[number] = reflector number"
  echo "[port] = Alphabetic port representation [a-z] (not case sensitive)"
  echo "e.g. ref 001 c  - in order to link to ref001 C"
  echo "e.g. dcs 757 a  - in order to link to dcs757 A"
  echo "e.g. xrf 307 d  - in order to link to xrf307 D"
  echo ""
  exit 1
fi

# Set RDX to lowercase Reflector type
RDX="$(echo $(basename ${0}) | tr '[A-Z]' '[a-z]')"

# Set REPN to Repeter Number padded to 3 characters
# If user enters less than 3 digits, pad with leading zeros to total 3 characters
REPN=$(printf "%03d" ${1})

# Set PORT to lowercase Port, in order to make the entry case-insensitive
PORT="$(echo ${2} | tr '[A-Z]' '[a-z]')"

# Link to Reflector and redirect stdout and stderr to /dev/null
sudo pistar-link ${RDX}${REPN}_${PORT} >/dev/null 2>&1

#   Wait 1 second. This is needed for the linked repeater to show up in the
#    /var/log/pi-star/Links.log file prior to displaying it.
sleep 1

#Display the linked to reflector as determined from /var/log/pi-star/Links.log
echo "Linked to $(awk '{print $12, $13}' /var/log/pi-star/Links.log)"
I addition to the script, I have created links to the script for each way that I want to be able to call the script. If I want to link to a DPlus Reflector you use the link for REF or ref. If you want to link to a DPlus reflector you use the link for XRF or xrf. If you want to link to a DCS reflector you use the link for DCS or dcs.

I created this script as /home/pi-star/bin/ref.
  1. Go into Read/Write mode: rpi-rw
  2. Make the directory to store the script (in my case, I called it bin): mkdir /home/pi-star/bin
  3. Change to the bin directory: cd /home/pi-star/bin
  4. Copy the above script to the new directory and call it by one of the names for the type of reflector: nano ref
  5. Paste the contents into the nano editor. Save the file: CTRL O
  6. Press [Enter] to accept the default name you specified when opening the editor: [Enter]
  7. Exit the editor: CTRL X
  8. Give execute permissions to the script: chmod 755 /home/pi-star/bin/ref
You now have an executable script that you can call by typing /home/pi-star/bin/ref 001 c
If you want to be able to just type ref 001 c, then you need to add /home/pi-star/bin to your PATH environment variable. To do that edit the /home/pi-star/.bashrc file and add the following lines to it:

Code: Select all

PATH=${PATH}:/home/pi-star/bin
After logging out and logging back in you will have the bin directory in your path so that you will not have to include the path in your command.

Next create the additional links for the DPlus and DCS reflectors:

Code: Select all

ln ref xrf
ln ref dcs
Now you can issue commands like:

Code: Select all

xrf 307 d
dcs 757 a
If you want to make it so that you can use UPPER CASE letters for REF, XRF, and DCS, then add these additional links:

Code: Select all

ln ref REF
ln ref XRF
ln ref DCS
After doing this, your /home/pi-star/bin directory will look similar to the following:

Code: Select all

pi-star@pi-star(rw):bin$ ls -l
total 24
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 dcs
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 DCS
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 ref
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 REF
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 xrf
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 XRF
Now to link to REF001 C, you can enter REF 1 C or ref 1 c
To link to XRF307 D, you can enter XRF 307 D or xrf 307 d
To link to DCS757 A, you can enter DCS 757 A or dcs757 a

Put pi-star back into Read Only mode: rpi-ro



**** Moderators Edit ****

Great that you are writing scripts and putting then up on the board, and not wanting to take away from the work you have done, but

Pistar has the ability to link from the command line written in, using Pistar-link.

**** Moderators Edit ****

73...
Scott - N7HHI
User avatar
G6WQH
Posts: 12
Joined: Mon Jun 18, 2018 6:27 pm
Location: IO93us

Re: Link to D-Star reflectors from the command line

Post by G6WQH »

Thank you - I will try this later - I can see it being very useful!
W4JEW
Posts: 59
Joined: Sun Aug 12, 2018 12:53 am
Location: Atlanta, GA, United States
Contact:

Re: Link to D-Star reflectors from the command line

Post by W4JEW »

VERY NICE!!!
Check out GeorgiaDMR.net - https://www.georgiadmr.net
And on Groups.io - https://groups.io/g/GeorgiaDMR

Jeff Hochberg
W4JEW
Atlanta, GA
User avatar
MW0MWZ
Site Admin
Posts: 1505
Joined: Wed Apr 04, 2018 9:15 pm
Location: Wales, UK
Contact:

Re: Link to D-Star reflectors from the command line

Post by MW0MWZ »

I'm pleased to see people writing their own scripts, but was "pistar-link" really too hard to use ?
Andy

73 de MW0MWZ
http://pistar.uk
User avatar
KE0FHS
Posts: 1122
Joined: Wed Apr 11, 2018 8:40 pm
Location: Colorado, USA
Contact:

Re: Link to D-Star reflectors from the command line

Post by KE0FHS »

MW0MWZ wrote: Sat Jan 19, 2019 9:41 pm I'm pleased to see people writing their own scripts, but was "pistar-link" really too hard to use ?
Wow, that's the first time I've heard of pistar-link. Nice! Any other gems like that?
73, Toshen, KE0FHS
Playing with Pi-Star (unofficial notes about setting up and using Pi-Star):
https://amateurradionotes.com/pi-star.htm
User avatar
N7HHI
Posts: 65
Joined: Thu Apr 12, 2018 11:33 pm
Location: Wentzville, MO
Contact:

Re: Link to D-Star reflectors from the command line

Post by N7HHI »

MW0MWZ wrote: Sat Jan 19, 2019 9:41 pm I'm pleased to see people writing their own scripts, but was "pistar-link" really too hard to use ?
Hi Andy,

Not that "pistar-link" was that hard to use, but my 62 year old brain couldn't remember the name and/or syntax without the need to look it up each time I went to use it. Just typing the reflector name and module was easier for me to remember. ;)
73...
Scott - N7HHI
KM6YNK
Posts: 15
Joined: Tue Jan 15, 2019 3:29 pm

Re: Link to D-Star reflectors from the command line

Post by KM6YNK »

where can I find the documentation on pistar-link command?
M1DNS
Pi-Star Team
Posts: 1388
Joined: Thu Apr 05, 2018 5:30 am

Re: Link to D-Star reflectors from the command line

Post by M1DNS »

KM6YNK wrote:where can I find the documentation on pistar-link command?
viewtopic.php?t=326#p1091

Andrew M1DNS, (Mod)

Andrew M1DNS.
Pi-star Admin Team.
SA0BUX
Posts: 7
Joined: Sun Sep 15, 2019 5:07 pm
Location: Stockholm

Re: Link to D-Star reflectors from the command line

Post by SA0BUX »

I discovered one problem with this script.

The line REPN=$(printf "%03d" ${1}) will return the octal value of ${1} if the value begins with 0 (zero)

So "xlx 010 b" will try to connect to xlx008b instead of xlx010b.

Numbers with a leading 0 is treated as octal in bash and this seems tricky to fix in scripts as all leading zeros needs to be removed.

https://www.unix.com/shell-programming- ... cimal.html

So remove leading zeros manually is probably easiest.
VK2ZCD
Posts: 2
Joined: Sat Jun 22, 2019 1:00 am

Re: Link to D-Star reflectors from the command line

Post by VK2ZCD »

Excellent script, Thank you

Ian VK2YG
Post Reply