1678 lines
49 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%+header%>
<script type="text/javascript" src="<%=resource%>/xhr.js"></script>
<script type="text/javascript">//<![CDATA[
window.onload=function()
{
//获取模组选择框元素
var modem_select = document.getElementById('modem_select');
//更换模组AT串口时触发
modem_select.addEventListener('change', function() {
//获取快捷命令
get_quick_commands();
//获取模组调试信息
document.getElementById("first_cache").checked=true;
get_modem_debug_info();
});
//获取标签菜单
var tab_menu = document.getElementById("tab_menu");
set_tab_event(tab_menu);
//获取快捷选项父元素
var quick_option_element = document.getElementById('quick_option_td');
//更换快捷选项时触发
quick_option_element.addEventListener('change', function(event) {
var target = event.target;
if (target.matches('input[type="radio"]')) {
//获取快捷命令
get_quick_commands();
}
});
//获取快捷AT命令选择框元素
var command_select = document.getElementById('command_select');
//更换快捷AT命令时触发
command_select.addEventListener("change", function() {
//自动填写到命令输入框
copy_to_input();
});
//获取快捷AT命令选择框元素
command_select = document.getElementById('command_select');
//点击快捷AT命令时触发解决情况再选的问题
command_select.addEventListener("click", function() {
//自动填写到命令输入框
copy_to_input();
});
//获取网络偏好选项元素
var prefer_option_auto = document.getElementById('prefer_option_auto');
var prefer_option_custom = document.getElementById('prefer_option_custom');
//网络偏好选项为自动时触发
prefer_option_auto.addEventListener('change', function() {
if (prefer_option_auto.checked)
{
//禁用偏好复选框
disabled_prefer_custom_config(true);
//全选偏好复选框
all_choose_prefer_custom_config(true);
}
});
//网络偏好选项为自定义时触发
prefer_option_custom.addEventListener('change', function() {
if (prefer_option_custom.checked)
{
//禁用偏好复选框
disabled_prefer_custom_config(false);
}
});
}
//设置标签菜单事件
function set_tab_event(parent_element)
{
//获取子元素
var childElements = parent_element.children;
//获取需要禁用的元素
for (var i = 0; i < childElements.length; i++)
{
childElements[i].addEventListener('click', function(event) {
tab_event(this);
document.getElementById("first_cache").checked=true;
get_modem_debug_info();
});
}
}
// 自动填写到快捷AT命令到输入框
function copy_to_input()
{
var command_select = document.getElementById("command_select").value;
document.getElementById("at_command").value = command_select;
}
// 发送AT命令
function send(at_port,at_command)
{
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "send_at_command")%>', {"port":at_port,"command":at_command},
function(x, data)
{
responseElement=document.getElementById("response");
if ("response" in data)
{
//显示当前时间
responseElement.value+=data["time"]+" ";
//显示返回值
responseElement.value+=data["response"];
//滚动到底部
responseElement.scrollTop = responseElement.scrollHeight;
}
}
);
}
// 发送AT命令前处理
function send_at_command(event)
{
//获取选中的模组选中的AT串口
var at_port = document.getElementById("modem_select").value;
if ( at_port.length == 0 )
{
alert("<%:Please choose a Modem%>");
return false;
}
//获取AT命令
var at_command = document.getElementById("at_command").value;
if ( at_command.length == 0 )
{
alert("<%:Please enter a AT Command%>");
return false;
}
//对双引号进行特殊处理
at_command=at_command.replaceAll("\"","\\\"");
//发送AT命令
send(at_port,at_command);
return true;
}
// 清除AT命令
function clean_at_command(event)
{
document.getElementById("at_command").value='';
}
// 清除AT响应
function clean_response(event)
{
document.getElementById("response").value='';
}
// 设置AT串口选项
function set_at_port(at_ports,translation)
{
// 获取模组选择框元素
var modem_select = document.getElementById('modem_select');
// 记录所选
var selected=modem_select.value;
// 删除原来的选项
modem_select.options.length=0;
//遍历每一个AT串口
for (var port of at_ports)
{
//更新keyAT串口value模块名称
for (var key in port)
{
var option = document.createElement('option');
option.value = key;
var language=navigator.language;
if (port[key].includes("unknown"))
{
option.text = port[key].replace("unknown", key);
}
else
{
option.text = port[key];
}
modem_select.appendChild(option);
}
}
// 恢复原来的选择
for (let i = 0; i < modem_select.options.length; i++)
{
if(modem_select.options[i].value == selected)
{
modem_select.selectedIndex=i;
break;
}
}
}
//获取当前启用的元素
function get_tab_enable_element(parent_element)
{
var disenable_element;
//获取子元素
var childElements = parent_element.children;
//获取需要禁用的元素
for (var i = 0; i < childElements.length; i++)
{
// 检查当前子元素的class属性是否为cbi-tab
if (childElements[i].classList.contains('cbi-tab'))
{
disenable_element=childElements[i];
break;
}
}
return disenable_element;
}
//获取需要禁用的元素
function get_enable_element(parent_element)
{
var enable_element;
//获取子元素
var childElements = parent_element.children;
//获取已启用的元素
for (var i = 0; i < childElements.length; i++)
{
// 检查当前子元素的class属性是否为cbi-tab
if (childElements[i].classList.contains('cbi-tab'))
{
enable_element=childElements[i];
break;
}
}
return enable_element;
}
// 设置标签显示
function set_tab_view(disenable_element,enable_element)
{
//获取tab内容父元素
var tab_context = document.getElementById('tab_context');
//禁用tab
disenable_element.classList.remove('cbi-tab');
disenable_element.classList.add('cbi-tab-disabled');
//禁用tab内容
var data_tab_disenable = disenable_element.getAttribute('data-tab');
var tab_context_disenable_element = tab_context.querySelector('div[data-tab="'+data_tab_disenable+'"]');
tab_context_disenable_element.setAttribute('data-tab-active','false');
tab_context_disenable_element.style.display="none";
//启用tab
enable_element.classList.remove('cbi-tab-disabled');
enable_element.classList.add('cbi-tab');
//启用tab内容
var data_tab_enable = enable_element.getAttribute('data-tab');
var tab_context_enable_element = tab_context.querySelector('div[data-tab="'+data_tab_enable+'"]');
tab_context_enable_element.setAttribute('data-tab-active','true');
tab_context_enable_element.style.display="block";
}
// 标签事件(更新选中的标签及标签内容)
function tab_event(tab_element)
{
//获取需要禁用的tab元素
// var tab_menu = document.getElementsByClassName("cbi-tabmenu")[0];
var tab_menu = document.getElementById("tab_menu");
var disenable_element=get_tab_enable_element(tab_menu);
if (tab_element != disenable_element) {
set_tab_view(disenable_element,tab_element);
}
}
// 无模组界面
function no_modems_view()
{
//更新提示信息
document.getElementById("info_message").innerHTML='<strong><%:No modems found%></strong>';
//显示提示信息
document.getElementById("cbi-info").style.display="block";
//隐藏模组选择界面
document.getElementById("cbi-modem").style.display="none";
//隐藏tab菜单界面
document.getElementById("tab_menu").style.display="none";
//隐藏tab内容界面
document.getElementById("tab_context").style.display="none";
}
// 未适配模组界面
function not_adapted_modems_view()
{
//更新提示信息
document.getElementById("info_message").innerHTML='<strong><%:Not adapted to this modem%></strong>';
//显示提示信息
document.getElementById("cbi-info").style.display="block";
//显示模组选择界面
document.getElementById("cbi-modem").style.display="block";
//显示标签内容界面
document.getElementById("tab_context").style.display="block";
//显示AT命令标题
document.getElementById("at_command_title").style.display="block";
//隐藏标签菜单界面
document.getElementById("tab_menu").style.display="none";
//在标签菜单选中AT命令
var data_tab="at_command_tab"
var at_command_tab_element = document.querySelector('li[data-tab="'+data_tab+'"]');
tab_event(at_command_tab_element);
}
// 全功能界面
function all_function_view()
{
//更新提示信息
document.getElementById("info_message").innerHTML='<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>"/><%:Loading modem%>...';
//显示模组选择界面
document.getElementById("cbi-modem").style.display="block";
//显示标签菜单界面
document.getElementById("tab_menu").style.display="flex";
//显示标签内容界面
document.getElementById("tab_context").style.display="block";
//隐藏AT命令标题
document.getElementById("at_command_title").style.display="none";
//隐藏提示信息
document.getElementById("cbi-info").style.display="none";
}
// 更新选项
function update_option(select_element,data,order)
{
//记录所选
var selected=select_element.value;
//删除原来的选项
select_element.options.length=0;
//是否有顺序
if (order)
{
//遍历每一条信息
for (var info of data)
{
//遍历每一条信息里的键
for (var key in info)
{
var option = document.createElement('option');
option.text = key;
option.value = info[key];
select_element.appendChild(option);
}
}
}
else
{
//遍历每一条信息里的键
for (var key of data)
{
var option = document.createElement('option');
option.text = key;
option.value = info[key];
select_element.appendChild(option);
}
}
//恢复原来的选择
for (let i = 0; i < select_element.options.length; i++)
{
if(select_element.options[i].value == selected)
{
select_element.selectedIndex=i;
break;
}
}
}
// 获取快捷命令
function get_quick_commands()
{
//获取快捷选项
var quick_option = document.querySelector('input[name="quick_option"]:checked').value;
//获取选中的模组
var at_port = document.getElementById("modem_select").value;
//获取AT命令
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_quick_commands")%>', {"option":quick_option,"port":at_port},
function(x, data)
{
//获取模组选择框元素
var command_select = document.getElementById('command_select');
//更新选项
update_option(command_select,data["quick_commands"],true);
}
);
}
// 全选网络偏好复选框
function all_choose_prefer_custom_config(status)
{
var checkboxes=document.getElementById('prefer_custom_config').querySelectorAll('input[type="checkbox"]');
for(checkbox of checkboxes)
{
//设置网络偏好复选框状态
checkbox.checked=status;
}
}
// 禁用网络偏好复选框
function disabled_prefer_custom_config(status)
{
var checkboxes=document.getElementById('prefer_custom_config').querySelectorAll('input[type="checkbox"]');
for(checkbox of checkboxes)
{
//禁用
checkbox.disabled=status;
}
}
// 禁用功能
function disabled_function(function_name,status)
{
//拨号模式
if (function_name=="mode")
{
modes=["qmi","ecm","mbim","rndis","ncm"]
for(mode of modes)
{
mode_element=document.getElementById('mode_option_'+mode)
if (mode_element!=null) {
mode_element.disabled=status;
}
}
//模式按钮
document.getElementById('mode_button').disabled=status;
}
//网络偏好
else if (function_name=="network_prefer")
{
//偏好选项
document.getElementById('prefer_option_auto').disabled=status;
document.getElementById('prefer_option_custom').disabled=status;
//网络偏好为自动则不启用
var prefer_option_auto = document.getElementById('prefer_option_auto');
if (!prefer_option_auto.checked)
{
//偏好复选框
disabled_prefer_custom_config(status);
}
//偏好按钮
document.getElementById('network_prefer_button').disabled=status;
}
}
// 设置拨号模式信息
function set_mode_info(mode_info)
{
//获取当前拨号模式
var current_mode=mode_info["mode"];
if (current_mode=="unknown")
{
return
}
//获取支持的拨号模式
var modes=mode_info["modes"];
//获取模式视图
var current_mode_view=current_mode.toUpperCase();
//设置当前拨号模式
document.getElementById('current_mode').innerHTML=current_mode_view;
//设置支持的拨号模式
var first_cache=document.getElementById("first_cache");
if (first_cache.checked)
{
var mode_option_view='';
for(mode of modes)
{
if (mode=="gobinet")
{
mode_option_view=mode_option_view.replace("QMI","QMI/GobiNet");
}
else
{
mode_option_view+='<span class="cbi-radio"><input type="radio" name="mode_option" id="mode_option_'+mode+'" value="'+mode+'"><span>'+mode.toUpperCase()+'</span></span>&nbsp;&nbsp;';
}
}
document.getElementById('mode_option').innerHTML=mode_option_view;
//设置拨号模式选项
element=document.getElementById('mode_option_'+current_mode).checked=true;
//设置第一次获取数据标志
first_cache.checked=false;
}
}
// 设置拨号模式
function set_mode()
{
//禁用功能
disabled_function("mode",true);
//获取模式选项
var mode_config = document.querySelector('input[name="mode_option"]:checked').value;
//获取选中的模组
var at_port = document.getElementById("modem_select").value;
//设置偏好
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_mode")%>', {"port":at_port,"mode_config":mode_config},
function(x, data)
{
//获取模组拨号模式
var current_mode=data;
//获取模式视图
var current_mode_view=current_mode.toUpperCase();
//设置当前拨号模式
document.getElementById('current_mode').innerHTML=current_mode_view;
//启用功能
disabled_function("mode",false);
}
);
}
// 获取当前网络视图
function get_current_prefer_view(network_prefer)
{
var current_prefer_view="";
//自动状态判断(全部选中为自动)
if (network_prefer["3G"]&&network_prefer["4G"]&&network_prefer["5G"])
{
//更新当前偏好
current_prefer_view="AUTO";
}
else
{
//更新当前偏好
for(key in network_prefer)
{
if (network_prefer[key]) {
current_prefer_view+=key+" ";
}
}
}
return current_prefer_view;
}
// 设置网络偏好信息
function set_network_prefer_info(network_prefer_info)
{
//获取模组网络偏好
var network_prefer=network_prefer_info["network_prefer"];
//获取偏好视图
var current_prefer_view=get_current_prefer_view(network_prefer);
//设置当前网络偏好
document.getElementById('current_prefer').innerHTML=current_prefer_view;
//设置偏好选项和复选框
var first_cache=document.getElementById("first_cache");
if (first_cache.checked)
{
if (network_prefer["3G"]&&network_prefer["4G"]&&network_prefer["5G"])
{
//设置偏好选项
document.getElementById('prefer_option_auto').checked=true;
//更新偏好配置
all_choose_prefer_custom_config(true);
//禁用用偏好复选框
disabled_prefer_custom_config(true);
}
else
{
//设置偏好选项
document.getElementById('prefer_option_custom').checked=true;
//更新偏好配置
for (key in network_prefer)
{
//设置偏好配置
var prefer_config_element=document.getElementById('prefer_config_'+key.toLowerCase());
if (prefer_config_element!=null) {
prefer_config_element.checked=network_prefer[key];
}
}
//启用偏好复选框
disabled_prefer_custom_config(false);
}
//设置第一次获取数据标志
first_cache.checked=false;
}
}
// 设置模组自检信息
function set_modem_self_test_info(self_test_info)
{
//获取电压
var voltage=self_test_info["voltage"];
//获取温度
var temperature=self_test_info["temperature"];
//设置当前电压
document.getElementById('current_voltage').innerHTML=voltage/1000+" V";
//设置当前温度
document.getElementById('current_temperature').innerHTML=temperature*1+" °C";
//设置电压状态
var state = '';
var css = '';
if (voltage<3135)
{
state = "<%:Abnormal%>";
color = "red";
}
else if (voltage>=3135 && voltage<3700)
{
state = "<%:Low%>";
color = "goldenrod";
}
else if (voltage>=3700 && voltage<4400) {
state = "<%:Normal%>";
color = "green";
}
else if (voltage>=4400) {
state = "<%:Abnormal%>";
color = "red";
}
else
{
state = "<%:Unknown%>";
color = "goldenrod";
}
var voltage_status=document.getElementById('voltage_status');
voltage_status.innerHTML=state;
voltage_status.style.color=color
//设置温度状态
state = '';
css = '';
if (temperature<45)
{
state = "<%:Normal%>";
color = "green";
}
else if (temperature>=45 && temperature<75)
{
state = "<%:Somewhat High%>";
color = "goldenrod";
}
else if (temperature>=75 && temperature<105) {
state = "<%:Excessively High%>";
color = "red";
}
else if (temperature>=105) {
state = "<%:Abnormal%>";
color = "red";
}
else
{
state = "<%:Unknown%>";
color = "goldenrod";
}
var temperature_status=document.getElementById('temperature_status');
temperature_status.innerHTML=state;
temperature_status.style.color=color
}
// 设置网络偏好
function set_network_prefer()
{
//禁用功能
disabled_function("network_prefer",true);
//获取偏好选项
var prefer_option = document.querySelector('input[name="prefer_option"]:checked').value;
//获取选中的模组
var at_port = document.getElementById("modem_select").value;
//获取偏好配置
var network_prefer_config={};
if (prefer_option=="auto")
{
network_prefer_config["3G"]=1;
network_prefer_config["4G"]=1;
network_prefer_config["5G"]=1;
}
else
{
var checkboxes=document.getElementById('prefer_custom_config').querySelectorAll('input[type="checkbox"]');
for(checkbox of checkboxes)
{
network_prefer_config[checkbox.value.toUpperCase()]=Number(checkbox.checked);
}
}
//设置偏好
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_network_prefer")%>', {"port":at_port,"prefer_config":network_prefer_config},
function(x, data)
{
//获取模组网络偏好
var network_prefer=data["network_prefer"];
//获取当前偏好视图
var current_prefer_view=get_current_prefer_view(network_prefer);
//设置模组当前网络偏好
document.getElementById('current_prefer').innerHTML=current_prefer_view;
//启用功能
disabled_function("network_prefer",false);
}
);
}
// 获取模组调试信息
function get_modem_debug_info()
{
//获取选中的模组
var at_port = document.getElementById("modem_select").value;
//获取当前启用的tab元素
var tab_menu = document.getElementById("tab_menu");
var tab_enable_element=get_tab_enable_element(tab_menu);
//获取当前选中的tab元素
var data_tab=tab_enable_element.getAttribute("data-tab").replace("_tab","");
if (data_tab=="mode") {
//获取拨号模式信息
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_mode_info")%>', {"port":at_port},
function(x, data)
{
var mode_info=data["mode_info"];
if (Object.keys(mode_info).length==0)
{
return false
}
//设置模式信息
set_mode_info(mode_info);
}
);
}
else if (data_tab=="network_prefer") {
//获取网络偏好信息
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_network_prefer_info")%>', {"port":at_port},
function(x, data)
{
var network_prefer_info=data["network_prefer_info"];
if (Object.keys(network_prefer_info).length==0)
{
return false
}
//设置网络偏好信息
set_network_prefer_info(network_prefer_info);
}
);
}
else if (data_tab=="self_test") {
//获取自检信息
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_self_test_info")%>', {"port":at_port},
function(x, data)
{
var self_test_info=data["self_test_info"];
if (Object.keys(self_test_info).length==0)
{
return false
}
//设置模组自检信息
set_modem_self_test_info(self_test_info);
}
);
}
//tom增加的功能
else if (data_tab == "lockband") {
//获取网络偏好信息
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_lockband")%>', { "port": at_port },
function (x, data) {
set_lockband_tab(data);
}
);
}
else if (data_tab == "lockcell") {
update_cell_config();
}
else if (data_tab == "set_imei") {
get_imei_info();
}
}
// 定时触发更新AT串口
XHR.poll(5,'<%=luci.dispatcher.build_url("admin", "network", "modem", "get_at_port")%>', null,
(function()
{
//缓存当前选择的模组
var modem_select_cache="";
var debug_params={view:0};
return function(x, data)
{
var at_ports=data["at_ports"];
var translation=data["translation"];
//设置AT串口选项
set_at_port(at_ports,translation);
//获取快捷命令
if (Object.keys(at_ports).length==0)
{
debug_params.view=0;
}
else
{
//获取当前的选择的模组名称
var modem_select_element = document.getElementById('modem_select');
var select_modem_name = modem_select_element.options[modem_select_element.selectedIndex].text;
if (select_modem_name.includes("ttyUSB")||select_modem_name.includes("at")||select_modem_name.includes("DUN"))
{
debug_params.view=2;
}
else
{
debug_params.view=1;
}
if (select_modem_name != modem_select_cache)
{
//获取快捷选项
var quick_option = document.querySelector('input[name="quick_option"]:checked').value;
if (quick_option=="auto") {
get_quick_commands();
}
//缓存当前选中的模组
modem_select_cache=select_modem_name;
//设置第一次获取数据标志
document.getElementById("first_cache").checked=true;
}
//获取模组调试信息
get_modem_debug_info();
}
//设置界面
if (debug_params.view==0) {
//显示无模组界面
no_modems_view();
}
else if (debug_params.view==1) {
//显示全功能界面
all_function_view();
}
else if (debug_params.view==2) {
//显示未适配模组界面
not_adapted_modems_view();
}
};
})()
);
//]]>
// tom增加的功能
// 更新neighbor cell信息
function update_cell_config() {
function onclick_copy_fun_gen(cellinfo) {
var arfcn = cellinfo["arfcn"];
var pci = cellinfo["pci"];
var rat = cellinfo["rat"];
return function () {
arfcn_input = document.getElementById('arfcn_input');
arfcn_input.value = arfcn;
pci_input = document.getElementById('pci_input');
pci_input.value = pci;
rat_select = document.getElementById('rat_select');
rat_select.value = rat;
};
}
var at_port = document.getElementById("modem_select").value;
neighbor_cell_info = document.getElementById('neighbor_cell_info');
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_neighbor_cellinfo")%>', { "port": at_port },
function (x, data) {
//remove all child nodes
while (neighbor_cell_info.firstChild) {
neighbor_cell_info.removeChild(neighbor_cell_info.firstChild);
}
//add new child nodes
lockcell_feature = data["Feature"];
//render feature button
lockcell_feature_div = document.getElementById('lockcell_feature');
for (key in lockcell_feature) {
v = lockcell_feature[key];
feature_button_id = "lockcell_feature_" + v;
if (document.getElementById(feature_button_id) != null) {
continue;
}
feature_button = document.createElement('input');
feature_button.type = "button";
feature_button.id = feature_button_id;
feature_button.value = key;
feature_button.className = "cbi-button-apply";
console.log("key:" + key + " feature:" + v)
feature_button.onclick = function () {
var at_port = document.getElementById("modem_select").value;
var pci = document.getElementById("pci_input").value;
var arfcn = document.getElementById("arfcn_input").value;
var rat = document.getElementById("rat_select").value;
var scs = document.getElementById("scs_select").value;
var nrband = document.getElementById("nrband_input").value;
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_lock_cell")%>', { "port": at_port, "func": this.id.replace("lockcell_feature_", ""), "pci": pci, "arfcn": arfcn, "celltype": rat, "scs": scs, "nrband": nrband },
function (x, data) {
console.log(data["response"]);
update_cell_config();
}
);
};
lockcell_feature_div.appendChild(feature_button);
}
lockcell_status = data["lockcell_status"];
neighbor_cells = {
"LTE": data["LTE"],
"NR": data["NR"]
}
try{
for (type in neighbor_cells) {
for (cell_info of neighbor_cells[type]) {
rat = type == "LTE" ? 0 : 1;
cell_info["rat"] = rat;
innerHTML = `RAT:${type} `
console.log(innerHTML)
for (cell_info_key in cell_info) {
if (cell_info[cell_info_key] == "") {
continue
}
innerHTML += `${cell_info_key}:${cell_info[cell_info_key]} `
}
cell_tr = document.createElement('tr');
cell_tr.className = "tr";
cell_td_left = document.createElement('td');
cell_td_left.className = "td";
cell_td_left.innerHTML = innerHTML;
cell_td_right = document.createElement('td');
cell_td_right.className = "td";
copy_botton = document.createElement('input');
copy_botton.type = "button";
copy_botton.innerHTML = "Copy";
copy_botton.className = "cbi-button";
copy_botton.value = "Copy";
copy_botton.onclick = onclick_copy_fun_gen(cell_info);
cell_td_right.appendChild(copy_botton);
cell_tr.appendChild(cell_td_left);
cell_tr.appendChild(cell_td_right);
neighbor_cell_info.appendChild(cell_tr);
}
}
}
catch (e) {
console.log(e);
}
lockcell_status_div = document.getElementById('current_cell_status');
childElements = lockcell_status_div.childNodes;
keys = Object.keys(lockcell_status);
eleids = [];
for (childElement of childElements) {
eleid = childElement.id;
if (eleid != undefined) {
eleids.push(eleid.replace("lockcell_", ""));
}
}
for (key of keys) {
if (lockcell_status[key] == "") {
if (eleids.includes(key)) {
lockcell_status_div.removeChild(document.getElementById("lockcell_" + key));
}
continue
}
id = "lockcell_" + key;
tr = document.getElementById(id);
td_left = document.getElementById(id + "_left");
td_right = document.getElementById(id + "_right");
if (tr == null) {
tr = document.createElement('tr');
tr.className = "tr";
tr.id = id;
td_left = document.createElement('td');
td_left.className = "td";
td_left.id = id + "_left";
td_right = document.createElement('td');
td_right.className = "td";
td_right.id = id + "_right";
lockcell_status_div.appendChild(tr);
tr.appendChild(td_left);
tr.appendChild(td_right);
}
td_left.innerHTML = key.toUpperCase();
td_right.innerHTML = lockcell_status[key].toUpperCase();
}
}
);
}
function lockcell_rat_onchange() {
if (document.getElementById("rat_select").value == "1") {
document.getElementById("nr_input_tr").style.display = "table-row";
document.getElementById("scs_input_tr").style.display = "table-row";
}
else {
document.getElementById("scs_input_tr").style.display = "none";
document.getElementById("nr_input_tr").style.display = "none";
}
}
//修改imei
function set_imei() {
var at_port = document.getElementById("modem_select").value;
var imei = document.getElementById("imei1_input").value;
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_imei")%>', { "port": at_port, "imei": imei },
function (x, data) {
set_imei_view(data);
}
);
}
function set_imei_view(imei_info) {
var imei = imei_info["imei"];
document.getElementById("imei1_input").value = imei;
}
function get_imei_info() {
var at_port = document.getElementById("modem_select").value;
var first_cache=document.getElementById("first_cache");
if (first_cache.checked)
{
document.getElementById("tab_menu").setAttribute("dont_edit", "true");
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_imei")%>', { "port": at_port },
function (x, data) {
set_imei_view(data);
}
);
first_cache.checked = false;
}
}
//锁频功能
class Lockband {
#lockband_config
#available_band
avalibale_bandid
#checkboxs = {}
set lock(band){
if (!this.#lockband_config.includes(band)){
this.#lockband_config.push(band)
//set checkbox
}
this.#checkboxs[band].checked = true;
}
set unlock(band){
this.#lockband_config = this.#lockband_config.filter(x => x != band)
//set checkbox
this.#checkboxs[band].checked = false;
}
createCheckbox(value,band){
let checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.className = "cbi-input-checkbox";
checkbox.value = band;
checkbox.setAttribute("display-band",value);
if (this.#lockband_config.includes(value)) {
this.lock(band);
}
let self = this;
checkbox.addEventListener("change",function(){
if (checkbox.checked){
self.lock = band;
}
else{
self.unlock = band;
}
});
this.#checkboxs[band] = checkbox;
}
createCheckboxs(){
for (let key in this.#available_band) {
let display_value = this.#available_band[key]
this.createCheckbox(display_value,key);
}
}
update(lockband_config){
for (let band in this.#available_band) {
if (lockband_config.includes(band)) {
this.lock = band;
}
else{
this.#checkboxs[band].checked = false;
this.unlock = band;
}
}
}
submit()
{
return this.#lockband_config;
}
render(){
let tr = document.createElement('tr');
tr.className = "tr cbi-section-table-row";
let td = document.createElement('td');
td.className = "td";
for (let checkbox in this.#checkboxs) {
let display_value = this.#checkboxs[checkbox].getAttribute("display-band");
let span = document.createElement('span');
span.innerHTML = display_value;
td.appendChild(this.#checkboxs[checkbox]);
td.appendChild(span);
}
tr.appendChild(td);
return tr;
}
constructor(lockband_info){
this.#lockband_config = lockband_info["lock_band"];
this.#available_band = lockband_info["available_band"];
this.avalibale_bandid = Object.keys(this.#available_band);
this.#checkboxs = [];
this.createCheckboxs();
this.update(this.#lockband_config);
}
}
function set_lockband_tab(lockband_info) {
if (typeof lb == "undefined") {
lb = {}
for (let RAT of Object.keys(lockband_info)) {
tr_header = document.createElement('div');
tr_header.className = "tr cbi-section-table-titles anonymous";
th = document.createElement('div');
th.className = "th cbi-section-table-cell";
th.innerHTML = RAT;
tr_header.appendChild(th);
document.getElementById('lockband_custom_config').appendChild(tr_header);
lb[RAT] = new Lockband(lockband_info[RAT]);
submit_btn = document.createElement('input');
submit_btn.type = "button";
submit_btn.value = "Submit";
submit_btn.addEventListener('click',
function () {
var at_port = document.getElementById("modem_select").value;
var config = lb[RAT].submit()
submit_config = ''
for (key of config) {
submit_config = key + "," + submit_config
}
submit_config = submit_config.substring(0, submit_config.length - 1)
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_lockband")%>', { "port": at_port, "lock_band_config": submit_config, "rat": RAT },
function (x, data) {
lb[RAT].update(data[RAT]["lock_band"])
}
);
})
select_all_btn = document.createElement('input');
select_all_btn.type = "button";
select_all_btn.value = "Select All";
select_all_btn.addEventListener('click', function () {
if (lb[RAT].submit().length == lb[RAT].avalibale_bandid.length) {
lb[RAT].update([])
}
else {
lb[RAT].update(lb[RAT].avalibale_bandid)
}
}
)
lockband_custom_config = document.getElementById('lockband_custom_config');
lockband_custom_config.appendChild(lb[RAT].render())
lockband_custom_config.appendChild(submit_btn);
lockband_custom_config.appendChild(select_all_btn);
}
}
var first_cache = document.getElementById("first_cache");
if (first_cache.checked) {
for (let RAT of Object.keys(lockband_info)) {
lb[RAT].update(lockband_info[RAT])
}
first_cache.checked = false;
}
}
</script>
<div class="cbi-map" id="cbi-modem-debug">
<h2 id="content" name="content"><%:Modem Debug%></h2>
<div class="cbi-map-descr"><%:Debug Your Module%></div>
<head>
<style type="text/css">
/* 消息样式 */
#info_message {
text-align: left;
font-size: 1.8em;
}
#info_message img {
vertical-align: middle;
}
#info_message a {
color: rgb(61, 143, 173);
font-size: 50%;
}
/* table {
width: 100%;
border-spacing: 10px;
border: 0px;
} */
tr td:first-child {
width: 33%;
}
/* AT命令响应 */
/* #response_label {
font-size: 15px;
} */
/* 隐藏tab菜单 */
.cbi-tabmenu {
display: none;
}
/* 隐藏tab内容 */
#tab_context {
display: none;
}
/* 隐藏AT命令标题 */
#at_command_title {
display: none;
}
/* AT命令响应 */
textarea {
background:#373737;
border:none;
color:#FFF;
width: 100%;
}
#popup {
width:560px;
height:190px;
padding:20px;
background-color:gainsboro;
border-style : solid;
position:fixed;
top : 40%;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
text-align: center;
display:none;
}
/*tom增加的功能 锁小区支持的feature button的按钮们*/
#lockcell_feature {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
</style>
</head>
<fieldset class="cbi-section" id="cbi-info" style="display: block;">
<div class="cbi-section fade-in">
<h3><%:Message%></h3>
<table class="table" id="message">
<tr class="tr">
<td colspan="2" class="td left">
<div id="info_message">
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>"/>
<%:Loading modem%>...
</div>
</td>
</tr>
</table>
</div>
</fieldset>
<fieldset class="cbi-section" id="cbi-modem" style="display: none;">
<div class="cbi-section fade-in">
<!-- <legend><%:Modem Select%></legend> -->
<h3><%:Modem Select%></h3>
<div class="cbi-section-node">
<div class="cbi-value">
<label class="cbi-value-title"><%:Modem Name%></label>
<div class="cbi-value-field">
<div class="cbi-checkbox">
<select name="modem_select" id="modem_select" class="cbi-input-select"></select>
</div>
<div class="cbi-value-description">
<%:Select a modem for debugging%>
</div>
</div>
</div>
<div class="cbi-value cbi-value-last" style="display: none;">
<label class="cbi-value-title"><%:First Cache%></label>
<div class="cbi-value-field">
<div class="cbi-checkbox">
<input id="first_cache" type="checkbox" checked>
</div>
<div class="cbi-value-description">
<%:First view tab context%>
</div>
</div>
</div>
</div>
</div>
</fieldset>
<ul class="cbi-tabmenu" id="tab_menu">
<li class="cbi-tab" data-tab="mode_tab"><a href="#"><%:Mode%></a></li>
<li class="cbi-tab-disabled" data-tab="network_prefer_tab"><a href="#"><%:Network Preferences%></a></li>
<li class="cbi-tab-disabled" data-tab="self_test_tab"><a href="#"><%:Self Test%></a></li>
<li class="cbi-tab-disabled" data-tab="at_command_tab"><a href="#"><%:AT Command%></a></li>
<li class="cbi-tab-disabled" data-tab="lockband_tab"><a href="#"><%:LockBand Settings%></a></li>
<li class="cbi-tab-disabled" data-tab="lockcell_tab"><a href="#"><%:Lock Cell/Arfcn Settings%></a></li>
<li class="cbi-tab-disabled" data-tab="set_imei_tab"><a href="#"><%:Set IMEI%></a></li>
</ul>
<div class="cbi-section-node cbi-section-node-tabbed" id="tab_context">
<!-- <div class="cbi-section cbi-tblsection" data-tab-active="true"> -->
<div class="cbi-section" data-tab="mode_tab" data-tab-title="<%:Mode%>" data-tab-active="true" style="display: block;">
<!-- <legend><%:Mode%></legend> -->
<!-- <h3><%:Mode%></h3> -->
<table class="table cbi-section-table">
<tbody>
<tr class="tr cbi-section-table-titles anonymous">
<th class="th cbi-section-table-cell"><%:Current%></th>
<th class="th cbi-section-table-cell"><%:Config%></th>
<th class="th cbi-section-table-cell cbi-section-actions"></th>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-1">
<td class="td cbi-value-field" data-title="<%:Current%>" id="current_mode"></td>
<td class="td cbi-value-field" data-title="<%:Config%>" id="mode_option">
<!-- <div>
<span class="cbi-radio">
<input type="radio" name="mode_option" id="mode_option_qmi" value="qmi" checked="true">
<span>QMI</span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="mode_option" id="mode_option_ecm" value="ecm">
<span>ECM</span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="mode_option" id="mode_option_mbim" value="mbim">
<span>MBIM</span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="mode_option" id="mode_option_rndis" value="rndis">
<span>RNDIS</span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="mode_option" id="mode_option_ncm" value="ncm">
<span>NCM</span>
</span>
</div> -->
</td>
<td class="td">
<div>
<button class="btn cbi-button cbi-button-apply" id="mode_button" onclick="set_mode()" alt="<%:Apply%>" title="<%:Apply%>"><%:Apply%></button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- <div class="cbi-section cbi-tblsection"> -->
<div class="cbi-section" data-tab="network_prefer_tab" data-tab-title="<%:Network Preferences%>" data-tab-active="false" style="display: none;">
<!-- <legend><%:Network Preferences%></legend> -->
<!-- <h3><%:Network Preferences%></h3> -->
<table class="table cbi-section-table">
<tbody>
<tr class="tr cbi-section-table-titles anonymous">
<th class="th cbi-section-table-cell"><%:Current%></th>
<th class="th cbi-section-table-cell"><%:Option%></th>
<th class="th cbi-section-table-cell"><%:Config%></th>
<th class="th cbi-section-table-cell cbi-section-actions"></th>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-1">
<td class="td cbi-value-field" data-title="<%:Current%>" id="current_prefer"></td>
<td class="td cbi-value-field" data-title="<%:Option%>" id="prefer_option">
<div>
<span class="cbi-radio">
<input type="radio" name="prefer_option" id="prefer_option_auto" value="auto" checked="true">
<span><%:Auto%></span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="prefer_option" id="prefer_option_custom" value="custom">
<span><%:Custom%></span>
</span>
</div>
</td>
<td class="td cbi-value-field" data-title="<%:Config%>" id="prefer_custom_config">
<div>
<span class="cbi-checkbox">
<input id="prefer_config_3g" type="checkbox" class="cbi-input-checkbox" value="3g">
<span><%:3G%></span>
</span> &nbsp;
<span class="cbi-checkbox">
<input id="prefer_config_4g" type="checkbox" class="cbi-input-checkbox" value="4g">
<span><%:4G%></span>
</span> &nbsp;
<span class="cbi-checkbox">
<input id="prefer_config_5g" type="checkbox" class="cbi-input-checkbox" value="5g">
<span><%:5G%></span>
</span>
</div>
</td>
<td class="td">
<div>
<button class="btn cbi-button cbi-button-apply" id="network_prefer_button" onclick="set_network_prefer()" alt="<%:Apply%>" title="<%:Apply%>"><%:Apply%></button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- <div class="cbi-section fade-in"> -->
<div class="cbi-section" data-tab="self_test_tab" data-tab-title="<%:Self Test%>" data-tab-active="false" style="display: none;">
<!-- <legend><%:Self Test%></legend> -->
<!-- <h3><%:Self Test%></h3> -->
<table class="table cbi-section-table">
<tbody>
<tr class="tr cbi-section-table-titles anonymous">
<th class="th cbi-section-table-cell"><%:Item%></th>
<th class="th cbi-section-table-cell"><%:Current%></th>
<th class="th cbi-section-table-cell"><%:Status%></th>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-1">
<td class="td cbi-value-field" data-title="<%:Item%>" id="voltage_label"><%:Voltage%></td>
<td class="td cbi-value-field" data-title="<%:Current%>" id="current_voltage"></td>
<td class="td cbi-value-field" data-title="<%:Status%>" id="voltage_status">-</td>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-2">
<td class="td cbi-value-field" data-title="<%:Item%>" id="temperature_label"><%:Temperature%></td>
<td class="td cbi-value-field" data-title="<%:Current%>" id="current_temperature"></td>
<td class="td cbi-value-field" data-title="<%:Status%>" id="temperature_status">-</td>
</tr>
</tbody>
</table>
</div>
<!-- <div class="cbi-section fade-in"> -->
<div class="cbi-section" data-tab="at_command_tab" data-tab-title="<%:AT Command%>" data-tab-active="false" style="display: none;">
<!-- <legend><%:AT Command%></legend> -->
<h3 id="at_command_title"><%:AT Command%></h3>
<table class="table" id="at_command_info">
<tbody>
<!-- <tr class="tr">
<td class="td left"><%:Modem Select%></td>
<td class="td left"><select name="modem_select" id="modem_select" class="cbi-input-select"></select></td>
</tr> -->
<tr class="tr">
<td class="td left"><%:Quick Option%></td>
<td class="td left" id="quick_option_td">
<div>
<span class="cbi-radio">
<input type="radio" name="quick_option" value="auto" checked="true">
<span><%:Auto%></span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="quick_option" value="custom">
<span><%:Custom%></span>
</span>
</div>
</td>
</tr>
<tr class="tr">
<td class="td left"><%:Quick Commands%></td>
<td class="td left"><select name="command_select" id="command_select" class="cbi-input-select"></select></td>
</tr>
<tr class="tr">
<td class="td left"><%:Enter Command%></td>
<td class="td left">
<div>
<input type="text" id="at_command" class="cbi-input-text"></input>
</div>
<div>
<input class="cbi-button cbi-button-apply" type="button" value="<%:Send%>" onclick="send_at_command()" alt="<%:Send%>" title="<%:Send%>">
<input class="cbi-button cbi-button-reset" type="button" value="<%:Clean%>" onclick="clean_at_command()" alt="<%:Clean%>" title="<%:Clean%>">
</div>
</td>
</tr>
<tr class="tr">
<td colspan="2" class="td left">
<div id="response_label"><%:Response%></div><br/>
<div><textarea readonly="readonly" id="response" rows="20" maxlength="160"></textarea></div>
<div class="cbi-page-actions">
<input class="btn cbi-button cbi-button-link" type="button" value="<%:Return to old page%>" onclick="location.href='/cgi-bin/luci/admin/network/modem/at_command_old'" alt="<%:Return to old page%>" title="<%:Return to old page%>">
<input class="btn cbi-button cbi-button-link" type="button" value="<%:Custom quick commands%>" onclick="location.href='/cgi-bin/luci/admin/network/modem/quick_commands_config'" alt="<%:Custom quick commands%>" title="<%:Custom quick commands%>">
<input class="cbi-button cbi-button-reset" type="button" value="<%:Clean%>" onclick="clean_response()" alt="<%:Clean%>" title="<%:Clean%>">
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- tom 添加的功能 -->
<!-- 锁频 -->
<div class="cbi-section" data-tab="lockband_tab" data-tab-title="<%:LockBand Settings%>" data-tab-active="false"
style="display: none;">
<!-- <legend><%:Network Preferences%></legend> -->
<!-- <h3><%:Network Preferences%></h3> -->
<table class="table cbi-section-table" >
<tbody id="lockband_custom_config">
<tr class="tr cbi-section-table-titles anonymous">
<th class="th cbi-section-table-cell">
<%:Config%>
</th>
</tr>
</tbody>
</table>
</div>
<!-- 锁小区、频点 -->
<div class="cbi-section" data-tab="lockcell_tab" data-tab-title="<%:Lock Cell/Arfcn Settings%>" data-tab-active="false"
style="display: none;">
<h3 id="Lock Cell/Arfcn_title">
<%:Current Settings%>
</h3>
<table class="table" id="CurrentStatus">
<tbody id="current_cell_status">
</tbody>
</table>
<h3 id="Lock Cell/Arfcn_title">
<%:Available Neighbor%>
</h3>
<table class="table" id="AvailableNeighbor">
<tbody id="neighbor_cell_info">
</tbody>
</table>
<!-- <legend><%:AT Command%></legend> -->
<h3 id="Lock Cell/Arfcn_title">
<%:Lock Cell/Arfcn Settings%>
</h3>
<table class="table" id="lockcell_info">
<tbody>
<tr class="tr">
<td class="td left">
<%:Select Rat%>
</td>
<td class="td left">
<select name="rat_select" id="rat_select" class="cbi-input-select"
onchange="lockcell_rat_onchange()">
<option value="0">4G</option>
<option value="1">5G</option>
</select>
</td>
</tr>
<tr class="tr">
<td class="td left">
<%:Enter Arfcn%>
</td>
<td class="td left">
<div>
<input type="text" id="arfcn_input" class="cbi-input-text"></input>
</div>
</td>
</tr>
<tr class="tr">
<td class="td left">
<%:Enter PCI%>
</td>
<td class="td left">
<div>
<input type="text" id="pci_input" class="cbi-input-text"></input>
</div>
</td>
</tr>
<tr class="tr" id="scs_input_tr" style="display:none;">
<td class="td left">
<%:Enter SCS%>
</td>
<td class="td left">
<select name="rat_select" id="scs_select" class="cbi-input-select">
<option value="0">15KHZ</option>
<option value="1">30KHZ</option>
<option value="2">60KHZ</option>
</select>
</td>
</tr>
<tr class="tr" id="nr_input_tr" style="display:none;">
<td class="td left">
<%:Enter NRBAND%>
</td>
<td class="td left">
<div>
<input type="text" id="nrband_input" class="cbi-input-text"></input>
</div>
</td>
</tr>
<tr class="tr">
<td class="td left">
<%:Submit%>
</td>
<td class="td left">
<div id="lockcell_feature">
</div>
</td>
</tr>
<span></span>
</tbody>
</table>
</div>
<!-- 设置IMEI -->
<div class="cbi-section" data-tab="set_imei_tab" data-tab-title="<%:Set IMEI%>" data-tab-active="false"
style="display: none;">
<table class="table cbi-section-table">
<tbody id="imei_setting">
<tr class="tr cbi-section-table-titles anonymous">
<th>
<%:IMEI%>
</th>
<th>
<%:Set IMEI%>
</th>
</tr>
<tr class="tr">
<td class="td" style="width: auto;">
<%:IMEI%>
</td>
<td class="td cbi-value-field">
<input type="text" id="imei1_input" class="cbi-input-text"></input>
</td>
</tr>
</tbody>
</table>
<input type="button" class="cbi-button-apply" onclick="set_imei()" value="<%:Apply%>">
</div>
</div>
</div>
<%+footer%>