luci-olsr: add snr for olsr neighbours and update Legend
authorPatrick Grimm <patrick@lunatiki.de>
Wed, 10 Jul 2013 17:52:38 +0000 (17:52 +0000)
committerPatrick Grimm <patrick@lunatiki.de>
Wed, 10 Jul 2013 17:52:38 +0000 (17:52 +0000)
applications/luci-olsr/luasrc/controller/olsr.lua
applications/luci-olsr/luasrc/tools/olsr.lua
applications/luci-olsr/luasrc/view/status-olsr/legend.htm
applications/luci-olsr/luasrc/view/status-olsr/neighbors.htm

index bef7e52..daedcf5 100644 (file)
@@ -227,9 +227,9 @@ function action_neigh(json)
                                for assocmac, assot in pairs(val.list) do
                                        assocmac = string.lower(assocmac or "")
                                        if rmac == assocmac then
                                for assocmac, assot in pairs(val.list) do
                                        assocmac = string.lower(assocmac or "")
                                        if rmac == assocmac then
-                                               signal = tonumber(assot.signal)
-                                               noise = tonumber(assot.noise)
-                                               snr = signal/noise
+                                               signal = tonumber(assot.signal)*-1
+                                               noise = tonumber(assot.noise)*-1
+                                               snr = noise - signal
                                        end
                                end
                        end
                                        end
                                end
                        end
index 425d09a..dfd8262 100644 (file)
@@ -26,3 +26,17 @@ function etx_color(etx)
        return color
 end
 
        return color
 end
 
+function snr_color(snr)
+       local color = "#bb3333"
+       if snr == 0 then
+               color = "#bb3333"
+       elseif snr > 30 then
+               color = "#00cc00"
+       elseif snr > 20 then
+               color = "#ffcb05"
+       elseif snr > 5 then
+               color = "#ff6600"
+       end
+       return color
+end
+
index 55b839f..7575c12 100644 (file)
@@ -3,9 +3,18 @@
        <li><strong>LQ: </strong><%:Success rate of packages received from the neighbour%></li>
        <li><strong>NLQ: </strong><%:Success rate of packages sent to the neighbour%></li>
        <li><strong>ETX: </strong><%:Expected retransmission count%></li>
        <li><strong>LQ: </strong><%:Success rate of packages received from the neighbour%></li>
        <li><strong>NLQ: </strong><%:Success rate of packages sent to the neighbour%></li>
        <li><strong>ETX: </strong><%:Expected retransmission count%></li>
-       <li><strong><span style="color:#00cc00"><%:Green%></span></strong>:<%:Very good (ETX < 2)%></li>
-       <li><strong><span style="color:#ffcb05"><%:Yellow%></span></strong>:<%:Good (2 < ETX < 4)%></li>
-       <li><strong><span style="color:#ff6600"><%:Orange%></span></strong>:<%:Still usable (4 < ETX < 10)%></li>
-       <li><strong><span style="color:#bb3333"><%:Red%></span></strong>:<%:Bad (ETX > 10)%></li>
+       <ul>
+               <li><strong><span style="color:#00cc00"><%:Green%></span></strong>:<%:Very good (ETX < 2)%></li>
+               <li><strong><span style="color:#ffcb05"><%:Yellow%></span></strong>:<%:Good (2 < ETX < 4)%></li>
+               <li><strong><span style="color:#ff6600"><%:Orange%></span></strong>:<%:Still usable (4 < ETX < 10)%></li>
+               <li><strong><span style="color:#bb3333"><%:Red%></span></strong>:<%:Bad (ETX > 10)%></li>
+       </ul>
+       <li><strong>SNR: </strong><%:Signal Noise Ratio%></li>
+       <ul>
+               <li><strong><span style="color:#00cc00"><%:Green%></span></strong>:<%:Very good (SNR > 30)%></li>
+               <li><strong><span style="color:#ffcb05"><%:Yellow%></span></strong>:<%:Good (30 > SNR > 20)%></li>
+               <li><strong><span style="color:#ff6600"><%:Orange%></span></strong>:<%:Still usable (20 > SNR > 5)%></li>
+               <li><strong><span style="color:#bb3333"><%:Red%></span></strong>:<%:Bad (SNR < 5)%></li>
+       </ul>
 </ul>
 
 </ul>
 
index 0fb9bc0..f3b3745 100644 (file)
@@ -24,6 +24,7 @@ if luci.http.formvalue("status") == "1" then
                        link.linkCost = 0
                end
                local color = olsrtools.etx_color(link.linkCost)
                        link.linkCost = 0
                end
                local color = olsrtools.etx_color(link.linkCost)
+               local snr_color = olsrtools.snr_color(link.snr)
                defaultgw_color = ""
                if link.defaultgw == 1 then
                        defaultgw_color = "#ffff99"
                defaultgw_color = ""
                if link.defaultgw == 1 then
                        defaultgw_color = "#ffff99"
@@ -43,6 +44,7 @@ if luci.http.formvalue("status") == "1" then
                        signal = string.format("%.3f", link.signal),
                        noise = string.format("%.3f", link.noise),
                        color = color,
                        signal = string.format("%.3f", link.signal),
                        noise = string.format("%.3f", link.noise),
                        color = color,
+                       snr_color = snr_color,
                        dfgcolor = defaultgw_color,
                        proto = link.proto
                        }
                        dfgcolor = defaultgw_color,
                        proto = link.proto
                        }
@@ -100,7 +102,7 @@ end
                                                '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
                                                '<td class="cbi-section-table-titles" style="background-color:%s" title="Signal: %s Noise: %s">%s</td>' +
                                                '</tr>',
                                                '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
                                                '<td class="cbi-section-table-titles" style="background-color:%s" title="Signal: %s Noise: %s">%s</td>' +
                                                '</tr>',
-                                               neigh.dfgcolor, neigh.ifn, neigh.lip, neigh.lmac, neigh.dfgcolor, neigh.lq, neigh.dfgcolor, neigh.nlq, neigh.color, neigh.cost, neigh.color, neigh.signal, neigh.noise, neigh.snr || '?'
+                                               neigh.dfgcolor, neigh.ifn, neigh.lip, neigh.lmac, neigh.dfgcolor, neigh.lq, neigh.dfgcolor, neigh.nlq, neigh.color, neigh.cost, neigh.snr_color, neigh.signal, neigh.noise, neigh.snr || '?'
                                        );
                                }
 
                                        );
                                }
 
@@ -140,6 +142,7 @@ end
                        end
 
                        color = olsrtools.etx_color(link.linkCost)
                        end
 
                        color = olsrtools.etx_color(link.linkCost)
+                       snr_color = olsrtools.snr_color(link.snr)
 
                        defaultgw_color = ""
                        if link.defaultgw == 1 then
 
                        defaultgw_color = ""
                        if link.defaultgw == 1 then
@@ -158,7 +161,7 @@ end
                        <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.linkQuality)%></td>
                        <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.neighborLinkQuality)%></td>
                        <td class="cbi-section-table-titles" style="background-color:<%=color%>"><%=string.format("%.3f", link.linkCost)%></td>
                        <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.linkQuality)%></td>
                        <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.neighborLinkQuality)%></td>
                        <td class="cbi-section-table-titles" style="background-color:<%=color%>"><%=string.format("%.3f", link.linkCost)%></td>
-                       <td class="cbi-section-table-titles" style="background-color:<%=color%>" title="Signal: <%=string.format("%.3f", link.signal)%> Noise: <%=string.format("%.3f", link.noise)%>"><%=string.format("%.3f", link.snr)%></td>
+                       <td class="cbi-section-table-titles" style="background-color:<%=snr_color%>" title="Signal: <%=string.format("%.3f", link.signal)%> Noise: <%=string.format("%.3f", link.noise)%>"><%=string.format("%.3f", link.snr)%></td>
                </tr>
                <% 
                        i = ((i % 2) + 1)
                </tr>
                <% 
                        i = ((i % 2) + 1)