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
27 extern WINDOW *main_sub, *win_for_help, *main_win;
29 enum { dBm, percentage, rawval } sts_viewtype = dBm;
32 scroll_rows(struct MacListStat *first, int begin, int end, int row,
36 struct MacListStat *curr = first;
44 while (end-- > begin) {
48 (sts_viewtype == dBm) ?
49 "%4u %02X%02X%02X%02X%02X%02X %3u%5u %3udBm"
51 (sts_viewtype == percentage) ?
52 "%4u %02X%02X%02X%02X%02X%02X %3u%5u %3u%%"
54 "%4u %02X%02X%02X%02X%02X%02X %3u%5u %3u",
55 begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
56 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
57 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
62 } else if (stat == 2) {
63 /* ATMEL410_SBRIDGES (firmware 1.4k.1) view */
65 (sts_viewtype == dBm) ?
66 "%2u %02X%02X%02X%02X%02X%02X %3d%% %4ddBm %3u %2u %s"
68 (sts_viewtype == percentage) ?
69 "%2u %02X%02X%02X%02X%02X%02X %3d%% %3u%% %3u %2u %s"
71 "%2u %02X%02X%02X%02X%02X%02X %3d%% %3u %3u %2u %s",
73 curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
74 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
75 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
77 conv_rssi(curr->rssi),
82 } else if (stat == 3) {
83 /* ATMEL12350_VERNET view */
85 (sts_viewtype == dBm) ?
86 "%2u %02X%02X%02X%02X%02X%02X %02X%02X%02X%02X%02X%02X "
89 (sts_viewtype == percentage) ?
90 "%2u %02X%02X%02X%02X%02X%02X %02X%02X%02X%02X%02X%02X "
93 "%2u %02X%02X%02X%02X%02X%02X %02X%02X%02X%02X%02X%02X "
96 curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
97 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
98 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF,
99 curr->ParentMacAddress[0] & 0xFF,
100 curr->ParentMacAddress[1] & 0xFF,
101 curr->ParentMacAddress[2] & 0xFF,
102 curr->ParentMacAddress[3] & 0xFF,
103 curr->ParentMacAddress[4] & 0xFF,
104 curr->ParentMacAddress[5] & 0xFF,
105 conv_rssi(curr->rssi),
111 /* generic ATMEL view */
112 sprintf(message, "%2u %02X%02X%02X%02X%02X%02X",
113 begin + i, curr->addr[0] & 0xFF, curr->addr[1] & 0xFF,
114 curr->addr[2] & 0xFF, curr->addr[3] & 0xFF,
115 curr->addr[4] & 0xFF, curr->addr[5] & 0xFF
118 mvwaddstr(main_sub, row + i, 0, message);
125 void print_help(char *mess)
127 unsigned short int j, len = (COLS - strlen(mess))/2;
129 werase(win_for_help);
131 for (j = 0; j <= len; j++) {
132 mvwaddch(win_for_help, 0, j, ' ');
133 mvwaddch(win_for_help, 0, COLS - j - 1, ' ');
136 mvwaddstr(win_for_help, 0, len, mess);
137 wrefresh(win_for_help);
140 void print_helperr(char *mess)
142 wattrset(win_for_help, COLOR_PAIR(4) | A_BOLD);
144 wattrset(win_for_help, COLOR_PAIR(1));
147 void print_bold(WINDOW *wptr, char *mess)
149 wattrset(wptr, A_BOLD);
151 wattrset(wptr, A_NORMAL);
155 void print_menusel(int y, int x, char *mess1, char *mess2)
157 mvwaddstr(main_sub, y, x, mess1);
158 print_bold(main_sub, mess2);
161 void print_bottom(char *mess)
165 extern short ap_type, ap_vendorext;
166 extern char *ap_types[], *ap_vendorexts[][3];
168 sprintf(message, _("Current AP: %s Type: %s Ext: %s"),
169 mess, ap_types[ap_type], ap_vendorexts[ap_type][ap_vendorext]);
171 for (i = 0; i < COLS - MCOLS - 1; i++)
172 mvwaddch(main_win, LINES - 3, i, ACS_BSBS);
174 wmove(main_win, LINES - 3, COLS - MCOLS - strlen(message) - 1);
175 print_bold(main_win, message);
178 void print_top(char *title_left, char *title_right)
182 wmove(main_win, 0, 0);
183 while (i++ < COLS - MCOLS - 1)
184 waddch(main_win, ACS_BSBS);
186 wattrset(main_win, A_BOLD);
188 mvwaddstr(main_win, 0, 2, title_left);
191 mvwaddstr(main_win, 0, COLS - MCOLS - strlen(title_right) - 2,
194 wattrset(main_win, A_NORMAL);
198 void print_top_rssi(char *message_r)
202 sprintf(message_l, "%s", VIEW);
203 switch (sts_viewtype) {
205 strcat(message_l, "RSSI in dBm");
208 strcat(message_l, "RSSI in percentage");
211 strcat(message_l, "RSSI in raw values");
213 print_top(message_l, message_r);
216 void clear_main(int m)
218 clear_main_new(m, LINES - 4);
221 void clear_main_new(int m, int n)
224 wmove(main_sub, m, 0);
225 for (i = m; i < n; i++)
226 for (j = 0; j < COLS - MCOLS - 1; j++)
227 waddch(main_sub, ' ');
231 int conv_rssi(int raw_rssi)
233 switch (sts_viewtype) {
235 return (-96 + raw_rssi);
237 return ((int)((minimum (raw_rssi, 40)) * (float)2.5));
241 /* Should never happen */