From 6f922f7ae9c58f359cbacbcf0c35a3bf3262f5c5 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Sun, 8 Oct 2023 22:21:28 +0200 Subject: [PATCH] openwrt: add device option Add the new device option to UCI. This allows configuring of the modem device instead of the serial port. This is helpful in case serial-enumeration is different between devices. Signed-off-by: David Bauer --- README.md | 10 +++++++++ .../files/quectel-timesync.config | 2 +- .../files/quectel-timesync.init | 21 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff90e16..800cb75 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,20 @@ Determines if the tool should operate in daemon mode on system-start. Valid values: `0` or `1` +## `device` + +Path for the modem device to use. + +In case this option is set, it overrides the `path` option. + +Example: `/dev/cdc-wdm0` + ## `path` Path for the serial interface to use. +This option is overriden by the `device` option. + Example: `/dev/ttyUSB4` ## `interval` diff --git a/openwrt/quectel-timesync/files/quectel-timesync.config b/openwrt/quectel-timesync/files/quectel-timesync.config index c92d606..9baac80 100644 --- a/openwrt/quectel-timesync/files/quectel-timesync.config +++ b/openwrt/quectel-timesync/files/quectel-timesync.config @@ -1,3 +1,3 @@ config quectel-timesync 'timesync' option enabled '0' - option path '/dev/ttyUSB4' + option device '/dev/cdc-wdm0' diff --git a/openwrt/quectel-timesync/files/quectel-timesync.init b/openwrt/quectel-timesync/files/quectel-timesync.init index 98102bb..18aba34 100644 --- a/openwrt/quectel-timesync/files/quectel-timesync.init +++ b/openwrt/quectel-timesync/files/quectel-timesync.init @@ -4,10 +4,31 @@ START=60 USE_PROCD=1 +tty_from_dev() { + local cdc_path tty_devpath filepath filename + + cdc_path="$(readlink -f /sys/class/usbmisc/$1/device/)" + tty_devpath="${cdc_path::-1}3" + + for filepath in "$tty_devpath"/* ; do + filename="$(basename "${filepath}")" + if [[ "$filename" == "ttyUSB*" ]]; then + echo "$filename" + fi + done +} + start_service() { local enabled="$(uci -q get quectel-timesync.@quectel-timesync[-1].enabled)" local interval="$(uci -q get quectel-timesync.@quectel-timesync[-1].interval)" local path="$(uci -q get quectel-timesync.@quectel-timesync[-1].path)" + local device="$(uci -q get quectel-timesync.@quectel-timesync[-1].device)" + local device_name + + [ -z "$device" ] || { + device_name="$(basename "$device")" + path="/dev/$(tty_from_dev "$device_name")" + } interval="${interval:-10}"