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..af74b48 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 + + 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}"