diff options
author | Harsh Sharma <harsh.sharma@multitech.com> | 2018-04-19 14:56:37 -0500 |
---|---|---|
committer | Harsh Sharma <harsh.sharma@multitech.com> | 2018-04-19 14:56:37 -0500 |
commit | a1e89171c91479369af13134828c2fb4a4fd824f (patch) | |
tree | c56691abc962a60036062082f97f64563741a693 /recipes-connectivity/lora/lora-packet-forwarder | |
parent | 5dc0d8ffad8679293b059d219e49299fcc43cfc1 (diff) | |
download | meta-mlinux-a1e89171c91479369af13134828c2fb4a4fd824f.tar.gz meta-mlinux-a1e89171c91479369af13134828c2fb4a4fd824f.tar.bz2 meta-mlinux-a1e89171c91479369af13134828c2fb4a4fd824f.zip |
Added Lora 2.1 Packet forwarder support
Diffstat (limited to 'recipes-connectivity/lora/lora-packet-forwarder')
-rwxr-xr-x | recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init | 123 | ||||
-rw-r--r-- | recipes-connectivity/lora/lora-packet-forwarder/mtcdt-2.1/lora-packet-forwarder.default | 2 |
2 files changed, 79 insertions, 46 deletions
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 ec81b9d..a671b7d 100755 --- a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder.init @@ -23,72 +23,103 @@ 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_2_1_hw="MTCDTIPHP-LORA-2.1" lora_mtcap_id="MTCAP-LORA" lora_mtcap_id868="MTCAP-LORA-868" lora_mtcap_id915="MTCAP-LORA-915" +lora_mtcdt_id868="MTCDTIPHP-LORA-868" +lora_mtcdt_id915="MTCDTIPHP-LORA-915" + +pkf_options="" + +gps_path="/dev/gps0" + read_lora_hw_info() { - # product-id of first lora card lora_id=$(mts-io-sysfs show lora/product-id 2> /dev/null) + lora_hw=$(mts-io-sysfs show lora/hw-version 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_mtac_id" ]]; then + setup_mtcdt + elif [[ "$lora_id" =~ "$lora_mtcap_id" ]]; then + setup_mtcap + elif [[ "$lora_hw" =~ "$lora_2_1_hw" ]]; then + setup_mtcdt_2_1 + else + return 1 + fi + return 0 +} + +setup_mtcdt() { 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_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 +} - 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 +setup_mtcap() { + 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 + echo "No valid configuration found for mtcap exiting." + exit 1 + fi - ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd + 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 - return 0 + 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 - return 1 + ln -sf /opt/lora/lora_pkt_fwd $pkt_fwd } +setup_mtcdt_2_1() { + if [[ "$lora_id" =~ "$lora_mtcdt_id868" ]]; then + CONFIG=/opt/lora/global_conf.json.MTAC_LORA_2_1_loc_single_antenna_16ch_EU868 + elif [[ "$lora_id" =~ "$lora_mtcdt_id915" ]]; then + CONFIG=/opt/lora/global_conf.json.MTAC_LORA_2_1_loc_single_antenna_16ch_US915 + else + echo "No valid configuration found for mtcdt 2.1, exiting." + exit 1 + fi + + opt_conf_file=$opt_conf_dir/global_conf.json + cp $CONFIG $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 + fi + + ln -sf /opt/lora/pkt_forwarder $pkt_fwd + + if [ -f $gps_path ]; then + pkf_options=" -g" + fi +} do_start() { @@ -98,7 +129,7 @@ do_start() { read_lora_hw_info if hardware_found; then - echo "Found $lora_id with $lora_hw hardware" + echo "Found $lora_id with $lora_hw hardware. Configuring" else echo "$0: LORA card not detected" exit 1 @@ -109,8 +140,6 @@ do_start() { exit 1 fi - echo -n "Starting $NAME: " - # # copy conf files to the run directory # @@ -122,8 +151,10 @@ do_start() { # # 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" + --pidfile $pkt_fwd_pidfile --startas /bin/bash -- -c "exec $pkt_fwd $pkf_options" renice -n -20 -p $(pgrep $(basename $pkt_fwd)) diff --git a/recipes-connectivity/lora/lora-packet-forwarder/mtcdt-2.1/lora-packet-forwarder.default b/recipes-connectivity/lora/lora-packet-forwarder/mtcdt-2.1/lora-packet-forwarder.default new file mode 100644 index 0000000..0f92640 --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/mtcdt-2.1/lora-packet-forwarder.default @@ -0,0 +1,2 @@ +# set to "yes" or "no" to control starting on boot +ENABLED="no" |