From 5ebcefe167c398e98567bb4c05d7e9fb5bcbcfe7 Mon Sep 17 00:00:00 2001 From: Jason Reiss Date: Fri, 14 Oct 2016 10:05:23 -0500 Subject: lora: move old usb packet forwarder and library utilities to new recipes add spi device path option to packet forwarder and library --- .../lora-network-server/lora-network-server.init | 67 +++++++++---- .../lora-network-server/lora-network-server.init~ | 105 +++++++++++++++++++++ 2 files changed, 156 insertions(+), 16 deletions(-) create mode 100755 recipes-connectivity/lora/lora-network-server/lora-network-server.init~ (limited to 'recipes-connectivity/lora/lora-network-server') diff --git a/recipes-connectivity/lora/lora-network-server/lora-network-server.init b/recipes-connectivity/lora/lora-network-server/lora-network-server.init index 4b80dc7..7a72b34 100755 --- a/recipes-connectivity/lora/lora-network-server/lora-network-server.init +++ b/recipes-connectivity/lora/lora-network-server/lora-network-server.init @@ -1,25 +1,39 @@ #!/bin/bash + NAME="lora-network-server" ENABLED="yes" + [ -f /etc/default/$NAME ] && source /etc/default/$NAME + run_dir=/var/run/lora conf_dir=/var/config/lora conf_file=$conf_dir/lora-network-server.conf conf_db=$conf_dir/lora-network-server.db + net_server=/opt/lora/lora-network-server net_server_log=/var/log/lora-network-server.log net_server_pidfile=$run_dir/$NAME.pid -pkt_fwd=/opt/lora/basic_pkt_fwd + +pkt_fwd=$run_dir/1/lora_pkt_fwd pkt_fwd_log=/var/log/lora-pkt-fwd-1.log pkt_fwd_pidfile=$run_dir/lora-pkt-fwd-1.pid + +port1=/sys/devices/platform/mts-io/ap1 +port2=/sys/devices/platform/mts-io/ap2 + + lora_us_id="MTAC-LORA-915" lora_eu_id="MTAC-LORA-868" +lora_usb_hw="MTAC-LORA-1.0" +lora_spi_hw="MTAC-LORA-1.1" +lora_h_hw="MTAC-LORA-1.5" + read_card_info() { # product-id of first lora card @@ -27,18 +41,35 @@ read_card_info() { lora_eui=$(mts-io-sysfs show lora/eui 2> /dev/null) # remove all colons lora_eui_raw=${lora_eui//:/} + lora_hw=$(mts-io-sysfs show lora/hw-version 2> /dev/null) } + card_found() { + if [ -d $port1 ] && [[ $(cat $port1/hw-version) = $lora_hw ]]; then + ln -sf /dev/spidev32766.2 /dev/spidev0.0 + elif [ -d $port2 ] && [[ $(cat $port2/hw-version) = $lora_hw ]]; then + ln -sf /dev/spidev32765.2 /dev/spidev0.0 + fi + if [ "$lora_id" = "$lora_us_id" ] || [ "$lora_id" = "$lora_eu_id" ]; then - echo "Found lora card $lora_id" - return 0 - else + if [ "$lora_hw" = "$lora_spi_hw" ] || [ "$lora_hw" = "$lora_h_hw" ]; then + ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd + return 0 + elif [ "$lora_hw" = "$lora_usb_hw" ]; then + ln -sf /opt/lora/basic_pkt_fwd-usb $pkt_fwd + return 0 + else + return 1 + fi + else return 1 fi } + do_start() { + mkdir -p $run_dir/1 read_card_info if ! [ -f $conf_file ]; then @@ -46,30 +77,32 @@ do_start() { exit 1 fi - if ! card_found; then + + if card_found; then + echo "Found $lora_id with $lora_hw hardware" + else echo "$0: MTAC-LORA not detected" exit 1 fi - echo -n "Starting $NAME: " - mkdir -p $run_dir/1 # start network server - start-stop-daemon --start --background --make-pidfile \ + start-stop-daemon --start --background --make-pidfile \ --pidfile $net_server_pidfile --startas /bin/bash -- -c "exec $net_server \ -c $conf_file --lora-eui $lora_eui --lora-path $run_dir --db $conf_db \ --noconsole -l $net_server_log >> $net_server_log 2>&1" sleep 2 - # start packet forwarder - start-stop-daemon --start --background --make-pidfile \ - --pidfile $pkt_fwd_pidfile --exec $pkt_fwd -- \ - -c $run_dir/1 + # start packet forwarder + /usr/sbin/start-stop-daemon --chdir $run_dir/1 --background --start --make-pidfile \ + --pidfile $pkt_fwd_pidfile --startas /bin/bash -- -c "exec $pkt_fwd" renice -n -20 -p $(pgrep lora-network-se) renice -n -20 -p $(pgrep $(basename $pkt_fwd)) + echo "OK" } + do_stop() { echo -n "Stopping $NAME: " start-stop-daemon --stop --quiet --oknodo --pidfile $net_server_pidfile --retry 15 @@ -78,20 +111,22 @@ do_stop() { echo "OK" } + if [ "$ENABLED" != "yes" ]; then echo "$NAME: disabled in /etc/default" exit fi + case "$1" in "start") - do_start + do_start ;; "stop") - do_stop + do_stop ;; "restart") - ## Stop the service and regardless of whether it was + ## Stop the service and regardless of whether it was ## running or not, start it again. do_stop do_start @@ -100,6 +135,6 @@ case "$1" in ## If no parameters are given, print which are avaiable. echo "Usage: $0 {start|stop|restart}" exit 1 - ;; + ;; esac diff --git a/recipes-connectivity/lora/lora-network-server/lora-network-server.init~ b/recipes-connectivity/lora/lora-network-server/lora-network-server.init~ new file mode 100755 index 0000000..4b80dc7 --- /dev/null +++ b/recipes-connectivity/lora/lora-network-server/lora-network-server.init~ @@ -0,0 +1,105 @@ +#!/bin/bash + +NAME="lora-network-server" +ENABLED="yes" + +[ -f /etc/default/$NAME ] && source /etc/default/$NAME + +run_dir=/var/run/lora +conf_dir=/var/config/lora +conf_file=$conf_dir/lora-network-server.conf +conf_db=$conf_dir/lora-network-server.db + +net_server=/opt/lora/lora-network-server +net_server_log=/var/log/lora-network-server.log +net_server_pidfile=$run_dir/$NAME.pid + +pkt_fwd=/opt/lora/basic_pkt_fwd +pkt_fwd_log=/var/log/lora-pkt-fwd-1.log +pkt_fwd_pidfile=$run_dir/lora-pkt-fwd-1.pid + +lora_us_id="MTAC-LORA-915" +lora_eu_id="MTAC-LORA-868" + +read_card_info() { + # product-id of first lora card + lora_id=$(mts-io-sysfs show lora/product-id 2> /dev/null) + lora_eui=$(mts-io-sysfs show lora/eui 2> /dev/null) + # remove all colons + lora_eui_raw=${lora_eui//:/} +} + +card_found() { + if [ "$lora_id" = "$lora_us_id" ] || [ "$lora_id" = "$lora_eu_id" ]; then + echo "Found lora card $lora_id" + return 0 + else + return 1 + fi +} + +do_start() { + read_card_info + + if ! [ -f $conf_file ]; then + echo "$0: $conf_file missing" + exit 1 + fi + + if ! card_found; then + echo "$0: MTAC-LORA not detected" + exit 1 + fi + + echo -n "Starting $NAME: " + mkdir -p $run_dir/1 + # start network server + start-stop-daemon --start --background --make-pidfile \ + --pidfile $net_server_pidfile --startas /bin/bash -- -c "exec $net_server \ + -c $conf_file --lora-eui $lora_eui --lora-path $run_dir --db $conf_db \ + --noconsole -l $net_server_log >> $net_server_log 2>&1" + sleep 2 + # start packet forwarder + start-stop-daemon --start --background --make-pidfile \ + --pidfile $pkt_fwd_pidfile --exec $pkt_fwd -- \ + -c $run_dir/1 + + renice -n -20 -p $(pgrep lora-network-se) + renice -n -20 -p $(pgrep $(basename $pkt_fwd)) + + echo "OK" +} + +do_stop() { + echo -n "Stopping $NAME: " + start-stop-daemon --stop --quiet --oknodo --pidfile $net_server_pidfile --retry 15 + start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5 + rm -f $net_server_pidfile $pkt_fwd_pidfile + echo "OK" +} + +if [ "$ENABLED" != "yes" ]; then + echo "$NAME: disabled in /etc/default" + exit +fi + +case "$1" in + "start") + do_start + ;; + "stop") + do_stop + ;; + "restart") + ## Stop the service and regardless of whether it was + ## running or not, start it again. + do_stop + do_start + ;; + *) + ## If no parameters are given, print which are avaiable. + echo "Usage: $0 {start|stop|restart}" + exit 1 + ;; +esac + -- cgit v1.2.3