Skip to content

Commit 6c158ec

Browse files
authored
Merge pull request #3 from hackrid/master
Adding RX and TX graphs to the plot
2 parents 07735da + c38046c commit 6c158ec

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ all : wifirx
22

33
LDFLAGS:=-lX11 -lm -lpthread -lXinerama -lXext
44

5+
6+
%.o: %.c
7+
gcc -c -o $@ $< -g3 -O0
8+
59
wifirx : wifirx.o XDriver.o DrawFunctions.o
610
gcc -o $@ $^ $(LDFLAGS)
711

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# wifirxpower
22
Linux-based WiFi RX Power Grapher
3+
4+
Screenshot:
5+
![alt text][logo]
6+
7+
[logo]: https://github.com/hackrid/wifirxpower/blob/master/wifirx_tx_rx.png "wifirxpower"

wifirx.c

+62-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,43 @@ unsigned long HSVtoHEX( float hue, float sat, float value )
9999

100100
int first = 0;
101101

102+
#define TX_BITRATE_LINE 14
103+
#define RX_BITRATE_LINE 15
104+
#define MBIT_OFFSET 12
105+
106+
void GetBitRates(const char * command, int *tx_bitrate, int *rx_bitrate)
107+
{
108+
FILE *fp;
109+
char line[1035];
110+
int i = 0;
111+
112+
/* Open the command for reading. */
113+
fp = popen(command, "r");
114+
if (fp == NULL) {
115+
printf("Failed to run command\n");
116+
exit(1);
117+
}
118+
119+
/* Read the output a line at a time*/
120+
while (fgets(line, sizeof(line) - 1, fp) != NULL)
121+
{
122+
if ((i == TX_BITRATE_LINE))
123+
{
124+
//printf("%s", line);
125+
*tx_bitrate = strtol(line+MBIT_OFFSET,0,10);
126+
}
127+
128+
if (i == RX_BITRATE_LINE)
129+
{
130+
//printf("%s", line);
131+
*rx_bitrate = strtol(line+MBIT_OFFSET,0,10);
132+
}
133+
i++;
134+
}
135+
136+
pclose(fp);
137+
}
138+
102139
int GetQuality( const char * interface, int * noise )
103140
{
104141
int sockfd;
@@ -155,7 +192,11 @@ int get_color( int nr )
155192

156193
#define POWERHISTORY 1024
157194
double powers[POWERHISTORY];
195+
double tx_rates[POWERHISTORY];
196+
double rx_rates[POWERHISTORY];
197+
158198
short screenx, screeny;
199+
unsigned char iw_command_buff[100];
159200

160201
int main( int argc, char ** argv )
161202
{
@@ -194,6 +235,8 @@ int main( int argc, char ** argv )
194235

195236
printf( "MIN: %f / MAX: %f\n", min, max );
196237

238+
sprintf(iw_command_buff,"iw dev %s station dump", argv[1]);
239+
197240
CNFGBGColor = 0x800000;
198241
CNFGDialogColor = 0x444444;
199242
CNFGSetup( "WifiRX", 640, 480 );
@@ -205,6 +248,9 @@ int main( int argc, char ** argv )
205248
int noise;
206249
double noisetot = 0;
207250
first = 1;
251+
int tx_bitrate;
252+
int rx_bitrate;
253+
208254
for( i = 0; i < 30; i++ )
209255
{
210256
j += GetQuality( argv[1], &noise );
@@ -213,8 +259,14 @@ int main( int argc, char ** argv )
213259
}
214260
j/=TITER;
215261
noise/=TITER;
216-
printf( "%4.1f %4.1f\n", j, noisetot );
262+
263+
GetBitRates(iw_command_buff, &tx_bitrate, &rx_bitrate);
264+
265+
printf( "Sig: %4.1f dBm Noise: %4.1f \nTX: %d MBit/s (red) RX: %d MBit/s (green)\n", j, noisetot, tx_bitrate, rx_bitrate);
266+
217267
powers[pl] = j;
268+
tx_rates[pl] = tx_bitrate;
269+
rx_rates[pl] = rx_bitrate;
218270
pl++;
219271
if( pl >= POWERHISTORY ) pl = 0;
220272

@@ -245,6 +297,15 @@ int main( int argc, char ** argv )
245297
k += POWERHISTORY;
246298
CNFGColor( get_color( powers[k] ) );
247299
CNFGTackSegment( i, 0, i, -(powers[k]+20)*(screeny/(100.0-20)) );
300+
301+
CNFGColor(0xFF); //red
302+
CNFGTackPixel(i, tx_rates[k]);
303+
CNFGTackPixel(i, tx_rates[k]+1);
304+
305+
CNFGColor(0xFF00); //green
306+
CNFGTackPixel(i, rx_rates[k]);
307+
CNFGTackPixel(i, rx_rates[k]+1);
308+
248309
}
249310
CNFGColor( 0xffffff );
250311

wifirx_tx_rx.png

136 KB
Loading

0 commit comments

Comments
 (0)