diff options
author | Mykyta Dorokhin <mykyta.dorokhin@globallogic.com> | 2017-05-25 10:13:35 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2017-05-25 11:21:10 -0500 |
commit | 30945f752514a91c8563238e31d34e7c574b13d2 (patch) | |
tree | 428c2dec953742dab80b2194a60574884b1523fc /recipes-connectivity/lora/lora-packet-forwarder/mtcap | |
parent | 81745d07f262be466b286aa3a32d4c2f0c34e016 (diff) | |
download | meta-mlinux-30945f752514a91c8563238e31d34e7c574b13d2.tar.gz meta-mlinux-30945f752514a91c8563238e31d34e7c574b13d2.tar.bz2 meta-mlinux-30945f752514a91c8563238e31d34e7c574b13d2.zip |
mtcap: initial support for MTCAP-LORA-US915 card
Diffstat (limited to 'recipes-connectivity/lora/lora-packet-forwarder/mtcap')
-rwxr-xr-x | recipes-connectivity/lora/lora-packet-forwarder/mtcap/lora-packet-forwarder.init | 107 |
1 files changed, 85 insertions, 22 deletions
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 index 9ffaf6d..b17a3d8 100755 --- a/recipes-connectivity/lora/lora-packet-forwarder/mtcap/lora-packet-forwarder.init +++ b/recipes-connectivity/lora/lora-packet-forwarder/mtcap/lora-packet-forwarder.init @@ -3,58 +3,122 @@ NAME="lora-packet-forwarder" ENABLED="yes" -START_STOP_DAEMON="/usr/sbin/start-stop-daemon" - [ -f /etc/default/$NAME ] && source /etc/default/$NAME run_dir=/var/run/lora -pkt_fwd=/opt/lora/lora_pkt_fwd -pkt_fwd_pidfile=$run_dir/lora-pkt-fwd-1.pid +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 -cfg_file=/opt/lora/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 + +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() { - echo "Starting $NAME: " + # 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 - eui=$(mts-io-sysfs show lora/eui) - # Remove colons - clean_eui="${eui//:/}" - echo "Setting gateway_id in $cfg_file to $clean_eui" - sed -i "s/\"gateway_ID\": \".*\"/\"gateway_ID\": \"$clean_eui\"/" $cfg_file + # copy conf files to the run directory + if [ -f $conf_file ]; then + cp $conf_file $run_dir/1/ + fi - mkdir -p $run_dir + if [ -f $conf_file_local ]; then + cp $conf_file_local $run_dir/1/ + fi # start packet forwarder - $START_STOP_DAEMON --start --background --make-pidfile \ - --pidfile $pkt_fwd_pidfile --startas /bin/bash --chdir "/opt/lora/" \ - -- -c "exec $pkt_fwd > $log_file 2>&1" + 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 + 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/$NAME" + 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 @@ -63,7 +127,6 @@ case "$1" in ## If no parameters are given, print which are avaiable. echo "Usage: $0 {start|stop|restart}" exit 1 - ;; + ;; esac - |