add support to use preset metric

This commit is contained in:
fujr 2024-11-13 13:14:28 +08:00
parent cb5704de73
commit 3d1730dc13

View File

@ -21,6 +21,13 @@ get_default_alias()
config_foreach _get_default_alias_by_slot config_foreach _get_default_alias_by_slot
} }
get_default_metric()
{
target_slot=$1
config_load qmodem
config_foreach _get_default_metric_by_slot
}
_get_associated_usb_by_path() _get_associated_usb_by_path()
{ {
local cfg="$1" local cfg="$1"
@ -43,6 +50,16 @@ _get_default_alias_by_slot()
} }
_get_default_metric_by_slot()
{
local cfg="$1"
config_get _get_slot $cfg slot
if [ "$target_slot" == "$_get_slot" ];then
config_get default_metric $cfg default_metric
fi
}
scan() scan()
{ {
local slot_type=$1 local slot_type=$1
@ -315,8 +332,10 @@ add()
else else
#aqcuire lock #aqcuire lock
lock /tmp/lock/modem_add lock /tmp/lock/modem_add
unset default_alias
unset default_metric
get_default_alias $slot get_default_alias $slot
get_default_metric $slot
modem_count=$(uci get qmodem.main.modem_count) modem_count=$(uci get qmodem.main.modem_count)
[ -z "$modem_count" ] && modem_count=0 [ -z "$modem_count" ] && modem_count=0
modem_count=$(($modem_count+1)) modem_count=$(($modem_count+1))
@ -327,6 +346,7 @@ add()
lock -u /tmp/lock/modem_add lock -u /tmp/lock/modem_add
#release lock #release lock
metric=$(($modem_count+10)) metric=$(($modem_count+10))
[ -n "$default_metric" ] && metric=$default_metric
uci batch << EOF uci batch << EOF
set qmodem.$section_name.path="$modem_path" set qmodem.$section_name.path="$modem_path"
set qmodem.$section_name.data_interface="$slot_type" set qmodem.$section_name.data_interface="$slot_type"