From 4df6d0b63e07cfe556c1d522e1a59f8223e0aa8d Mon Sep 17 00:00:00 2001 From: Michele Di Maria Date: Sat, 17 Dec 2011 21:38:30 +0100 Subject: - Added 40x2 display size (I found out that some display has this size) - I managed in the code ALL the drivers available in the package. Consider that before this change only 12 drivers on 35 were supported. Now all the selectable panels are supposed to work, with the default configuration values. If someone has problems with the new added drivers please let me know - I added the IN/OUT statistics for a selectable interface. For the selected interface IN and OUT bytes are shown - In the summary (visible to the ones that have a 4 line display) I added, if the width of the panel is bigger than 16 rows, the frequency in percent currently used - I reduced the CPU interval in the load calculation from 1s to 250ms. This because setting the refresh of the panel to 1 second was actually 2 seconts (1 to wait for the refresh, 1 to wait for the CPU calculation) --- config/lcdproc-dev/lcdproc.inc | 140 +++++++++++++++++++++++++++++---- config/lcdproc-dev/lcdproc.xml | 4 +- config/lcdproc-dev/lcdproc_client.php | 106 +++++++++++++++++++------ config/lcdproc-dev/lcdproc_screens.xml | 15 +++- 4 files changed, 225 insertions(+), 40 deletions(-) (limited to 'config/lcdproc-dev') diff --git a/config/lcdproc-dev/lcdproc.inc b/config/lcdproc-dev/lcdproc.inc index d4ff92fa..b82a59e6 100644 --- a/config/lcdproc-dev/lcdproc.inc +++ b/config/lcdproc-dev/lcdproc.inc @@ -49,7 +49,7 @@ if((int)exec('pgrep LCDd | wc -l') > 0) return true; return false; - } + } function lcdproc_write_config($file, $text) { $handle = fopen($file, 'w'); @@ -75,16 +75,16 @@ function before_form_lcdproc($pkg) { global $config; - config_lock(); - + config_lock(); + config_unlock(); } function before_form_lcdproc_screens($pkg) { global $config; - config_lock(); - + config_lock(); + config_unlock(); } @@ -149,6 +149,9 @@ case "20x4": continue; break; + case "40x2": + continue; + break; default: $input_errors[] = "The chosen display size is not valid"; break; @@ -228,12 +231,12 @@ $config_text .= "DownKey=Down\n"; /* lcdproc default driver definitions */ - switch($lcdproc_config[driver]) { + switch($lcdproc_config[driver]) { case "bayrad": $config_text .= "[{$lcdproc_config['driver']}]\n"; $config_text .= "Device={$realport}\n"; $config_text .= "Speed=9600\n"; - break; + break; case "CFontz": $config_text .= "[{$lcdproc_config['driver']}]\n"; $config_text .= "Device={$realport}\n"; @@ -292,6 +295,18 @@ $config_text .= "OffBrightness=0\n"; $config_text .= "Brightness=500\n"; break; + case "EyeboxOne": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Backlight=yes\n"; + $config_text .= "Speed=19200\n"; + break; + case "glk": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Contrast=560\n"; + $config_text .= "Speed=19200\n"; + break; case "hd44780": $config_text .= "[{$lcdproc_config['driver']}]\n"; $config_text .= "driverpath=/usr/local/lib/lcdproc/\n"; @@ -307,13 +322,78 @@ $config_text .= "DelayMult=1\n"; $config_text .= "DelayBus=true\n"; $config_text .= "Size={$lcdproc_config['size']}\n"; - break; + break; + case "icp_a106": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + break; + case "IOWarrior": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + break; + case "lb216": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Brightness=255\n"; + $config_text .= "Speed=9600\n"; + $config_text .= "Reboot=no\n"; + break; + case "lcdm001": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + break; + case "lcterm": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + break; + case "MD8800": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Brightness=1000\n"; + $config_text .= "OffBrightness=0\n"; + break; + case "ms6931": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Brightness=255\n"; + $config_text .= "Reboot=no\n"; + break; + case "mtc_s16209x": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Brightness=255\n"; + $config_text .= "Reboot=no\n"; + break; + case "MtxOrb": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Contrast=480\n"; + $config_text .= "Type=lcd\n"; + $config_text .= "hasAdjustableBacklight=yes\n"; + $config_text .= "Reboot=no\n"; + $config_text .= "Brightness=1000\n"; + $config_text .= "OffBrightness=0\n"; + $config_text .= "Speed=19200\n"; + break; case "nexcom": $config_text .= "[{$lcdproc_config['driver']}]\n"; $config_text .= "driverpath =/usr/local/lib/lcdproc/\n"; $config_text .= "Device={$realport}\n"; $config_text .= "Size={$lcdproc_config['size']}\n"; - break; + break; + case "NoritakeVFD": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Brightness=1000\n"; + $config_text .= "OffBrightness=0\n"; + $config_text .= "Speed=9600\n"; + $config_text .= "Parity=0\n"; + $config_text .= "Reboot=no\n"; + break; case "picolcd": $config_text .= "[{$lcdproc_config['driver']}]\n"; $config_text .= "driverpath=/usr/local/lib/lcdproc/\n"; @@ -336,16 +416,48 @@ $config_text .= "Device={$realport}\n"; $config_text .= "Size={$lcdproc_config['size']}\n"; break; + case "sed1330": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + break; + case "sed1520": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + break; + case "serialPOS": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Type=AEDEX\n"; + $config_text .= "Speed=9600\n"; + break; + case "serialVFD": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "use_parallel=no\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Size={$lcdproc_config['size']}\n"; + $config_text .= "Type=0\n"; //Just the first + $config_text .= "Brightness=1000\n"; + $config_text .= "OffBrightness=0\n"; + $config_text .= "Speed=9600\n"; + $config_text .= "ISO_8859_1=yes\n"; + break; + case "shuttleVFD": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + break; case "SureElec": $config_text .= "[{$lcdproc_config['driver']}]\n"; $config_text .= "driverpath =/usr/local/lib/lcdproc/\n"; $config_text .= "Device={$realport}\n"; $config_text .= "Size={$lcdproc_config['size']}\n"; - $config_text .= "Edition=2\n"; + $config_text .= "Edition=2\n"; $config_text .= "Contrast=200\n"; - $config_text .= "Brightness=480\n"; + $config_text .= "Brightness=480\n"; $config_text .= "Speed=19200\n"; break; + case "sli": + $config_text .= "[{$lcdproc_config['driver']}]\n"; + $config_text .= "Device={$realport}\n"; + $config_text .= "Speed=9600\n"; + break; default: lcdproc_warn("The chosen lcdproc driver is not a valid choice"); unset($lcdproc_config[driver]); @@ -370,12 +482,12 @@ EOD; $stop = << - Services: LCDproc 0.5.4 pkg v. 0.1 + Services: LCDproc 0.5.4 pkg v. 0.3 lcdproc - 0.5.4 pkg v. 0.2 + 0.5.4 pkg v. 0.3 Save /usr/local/pkg/lcdproc.inc diff --git a/config/lcdproc-dev/lcdproc_client.php b/config/lcdproc-dev/lcdproc_client.php index 5c0edb77..52656fdc 100644 --- a/config/lcdproc-dev/lcdproc_client.php +++ b/config/lcdproc-dev/lcdproc_client.php @@ -32,8 +32,9 @@ */ require_once("config.inc"); require_once("functions.inc"); + require_once("interfaces.inc"); require_once("/usr/local/pkg/lcdproc.inc"); - + function get_pfstate() { global $config; $matches = ""; @@ -70,25 +71,12 @@ return $memUsage; } - /*function array_combine($arr1, $arr2) { - $out = array(); - - $arr1 = array_values($arr1); - $arr2 = array_values($arr2); - - foreach($arr1 as $key1 => $value1) { - $out[(string)$value1] = $arr2[$key1]; - } - - return $out; - }*/ - /* Calculates non-idle CPU time and returns as a percentage */ function cpu_usage() { - $duration = 1; + $duration = 250000; $diff = array('user', 'nice', 'sys', 'intr', 'idle'); $cpuTicks = array_combine($diff, explode(" ", `/sbin/sysctl -n kern.cp_time`)); - sleep($duration); + usleep($duration); $cpuTicks2 = array_combine($diff, explode(" ", `/sbin/sysctl -n kern.cp_time`)); $totalStart = array_sum($cpuTicks); @@ -157,6 +145,19 @@ $status = "$curfreq\/$maxfreq Mhz"; return($status); } + + function get_cpufrequency_perc(){ + $cpufreqs = ""; + exec("/sbin/sysctl -n dev.cpu.0.freq_levels", $cpufreqs); + $cpufreqs = explode(" ", trim($cpufreqs[0])); + $maxfreq = explode("/", $cpufreqs[0]); + $maxfreq = $maxfreq[0]; + $curfreq = ""; + exec("/sbin/sysctl -n dev.cpu.0.freq", $curfreq); + $curfreq = trim($curfreq[0]); + $status = $curfreq/$maxfreq * 100; + return($status); + } function get_interfaces_stats() { global $g; @@ -454,6 +455,41 @@ } } + function get_traffic_stats(&$in_data, &$out_data){ + global $config; + global $traffic_last_ugmt, $traffic_last_ifin, $traffic_last_ifout; + $lcdproc_screen_config = $config['installedpackages']['lcdprocscreens']['config'][0]; + /* read the configured interface */ + $ifnum = $lcdproc_screen_config['scr_traffic_interface']; + /* get the real interface name (code from ifstats.php)*/ + $realif = get_real_interface($ifnum); + if(!$realif) + $realif = $ifnum; // Need for IPSec case interface. + /* get the interface stats (code from ifstats.php)*/ + $ifinfo = pfSense_get_interface_stats($realif); + /* get the current time (code from ifstats.php)*/ + $temp = gettimeofday(); + $timing = (double)$temp["sec"] + (double)$temp["usec"] / 1000000.0; + /* calculate the traffic stats */ + $deltatime = $timing - $traffic_last_ugmt; + $in_data = "IN: " . formatSpeedBits(((double)$ifinfo['inbytes']-$traffic_last_ifin)/$deltatime); + $out_data = "OUT: " . formatSpeedBits(((double)$ifinfo['outbytes']-$traffic_last_ifout)/$deltatime); + $traffic_last_ugmt = $timing; + $traffic_last_ifin = (double)$ifinfo['inbytes']; + $traffic_last_ifout = (double)$ifinfo['outbytes']; + } + + function formatSpeedBits($speed) { + /* format speed in bits/sec, input: bytes/sec + Code from: graph.php ported to PHP*/ + if ($speed < 125000) + {return sprintf("%3d.1 Kbps", $speed / 125);} + if ($speed < 125000000) + {return sprintf("%3d.1 Mbps", $speed / 125000);} + // else + return sprintf("%3d.1 Gbps", $speed / 125000000); + } + function add_summary_declaration(&$lcd_cmds, $name) { $lcdpanel_height = get_lcdpanel_height(); if ($lcdpanel_height >= "4") @@ -466,7 +502,10 @@ function add_summary_values(&$lcd_cmds, $name, $lcd_summary_data, $lcdpanel_width) { if ($lcd_summary_data != "") { - $lcd_cmds[] = "widget_set $name title_summary 1 3 $lcdpanel_width 3 h 2 \"CPU MEM STATES\""; + if ($lcdpanel_width > "16") + {$lcd_cmds[] = "widget_set $name title_summary 1 3 $lcdpanel_width 3 h 2 \"CPU MEM STATES FREQ\"";} + else + {$lcd_cmds[] = "widget_set $name title_summary 1 3 $lcdpanel_width 3 h 2 \"CPU MEM STATES\"";} $lcd_cmds[] = "widget_set $name text_summary 1 4 $lcdpanel_width 4 h 2 \"{$lcd_summary_data}\""; } } @@ -597,7 +636,15 @@ $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; $lcd_cmds[] = "widget_add $name title_wdgt string"; $lcd_cmds[] = "widget_add $name text_wdgt scroller"; - break; + break; + case "scr_traffic": + $lcd_cmds[] = "screen_add $name"; + $lcd_cmds[] = "screen_set $name heartbeat off"; + $lcd_cmds[] = "screen_set $name name $name"; + $lcd_cmds[] = "screen_set $name duration $refresh_frequency"; + $lcd_cmds[] = "widget_add $name title_wdgt string"; + $lcd_cmds[] = "widget_add $name text_wdgt string"; + break; } add_summary_declaration($lcd_cmds, $name); } @@ -615,6 +662,7 @@ if(empty($g['product_name'])) { $g['product_name'] = "pfSense"; } + $refresh_frequency = get_lcdpanel_refresh_frequency(); /* keep a counter to see how many times we can loop */ $i = 1; @@ -622,7 +670,10 @@ /* prepare the summary data */ if ($lcdpanel_height >= "4") { $summary_states = split("/",get_pfstate()); - $lcd_summary_data = sprintf("%02d%% %02d%% %6d", cpu_usage(), mem_usage(), $summary_states[0]); + $lcd_summary_data = sprintf("%02d%% %02d%% %6d", cpu_usage(), mem_usage(), $summary_states[0]); + if ($lcdpanel_width > "16") { + $lcd_summary_data = $lcd_summary_data . sprintf(" %3d%%", get_cpufrequency_perc()); + } } else { $lcd_summary_data = "";} @@ -710,16 +761,27 @@ $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"+ CPU Frequency\""; $lcd_cmds[] = "widget_set $name text_wdgt 1 2 $lcdpanel_width 2 h 2 \"{$cpufreq}\""; break; + case "scr_traffic": + get_traffic_stats($in_data, $out_data); + $lcd_cmds[] = "widget_set $name title_wdgt 1 1 \"{$in_data}\""; + $lcd_cmds[] = "widget_set $name text_wdgt 1 2 \"{$out_data}\""; + break; } add_summary_values($lcd_cmds, $name, $lcd_summary_data, $lcdpanel_width); - $widget_counter++; + if ($name != "scr_traffic_interface") { + $widget_counter++; + add_summary_values($lcd_cmds, $name, $lcd_summary_data, $lcdpanel_width); + } } send_lcd_commands($lcd, $lcd_cmds); sleep($refresh_frequency * $widget_counter); $i++; } } - + /* Initialize the wan traffic counters */ + $traffic_last_ugmt = 0; + $traffic_last_ifin = 0; + $traffic_last_ifout = 0; /* Connect to the LCDd port and interface with the LCD */ $lcd = fsockopen(LCDPROC_HOST, LCDPROC_PORT, $errno, $errstr, 10); if (!$lcd) { @@ -730,4 +792,4 @@ /* loop exited? Close fd and wait for the script to kick in again */ fclose($lcd); } -?> +?> \ No newline at end of file diff --git a/config/lcdproc-dev/lcdproc_screens.xml b/config/lcdproc-dev/lcdproc_screens.xml index e0597d58..acde02ca 100644 --- a/config/lcdproc-dev/lcdproc_screens.xml +++ b/config/lcdproc-dev/lcdproc_screens.xml @@ -2,7 +2,7 @@ Services: LCDproc: Screens lcdproc_screens - 0.5.2_1-p9 + 0.5.4 pkg v. 0.3 Save /usr/local/pkg/lcdproc.inc @@ -92,7 +92,18 @@ Enable CPU Frequency scr_cpufrequency checkbox - + + + Enable Interface Traffic + scr_traffic + checkbox + + + > interface selected + scr_traffic_interface + interfaces_selection + If Interface Traffic is enabled, here you specify which interface to monitor + before_form_lcdproc_screens(&$pkg); -- cgit v1.2.3