From fdffad3583c0c6621284e4d4e9183ef10c3c7c66 Mon Sep 17 00:00:00 2001 From: Mykyta Dorokhin Date: Fri, 26 May 2017 13:46:04 -0500 Subject: merge lora-packet-forwarder mtcdt and mtcap init scripts into one --- ...obal_conf.json.3.1.0.MTCAP-LORA-1-5.US915.basic | 20 +-- .../lora-packet-forwarder.init | 167 +++++++++++++++++++++ .../mtcap/lora-packet-forwarder.init | 132 ---------------- .../mtcdt/lora-packet-forwarder.init | 121 --------------- 4 files changed, 169 insertions(+), 271 deletions(-) create mode 100755 recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init delete mode 100755 recipes-connectivity/lora/lora-packet-forwarder/mtcap/lora-packet-forwarder.init delete mode 100755 recipes-connectivity/lora/lora-packet-forwarder/mtcdt/lora-packet-forwarder.init diff --git a/recipes-connectivity/lora/lora-packet-forwarder/global_conf.json.3.1.0.MTCAP-LORA-1-5.US915.basic b/recipes-connectivity/lora/lora-packet-forwarder/global_conf.json.3.1.0.MTCAP-LORA-1-5.US915.basic index 6d56f3b..c357414 100644 --- a/recipes-connectivity/lora/lora-packet-forwarder/global_conf.json.3.1.0.MTCAP-LORA-1-5.US915.basic +++ b/recipes-connectivity/lora/lora-packet-forwarder/global_conf.json.3.1.0.MTCAP-LORA-1-5.US915.basic @@ -1,7 +1,7 @@ { "SX1301_conf" : { - "antenna_gain" : 0, /* antenna gain, in dBi */ + "antenna_gain" : 0, "chan_FSK" : { "bandwidth" : 125000, @@ -71,7 +71,7 @@ { "enable" : false, "nb_channel" : 1, - "rssi_target" : 160, /* rssi in dBm = -lbt_rssi_target/2 */ + "rssi_target" : 160, "scan_time_us" : 5000, "start_freq" : 869525000, "tx_delay_1ch_us" : 4000000, @@ -100,7 +100,6 @@ { "dig_gain" : 0, "mix_gain" : 11, - /* TX gain table, index 0 */ "pa_gain" : 0, "rf_power" : -6 }, @@ -108,7 +107,6 @@ { "dig_gain" : 0, "mix_gain" : 13, - /* TX gain table, index 1 */ "pa_gain" : 0, "rf_power" : -3 }, @@ -116,7 +114,6 @@ { "dig_gain" : 0, "mix_gain" : 15, - /* TX gain table, index 10 */ "pa_gain" : 2, "rf_power" : 16 }, @@ -124,7 +121,6 @@ { "dig_gain" : 0, "mix_gain" : 10, - /* TX gain table, index 11 */ "pa_gain" : 3, "rf_power" : 20 }, @@ -132,7 +128,6 @@ { "dig_gain" : 0, "mix_gain" : 12, - /* TX gain table, index 12 */ "pa_gain" : 3, "rf_power" : 23 }, @@ -140,7 +135,6 @@ { "dig_gain" : 0, "mix_gain" : 13, - /* TX gain table, index 13 */ "pa_gain" : 3, "rf_power" : 25 }, @@ -148,7 +142,6 @@ { "dig_gain" : 0, "mix_gain" : 15, - /* TX gain table, index 14 */ "pa_gain" : 3, "rf_power" : 26 }, @@ -156,7 +149,6 @@ { "dig_gain" : 0, "mix_gain" : 15, - /* TX gain table, index 15 */ "pa_gain" : 3, "rf_power" : 27 }, @@ -164,7 +156,6 @@ { "dig_gain" : 0, "mix_gain" : 9, - /* TX gain table, index 2 */ "pa_gain" : 1, "rf_power" : 0 }, @@ -172,7 +163,6 @@ { "dig_gain" : 0, "mix_gain" : 10, - /* TX gain table, index 3 */ "pa_gain" : 1, "rf_power" : 3 }, @@ -180,7 +170,6 @@ { "dig_gain" : 0, "mix_gain" : 12, - /* TX gain table, index 4 */ "pa_gain" : 1, "rf_power" : 6 }, @@ -188,7 +177,6 @@ { "dig_gain" : 0, "mix_gain" : 10, - /* TX gain table, index 5 */ "pa_gain" : 2, "rf_power" : 10 }, @@ -196,7 +184,6 @@ { "dig_gain" : 0, "mix_gain" : 11, - /* TX gain table, index 6 */ "pa_gain" : 2, "rf_power" : 11 }, @@ -204,7 +191,6 @@ { "dig_gain" : 0, "mix_gain" : 11, - /* TX gain table, index 7 */ "pa_gain" : 2, "rf_power" : 12 }, @@ -212,7 +198,6 @@ { "dig_gain" : 0, "mix_gain" : 12, - /* TX gain table, index 8 */ "pa_gain" : 2, "rf_power" : 13 }, @@ -220,7 +205,6 @@ { "dig_gain" : 0, "mix_gain" : 13, - /* TX gain table, index 9 */ "pa_gain" : 2, "rf_power" : 14 } diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init new file mode 100755 index 0000000..ec81b9d --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init @@ -0,0 +1,167 @@ +#!/bin/bash + + +NAME="lora-packet-forwarder" +ENABLED="yes" + + +[ -f /etc/default/$NAME ] && source /etc/default/$NAME + +run_dir=/var/run/lora +opt_conf_dir=/opt/lora +conf_dir=/var/config/lora +conf_file=$conf_dir/global_conf.json +conf_file_local=$conf_dir/local_conf.json + +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_mtac_id="MTAC-LORA" +lora_1_0_hw="MTAC-LORA-1.0" +lora_1_5_h_hw="MTAC-LORA-1.5" + +lora_mtcap_id="MTCAP-LORA" +lora_mtcap_id868="MTCAP-LORA-868" +lora_mtcap_id915="MTCAP-LORA-915" + +read_lora_hw_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//:/} + lora_hw=$(mts-io-sysfs show lora/hw-version 2> /dev/null) +} + +hardware_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_mtac_id" ]]; then + # + # MTCDT + # + if [ "$lora_hw" = "$lora_1_0_hw" ] && [[ ! "$lora_id" =~ .*-SPI ]]; then + ln -sf /opt/lora/basic_pkt_fwd-usb $pkt_fwd + else + ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd + fi + + return 0 + elif [[ "$lora_id" =~ "$lora_mtcap_id" ]]; then + # + # MTCAP + # + # Generate default forwarder configuration based on detected LORA hardware + # + if [ "$lora_id" = "$lora_mtcap_id868" ]; then + GLOBAL_CONF=/opt/lora/global_conf.json.MTCAP_LORA_1_5.EU868 + elif [ "$lora_id" = "$lora_mtcap_id915" ]; then + GLOBAL_CONF=/opt/lora/global_conf.json.MTCAP_LORA_1_5.US915 + else + return 1 + fi + + opt_conf_file=$opt_conf_dir/global_conf.json + opt_conf_file_local=$opt_conf_dir/local_conf.json + + cp $GLOBAL_CONF $opt_conf_file + sed -i "s/\"gateway_ID\": \".*\"/\"gateway_ID\": \"$lora_eui_raw\"/" $opt_conf_file + + if ! [ -f $conf_file ]; then + mkdir -p /var/config/lora/ + cp $opt_conf_file $conf_file + cp $opt_conf_file_local $conf_file_local + fi + + ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd + + return 0 + fi + + return 1 +} + + +do_start() { + + mkdir -p $run_dir/1 + rm -rf $run_dir/1/* + + read_lora_hw_info + + if hardware_found; then + echo "Found $lora_id with $lora_hw hardware" + else + echo "$0: LORA card not detected" + exit 1 + fi + + if ! [ -f $conf_file ]; then + echo "$0: $conf_file missing" + exit 1 + fi + + echo -n "Starting $NAME: " + + # + # copy conf files to the run directory + # + cp $conf_file $run_dir/1/ + if [ -f $conf_file_local ]; then + cp $conf_file_local $run_dir/1/ + fi + + # + # 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 $(basename $pkt_fwd)) + + echo "OK" +} + + +do_stop() { + echo -n "Stopping $NAME: " + start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5 + rm -f $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 + diff --git a/recipes-connectivity/lora/lora-packet-forwarder/mtcap/lora-packet-forwarder.init b/recipes-connectivity/lora/lora-packet-forwarder/mtcap/lora-packet-forwarder.init deleted file mode 100755 index b17a3d8..0000000 --- a/recipes-connectivity/lora/lora-packet-forwarder/mtcap/lora-packet-forwarder.init +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/bash - -NAME="lora-packet-forwarder" -ENABLED="yes" - -[ -f /etc/default/$NAME ] && source /etc/default/$NAME - -run_dir=/var/run/lora -conf_file=/var/config/lora/global_conf.json -conf_file_local=/var/config/lora/local_conf.json -opt_conf_file=/opt/lora/global_conf.json -opt_conf_file_local=/opt/lora/local_conf.json -log_file=/var/log/lora-pkt-fwd.log - -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 - -lora_mtcap_id="MTCAP-LORA" -lora_mtcap_id868="MTCAP-LORA-868" -lora_mtcap_id915="MTCAP-LORA-915" - -read_lora_hw_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//:/} - lora_hw=$(mts-io-sysfs show lora/hw-version 2> /dev/null) -} - -hardware_found() { - if [[ "$lora_id" =~ "$lora_mtcap_id" ]]; then - # - # create /opt/lora/global_conf.json based on detected LORA card - # - if [ "$lora_id" = "$lora_mtcap_id868" ]; then - GLOBAL_CONF=/opt/lora/global_conf.json.MTCAP_LORA_1_5.EU868 - elif [ "$lora_id" = "$lora_mtcap_id915" ]; then - GLOBAL_CONF=/opt/lora/global_conf.json.MTCAP_LORA_1_5.US915 - else - return 1 - fi - - cp $GLOBAL_CONF $opt_conf_file - echo "Setting gateway_id in $opt_conf_file to $lora_eui_raw" - sed -i "s/\"gateway_ID\": \".*\"/\"gateway_ID\": \"$lora_eui_raw\"/" $opt_conf_file - - # - # copy global_json.conf and local_json.conf files to /var/config/ if it is not there yet - # - if ! [ -f $conf_file ]; then - mkdir -p /var/config/lora/ - cp $opt_conf_file $conf_file - cp $opt_conf_file_local $conf_file_local - fi - - ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd - else - return 1 - fi - -} - -do_start() { - # create run directory - mkdir -p $run_dir/1 - rm -rf $run_dir/1/* - - read_lora_hw_info - - if hardware_found; then - echo "Found $lora_id with $lora_hw hardware" - else - echo "$0: LORA not detected" - exit 1 - fi - - # copy conf files to the run directory - if [ -f $conf_file ]; then - cp $conf_file $run_dir/1/ - fi - - if [ -f $conf_file_local ]; then - cp $conf_file_local $run_dir/1/ - fi - - # start packet forwarder - echo -n "Starting $NAME: " - /usr/sbin/start-stop-daemon --chdir $run_dir/1 --background --start --make-pidfile \ - --pidfile $pkt_fwd_pidfile --startas /bin/bash -- -c "exec $pkt_fwd > $log_file 2>&1" - - renice -n -20 -p $(pgrep $(basename $pkt_fwd)) - - echo "OK" -} - - -do_stop() { - echo -n "Stopping $NAME: " - start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5 - rm -f $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 - diff --git a/recipes-connectivity/lora/lora-packet-forwarder/mtcdt/lora-packet-forwarder.init b/recipes-connectivity/lora/lora-packet-forwarder/mtcdt/lora-packet-forwarder.init deleted file mode 100755 index fa4e1b4..0000000 --- a/recipes-connectivity/lora/lora-packet-forwarder/mtcdt/lora-packet-forwarder.init +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/bash - - -NAME="lora-packet-forwarder" -ENABLED="yes" - - -[ -f /etc/default/$NAME ] && source /etc/default/$NAME - -run_dir=/var/run/lora -conf_dir=/var/config/lora -conf_file=$conf_dir/global_conf.json - -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_mtac_id="MTAC-LORA" -lora_1_0_hw="MTAC-LORA-1.0" -lora_1_5_h_hw="MTAC-LORA-1.5" - - -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//:/} - 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_mtac_id" ]]; then - if [ "$lora_hw" = "$lora_1_0_hw" ] && [[ ! "$lora_id" =~ .*-SPI ]]; then - ln -sf /opt/lora/basic_pkt_fwd-usb $pkt_fwd - else - ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd - fi - - return 0 - else - return 1 - fi -} - - -do_start() { - - mkdir -p $run_dir/1 - read_card_info - - if ! [ -f $conf_file ]; then - echo "$0: $conf_file missing" - exit 1 - fi - - - 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: " - # start packet forwarder - cp $conf_dir/global_conf.json $run_dir/1/global_conf.json - /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 $(basename $pkt_fwd)) - - - echo "OK" -} - - -do_stop() { - echo -n "Stopping $NAME: " - start-stop-daemon --stop --quiet --oknodo --pidfile $pkt_fwd_pidfile --retry 5 - rm -f $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