]> git.sur5r.net Git - gsconf/blob - shell_port.c
added port diag command
[gsconf] / shell_port.c
1 #include "shell.h"
2
3 void shell_port(char ** argv, int elem) {
4         
5         int n, i;
6         
7         if (elem == 1) {
8         
9                 return;
10         }
11         if (strncmp(argv[1], "show", 4) == 0) {
12                 printf("Port\tSpeed\t\tBytes In\t\tBytes Out\n");
13                 for (n = 0; n< 5; n++) {
14                         printf("%i\t%s\t% 8lu\t\t% 8lu\n", n, 
15                         (settings.portStatistics[n].state == 0x05 ? "1000 Mbit/s" : (settings.portStatistics[n].state == 0x04 ? "100 Mbit/s" : (settings.portStatistics[n].state == 0x03 ? "10 Mbit/s":  (settings.portStatistics[n].state == 0x00 ? "No Cable": "???")))),
16                         settings.portStatistics[n].bytesIn,
17                         settings.portStatistics[n].bytesOut
18                         );
19                 }
20         } else if (strncmp(argv[1], "diag", 4) == 0) {
21                 if (elem != 3) {
22                         printf("Port needed\n");
23                         return;
24                 }
25                 
26                 n = atoi(argv[2]);
27                 
28                 if (n < 1 | n > 5) {
29                         printf("Invalid Port\n");
30                         return;
31                 }
32                 
33                 password();
34                 i = gs105e_cableDiagnostics((char) n);
35                 
36                 printError(i);
37                 if (i != 0)
38                         return;
39                 if (settings.portStatistics[n].cableError) {
40                         printf("\033[91mError detected: %s in %i m\033[0m\n", 
41                         (settings.portStatistics[n].cableError == 0x03 ? "short circuit" : (settings.portStatistics[n].cableError == 0x02 ? "Only one pair Connected!": "damaged")),
42                         settings.portStatistics[n].errorDist
43                         );
44                         
45                 }else{
46                         if (settings.portStatistics[n].errorDist == 0 )
47                                 printf("\033[92mSeems no Cable is connected!?\033[0m\n");
48                         else
49                                 printf("\033[92mCable is fine!\033[0m\n", settings.portStatistics[n].errorDist);
50                 }
51         }
52 }