hamlib: Added init and config files
authorJesper Henriksen <mail-openwrt@jesper.io>
Sun, 12 Feb 2023 13:29:39 +0000 (14:29 +0100)
committerJesper Henriksen <mail-openwrt@jesper.io>
Sun, 12 Feb 2023 13:30:36 +0000 (14:30 +0100)
Signed-off-by: Jesper Henriksen <mail-openwrt@jesper.io>
utils/hamlib/Makefile
utils/hamlib/files/rigctld.conf [new file with mode: 0644]
utils/hamlib/files/rigctld.init [new file with mode: 0755]

index 91ef7546685c79f28a70a7f5ce26908777e09eb9..553aa57b76ba489f11315dbc43d21223ed8d5648 100644 (file)
@@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=hamlib
 PKG_VERSION:=4.5.4
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=@SF/hamlib
@@ -43,6 +43,10 @@ define Package/hamlib
   DEPENDS:=+libhamlib
 endef
 
+define Package/hamlib/conffiles
+/etc/config/rigctld
+endef
+
 define Package/hamlib/description
   $(call Package/hamlib/Default/description)
 
@@ -90,6 +94,12 @@ CONFIGURE_VARS+= \
 define Package/hamlib/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(CP) $(PKG_INSTALL_DIR)/usr/bin/{rig,rot}* $(1)/usr/bin/
+
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/rigctld.init $(1)/etc/init.d/rigctld
+
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) ./files/rigctld.conf $(1)/etc/config/rigctld
 endef
 
 define Package/libhamlib/install
diff --git a/utils/hamlib/files/rigctld.conf b/utils/hamlib/files/rigctld.conf
new file mode 100644 (file)
index 0000000..fc8acd2
--- /dev/null
@@ -0,0 +1,24 @@
+config rig 'kx3'
+       option enabled '0'
+       option model '2045'
+       option rig_file '/dev/ttyUSB0'
+       option serial_speed '38400'
+
+config rig 'example'
+       option enabled '0'
+       option model ''
+       option rig_file ''
+       option ptt_file ''
+       option dcd_file ''
+       option ptt_type ''
+       option dcd_type ''
+       option serial_speed ''
+       option civaddr ''
+       option listen_addr ''
+       option port ''
+       option set_conf ''
+       option vfo ''
+       option verbose ''
+       option twiddle_timeout ''
+       option uplink ''
+       option debug_time_stamps ''
\ No newline at end of file
diff --git a/utils/hamlib/files/rigctld.init b/utils/hamlib/files/rigctld.init
new file mode 100755 (executable)
index 0000000..9eef5cd
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/sh /etc/rc.common
+USE_PROCD=1
+
+START=50
+STOP=50
+
+NAME=rigctld
+TYPE=rig
+BIN=/usr/bin/rigctld
+
+# option model '1234' => --model=1234
+OPTIONS_STRING="model rig_file ptt_file dcd_file ptt_type dcd_type serial_speed civaddr listen_addr port set_conf twiddle_timeout uplink"
+# option vfo '1' => --vfo
+OPTIONS_BOOL="debug_time_stamps vfo"
+# option verbose '3' => --verbose --verbose --verbose
+OPTIONS_CUMULATIVE="verbose"
+
+start_service() {
+       local instance="$1"
+
+       config_load "${NAME}"
+
+       if [ -n "$instance" ]; then
+               start_instance "$instance"
+       else
+               config_foreach start_instance "$TYPE"
+       fi
+}                 
+
+start_instance() {
+       local instance="$1"
+
+       config_get_bool "enabled" "$instance" "enabled" 0
+       [ "$enabled" -gt 0 ] || return
+
+       procd_open_instance "$instance"
+
+       procd_set_param command "$BIN"
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+
+       local option
+       local value
+
+       for option in $OPTIONS_STRING; do
+               config_get value "$instance" "$option"
+               [ -n "$value" ] || continue
+
+               option="${option//_/-}"
+               procd_append_param command "--$option=$value"
+       done
+       
+       for option in $OPTIONS_BOOL; do
+               config_get_bool value "$instance" "$option" 0
+               [ "$value" -eq 1 ] || continue
+               
+               option="${option//_/-}"
+               procd_append_param command "--$option"
+       done
+
+       for option in $OPTIONS_CUMULATIVE; do
+               config_get value "$instance" "$option" 0
+               [ -n "$value" ] || continue
+
+               option="${option//_/-}"
+
+               local i=0
+               while [ $i -lt "$value" ]; do
+                       procd_append_param command "--$option"
+                       let i++
+               done
+       done
+
+       procd_close_instance
+}
\ No newline at end of file