Skip to content

Commit 50233c2

Browse files
committed
add more options to get maidenhead
- it has pull #185 changes - other improvements and - implemented maidenhead grid locator on the C (conky/maidenhead.c) language: - get maidenhead (c implementation) with gpspipe (to get latitude and longitude) gcc is required. see conky/get-grid file. - get maidenhead (c implementation) with passing arguments (passing latitude and longitude as arguments) gcc is required. see conky/get-grid file. - get maidenhead (ruby implementation) fallback to this one if gcc is not installed (different OS maybe). see conky/get-grid.rb file.
1 parent 78edbfb commit 50233c2

File tree

10 files changed

+264
-67
lines changed

10 files changed

+264
-67
lines changed

conky/conky-7inch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ ${font Arial:size=12}${color Yellow}${alignc}N0CALL
3333
${voffset -30}
3434
${font Arial:bold:size=08}${color White}Gridsquare ${alignr}${color Yellow}${execi 60 cat /run/user/1000/gridinfo.txt | cut -c1-8}
3535
#${font Arial:bold:size=12}${color White}Radio Freq ${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq | cut -c1-6}
36-
${color Yellow}LOCAL${alignr}ZULU
3736
${voffset -20}
3837
${color DarkSlateGray}${hr 2}
38+
${color Yellow}LOCAL${alignr}ZULU
3939
${font Arial:bold:size=08}${color White}${time %H:%M:%S}\
4040
${alignr}${tztime Zulu %H:%M:%S}
4141
${font Arial:bold:size=08}${color White}${time %d%b%y}\

conky/conky-large

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ ${font Arial:bold:size=18}${color White}Gridsquare ${alignr}${color Yellow}${exe
4141
#${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7}
4242
#${font Arial:bold:size=18}${color White}Radio Freq B ${if_match "VFOB" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\
4343
#${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOB | cut -c1-7}
44-
45-
${color Yellow}LOCAL${alignr}ZULU
4644
${voffset -45}
4745
${color DarkSlateGray}${hr 2}
4846
${voffset -35}
47+
${color Yellow}LOCAL${alignr}ZULU
4948
${font Arial:bold:size=25}${color White}${time %H:%M:%S}\
5049
${alignr}${tztime Zulu %H:%M:%S}
5150
${font Arial:bold:size=25}${color White}${time %d%b%y}\

conky/conky-medium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ ${font Arial:bold:size=12}${color White}Gridsquare ${alignr}${color Yellow}${exe
4040
#${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7}
4141
#${font Arial:bold:size=12}${color White}Radio Freq B ${if_match "VFOB" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\
4242
#${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOB | cut -c1-7}
43-
${color Yellow}LOCAL${alignr}ZULU
4443
${color DarkSlateGray}${hr 2}
44+
${color Yellow}LOCAL${alignr}ZULU
4545
${font Arial:bold:size=15}${color White}${time %H:%M:%S}\
4646
${alignr}${tztime Zulu %H:%M:%S}
4747
${font Arial:bold:size=15}${color White}${time %d%b%y}\

conky/conky-small

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ ${font Arial:bold:size=08}${color White}Gridsquare ${alignr}${color Yellow}${exe
4040
#${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7}
4141
#${font Arial:bold:size=12}${color White}Radio Freq B ${if_match "VFOB" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\
4242
#${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOB | cut -c1-7}
43-
${color Yellow}LOCAL${alignr}ZULU
4443
${voffset -20}
4544
${color DarkSlateGray}${hr 2}
45+
${color Yellow}LOCAL${alignr}ZULU
4646
${font Arial:bold:size=08}${color White}${time %H:%M:%S}\
4747
${alignr}${tztime Zulu %H:%M:%S}
4848
${font Arial:bold:size=08}${color White}${time %d%b%y}\

conky/get-grid

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,57 @@
1-
#!/usr/bin/env ruby
1+
#!/usr/bin/env bash
2+
set -e
3+
[ -n "$DEBUG" ] && set -x
24

3-
require 'gpsd_client'
4-
require 'maidenhead'
5-
require 'socket'
6-
require 'json'
5+
LAT=$1
6+
LON=$2
7+
HOST=$3
8+
PORT=$4
79

8-
ft8call_port = 2237
10+
if [ "$HOST" = "" ]; then
11+
HOST=localhost
12+
fi
13+
if [ "$PORT" = "" ]; then
14+
PORT=2947
15+
fi
916

10-
gpsd = GpsdClient::Gpsd.new()
11-
gpsd.start()
12-
apicmd = {}
17+
compile_maidenhead() {
18+
gcc $HOME/bin/conky/maidenhead.c -o $HOME/bin/conky/mh
19+
chmod +x $HOME/bin/conky/mh
20+
}
1321

14-
# get maidenhead if gps is ready
15-
if gpsd.started?
16-
pos = gpsd.get_position
17-
maid = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 5)
18-
# puts "lat = #{pos[:lat]}, lon = #{pos[:lon]}, grid = #{maid}"
19-
apicmd = {:type => "STATION.SET_GRID", :value => maid}
20-
end
22+
get_maidenhead_with_ruby() {
23+
grid=$(ruby get-grid.rb)
24+
}
2125

22-
puts "#{maid}"
26+
get_maidenhead_with_gpspipe() {
27+
if ! hash gpspipe 2>/dev/null; then
28+
sudo apt install -y gpsd-clients jq
29+
fi
30+
nema=$(gpspipe -w -r $HOST:$PORT | grep -m 1 TPV)
31+
# GPS Coordinate Set
32+
lat=$(echo $nema | jq -r '"\(.lat)"')
33+
[ -z "$lat" ] && echo "Latitude error?" && exit
34+
lon=$(echo $nema | jq -r '"\(.lon)"')
35+
[ -z "$lon" ] && echo "Longitude error?" && exit
36+
grid=$($HOME/bin/conky/mh -a $lat -l $lon)
37+
}
38+
39+
get_maidenhead_with_args() {
40+
grid=$($HOME/bin/conky/mh -a $LAT -l $LON)
41+
}
42+
43+
if hash gcc 2>/dev/null; then
44+
compile_maidenhead
45+
fi
46+
47+
if [ -z "$LAT" ]; then
48+
if hash ruby 2>/dev/null; then
49+
get_maidenhead_with_ruby
50+
else
51+
get_maidenhead_with_gpspipe
52+
fi
53+
else
54+
get_maidenhead_with_args
55+
fi
56+
echo $grid
2357

conky/get-grid.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'gpsd_client'
4+
require 'maidenhead'
5+
require 'socket'
6+
require 'json'
7+
8+
ft8call_port = 2237
9+
10+
options = {:host => ARGV[0] ||= ENV["HOST"], :port => ARGV[1] ||= ENV["PORT"] }
11+
12+
gpsd = GpsdClient::Gpsd.new(options)
13+
gpsd.start()
14+
apicmd = {}
15+
16+
# get maidenhead if gps is ready
17+
if gpsd.started?
18+
pos = gpsd.get_position
19+
maid = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 5)
20+
# puts "lat = #{pos[:lat]}, lon = #{pos[:lon]}, grid = #{maid}"
21+
apicmd = {:type => "STATION.SET_GRID", :value => maid}
22+
end
23+
24+
puts "#{maid}"
25+

conky/get-vfo

100755100644
File mode changed.

conky/maidenhead.c

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/* Taken from https://opensource.com/article/19/5/how-write-good-c-main-function */
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <unistd.h>
5+
#include <libgen.h>
6+
#include <errno.h>
7+
#include <string.h>
8+
#include <getopt.h>
9+
10+
#define OPTSTR "va:l:h"
11+
#define USAGE_FMT "%s [-v] [-a latitude] [-l longitude] [-h]"
12+
#define ERR_LAT "lat"
13+
#define ERR_LON "lon"
14+
#define ERR_DO_GET_GRID "do_get_grid blew up"
15+
#define DEFAULT_PROGNAME "get_grid"
16+
17+
extern int errno;
18+
extern char *optarg;
19+
extern int opterr, optind;
20+
21+
typedef struct {
22+
int verbose;
23+
char *dst;
24+
double lon;
25+
double lat;
26+
} options_t;
27+
28+
int dumb_global_variable = -11;
29+
void usage(char *progname, int opt);
30+
int do_get_grid(options_t *options);
31+
void calcLocator(char *dst, double lat, double lon);
32+
33+
int main(int argc, char *argv[]) {
34+
int opt;
35+
options_t options = { 0, 0, 0.0, 0.0 };
36+
37+
opterr = 0;
38+
39+
while ((opt = getopt(argc, argv, OPTSTR)) != EOF)
40+
switch(opt) {
41+
case 'a':
42+
if (!(options.lat = strtod(optarg, &optarg) )) {
43+
perror(ERR_LAT);
44+
exit(EXIT_FAILURE);
45+
/* NOTREACHED */
46+
}
47+
break;
48+
49+
case 'l':
50+
if (!(options.lon = strtod(optarg, &optarg) )) {
51+
perror(ERR_LON);
52+
exit(EXIT_FAILURE);
53+
/* NOTREACHED */
54+
}
55+
break;
56+
57+
case 'v':
58+
options.verbose += 1;
59+
break;
60+
61+
case 'h':
62+
default:
63+
usage(basename(argv[0]), opt);
64+
/* NOTREACHED */
65+
break;
66+
}
67+
68+
if (do_get_grid(&options) != EXIT_SUCCESS) {
69+
perror(ERR_DO_GET_GRID);
70+
exit(EXIT_FAILURE);
71+
/* NOTREACHED */
72+
}
73+
fprintf(stdout, "%s", options.dst);
74+
free(options.dst);
75+
return EXIT_SUCCESS;
76+
}
77+
78+
void usage(char *progname, int opt) {
79+
fprintf(stderr, USAGE_FMT, progname ? progname:DEFAULT_PROGNAME);
80+
exit(EXIT_FAILURE);
81+
/* NOTREACHED */
82+
}
83+
84+
int do_get_grid(options_t *options) {
85+
if (!options) {
86+
errno = EINVAL;
87+
return EXIT_FAILURE;
88+
}
89+
90+
if (!options->lon || !options->lat) {
91+
errno = ENOENT;
92+
return EXIT_FAILURE;
93+
}
94+
95+
options->dst = malloc((sizeof(char) * 3) + 1); /* + 1 allows for null string terminator. */
96+
97+
calcLocator(options->dst, options->lat, options->lon);
98+
return EXIT_SUCCESS;
99+
}
100+
101+
/* https://ham.stackexchange.com/a/5599 */
102+
void calcLocator(char *dst, double lat, double lon) {
103+
int o1, o2, o3;
104+
int a1, a2, a3;
105+
double remainder;
106+
// longitude
107+
remainder = lon + 180.0;
108+
o1 = (int)(remainder / 20.0);
109+
remainder = remainder - (double)o1 * 20.0;
110+
o2 = (int)(remainder / 2.0);
111+
remainder = remainder - 2.0 * (double)o2;
112+
o3 = (int)(12.0 * remainder);
113+
114+
// latitude
115+
remainder = lat + 90.0;
116+
a1 = (int)(remainder / 10.0);
117+
remainder = remainder - (double)a1 * 10.0;
118+
a2 = (int)(remainder);
119+
remainder = remainder - (double)a2;
120+
a3 = (int)(24.0 * remainder);
121+
dst[0] = (char)o1 + 65;
122+
dst[1] = (char)a1 + 65;
123+
dst[2] = (char)o2 + 48;
124+
dst[3] = (char)a2 + 48;
125+
dst[4] = (char)o3 + 97;
126+
dst[5] = (char)a3 + 97;
127+
/* dst[0] = (char)o1 + 'A';
128+
dst[1] = (char)a1 + 'A';
129+
dst[2] = (char)o2 + '0';
130+
dst[3] = (char)a2 + '0';
131+
dst[4] = (char)o3 + 'A';
132+
dst[5] = (char)a3 + 'A';*/
133+
dst[6] = (char)0;
134+
}

conky/update

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
mkdir -p $HOME/bin/conky
4+
cp -p $HOME/pi-build/conky/* $HOME/bin/conky/
5+
chmod +x $HOME/bin/conky/get-grid $HOME/bin/conky/get-freq $HOME/bin/conky/grid $HOME/bin/conky/setconky
6+
7+
#Create files needed for autostart at login
8+
#Fix issue https://github.com/km4ack/pi-build/issues/83
9+
10+
cat <<EOF > $HOME/.local/share/applications/conky.desktop
11+
[Desktop Entry]
12+
Name=Conky
13+
Comment=Conky
14+
GenericName=Conky Screen Background Monitor
15+
Exec=conky
16+
Icon=/home/pi/bin/conky/conky-logo.png
17+
Type=Application
18+
Encoding=UTF-8
19+
Terminal=false
20+
Categories=HamRadio
21+
Keywords=Radio
22+
EOF
23+
24+
ln -sf $HOME/.local/share/applications/conky.desktop $HOME/.config/autostart/conky.desktop
25+
26+
#####Add setconky to main menu
27+
cat <<EOF > $HOME/.local/share/applications/setconky.desktop
28+
[Desktop Entry]
29+
Name=Conky-Prefs
30+
Comment=Conky-Prefs
31+
GenericName=Change Conky Preferences
32+
Exec=/home/pi/bin/conky/setconky
33+
Icon=/home/pi/bin/conky/conky-logo.png
34+
Type=Application
35+
Encoding=UTF-8
36+
Terminal=false
37+
Categories=Settings;DesktopSettings;GTK;X-LXDE-Settings;
38+
Keywords=Radio,Conky
39+
EOF

functions/additional.function

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -121,59 +121,25 @@ sudo locale-gen
121121
# CONKY
122122
##################################
123123
CONKY(){
124-
if ! hash conky 2>/dev/null; then
125-
sudo apt install -y conky
126-
fi
124+
if ! hash conky 2>/dev/null; then
125+
sudo apt install -y conky
126+
fi
127127
touch $HOME/Documents/mylog.txt #conky will fail to load if this file doesn't exist
128128
touch /var/lib/misc/dnsmasq.leases #conky will fail to load if this file doesn't exist
129-
sudo apt-get install -y ruby2.5
130-
sudo gem install gpsd_client
131-
sudo gem install maidenhead
129+
if ! hash gcc 2>/dev/null; then
130+
sudo apt-get install -y ruby2.5
131+
sudo gem install gpsd_client
132+
sudo gem install maidenhead
133+
fi
132134
cp $MYPATH/conky/.conkyrc $HOME/.conkyrc
133-
mkdir -p $HOME/bin/conky
134-
cp $MYPATH/conky/* $HOME/bin/conky/
135-
chmod +x $HOME/bin/conky/get-grid $HOME/bin/conky/temp-conv $HOME/bin/conky/get-freq $HOME/bin/conky/grid
136135
sed -i "s/N0CALL/$CALL/" $HOME/.conkyrc
136+
137137
#Line below is for https://github.com/km4ack/pi-build/issues/198
138138
echo "#Update GPS maidenhead for conky" >> $TEMPCRON
139139
echo "*/1 * * * * /home/pi/bin/conky/grid" >> $TEMPCRON
140140

141-
#Create files needed for autostart at login
142-
#Fix issue https://github.com/km4ack/pi-build/issues/83
143-
144-
cat <<EOF > $HOME/.local/share/applications/conky.desktop
145-
[Desktop Entry]
146-
Name=Conky
147-
Comment=Conky
148-
GenericName=Conky Screen Background Monitor
149-
Exec=conky
150-
Icon=/home/pi/pi-build/conky/conky-logo.png
151-
Type=Application
152-
Encoding=UTF-8
153-
Terminal=false
154-
Categories=HamRadio
155-
Keywords=Radio
156-
EOF
157-
158-
ln -sf $HOME/.local/share/applications/conky.desktop $HOME/.config/autostart/conky.desktop
159-
160-
#####Add setconky to main menu
161-
chmod +x $HOME/pi-build/conky/setconky
162-
163-
cat <<EOF > $HOME/.local/share/applications/setconky.desktop
164-
[Desktop Entry]
165-
Name=Conky-Prefs
166-
Comment=Conky-Prefs
167-
GenericName=Change Conky Preferences
168-
Exec=/home/pi/pi-build/conky/setconky
169-
Icon=/home/pi/pi-build/conky/conky-logo.png
170-
Type=Application
171-
Encoding=UTF-8
172-
Terminal=false
173-
Categories=Settings;DesktopSettings;GTK;X-LXDE-Settings;
174-
Keywords=Radio,Conky
175-
EOF
176-
141+
# Add the rest of the code here so that it can be use for installation and locally
142+
bash $MYPATH/conky/update
177143
}
178144

179145
##################################

0 commit comments

Comments
 (0)