-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
- Loading branch information
Showing
10 changed files
with
264 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,57 @@ | ||
#!/usr/bin/env ruby | ||
#!/usr/bin/env bash | ||
set -e | ||
[ -n "$DEBUG" ] && set -x | ||
|
||
require 'gpsd_client' | ||
require 'maidenhead' | ||
require 'socket' | ||
require 'json' | ||
LAT=$1 | ||
LON=$2 | ||
HOST=$3 | ||
PORT=$4 | ||
|
||
ft8call_port = 2237 | ||
if [ "$HOST" = "" ]; then | ||
HOST=localhost | ||
fi | ||
if [ "$PORT" = "" ]; then | ||
PORT=2947 | ||
fi | ||
|
||
gpsd = GpsdClient::Gpsd.new() | ||
gpsd.start() | ||
apicmd = {} | ||
compile_maidenhead() { | ||
gcc $HOME/bin/conky/maidenhead.c -o $HOME/bin/conky/mh | ||
chmod +x $HOME/bin/conky/mh | ||
} | ||
|
||
# get maidenhead if gps is ready | ||
if gpsd.started? | ||
pos = gpsd.get_position | ||
maid = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 5) | ||
# puts "lat = #{pos[:lat]}, lon = #{pos[:lon]}, grid = #{maid}" | ||
apicmd = {:type => "STATION.SET_GRID", :value => maid} | ||
end | ||
get_maidenhead_with_ruby() { | ||
grid=$(ruby get-grid.rb) | ||
} | ||
|
||
puts "#{maid}" | ||
get_maidenhead_with_gpspipe() { | ||
if ! hash gpspipe 2>/dev/null; then | ||
sudo apt install -y gpsd-clients jq | ||
fi | ||
nema=$(gpspipe -w -r $HOST:$PORT | grep -m 1 TPV) | ||
# GPS Coordinate Set | ||
lat=$(echo $nema | jq -r '"\(.lat)"') | ||
[ -z "$lat" ] && echo "Latitude error?" && exit | ||
lon=$(echo $nema | jq -r '"\(.lon)"') | ||
[ -z "$lon" ] && echo "Longitude error?" && exit | ||
grid=$($HOME/bin/conky/mh -a $lat -l $lon) | ||
} | ||
|
||
get_maidenhead_with_args() { | ||
grid=$($HOME/bin/conky/mh -a $LAT -l $LON) | ||
} | ||
|
||
if hash gcc 2>/dev/null; then | ||
compile_maidenhead | ||
fi | ||
|
||
if [ -z "$LAT" ]; then | ||
if hash ruby 2>/dev/null; then | ||
get_maidenhead_with_ruby | ||
else | ||
get_maidenhead_with_gpspipe | ||
fi | ||
else | ||
get_maidenhead_with_args | ||
fi | ||
echo $grid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'gpsd_client' | ||
require 'maidenhead' | ||
require 'socket' | ||
require 'json' | ||
|
||
ft8call_port = 2237 | ||
|
||
options = {:host => ARGV[0] ||= ENV["HOST"], :port => ARGV[1] ||= ENV["PORT"] } | ||
|
||
gpsd = GpsdClient::Gpsd.new(options) | ||
gpsd.start() | ||
apicmd = {} | ||
|
||
# get maidenhead if gps is ready | ||
if gpsd.started? | ||
pos = gpsd.get_position | ||
maid = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 5) | ||
# puts "lat = #{pos[:lat]}, lon = #{pos[:lon]}, grid = #{maid}" | ||
apicmd = {:type => "STATION.SET_GRID", :value => maid} | ||
end | ||
|
||
puts "#{maid}" | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* Taken from https://opensource.com/article/19/5/how-write-good-c-main-function */ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <libgen.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
#include <getopt.h> | ||
|
||
#define OPTSTR "va:l:h" | ||
#define USAGE_FMT "%s [-v] [-a latitude] [-l longitude] [-h]" | ||
#define ERR_LAT "lat" | ||
#define ERR_LON "lon" | ||
#define ERR_DO_GET_GRID "do_get_grid blew up" | ||
#define DEFAULT_PROGNAME "get_grid" | ||
|
||
extern int errno; | ||
extern char *optarg; | ||
extern int opterr, optind; | ||
|
||
typedef struct { | ||
int verbose; | ||
char *dst; | ||
double lon; | ||
double lat; | ||
} options_t; | ||
|
||
int dumb_global_variable = -11; | ||
void usage(char *progname, int opt); | ||
int do_get_grid(options_t *options); | ||
void calcLocator(char *dst, double lat, double lon); | ||
|
||
int main(int argc, char *argv[]) { | ||
int opt; | ||
options_t options = { 0, 0, 0.0, 0.0 }; | ||
|
||
opterr = 0; | ||
|
||
while ((opt = getopt(argc, argv, OPTSTR)) != EOF) | ||
switch(opt) { | ||
case 'a': | ||
if (!(options.lat = strtod(optarg, &optarg) )) { | ||
perror(ERR_LAT); | ||
exit(EXIT_FAILURE); | ||
/* NOTREACHED */ | ||
} | ||
break; | ||
|
||
case 'l': | ||
if (!(options.lon = strtod(optarg, &optarg) )) { | ||
perror(ERR_LON); | ||
exit(EXIT_FAILURE); | ||
/* NOTREACHED */ | ||
} | ||
break; | ||
|
||
case 'v': | ||
options.verbose += 1; | ||
break; | ||
|
||
case 'h': | ||
default: | ||
usage(basename(argv[0]), opt); | ||
/* NOTREACHED */ | ||
break; | ||
} | ||
|
||
if (do_get_grid(&options) != EXIT_SUCCESS) { | ||
perror(ERR_DO_GET_GRID); | ||
exit(EXIT_FAILURE); | ||
/* NOTREACHED */ | ||
} | ||
fprintf(stdout, "%s", options.dst); | ||
free(options.dst); | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
void usage(char *progname, int opt) { | ||
fprintf(stderr, USAGE_FMT, progname ? progname:DEFAULT_PROGNAME); | ||
exit(EXIT_FAILURE); | ||
/* NOTREACHED */ | ||
} | ||
|
||
int do_get_grid(options_t *options) { | ||
if (!options) { | ||
errno = EINVAL; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if (!options->lon || !options->lat) { | ||
errno = ENOENT; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
options->dst = malloc((sizeof(char) * 3) + 1); /* + 1 allows for null string terminator. */ | ||
|
||
calcLocator(options->dst, options->lat, options->lon); | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
/* https://ham.stackexchange.com/a/5599 */ | ||
void calcLocator(char *dst, double lat, double lon) { | ||
int o1, o2, o3; | ||
int a1, a2, a3; | ||
double remainder; | ||
// longitude | ||
remainder = lon + 180.0; | ||
o1 = (int)(remainder / 20.0); | ||
remainder = remainder - (double)o1 * 20.0; | ||
o2 = (int)(remainder / 2.0); | ||
remainder = remainder - 2.0 * (double)o2; | ||
o3 = (int)(12.0 * remainder); | ||
|
||
// latitude | ||
remainder = lat + 90.0; | ||
a1 = (int)(remainder / 10.0); | ||
remainder = remainder - (double)a1 * 10.0; | ||
a2 = (int)(remainder); | ||
remainder = remainder - (double)a2; | ||
a3 = (int)(24.0 * remainder); | ||
dst[0] = (char)o1 + 65; | ||
dst[1] = (char)a1 + 65; | ||
dst[2] = (char)o2 + 48; | ||
dst[3] = (char)a2 + 48; | ||
dst[4] = (char)o3 + 97; | ||
dst[5] = (char)a3 + 97; | ||
/* dst[0] = (char)o1 + 'A'; | ||
dst[1] = (char)a1 + 'A'; | ||
dst[2] = (char)o2 + '0'; | ||
dst[3] = (char)a2 + '0'; | ||
dst[4] = (char)o3 + 'A'; | ||
dst[5] = (char)a3 + 'A';*/ | ||
dst[6] = (char)0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
|
||
mkdir -p $HOME/bin/conky | ||
cp -p $HOME/pi-build/conky/* $HOME/bin/conky/ | ||
chmod +x $HOME/bin/conky/get-grid $HOME/bin/conky/get-freq $HOME/bin/conky/grid $HOME/bin/conky/setconky | ||
|
||
#Create files needed for autostart at login | ||
#Fix issue https://github.com/km4ack/pi-build/issues/83 | ||
|
||
cat <<EOF > $HOME/.local/share/applications/conky.desktop | ||
[Desktop Entry] | ||
Name=Conky | ||
Comment=Conky | ||
GenericName=Conky Screen Background Monitor | ||
Exec=conky | ||
Icon=/home/pi/bin/conky/conky-logo.png | ||
Type=Application | ||
Encoding=UTF-8 | ||
Terminal=false | ||
Categories=HamRadio | ||
Keywords=Radio | ||
EOF | ||
|
||
ln -sf $HOME/.local/share/applications/conky.desktop $HOME/.config/autostart/conky.desktop | ||
|
||
#####Add setconky to main menu | ||
cat <<EOF > $HOME/.local/share/applications/setconky.desktop | ||
[Desktop Entry] | ||
Name=Conky-Prefs | ||
Comment=Conky-Prefs | ||
GenericName=Change Conky Preferences | ||
Exec=/home/pi/bin/conky/setconky | ||
Icon=/home/pi/bin/conky/conky-logo.png | ||
Type=Application | ||
Encoding=UTF-8 | ||
Terminal=false | ||
Categories=Settings;DesktopSettings;GTK;X-LXDE-Settings; | ||
Keywords=Radio,Conky | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters