javascript: addButtons();
monitor = [1, 3, 7, 20];
mainband = null;
_2ndrun = null;
suspend = 0;
function currentBand() {
    if (suspend == 1) return;
    console.log("Get Signal");
    $("#dhcp_mask").show();
    $("#dhcp_dns").show();
    $.ajax({
        type: "GET",
        async: true,
        url: '/api/device/signal',
        error: function(request, status, error) {
            alert("Signal Error:" + request.status + "\n" + "message:" + request.responseText + "\n" + "error:" + error);
        },
        success: function(data) {
            console.log("Get Signal data="+data);
            vars = ['rssi', 'rsrp', 'rsrq', 'sinr', 'dlbandwidth', 'ulbandwidth', 'band', 'cell_id', 'plmn'];
            for (i = 0; i < vars.length; i++) {
                window[vars[i]] = extractXML(vars[i], data);
                $('#' + vars[i]).html(window[vars[i]]);
                console.log("Get Signal windows["+i+"]="+window[vars[i]]);
            }
            setgraph('rsrp', rsrp, -130, -70);
            setgraph('rsrq', rsrq, -16, -3);
            hex = Number(cell_id).toString(16);
            hex2 = hex.substring(0, hex.length - 2);
            enbid = parseInt(hex2, 16).toString();
            $('#enbid').html(enbid);
            if (plmn == '22201') {
                plmn = '2221';
            }
            if (plmn == '22299') {
                plmn = '22288';
            }
            if ((plmn == '22250') && (enbid.length == 6)) {
                plmn = '22288';
            }
            link_lte = "https://lteitaly.it/internal/map.php#bts=" + plmn + "." + enbid;
            $("#lteitaly").attr("href", link_lte);
        }
    });
    console.log("Get Net Mode");
    $.ajax({
        type: "GET",
        async: true,
        url: '/api/net/net-mode',
        error: function(request, status, error) {
            alert("Signal Error:" + request.status + "\n" + "message:" + request.responseText + "\n" + "error:" + error);
        },
        success: function(data) {
            lteband = extractXML('LTEBand', data);
            $('#allowed').html(_4GType(lteband));
        }
    });
}
function extractXML(tag, data) {
    try {
        return data.split("</" + tag + ">")[0].split("<" + tag + ">")[1];
    } catch (err) {
        return err.message;
    }
}
function setgraph(p, val, min, max) {
    val = parseInt(val.replace("dBm", "").replace("dB"));
    x = (val - min) / (max - min) * 100;
    xs = String(x) + "%";
    e = "#" + p + "b";
    $(e).width(xs);
    $(e).html(p + " : " + window[p]);
    if (x < 50) {
        $(e).css("background-color", "yellow").css("color", 'black')
    } else if (x > 85) {
        $(e).css("background-color", "orange").css("color", 'white')
    } else {
        $(e).css("background-color", "green").css("color", 'white')
    }
}
function _4GType(data) {
    data_out = "";
    for (x = 0; x < monitor.length; x++) {
        tb = Math.pow(2, monitor[x] - 1);
        if ((parseInt(data, 16)) & (tb)) {
            data_out += "B" + String(monitor[x]) + "+";
        }
    }
    data_out = data_out.replace(/\++$/, "");
    return data_out;
}
function ltebandselection(bs) {
    console.log("CALLED" + bs);
    if (mainband) mainband = null;
    if (arguments.length == 0) {
        var band = prompt("Please input desirable LTE band number, separated by + char (example 1+3+20).If you want to use every supported bands, write 'AUTO'.", "AUTO");
        if (band) band = band.toLowerCase();
        if (band == null || band === "") {
            return;
        }
    } else var band = arguments[0];
    var bs = band.split("+");
    var ltesum = 0;
    if (band.toUpperCase() === "AUTO") {
        ltesum = "7FFFFFFFFFFFFFFF";
    } else {
        for (var i = 0; i < bs.length; i++) {
            if (bs.toLowerCase().indexOf('m') != -1) {
                bs = bs.replace('m', '');
                mainband = bs;
            }
            if (bs.toUpperCase() === "AUTO") {
                ltesum = "7FFFFFFFFFFFFFFF";
                break;
            } else ltesum = ltesum + Math.pow(2, parseInt(bs) - 1);
        }
        ltesum = ltesum.toString(16);
    }
    if (mainband) {
        console.log("Set Main");
        _2ndrun = bs;
        ltebandselection(String(mainband));
        return;
    }
    suspend = 1;
    $.ajax({
        type: "GET",
        async: true,
        url: '/html/home.html',
        error: function(request, status, error) {
            alert("Token Error:" + request.status + "\n" + "message:" + request.responseText + "\n" + "error:" + error);
        },
        success: function(data) {
            var datas = data.split('name="csrf_token" content="');
            var token = datas[datas.length - 1].split('"')[0];
            setTimeout(function() {
                $.ajax({
                    type: "POST",
                    async: true,
                    url: '/api/net/net-mode',
                    headers: {
                        '__RequestVerificationToken': token
                    },
                    contentType: 'application/xml',
                    data: '<request><NetworkMode>00</NetworkMode><NetworkBand>3FFFFFFF</NetworkBand><LTEBand>' + ltesum + '</LTEBand></request>',
                    success: function(nd) {
                        console.log("success netmode");
                        $("#band").html("<span style=\"color:green;\">OK</span>");
                        if (_2ndrun) {
                            console.log("Wait 2s");
                            window.setTimeout(function() {
                                console.log("Launch Netmode");
                                ltebandselection(_2ndrun.join("+"));
                                _2ndrun = false;
                            }, 2000);
                        } else {
                            suspend = 0;
                        }
                    },
                    error: function(request, status, error) {
                        alert("Net Mode Error:" + request.status + "\n" + "message:" + request.responseText + "\n" + "error:" + error);
                    }
                });
            }, 2000);
        }
    });
}
window.setInterval(currentBand, 2500);
function addButtons() {
    $(".headcontainer").slideUp();
    $("body").prepend("<style> .val{color:red;font-weight:strong;} .p{border:1px solid #ccc;width:auto;height:20px;} .v{height:20px;} </style> <div class=\"p\"><div class=\"v\" id=\"rsrpb\"></div></div> <div class=\"p\"><div class=\"v\" id=\"rsrqb\"></div></div> <a style=\"font-size:1.4em;margin-right:30px;color:#04a;\" onclick=\"ltebandselection()\">BANDS</a> <div style=\"display:inline;\"> RSRP:<span class=\"val\" id=\"rsrp\">0</span>   RSRQ:<span class=\"val\" id=\"rsrq\">0</span>   RSSI:<span class=\"val\" id=\"rssi\">0</span>   SINR:<span class=\"val\" id=\"sinr\">0</span>         ENB ID:<a id=\"lteitaly\" target=\"lteitaly\" href\"#\"><span class=\"val\" style=\"font-weight:bold;text-decoration:underline;\" id=\"enbid\">0</span></a>   CELL ID:<span class=\"val\" id=\"cell_id\">0</span>       BAND:<span class=\"val\" id=\"band\">0</span>(<span class=\"val\" id=\"dlbandwidth\">0</span>/<span class=\"val\" id=\"ulbandwidth\">0</span>)    SET:<span class=\"val\" id=\"allowed\">0</span> </div>");
}