1
0
Fork 0

Initial status bandwidth updater

master
Matthieu Lalonde 14 years ago
parent 051581253e
commit 80656b2fb1

@ -17,7 +17,6 @@
F2511F5C13914A120053990C /* MenuIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = F2511F5B13914A120053990C /* MenuIcon.png */; };
F2511FFB1391543E0053990C /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F2511FFA1391543E0053990C /* WebKit.framework */; };
F25120A213918CD10053990C /* AppIcon.icns in Resources */ = {isa = PBXBuildFile; fileRef = F25120A113918CD10053990C /* AppIcon.icns */; };
F2F4DA7E139831140060CFE9 /* WRTRequestParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F2F4DA7D139831140060CFE9 /* WRTRequestParser.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -39,8 +38,6 @@
F2511F5B13914A120053990C /* MenuIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = MenuIcon.png; sourceTree = "<group>"; };
F2511FFA1391543E0053990C /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
F25120A113918CD10053990C /* AppIcon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon.icns; sourceTree = "<group>"; };
F2F4DA7C139831140060CFE9 /* WRTRequestParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WRTRequestParser.h; sourceTree = "<group>"; };
F2F4DA7D139831140060CFE9 /* WRTRequestParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WRTRequestParser.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -63,8 +60,6 @@
256AC3D90F4B6AC300CF3369 /* DDWRT_MonitorAppDelegate.m */,
96DEDE28139486BB00EF8526 /* WRTStatusClient.h */,
96DEDE29139486BB00EF8526 /* WRTStatusClient.m */,
F2F4DA7C139831140060CFE9 /* WRTRequestParser.h */,
F2F4DA7D139831140060CFE9 /* WRTRequestParser.m */,
);
name = Classes;
sourceTree = "<group>";
@ -208,7 +203,6 @@
8D11072D0486CEB800E47090 /* main.m in Sources */,
256AC3DA0F4B6AC300CF3369 /* DDWRT_MonitorAppDelegate.m in Sources */,
96DEDE2A139486BB00EF8526 /* WRTStatusClient.m in Sources */,
F2F4DA7E139831140060CFE9 /* WRTRequestParser.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -74,6 +74,7 @@
WRTStatusClient *wrt_client;
NSTimeInterval _lastDateThroughput;
unsigned long long _lastInThroughput;
unsigned long long _lastOutThroughput;

@ -37,7 +37,7 @@
[wrt_client getConnectionStatus];
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
_readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"] target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
_readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"]+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
[_readTimer fire];
@ -334,6 +334,12 @@
[self showMenubarIcon:false];
}
if (_wrtReachable == true) {
[wrt_client getStatusUpdate:[NSString stringWithFormat:@"fetchif.cgi?%@", [wrt_client getWanPort]] delegate:self callback:@selector(throughputCallback:)];
//[wrt_client getStatusUpdate:@"Status_Router.live.asp" delegate:self callback:@selector(doUpdateStatus:)];
//[wrt_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(wanRequestCallback:)];
}
//WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"];
@ -341,32 +347,51 @@
- (void) throughputCallback:(NSData *)data
{
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
/*NSDate *start = [NSDate date];
NSTimeInterval timeInterval = [start timeIntervalSinceNow];
NSLog(@"%f", timeInterval);
NSString *key = [NSString stringWithFormat:@"%@:", [wrt_client getWanPort]];
stringData = [stringData substringFromIndex:([stringData rangeOfString:key].location + [key length])];
NSArray *parts = [stringData componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSArray *filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
stringData = [filteredArray componentsJoinedByString:@" "];
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
stringData = [stringData substringFromIndex:([stringData rangeOfString:@":"].location + 1)];
NSArray *listItems = [stringData componentsSeparatedByString:@" "];
NSLog(@"%@", [listItems objectAtIndex:0]);
unsigned long long ifIn = [NSNumber numberWithString:[listItems objectAtIndex:0]];
unsigned long long ifOut = [NSNumber numberWithString:[listItems objectAtIndex:8]];
unsigned long long ifIn = strtoull([[listItems objectAtIndex:0] UTF8String], NULL, 0);
unsigned long long ifOut = strtoull([[listItems objectAtIndex:8] UTF8String], NULL, 0);
if (_lastInThroughput != 0) {
unsigned long long diffIn = ifIn - _lastInThroughput;
unsigned long long diffOut = ifOut - _lastOutThroughput;
double speedIn = diffIn / ([NSDate timeIntervalSinceReferenceDate] - _lastDateThroughput);
double speedOut = diffOut / ([NSDate timeIntervalSinceReferenceDate] - _lastDateThroughput);
speedIn = round(2.2f * speedIn) / 2.2f;
speedOut = round(2.2f * speedOut) / 2.2f;
[self setMenubarText:[NSString stringWithFormat:@"%@s\n%@s", [self stringFromFileSize:speedIn], [self stringFromFileSize:speedOut]]];
}
_lastDateThroughput = [NSDate timeIntervalSinceReferenceDate];
_lastInThroughput = ifIn;
_lastOutThroughput = ifOut;
NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];*/
NSLog(@"In %llu Out %llu", ifIn, ifOut);
}
-(void)doUpdateStatus:(NSData *)data
{
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
/*
NSString *ipconn = [self getKey:stringData key:@"ip_conntrack"];
NSString *wanip = [self getKey:stringData key:@"ipinfo"];
wanip = [wanip substringFromIndex:([wanip rangeOfString:@" "].location+1)];
NSString *ipconn = [wrt_client getKey:stringData key:@"ip_conntrack"];
NSString *wanip = [wrt_client getKey:stringData key:@"ipinfo"];
NSRange startRange = [wanip rangeOfString:@" "];
wanip = [wanip substringFromIndex:(startRange.location+1)];
NSString *uptime = [self getKey:stringData key:@"uptime"];
NSString *uptime = [wrt_client getKey:stringData key:@"uptime"];
NSString *loadSplit = @", load average: ";
NSString *load = [uptime substringFromIndex:[uptime rangeOfString:loadSplit].location+[loadSplit length]];
uptime = [uptime substringToIndex:[uptime rangeOfString:@", load"].location]; // Cut the load
@ -377,7 +402,7 @@
[menuUptime setTitle:uptime];
[menuLoad setTitle:load];
[menuLoad setHidden:false];
[menuConnections setTitle:[NSString stringWithFormat:@"Connections: %@", ipconn]];*/
[menuConnections setTitle:[NSString stringWithFormat:@"Connections: %@", ipconn]];
}
- (void) refreshMenu:(id)sender
@ -396,20 +421,14 @@
//WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"];
[wrt_client getStatusUpdate:@"Status_Bandwidth.asp" delegate:self callback:@selector(wanRequestCallback:)];
}
- (void) wanRequestCallback:(NSData *)data
{
NSLog(@"Received callback for request");
NSLog(@"Length: %lu", [data length]);
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"%@", stringData);
/*
NSString *wanStatus = [self getKey:stringData key:@"wan_status"];
NSString *wanName = [self getKey:stringData key:@"wan_shortproto"];
NSString *wanStatus = [wrt_client getKey:stringData key:@"wan_status"];
NSString *wanName = [wrt_client getKey:stringData key:@"wan_shortproto"];
if ([wanName isEqualToString:@"pppoe"] == true) {
wanName = @"PPPoE";
} else if ([wanName isEqualToString:@"static"] == true) {
@ -421,11 +440,13 @@
wanStatus = [wanStatus substringToIndex:[wanStatus rangeOfString:@"&"].location];
[menuWanStatus setTitle:[NSString stringWithFormat:@"%@ %@", wanName, wanStatus]];
/*
if ([_appMenu image] != nil) {
[self showMenubarIcon:[wanStatus isEqualToString:@"Connected"]];
}
*/
NSString *wanUptime = [self getKey:stringData key:@"wan_uptime"];
NSString *wanUptime = [wrt_client getKey:stringData key:@"wan_uptime"];
if ([wanStatus isEqualToString:@"Connected"] == true) {
[menuWanUptime setTitle:wanUptime];
[menuWanUptime setHidden:false];
@ -442,17 +463,17 @@
}
NSString *trafficIn = [self getKey:stringData key:@"ttraff_in"];
NSString *trafficOut = [self getKey:stringData key:@"ttraff_out"];
NSString *trafficIn = [wrt_client getKey:stringData key:@"ttraff_in"];
NSString *trafficOut = [wrt_client getKey:stringData key:@"ttraff_out"];
trafficIn = [self stringFromFileSize:([trafficIn longLongValue] * 1024 * 1024)];
trafficOut = [self stringFromFileSize:([trafficOut longLongValue] * 1024 * 1024)];
[menuWanTrafficIn setTitle:[NSString stringWithFormat:@"In: %@", trafficIn]];
[menuWanTrafficOut setTitle:[NSString stringWithFormat:@"Out: %@", trafficOut]];
NSString *wanDNS0 = [self getKey:stringData key:@"wan_dns0"];
NSString *wanDNS1 = [self getKey:stringData key:@"wan_dns1"];
NSString *wanDNS2 = [self getKey:stringData key:@"wan_dns2"];
NSString *wanDNS0 = [wrt_client getKey:stringData key:@"wan_dns0"];
NSString *wanDNS1 = [wrt_client getKey:stringData key:@"wan_dns1"];
NSString *wanDNS2 = [wrt_client getKey:stringData key:@"wan_dns2"];
if ([wanDNS0 length] > 0) {
[menuWanDNS setEnabled:true];
@ -471,7 +492,7 @@
[menuWanDNSItem2 setTitle: wanDNS2];
[menuWanDNSItem2 setHidden:false];
}
*/
[stringData release];
}

@ -133,8 +133,10 @@
returnData = [returnData substringToIndex:[returnData rangeOfString:@"}"].location];
}
if (returnData) {
returnData = [returnData stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
}
//[keyString release];

Loading…
Cancel
Save