On 19 Jan 2012, at 22:17, John Crispin wrote:

> 
>> 
>> Anyway ... just a few ideas, interested in thoughts, I can post the
>> current patches if there's interest, or happy to explore other ideas if
>> I'm way off the mark.
> 
> sure, show us your patch please ;)
> _______________________________________________

Ok, these aren't in the right format for a couple of reasons (namely that I 
haven't got a LuCI tree checked out yet, and that I'm still working on the main 
script and haven't put it back into the main tree), but hopefully this will 
give you a feel for what I'm talking about….

Firstly the main dsl_control script (/etc/init.d/dsl_control) … used to 
stop/start and provide hardware specific stats, this is still work in progress, 
I'll tidy it up and add more functionality (and error checking) over the next 
couple of days, and build a proper patch...

#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org
START=99

EXTRA_COMMANDS="status luastat"
EXTRA_HELP="    status  Get DSL status information
        lustat  Get status information if lua friendly format" 

#
# Basic functions to send CLI commands to the dsl_cpe_control daemon
#
dsl_cmd() {
        echo "$@" > /tmp/pipe/dsl_cpe0_cmd
        cat /tmp/pipe/dsl_cpe0_ack
}
dsl_val() {
        echo $(expr "$1" : '.*'$2'=\([[:alnum:]]*\).*')
}

#
# Simple divide by 10 routine to cope with one decimal place
#
dbt() {
        local a=$(expr $1 / 10)
        local b=$(expr $1 % 10)
        echo "${a}.${b}"
}
#
# Take a number and convert to k or meg
#
scale() {
        local val=$1
        local a
        local b
        
        if [ "$val" -gt 1000000 ]; then
                a=$(expr $val / 1000)
                b=$(expr $a % 1000)
                a=$(expr $a / 1000)
                printf "%d.%03d Mb" ${a} ${b}
        elif [ "$val" -gt 1000 ]; then
                a=$(expr $val / 1000)
                printf "%d Kb" ${a}
        else
                echo "${val} b"
        fi
}


start() {

        # start CPE dsl daemon in the background
        /sbin/dsl_cpe_control -i \
                        -n /sbin/dsl_notify.sh \
                        -f /lib/firmware/ModemHWE.bin &

#       PS=`ps`
#       echo $PS | grep -q dsl_cpe_control && {
#               # workaround for nfs: allow write to pipes for non-root
#               while [ ! -e /tmp/pipe/dsl_cpe1_ack ] ; do sleep 1; done
#               chmod a+w /tmp/pipe/dsl_*
#       }
        echo $PS | grep -q dsl_cpe_control || {
                echo "Start of dsl_cpe_control failed!!!"
                false
        }
}




data_rates() {
        local csg
        local dru
        local drd
        local sdru
        local sdrd
        
        csg=$(dsl_cmd g997csg 0 1)
        drd=$(dsl_val "$csg" ActualDataRate)
        
        csg=$(dsl_cmd g997csg 0 0)
        dru=$(dsl_val "$csg" ActualDataRate)
        
        sdrd=$(scale $drd)
        sdru=$(scale $dru)
        
        if [ "$action" = "luastat" ]; then
                echo "dsl.data_rate_down=$drd"
                echo "dsl.data_rate_up=$dru"
                echo "dsl.data_rate_down_s=\"$sdrd\""
                echo "dsl.data_rate_up_s=\"$sdru\""
        else
                echo "Data Rate:                ${sdrd}/s / ${sdru}/s"
        fi
}

line_data() {
        local lsg
        local latnu
        local latnd
        local snru
        local snrd
        
        lsg=$(dsl_cmd g997lsg 1 1)
        latnd=$(dsl_val "$lsg" LATN)
        snrd=$(dsl_val "$lsg" SNR)
        
        lsg=$(dsl_cmd g997lsg 0 1)
        latnu=$(dsl_val "$lsg" LATN)
        snru=$(dsl_val "$lsg" SNR)
        
        latnd=$(dbt $latnd)
        latnu=$(dbt $latnu)
        snrd=$(dbt $snrd)
        snru=$(dbt $snru)
        
        if [ "$action" = "luastat" ]; then
                echo "dsl.line_attenuation_down=$latnd"
                echo "dsl.line_attenuation_up=$latnu"
                echo "dsl.noise_margin_down=$snrd"
                echo "dsl.noise_margin_up=$snru"
        else
                echo "Line Attenuation: ${latnd}dB / ${latnu}dB"
                echo "Noise Margin:             ${snrd}dB / ${snru}dB"
        fi
}


line_state() {
        local lsg=$(dsl_cmd lsg)
        local ls=$(dsl_val "$lsg" nLineState);
        local s;

        
        case "$ls" in
                "0x0")          s="not initialized" ;;
                "0x1")          s="exception" ;;
                "0x10")         s="not updated" ;;
                "0xff")         s="idle request" ;;
                "0x100")        s="idle" ;;
                "0x1ff")        s="silent request" ;;
                "0x200")        s="silent" ;;
                "0x300")        s="handshake" ;;
                "0x380")        s="full_init" ;;
                "0x400")        s="discovery" ;;
                "0x500")        s="training" ;;
                "0x600")        s="analysis" ;;
                "0x700")        s="exchange" ;;
                "0x800")        s="showtime_no_sync" ;;
                "0x801")        s="showtime_tc_sync" ;;
                "0x900")        s="fastretrain" ;;
                "0xa00")        s="lowpower_l2" ;;
                "0xb00")        s="loopdiagnostic active" ;;
                "0xb10")        s="loopdiagnostic data exchange" ;;
                "0xb20")        s="loopdiagnostic data request" ;;
                "0xc00")        s="loopdiagnostic complete" ;;
                "0x1000000")    s="test" ;;
                "0xd00")        s="resync" ;;
                "0x3c0")        s="short init entry" ;;
                *)              s="unknown" ;;
        esac
        
        if [ $action = "luastat" ]; then
                echo "dsl.line_state_num=$ls"
                echo "dsl.line_state_detail=\"$s\""
                if [ "$ls" = "0x801" ]; then
                        echo "dsl.line_state=\"UP\""
                else
                        echo "dsl.line_state=\"DOWN\""
                fi
        else
                if [ "$ls" = "0x801" ]; then
                        echo "Line State:               UP [$ls: $s]"
                else
                        echo "Line State:               DOWN [$ls: $s]"
                fi
        fi
}



status() {      
        line_state
        data_rates
        line_data
}

luastat() {
        echo "local dsl={}"
        status
        echo "return dsl"
}

…. and now the patch to LuCI to provide basic DSL stats on the admin_overview 
page, this works pretty well (although needs some error checking), but I think 
you also need the same detail (probably in the network admin page) with buttons 
to stop and start the DSL line (which for lantiq is stopping or starting the 
daemon)…

essele@linux-dev:~/openwrt$ diff -u 
trunk/staging_dir/target-mips_r2_uClibc-0.9.32/root-lantiq/usr/lib/lua/luci/view/admin_status/index.htm
 dev/index.htm 
--- 
trunk/staging_dir/target-mips_r2_uClibc-0.9.32/root-lantiq/usr/lib/lua/luci/view/admin_status/index.htm
     2011-10-10 17:08:00.000000000 +0100
+++ dev/index.htm       2012-01-20 07:11:41.352076158 +0000
@@ -21,6 +21,7 @@
        local has_dhcp = luci.fs.access("/etc/config/dhcp")
        local has_wifi = luci.fs.stat("/etc/config/wireless")
              has_wifi = has_wifi and has_wifi.size > 0
+       local has_dsl = luci.fs.stat("/etc/init.d/dsl_control")
 
        if luci.http.formvalue("status") == "1" then
                local ntm = require "luci.model.network".init()
@@ -88,12 +89,19 @@
                                link    = wan6:adminlink()
                        }
                end
+               
+               if has_dsl then
+                       local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control 
luastat")
+                       local dsl_func = loadstring(dsl_stat)
+                       rv.dsl = dsl_func()
+               end
 
                luci.http.prepare_content("application/json")
                luci.http.write_json(rv)
 
                return
        end
+       
 
        local system, model = luci.sys.sysinfo()
 -%>
@@ -222,6 +230,30 @@
                                ss6.innerHTML = '<em>Not connected</em>';
                        }
                        <% end %>
+                       
+                       <% if has_dsl then %>
+                               var dsl_i = document.getElementById('dsl_i');
+                               var dsl_s = document.getElementById('dsl_s');
+                       
+                               var s = String.format(
+                                       '<strong><%:Status%>: </strong>%s<br 
/>' +
+                                       '<strong><%:Line State%>: </strong>%s 
[0x%x]<br />' +
+                                       '<strong><%:Line Speed%>: </strong>%s/s 
/ %s/s<br />' +
+                                       '<strong><%:Line Attenuation%>: 
</strong>%s dB / %s dB<br />' +
+                                       '<strong><%:Noise Margin%>: </strong>%s 
dB / %s dB<br />',
+                                               info.dsl.line_state, 
info.dsl.line_state_detail,
+                                               info.dsl.line_state_num,
+                                               info.dsl.data_rate_down_s, 
info.dsl.data_rate_up_s,
+                                               info.dsl.line_attenuation_down, 
info.dsl.line_attenuation_up,
+                                               info.dsl.noise_margin_down, 
info.dsl.noise_margin_up
+                                               
+                               );
+                               dsl_s.innerHTML = 
String.format('<small>%s</small>', s);
+                               dsl_i.innerHTML = String.format(
+                                       '<img 
src="<%=resource%>/icons/ethernet.png" />' +
+                                       '<br /><small>ADSL</small>'
+                               );
+                       <% end %>
 
                        <% if has_dhcp then %>
                        var ls = document.getElementById('lease_status_table');
@@ -528,6 +560,20 @@
        </table>
 </fieldset>
 <% end %>
+
+<% if has_dsl then %>
+<fieldset class="cbi-section">
+       <legend><%:ADSL%></legend>
+       <table width="100%" cellspacing="10">
+               <tr><td width="33%" style="vertical-align:top"><%:ADSL 
Status%></td><td>
+                       <table><tr>
+                               <td id="dsl_i" style="width:16px; 
text-align:center; padding:3px"><img 
src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
+                               <td id="dsl_s" style="vertical-align:middle; 
padding: 3px"><em><%:Collecting data...%></em></td>
+                       </tr></table>
+               </td></tr>
+       </table>
+</fieldset>
+<% end %>
 
 <% if has_wifi then %>
 <fieldset class="cbi-section">






_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to