Skip to content

Commit

Permalink
openwrt: add device option
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
blocktrron committed Oct 8, 2023
1 parent aaca2ce commit ce32012
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion openwrt/quectel-timesync/files/quectel-timesync.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
config quectel-timesync 'timesync'
option enabled '0'
option path '/dev/ttyUSB4'
option device '/dev/cdc-wdm0'
21 changes: 21 additions & 0 deletions openwrt/quectel-timesync/files/quectel-timesync.init
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down

0 comments on commit ce32012

Please sign in to comment.