more advanced Nginx settings in GUI
[tomato.git] / release / src-rt-6.x.4708 / router / rc / blink_5g.c
blob67ca476c19d1d9e43a7d82f7cb503ab8b302cafb
1 #include "rc.h"
2 #include <shared.h>
4 static char *interface = NULL;
5 static int rand_seed_by_time(void)
7 time_t atime;
9 time(&atime);
10 srand((unsigned long)atime);
12 return rand();
15 static unsigned long get_5g_count()
17 FILE *f;
18 char buf[256];
19 char *ifname, *p;
20 unsigned long counter1, counter2;
22 if((f = fopen("/proc/net/dev", "r"))==NULL) return -1;
24 fgets(buf, sizeof(buf), f);
25 fgets(buf, sizeof(buf), f);
27 counter1=counter2=0;
29 while (fgets(buf, sizeof(buf), f)) {
30 if((p=strchr(buf, ':'))==NULL) continue;
31 *p = 0;
32 if((ifname = strrchr(buf, ' '))==NULL) ifname = buf;
33 else ++ifname;
35 if(strcmp(ifname, interface)) continue;
37 if(sscanf(p+1, "%lu%*u%*u%*u%*u%*u%*u%*u%*u%lu", &counter1, &counter2)!=2) continue;
40 fclose(f);
42 return counter1;
45 int blink_5g_main(int argc, char *argv[])
47 static unsigned int blink_5g = 0;
48 static unsigned int data_5g = 0;
49 unsigned long count_5g;
50 int i;
51 static int j;
52 static int status = -1;
53 static int status_old;
54 if (fork() != 0) return 0;
55 setsid();
56 signal(SIGCHLD, chld_reap);
57 #define INTERFACE_MAXLEN 10
58 interface = calloc(INTERFACE_MAXLEN,1);
59 char *tmp_interface = nvram_get("blink_5g_interface");
60 if(tmp_interface)
61 strncpy(interface,tmp_interface, INTERFACE_MAXLEN);
62 // check data per 10 count
63 while(1){
64 if(!tmp_interface){
65 sleep(5);
66 tmp_interface = nvram_get("blink_5g_interface");
67 if(tmp_interface)
68 strncpy(interface,tmp_interface, INTERFACE_MAXLEN);
69 continue;
71 count_5g = get_5g_count();
72 if(count_5g && data_5g!=count_5g) {
73 blink_5g = 1;
74 data_5g = count_5g;
76 else
77 blink_5g = 0;
78 led(LED_5G, LED_ON);
80 if(blink_5g) {
81 j = rand_seed_by_time() % 3;
82 for(i=0;i<10;i++) {
83 usleep(33*1000);
84 status_old = status;
85 if (((i%2)==0) && (i > (3 + 2*j)))
86 status = 0;
87 else
88 status = 1;
90 if (status != status_old)
92 if (status)
93 led(LED_5G, LED_ON);
94 else
95 led(LED_5G, LED_OFF);
98 led(LED_5G, LED_ON);
100 else
101 usleep(50000);