Skip to content

Commit 07735da

Browse files
committed
Update - use dbm
1 parent 55f5c40 commit 07735da

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

wifirx.c

+27-12
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ unsigned long HSVtoHEX( float hue, float sat, float value )
9797
return (ob<<16) | (og<<8) | ora;
9898
}
9999

100-
int GetQuality( const char * interface )
100+
int first = 0;
101+
102+
int GetQuality( const char * interface, int * noise )
101103
{
102104
int sockfd;
103105
struct iw_statistics stats;
@@ -115,25 +117,31 @@ int GetQuality( const char * interface )
115117

116118
/* Any old socket will do, and a datagram socket is pretty cheap */
117119
if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
118-
perror("Could not create simple datagram socket");
120+
if( first ) perror("Could not create simple datagram socket");
121+
first = 0;
119122
//exit(EXIT_FAILURE);
120123
return -1;
121124
}
122125

123126
/* Perform the ioctl */
124127
if(ioctl(sockfd, SIOCGIWSTATS, &req) == -1) {
125-
perror("Error performing SIOCGIWSTATS");
128+
if( first ) perror("Error performing SIOCGIWSTATS");
129+
first = 0;
126130
close(sockfd);
127131
return -1;
128132
}
129133

130134
close(sockfd);
131135

132-
return stats.qual.level;
136+
first = 0;
137+
if( noise ) *noise = -256+stats.qual.noise;
138+
139+
return -256+stats.qual.level;
133140
}
134141

135-
int min = 5800;
136-
int max = 6600;
142+
#define TITER 30
143+
double min = -90;
144+
double max = -50;
137145

138146
int get_color( int nr )
139147
{
@@ -146,7 +154,7 @@ int get_color( int nr )
146154
}
147155

148156
#define POWERHISTORY 1024
149-
int powers[POWERHISTORY];
157+
double powers[POWERHISTORY];
150158
short screenx, screeny;
151159

152160
int main( int argc, char ** argv )
@@ -184,21 +192,28 @@ int main( int argc, char ** argv )
184192
max = atoi( argv[4] );
185193
}
186194

187-
printf( "MIN: %d / MAX: %d\n", min, max );
195+
printf( "MIN: %f / MAX: %f\n", min, max );
188196

189197
CNFGBGColor = 0x800000;
190198
CNFGDialogColor = 0x444444;
191199
CNFGSetup( "WifiRX", 640, 480 );
192200

193201
while(1)
194202
{
195-
int i, j = 0;
203+
int i;
204+
double j = 0;
205+
int noise;
206+
double noisetot = 0;
207+
first = 1;
196208
for( i = 0; i < 30; i++ )
197209
{
198-
j += GetQuality( argv[1] );
210+
j += GetQuality( argv[1], &noise );
211+
noisetot += noise;
199212
usleep(2000);
200213
}
201-
printf( "%d\n", j );
214+
j/=TITER;
215+
noise/=TITER;
216+
printf( "%4.1f %4.1f\n", j, noisetot );
202217
powers[pl] = j;
203218
pl++;
204219
if( pl >= POWERHISTORY ) pl = 0;
@@ -229,7 +244,7 @@ int main( int argc, char ** argv )
229244
while( k < 0 )
230245
k += POWERHISTORY;
231246
CNFGColor( get_color( powers[k] ) );
232-
CNFGTackSegment( i, screeny, i, screeny - powers[k]/30 );
247+
CNFGTackSegment( i, 0, i, -(powers[k]+20)*(screeny/(100.0-20)) );
233248
}
234249
CNFGColor( 0xffffff );
235250

0 commit comments

Comments
 (0)