diff options
author | Jason Reiss <jreiss@multitech.com> | 2016-12-20 08:01:59 -0600 |
---|---|---|
committer | Jason Reiss <jreiss@multitech.com> | 2016-12-20 08:01:59 -0600 |
commit | 97fe7114ff532b2017dd2abc5cba620c216ff8f3 (patch) | |
tree | b764c3839060643626beecd31422bf184589d10a /recipes-connectivity | |
parent | 622c63590925e829d0444a01d458e6b2c7c40205 (diff) | |
download | meta-mlinux-97fe7114ff532b2017dd2abc5cba620c216ff8f3.tar.gz meta-mlinux-97fe7114ff532b2017dd2abc5cba620c216ff8f3.tar.bz2 meta-mlinux-97fe7114ff532b2017dd2abc5cba620c216ff8f3.zip |
lora: add packet forwarder init script for Conduit
Diffstat (limited to 'recipes-connectivity')
3 files changed, 125 insertions, 1 deletions
diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.default.mtcdt b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.default.mtcdt new file mode 100644 index 0000000..0f92640 --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.default.mtcdt @@ -0,0 +1,2 @@ +# set to "yes" or "no" to control starting on boot +ENABLED="no" diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init.mtcdt b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init.mtcdt new file mode 100755 index 0000000..510f171 --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init.mtcdt @@ -0,0 +1,115 @@ +#!/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 + +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 + 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 + diff --git a/recipes-connectivity/lora/lora-packet-forwarder_3.0.0.bb b/recipes-connectivity/lora/lora-packet-forwarder_3.0.0.bb index 85fb8e3..d3c3e15 100644 --- a/recipes-connectivity/lora/lora-packet-forwarder_3.0.0.bb +++ b/recipes-connectivity/lora/lora-packet-forwarder_3.0.0.bb @@ -6,14 +6,16 @@ SECTION = "console/utils" LICENSE = "SEMTECH" LIC_FILES_CHKSUM = "file://LICENSE;md5=22af7693d7b76ef0fc76161c4be76c45" DEPENDS = "lora-gateway" -PR = "r7" +PR = "r8" SRCREV = "v${PV}" SRC_URI = "git://github.com/Lora-net/packet_forwarder.git;protocol=git \ file://README.md \ file://lora-packet-forwarder.init \ + file://lora-packet-forwarder.init.mtcdt \ file://lora-packet-forwarder.default \ + file://lora-packet-forwarder.default.mtcdt \ file://global_conf.json.3.0.0.PCB_E336.EU868.basic.clksrc0 \ file://global_conf.json.3.0.0.MTAC_LORA_1_0.EU868.basic.clksrc0 \ file://global_conf.json.3.0.0.MTAC_LORA_1_5.EU868.basic.clksrc0 \ @@ -52,6 +54,11 @@ do_install_append_mtcdt() { install -m 755 ${WORKDIR}/global_conf.json.3.0.0.MTAC_LORA_1_5.EU868.basic.clksrc0 ${D}${LORA_DIR}/global_conf.json install -m 755 ${WORKDIR}/global_conf.json.3.0.0.MTAC_LORA_1_0.EU868.basic.clksrc0 ${D}${LORA_DIR}/global_conf.json.MTAC_LORA_1_0 install -m 755 ${WORKDIR}/global_conf.json.3.0.0.MTAC_LORA_1_5.EU868.basic.clksrc0 ${D}${LORA_DIR}/global_conf.json.MTAC_LORA_1_5 + + install -d ${D}${sysconfdir}/default + install -m 0644 ${WORKDIR}/lora-packet-forwarder.default.mtcdt ${D}${sysconfdir}/default/lora-packet-forwarder + install -d ${D}${sysconfdir}/init.d + install -m 0755 ${WORKDIR}/lora-packet-forwarder.init.mtcdt ${D}${sysconfdir}/init.d/lora-packet-forwarder } do_install_append_mtcap() { |