2 * scr.c from Access Point SNMP Utils for Linux
3 * program output & screen related functions
5 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License Version 2 from
9 * June 1991 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "ap-curses.h"
28 extern WINDOW *main_sub, *win_for_help, *main_win;
30 enum { dBm, percentage, rawval } sts_viewtype = dBm;
33 scroll_rows(struct MacListStat *first, int begin, int end, int row,
37 struct MacListStat *curr = first;
45 while (end-- > begin) {
49 (sts_viewtype == dBm) ?
50 "%4u %02X%02X%02X%02X%02X%02X %3u%5u %3udBm"
52 (sts_viewtype == percentage) ?
53 "%4u %02X%02X%02X%02X%02X%02X %3u%5u %3u%%"
55 "%4u %02X%02X%02X%02X%02X%02X %3u%5u %3u",
56 begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
57 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
58 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
63 } else if (stat == 2) {
64 /* ATMEL410_SBRIDGES (firmware 1.4k.1) view */
66 (sts_viewtype == dBm) ?
67 "%2u %02X%02X%02X%02X%02X%02X %3d%% %4ddBm %3u %2u %s"
69 (sts_viewtype == percentage) ?
70 "%2u %02X%02X%02X%02X%02X%02X %3d%% %3u%% %3u %2u %s"
72 "%2u %02X%02X%02X%02X%02X%02X %3d%% %3u %3u %2u %s",
74 curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
75 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
76 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
78 conv_rssi(curr->rssi),
83 } else if (stat == 3) {
84 /* ATMEL12350_VERNET view */
86 (sts_viewtype == dBm) ?
87 "%2u %02X%02X%02X%02X%02X%02X %02X%02X%02X%02X%02X%02X "
90 (sts_viewtype == percentage) ?
91 "%2u %02X%02X%02X%02X%02X%02X %02X%02X%02X%02X%02X%02X "
94 "%2u %02X%02X%02X%02X%02X%02X %02X%02X%02X%02X%02X%02X "
97 curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
98 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
99 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
100 curr->ParentMacAddress[0] & 0xFF,
101 curr->ParentMacAddress[1] & 0xFF,
102 curr->ParentMacAddress[2] & 0xFF,
103 curr->ParentMacAddress[3] & 0xFF,
104 curr->ParentMacAddress[4] & 0xFF,
105 curr->ParentMacAddress[5] & 0xFF,
106 conv_rssi(curr->rssi),
112 /* generic ATMEL view */
113 sprintf(message, "%2u %02X%02X%02X%02X%02X%02X",
114 begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
115 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
116 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF
119 mvwaddstr(main_sub, row + i, 0, message);
126 void print_help(char *mess)
128 unsigned short int j, len = (COLS - strlen(mess))/2;
130 werase(win_for_help);
132 for (j = 0; j <= len; j++) {
133 mvwaddch(win_for_help, 0, j, ' ');
134 mvwaddch(win_for_help, 0, COLS - j - 1, ' ');
137 mvwaddstr(win_for_help, 0, len, mess);
138 wrefresh(win_for_help);
141 void print_helperr(char *mess)
143 wattrset(win_for_help, COLOR_PAIR(4) | A_BOLD);
145 wattrset(win_for_help, COLOR_PAIR(1));
148 void print_title(char *mess)
152 for (i = 0; i < COLS - MCOLS - 1; i++)
153 mvwaddch(main_win, 0, i, ACS_BSBS);
154 wattrset(main_win, A_BOLD);
155 mvwaddstr(main_win, 0, COLS - MCOLS - strlen(mess) - 2, mess);
156 wattrset(main_win, A_NORMAL);
160 void print_viewtype(char *mess)
163 * note: when used to update with different strlen(mess) than previous one,
164 * call print_title() before this one so that the top line gets updated !
166 wattrset(main_win, A_BOLD);
167 mvwaddstr(main_win, 0, 1, "View: ");
168 waddstr(main_win, mess);
169 wattrset(main_win, A_NORMAL);
173 void print_viewtype_rssi()
175 switch (sts_viewtype) {
177 print_viewtype("RSSI in dBm");
180 print_viewtype("RSSI in percentage");
183 print_viewtype("RSSI in raw values");
187 void print_menusel(int y, int x, char *mess1, char *mess2)
189 mvwaddstr(main_sub, y, x, mess1);
190 wattrset(main_sub, A_BOLD);
191 waddstr(main_sub, mess2);
192 wattrset(main_sub, A_NORMAL);
196 void print_bottom(char *mess)
200 extern short ap_type;
201 extern char *ap_types[];
203 sprintf(message, _("Current AP: %s Type: %s"), mess, ap_types[ap_type]);
205 for (i = 0; i < COLS - MCOLS - 1; i++)
206 mvwaddch(main_win, LINES - 3, i, ACS_BSBS);
207 wattrset(main_win, A_BOLD);
208 mvwaddstr(main_win, LINES - 3, COLS - MCOLS - strlen(message) - 1,
210 wattrset(main_win, A_NORMAL);
215 void clear_main(int m)
217 clear_main_new(m, LINES - 4);
220 void clear_main_new(int m, int n)
223 wmove(main_sub, m, 0);
224 for (i = m; i < n; i++)
225 for (j = 0; j < COLS - MCOLS - 1; j++)
226 waddch(main_sub, ' ');
230 int conv_rssi(int raw_rssi)
232 switch (sts_viewtype) {
234 return (-96 + raw_rssi);
236 return ((int)((minimum (raw_rssi, 40)) * (float)2.5));
240 /* Should never happen */