[kismac] [binaervarianz] r122 - in KisMACng/Sources: Driver/USBIntersilJack Support

  • From: svn@xxxxxxxxxxxxxxxx
  • To: kismac@xxxxxxxxxxxxx
  • Date: Tue, 18 Apr 2006 15:10:12 +0200

Author: robin
Date: 2006-04-18 15:10:12 +0200 (Tue, 18 Apr 2006)
New Revision: 122

Modified:
   KisMACng/Sources/Driver/USBIntersilJack/USBIntersil.mm
   KisMACng/Sources/Support/GPSController.h
   KisMACng/Sources/Support/GPSController.m
Log:
* USB Prism2 driver automatically resets if errors occur (e.g. following sleep)
* attempts to reconnect to GPSd if connection terminated (e.g. idle timeout 
after 15 minutes or more asleep)



Modified: KisMACng/Sources/Driver/USBIntersilJack/USBIntersil.mm
===================================================================
--- KisMACng/Sources/Driver/USBIntersilJack/USBIntersil.mm      2006-04-18 
07:23:59 UTC (rev 121)
+++ KisMACng/Sources/Driver/USBIntersilJack/USBIntersil.mm      2006-04-18 
13:10:12 UTC (rev 122)
@@ -89,14 +89,22 @@
     if (!_devicePresent) return false;
     if (!_deviceInit) return false;
     
+       // _doCommand(wlcInit,0) seems to be the key part of _reset() to make 
the USB driver work after sleeping        
+       // how about we only call this when an error occurs
+/*    if (_doCommand(wlcInit, 0) != kIOReturnSuccess) {
+        NSLog(@"USBIntersilJack::::startCapture: _doCommand(wlcInit, 0) 
failed\n");
+        return false;
+    } */
+
     if ((!_isEnabled) && (_disable() != kIOReturnSuccess)) {
-        NSLog(@"MACJackCard::startCapture: Couldn't disable card\n");
+        NSLog(@"USBIntersilJack::::startCapture: Couldn't disable card\n");
         return false;
     }
     
     if (setChannel(channel) == false) {
-        NSLog(@"USBIntersilJack::::startCapture: setChannel(%d) failed\n",
+        NSLog(@"USBIntersilJack::::startCapture: setChannel(%d) failed - 
resetting...\n",
                  channel);
+               _reset();
         return false;
     }
 

Modified: KisMACng/Sources/Support/GPSController.h
===================================================================
--- KisMACng/Sources/Support/GPSController.h    2006-04-18 07:23:59 UTC (rev 
121)
+++ KisMACng/Sources/Support/GPSController.h    2006-04-18 13:10:12 UTC (rev 
122)
@@ -34,6 +34,7 @@
 @interface GPSController : NSObject {
     bool    _gpsThreadUp;
     bool    _gpsShallRun;
+       bool    _gpsdReconnect;
     bool    _reliable;
     bool    _tripmateMode;
     int     _traceInterval;

Modified: KisMACng/Sources/Support/GPSController.m
===================================================================
--- KisMACng/Sources/Support/GPSController.m    2006-04-18 07:23:59 UTC (rev 
121)
+++ KisMACng/Sources/Support/GPSController.m    2006-04-18 13:10:12 UTC (rev 
122)
@@ -64,6 +64,7 @@
     _gpsThreadUp    = NO;
     _gpsShallRun    = NO;
     _debugEnabled   = NO;
+       _gpsdReconnect  = YES;
     _lastAdd        = [[NSDate date] retain];
     _linesRead      = 0;
 
@@ -91,6 +92,10 @@
 
     [self stop];
     
+       sleep(1);
+       
+       _gpsdReconnect = YES;
+       
     [WaveHelper secureReplace:&_gpsDevice withObject:device];
     [WaveHelper secureRelease:&_lastUpdate];
     [WaveHelper secureRelease:&_sectorStart];
@@ -733,50 +738,52 @@
 
         sets = [NSUserDefaults standardUserDefaults];
         
-        sockd  = socket(AF_INET, SOCK_STREAM, 0);
-        if (sockd == -1) {
-            NSLog(@"Socket creation failed!");
-                       [self setStatus:NSLocalizedString(@"Could not create 
GPSd socket.", @"GPS status")];
-            goto err;
-        }
-        
-        hostname = [[sets objectForKey:@"GPSDaemonHost"] cString];
-        
-        if (inet_addr(hostname) != INADDR_NONE) {
-            ip = inet_addr(hostname);
-        } else {
-            hp = gethostbyname(hostname);
-            if (hp == NULL) {
-                NSLog(@"Could not resolve %s", hostname);
-                               [self setStatus:NSLocalizedString(@"Could not 
resolve GPSd server.", @"GPS status")];
-                goto err;
-            }
-            ip = *(int *)hp->h_addr_list[0];
-        }
-        
-        /* server address */
-        serv_name.sin_addr.s_addr = ip;
-        serv_name.sin_family = AF_INET;
-        serv_name.sin_port = htons([sets integerForKey:@"GPSDaemonPort"]);
+               while(_gpsdReconnect) {
+                       sockd  = socket(AF_INET, SOCK_STREAM, 0);
+                       if (sockd == -1) {
+                               NSLog(@"Socket creation failed!");
+                               [self setStatus:NSLocalizedString(@"Could not 
create GPSd socket.", @"GPS status")];
+                               goto err;
+                       }
+                       
+                       hostname = [[sets objectForKey:@"GPSDaemonHost"] 
cString];
+                       
+                       if (inet_addr(hostname) != INADDR_NONE) {
+                               ip = inet_addr(hostname);
+                       } else {
+                               hp = gethostbyname(hostname);
+                               if (hp == NULL) {
+                                       NSLog(@"Could not resolve %s", 
hostname);
+                                       [self 
setStatus:NSLocalizedString(@"Could not resolve GPSd server.", @"GPS status")];
+                                       goto err;
+                               }
+                               ip = *(int *)hp->h_addr_list[0];
+                       }
+                       
+                       /* server address */
+                       serv_name.sin_addr.s_addr = ip;
+                       serv_name.sin_family = AF_INET;
+                       serv_name.sin_port = htons([sets 
integerForKey:@"GPSDaemonPort"]);
 
-        NSLog(@"Connecting to gpsd (%s)",inet_ntoa(serv_name.sin_addr));
+                       NSLog(@"Connecting to gpsd 
(%s)",inet_ntoa(serv_name.sin_addr));
 
-        /* connect to the server */
-        status = connect(sockd, (struct sockaddr*)&serv_name, 
sizeof(serv_name));
-        
-        if (status == -1) {
-            NSLog(@"Could not connect to %s port %d", hostname, [sets 
integerForKey:@"GPSDaemonPort"]);
-                       [self setStatus:NSLocalizedString(@"Could not connect 
to GPSd.", @"GPS status")];
-                       goto err;
-        }
+                       /* connect to the server */
+                       status = connect(sockd, (struct sockaddr*)&serv_name, 
sizeof(serv_name));
+                       
+                       if (status == -1) {
+                               NSLog(@"Could not connect to %s port %d", 
hostname, [sets integerForKey:@"GPSDaemonPort"]);
+                               [self setStatus:NSLocalizedString(@"Could not 
connect to GPSd.", @"GPS status")];
+                               goto err;
+                       }
 
-        NSLog(@"GPS started successfully in GPSd mode.\n");
-        [self setStatus:NSLocalizedString(@"GPS started in GPSd mode.", @"GPS 
status")];
+                       NSLog(@"GPS started successfully in GPSd mode.\n");
+                       [self setStatus:NSLocalizedString(@"GPS started in GPSd 
mode.", @"GPS status")];
 
-        [self continousParseGPSd: sockd];
-        close(sockd);
+                       [self continousParseGPSd: sockd];
+                       close(sockd);
 
-        [self setStatus:NSLocalizedString(@"GPSd connection terminated.", 
@"GPS status")];
+                       [self setStatus:NSLocalizedString(@"GPSd connection 
terminated - reconnecting...", @"GPS status")];
+               }
     err:
         [_gpsLock unlock];
         _gpsThreadUp = NO;
@@ -799,6 +806,7 @@
 - (void)stop {
     int fd;
     _gpsShallRun=NO;
+       _gpsdReconnect=NO;
 
     [self setStatus:NSLocalizedString(@"Trying to terminate GPS subsystem.", 
@"GPS status")];
     


Other related posts:

  • » [kismac] [binaervarianz] r122 - in KisMACng/Sources: Driver/USBIntersilJack Support