diff options
author | Harsh Sharma <harsh.sharma@multitech.com> | 2023-04-25 15:34:25 -0500 |
---|---|---|
committer | Harsh Sharma <harsh.sharma@multitech.com> | 2023-04-25 15:34:25 -0500 |
commit | 1d7df5598e3d0f3a7c0698596fafc776d5eb8737 (patch) | |
tree | ca9d1858bffe8554ca2318aab057cfb533a79486 /recipes-connectivity | |
parent | 1f707a15f182ac4723708a36ba0b0cfdc31a67b6 (diff) | |
download | meta-mlinux-1d7df5598e3d0f3a7c0698596fafc776d5eb8737.tar.gz meta-mlinux-1d7df5598e3d0f3a7c0698596fafc776d5eb8737.tar.bz2 meta-mlinux-1d7df5598e3d0f3a7c0698596fafc776d5eb8737.zip |
Bug fix: lns init script
Diffstat (limited to 'recipes-connectivity')
-rwxr-xr-x | recipes-connectivity/lora/lora-network-server/lora-network-server.init | 32 | ||||
-rwxr-xr-x | recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init | 59 |
2 files changed, 79 insertions, 12 deletions
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 862f97a..3c2764a 100755 --- a/recipes-connectivity/lora/lora-network-server/lora-network-server.init +++ b/recipes-connectivity/lora/lora-network-server/lora-network-server.init @@ -59,19 +59,33 @@ dual_cards_installed=false gps_path="/dev/gps0" read_lora_hw_info() { - hw_id=$(mts-io-sysfs show product-id 2> /dev/null) + set +e + + hw_id=$(mts-io-sysfs show hw-version) # product-id of first lora card lora_id=$(mts-io-sysfs show lora/product-id 2> /dev/null) + if [ $? -ne 0 ]; then + lora_id="NONE" + fi lora_eui=$(mts-io-sysfs show lora/eui 2> /dev/null) + if [ $? -ne 0 ]; then + lora_eui=$(mts-io-sysfs show mac-eth) + lora_eui=${lora_eui:0:8}":FF:FF"${lora_eui:8:16} + fi # remove all colons lora_eui_raw=${lora_eui//:} lora_hw=$(mts-io-sysfs show lora/hw-version 2> /dev/null) + if [ $? -ne 0 ]; then + lora_hw="NONE" + fi if [ -d $port1 ] && [[ $(cat $port1/hw-version) =~ "LORA-1.5" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "LORA-1.5" ]]; then dual_cards_installed=true elif [ -d $port1 ] && [[ $(cat $port1/hw-version) =~ "MTAC-003" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "MTAC-003" ]]; then dual_cards_installed=true + elif [ -d $port1 ] && [[ $(cat $port1/hw-version) =~ "LORA-2G4" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "LORA-2G4" ]]; then + dual_cards_installed=true fi if [[ "$dual_cards_installed" = "true" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "LORA-1.5" || $(cat $port2/hw-version) =~ "LORA-2G4" || $(cat $port2/hw-version) =~ "MTAC-003" ]]; then @@ -83,6 +97,20 @@ read_lora_hw_info() { lora_2_eui_raw=${lora_2_eui//:} fi + set -e + + # Check USB id for Semtech Card + if [[ $(lsusb | grep 05c9:5740) =~ "05c9:5740" ]] && [[ ! "$lora_id" =~ "$lora_mtac_2g4_id" ]]; then + lora_id=$lora_mtac_2g4_id + lora_hw=$lora_2g4_hw + lora_eui=$(mts-io-sysfs show mac-eth) + lora_eui=${lora_eui:0:8}":FF:FF"${lora_eui:8:16} + LORA_CAPABLE=true + # Check USB id for Semtech Card in Bootloader mode + elif [[ $(lsusb | grep 0483:df11) =~ "0483:df11" ]]; then + echo "Semtech 2g4 MTAC card detected in Bootloader Mode, remove power from Conduit and restore" + return 1 + fi } setup_mtcdt3() { @@ -344,7 +372,7 @@ do_stop() { start-stop-daemon --stop --quiet --oknodo --pidfile $net_server_pidfile --retry TERM/60/KILL/5 start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5 start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_2_pidfile --retry 5 - rm -f $net_server_pidfile $pkt_fwd_pidfile + rm -f $net_server_pidfile $pkt_fwd_pidfile $pkt_fwd_2_pidfile echo "OK" } diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init index 6aaf26f..6320d2a 100755 --- a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init @@ -2,6 +2,7 @@ NAME="lora-packet-forwarder" +LOCK="/var/lock/$NAME" ENABLED="yes" @@ -72,19 +73,33 @@ pkt_fwd_options="" gps_path="/dev/gps0" read_lora_hw_info() { - hw_id=$(mts-io-sysfs show product-id 2> /dev/null) + set +e + + hw_id=$(mts-io-sysfs show hw-version) # product-id of first lora card lora_id=$(mts-io-sysfs show lora/product-id 2> /dev/null) + if [ $? -ne 0 ]; then + lora_id="NONE" + fi lora_eui=$(mts-io-sysfs show lora/eui 2> /dev/null) + if [ $? -ne 0 ]; then + lora_eui=$(mts-io-sysfs show mac-eth) + lora_eui=${lora_eui:0:8}":FF:FF"${lora_eui:8:16} + fi # remove all colons lora_eui_raw=${lora_eui//:} lora_hw=$(mts-io-sysfs show lora/hw-version 2> /dev/null) + if [ $? -ne 0 ]; then + lora_hw="NONE" + fi if [ -d $port1 ] && [[ $(cat $port1/hw-version) =~ "LORA-1.5" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "LORA-1.5" ]]; then dual_cards_installed=true elif [ -d $port1 ] && [[ $(cat $port1/hw-version) =~ "MTAC-003" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "MTAC-003" ]]; then dual_cards_installed=true + elif [ -d $port1 ] && [[ $(cat $port1/hw-version) =~ "LORA-2G4" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "LORA-2G4" ]]; then + dual_cards_installed=true fi if [[ "$dual_cards_installed" = "true" ]] && [ -d $port2 ] && [[ $(cat $port2/hw-version) =~ "LORA-1.5" || $(cat $port2/hw-version) =~ "LORA-2G4" || $(cat $port2/hw-version) =~ "MTAC-003" ]]; then @@ -96,6 +111,20 @@ read_lora_hw_info() { lora_2_eui_raw=${lora_2_eui//:} fi + set -e + + # Check USB id for Semtech Card + if [[ $(lsusb | grep 05c9:5740) =~ "05c9:5740" ]] && [[ ! "$lora_id" =~ "$lora_mtac_2g4_id" ]]; then + lora_id=$lora_mtac_2g4_id + lora_hw=$lora_2g4_hw + lora_eui=$(mts-io-sysfs show mac-eth) + lora_eui=${lora_eui:0:8}":FF:FF"${lora_eui:8:16} + LORA_CAPABLE=true + # Check USB id for Semtech Card in Bootloader mode + elif [[ $(lsusb | grep 0483:df11) =~ "0483:df11" ]]; then + echo "Semtech 2g4 MTAC card detected in Bootloader Mode, remove power from Conduit and restore" + return 1 + fi } hardware_found() { @@ -408,34 +437,44 @@ do_stop() { echo -n "Stopping $NAME: " start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5 start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_2_pidfile --retry 5 - rm -f $pkt_fwd_pidfile + rm -f $pkt_fwd_pidfile $pkt_fwd_2_pidfile echo "OK" } -if [ "$ENABLED" != "yes" ]; then - echo "$NAME: disabled in /etc/default" - exit -fi +force_stop() { + do_stop + rm -fr $LOCK +} +function try_lock() { + if mkdir $LOCK; then + trap "rm -fr $LOCK" EXIT + else + echo "Lora Network Server lock not acquired, resource in use" + exit 1 + fi +} case "$1" in "start") - do_start + try_lock + do_start ;; "stop") - do_stop + force_stop ;; "restart") ## Stop the service and regardless of whether it was ## running or not, start it again. + try_lock do_stop + sleep 5 do_start ;; *) ## If no parameters are given, print which are avaiable. echo "Usage: $0 {start|stop|restart}" exit 1 - ;; + ;; esac - |