*** as_gps.c.orig	Mon Sep 20 12:19:19 1999
--- as_gps.c	Sun Nov  7 23:23:01 1999
***************
*** 53,60 ****
      ttyset.c_ispeed = B9600;
      ttyset.c_ospeed = B9600;
  #endif
!     ttyset.c_cflag &= ~(PARENB | CRTSCTS);
!     ttyset.c_cflag |= (CSIZE & CS8) | CREAD | CLOCAL;
  
      ttyset.c_iflag = ttyset.c_oflag = ttyset.c_lflag = (tcflag_t) 0;
  
--- 53,59 ----
      ttyset.c_ispeed = B9600;
      ttyset.c_ospeed = B9600;
  #endif
!     ttyset.c_cflag |= (CSIZE & CS8) | CREAD | CLOCAL | PARENB | CRTSCTS;
  
      ttyset.c_iflag = ttyset.c_oflag = ttyset.c_lflag = (tcflag_t) 0;
  
***************
*** 92,98 ****
        if(read(as_gps_file, &cur, 1) != 1)
          return 0;
  
!       if((last == cur) && (cur >= 0xb0) && (cur <= 0xca))
        { // start of a response
          mode = data[0] = data[1] = cur;
          offset = 2;
--- 91,97 ----
        if(read(as_gps_file, &cur, 1) != 1)
          return 0;
  
!       if((last == cur) && (cur >= 0xb0) && (cur <= 0xcb))
        { // start of a response
          mode = data[0] = data[1] = cur;
          offset = 2;
***************
*** 114,119 ****
--- 113,119 ----
    {
      printf("Checksum Error: Cmd:%02x, E:%d, E:%02x, A:%02x\n",
        data[0], checksum, checksum, data[as_gps_rcv_size[mode - 0xB0]-2]);
+     mode = 0x0;
      return 1;
    }
  
***************
*** 133,140 ****
--- 133,154 ----
        *result_data = (void *) malloc(sizeof(AS_GPS_ReceiverMode));
        as_gps_parse_receiver_mode(data, *result_data);
        break;
+ 
+     case 0xcb: /* Receive sat */
+       *result_data = (void *) malloc(sizeof(AS_GPS_ReceiveSats));
+       as_gps_parse_receive_sats(data, *result_data);
+       break;
+ 
+ #ifdef INCLUDE_GPS_CONDITION
+     case 0xc6: /* gps condition */
+       *result_data = (void *) malloc(sizeof(AS_GPS_Condition));
+       as_gps_parse_gps_condition(data, *result_data);
+       break;
+ #endif
+ 
      default:
        printf("Unsupported cmd: '%x'\n", mode);
+       mode = 0x0;
        return 0;
    }
  
***************
*** 154,169 ****
--- 168,203 ----
  {
  //     printf("Receiver Mode: %02x %02x %02x %02x %02x\n", 
  //       data[2], data[3], data[4], data[5], data[6]);
+   rcv->status = data[2];
+   rcv->elevation_mask = data[3];
+   rcv->signal_level_mask = data[4];  /* .2 units */
+   rcv->PDOP_limit = data[5];
+   rcv->smooth_level = data[6];
+   rcv->hgt = (double)(data[7]<<8 | data[8]);
  }
  
+ static time_t as_UTC_offset=-1L;
  int as_gps_parse_position_data(unsigned char *data, AS_GPS_PositionData *pos)
  {
    signed lat_tmp, lgt_tmp, hdg_tmp, speed_tmp;
    signed short hgt_tmp;
    unsigned entry, entries, sat_status;
    int sat;
+   static int century_bias;
    struct tm tm;
  
+ #if BREAK_WHEN_DST_CHANGES
+   if(as_UTC_offset == -1L) {  /* determine proper delta from UTC to localtime */
+ #endif
+     time(&as_UTC_offset);  /* system's UTC value */
+     memcpy(&tm, gmtime(&as_UTC_offset), sizeof(struct tm));
+     tm.tm_isdst = -1;  /* gmtime may not set isdst right.  We force to "don't know" */
+     century_bias = tm.tm_year - (tm.tm_year % 100);  /* 0, 100, ... */
+     as_UTC_offset = mktime(&tm) - as_UTC_offset;  /* positive if W if Grenwich */
+ #if BREAK_WHEN_DST_CHANGES
+   }
+ #endif
+ 
    pos->healthy = data[32];
    pos->status = data[2];
   
***************
*** 193,208 ****
    pos->speed = (double) speed_tmp / 4.0;
  
    pos->speed_error = (double) data[20] / 4.0;
  
!   tm.tm_year = bcd2uchar(data[24]);
    tm.tm_mon  = bcd2uchar(data[25])-1;
    tm.tm_mday = bcd2uchar(data[26]);
  
    tm.tm_hour = bcd2uchar(data[27]);
    tm.tm_min  = bcd2uchar(data[28]);
    tm.tm_sec  = bcd2uchar(data[29]);
  
!   pos->time = mktime(&tm);
  
    pos->HDOP = (double) data[30] * 0.2;
    pos->VDOP = (double) data[31] * 0.2;
--- 227,247 ----
    pos->speed = (double) speed_tmp / 4.0;
  
    pos->speed_error = (double) data[20] / 4.0;
+   pos->unknown[0] = data[21];
+   pos->unknown[1] = data[22];
+   pos->unknown[2] = data[23];
+   pos->unknown[3] = data[41];
  
!   tm.tm_year = bcd2uchar(data[24]) + century_bias;  /* #define to 100 after 1/1/2000 */
    tm.tm_mon  = bcd2uchar(data[25])-1;
    tm.tm_mday = bcd2uchar(data[26]);
  
    tm.tm_hour = bcd2uchar(data[27]);
    tm.tm_min  = bcd2uchar(data[28]);
    tm.tm_sec  = bcd2uchar(data[29]);
+   tm.tm_isdst= -1;  /* dunno if DST  */
  
!   pos->time = mktime(&tm) - as_UTC_offset;  /* compensate for mktime()'s TZ correction */
  
    pos->HDOP = (double) data[30] * 0.2;
    pos->VDOP = (double) data[31] * 0.2;
***************
*** 219,227 ****
    for(entry = 0; entry < 8; entry++)
      pos->sat_entries[entry].valid = 0;
  
!   for(entry = 0, sat = 31; sat >= 0; sat--)
    {
!     if(entries & 0x80000000)
      {
        unsigned status;
  
--- 258,266 ----
    for(entry = 0; entry < 8; entry++)
      pos->sat_entries[entry].valid = 0;
  
!   for(entry = 0, sat = 1; sat < 33; sat++)
    {
!     if(entries & 0x00000001)
      {
        unsigned status;
  
***************
*** 242,253 ****
        entry++;
      }
  
!     entries = entries << 1;
    }
  
    return 0;
  }
  
  void as_gps_print_sat_entries(const AS_GPS_SatEntry *sat_entries)
  {
    unsigned entry;
--- 281,419 ----
        entry++;
      }
  
!     entries = entries >> 1;
    }
  
    return 0;
  }
  
+ 
+ #ifdef INCLUDE_GPS_CONDITION
+ int xbcd2int(unsigned char *bcd)
+ {
+   int result, sign=1;
+ 
+   if((char)(*bcd&0xf) == 0xB)
+ 	 sign=-1;
+   bcd++;
+   result = 100 * ((char)((*bcd>>4)&0xf)*10 + (char)(*bcd&0xf));
+   bcd++;
+   result += (char)((*bcd>>4)&0xf)*10 + (char)(*bcd&0xf);
+   return (sign * result);
+ }
+ 
+ double xbcd2lat(unsigned char *bcd)
+ {
+   char digit;
+   int deg, sign=1;
+   double result;
+ 
+   if( (char)((*bcd>>4)&0xf) == 0xB)
+ 	sign=-1;
+   digit = (char)(*bcd&0xf);
+   if(digit==10) digit=0;  /* leading blank */
+   deg = 100 * digit;
+ printf("debug: deg=%d, byte=%x\n", deg, *bcd);
+   bcd++;
+   deg += (char)((*bcd>>4)&0xf)*10 + (char)(*bcd&0xf);
+   bcd++;
+   result = (double)deg + (double)((char)((*bcd>>4)&0xf)*10 + (char)(*bcd&0xf))/60.0;
+ printf("debug: deg=%d, byte=%x, result=%8.5f\n", deg, *bcd, result);
+   bcd++;
+   result += (double)((char)((*bcd>>4)&0xf)*10 + (char)(*bcd&0xf))/3600.0;
+   return (sign * result);
+ }
+ 
+ int as_gps_parse_gps_condition(unsigned char *data, AS_GPS_Condition *cnd)
+ {
+   unsigned i;
+   struct tm tm;
+ 
+   cnd->status = data[2];
+   cnd->healthy = bcd2uchar(data[3]);
+   cnd->visible = bcd2uchar(data[4]);
+   cnd->height = xbcd2int(data+5);
+   cnd->lgt = xbcd2lat(data+8);
+   cnd->lat = xbcd2lat(data+14);
+ 
+ #ifndef CENTURY_BIAS
+ #define CENTURY_BIAS 0
+ #endif
+   tm.tm_year = bcd2uchar(data[20]) + CENTURY_BIAS;  /* #define to 100 after 1/1/2000 */
+   tm.tm_mon  = bcd2uchar(data[21])-1;
+   tm.tm_mday = bcd2uchar(data[22]);
+ 
+   tm.tm_hour = bcd2uchar(data[23]);
+   tm.tm_min  = bcd2uchar(data[24]);
+   tm.tm_sec  = bcd2uchar(data[25]);
+   tm.tm_isdst= -1;  /* dunno if DST  */
+ 
+   cnd->time = mktime(&tm) - as_UTC_offset;  /* compensate for mktime()'s TZ correction */
+   for (i=0; i<8; i++) {
+     cnd->id_lvl[i].id = bcd2uchar(data[26+2*i]);
+     cnd->id_lvl[i].level = bcd2uchar(data[27+2*i]);
+   }
+   cnd->diag[0] = data[42];
+   cnd->diag[1] = data[43];
+ }
+ 
+ void as_gps_print_gps_condition(const AS_GPS_Condition *cnd)
+ {
+   int i;
+ 
+   printf("GPS Condition:  ");
+   switch(cnd->status & 0xF)
+   {
+     case 0x0: printf("No Decoded Sats"); break;
+     case 0x1: printf("1 Decoded Sat"); break;
+     case 0x2: printf("2 Decoded Sats"); break;
+     case 0x3: printf("2D Fix"); break;
+     case 0x4: printf("3D Fix"); break;
+     case 0x5: printf("Acceleration > 1G"); break;
+     case 0x9: printf("Receiver error"); break;
+   }
+   printf(",  %d healthy, %d sats visible\n", cnd->healthy, cnd->visible);
+   printf("  Lat: %02.7f, Long: %02.7f,", cnd->lat, cnd->lgt);
+   printf(" Height: %5dm,", cnd->height);
+   printf(" %s", asctime(localtime(&cnd->time)));
+ 
+   for(i=0; i<8; i++) {
+     printf("  Sat: %2d,  Lvl: %2d\n", cnd->id_lvl[i].id, cnd->id_lvl[i].level);
+   }
+   if ((cnd->diag[0]>>4)&0xf == 1) printf("  cold start RAM check NG1");
+   else if ((cnd->diag[0]>>4)&0xf == 2) printf("  cold start RAM check NG2");
+   if (cnd->diag[0]&0xf == 1) printf("  cold start RTC err 1");
+   else if (cnd->diag[0]&0xf == 2) printf("  cold start RTC err 2");
+   if (cnd->diag[1]&0xf == 1) printf("   Almanac too old");
+ }
+ #endif
+ 
+ int as_gps_parse_receive_sats(unsigned char *data, AS_GPS_ReceiveSats *rcv)
+ {
+   unsigned entry;
+ 
+   rcv->seconds = data[2];
+   rcv->almanac_age = data[43];
+ 
+   for(entry = 0; entry < 8; entry++)
+   {
+      rcv->sat_entries[entry].id = data[3+5*entry];  /* 0 means not used */
+      rcv->sat_entries[entry].condition = data[4+5*entry];
+      rcv->sat_entries[entry].level = data[5+5*entry];  /* in .2 units */
+      rcv->sat_entries[entry].azimuth = data[6+5*entry] * 360 / 256;
+      rcv->sat_entries[entry].elevation = data[6+5*entry] * 180 / 256;
+   }
+ 
+   for(entry = 0; entry < 32; entry++)
+   {
+      int byteoffset = entry/8;
+      int bitoffset = entry%8;
+      int mask = 0x01<<bitoffset;
+ 
+      rcv->health[entry] = (data[44+byteoffset] & mask) ? 'H' : 'U';
+   }
+ }
+ 
  void as_gps_print_sat_entries(const AS_GPS_SatEntry *sat_entries)
  {
    unsigned entry;
***************
*** 289,294 ****
--- 455,497 ----
    }
  }
  
+ void as_gps_print_receive_sats(const AS_GPS_ReceiveSats *rcv)
+ {
+   unsigned entry;
+ 
+   printf("Almanac Age %d days;", rcv->almanac_age);
+ 
+   printf(" Sat Health 1..32: %.4s %.4s %.4s %.4s  %.4s %.4s %.4s %.4s\n",
+     rcv->health, rcv->health+4, rcv->health+8, rcv->health+12,
+     rcv->health+16, rcv->health+20, rcv->health+24, rcv->health+28);
+ 
+   for(entry = 0; entry < 8; entry++)
+   {
+     AS_GPS_SatInfoEntry sat_entry = rcv->sat_entries[entry];
+     if (sat_entry.id == 0) continue; /* slot not used */
+     printf("    Sat: %2d Cond: svacc=%2d,", sat_entry.id,
+ 	                       (sat_entry.condition>>4)&0xf);
+ 
+     switch(sat_entry.condition&0xf)
+     {
+       case 1: 
+         printf("Searching         "); break;
+       case 2: 
+         printf("Tracking          "); break;
+       case 4:  
+         printf("Decoded (Not Used)"); break;
+       case 8: 
+         printf("Decoded (Used)    "); break;
+       default:
+         printf("Unknown bit config"); break;
+     }
+     
+     printf(" Lvl: %2d", sat_entry.level);
+     printf("  Az: %3d El: %3d\n", sat_entry.azimuth, sat_entry.elevation);
+   }
+ 
+ }
+ 
  void as_gps_print_position_data(const AS_GPS_PositionData *pos)
  {
    printf("Position Data: ");
***************
*** 321,336 ****
  //    pos->lat, avg_lat / (double) avg_cnt,
  //    pos->lgt, avg_lgt / (double) avg_cnt);
  //  else
!     printf("  Lat: %02.7f, Long: %02.7f\n", pos->lat, pos->lgt);
! 
!   printf("  %s", asctime(localtime(&pos->time)));
  
-   printf("  HDOP: %02.1f, VDOP: %02.1f\n", pos->HDOP, pos->VDOP);
-   printf("  Height: %04.1fm\n", pos->hgt);
-   printf("  Error Ellipse: Long: %dm, Short: %dm\n", pos->long_error, pos->short_error);
    printf("  Heading: %3.6f +/- %2.6f deg cw from N\n", pos->heading,
! pos->heading_error);
    printf("  Speed: %3.6f +/- %3.6f km/h\n", pos->speed, pos->speed_error);
  
    as_gps_print_sat_entries(pos->sat_entries);
  }
--- 524,540 ----
  //    pos->lat, avg_lat / (double) avg_cnt,
  //    pos->lgt, avg_lgt / (double) avg_cnt);
  //  else
!     printf("  Lat: %02.7f, Long: %02.7f,", pos->lat, pos->lgt);
!   printf(" Height: %04.1fm,", pos->hgt);
!   printf(" %s", asctime(localtime(&pos->time)));
  
    printf("  Heading: %3.6f +/- %2.6f deg cw from N\n", pos->heading,
! 	 pos->heading_error);
    printf("  Speed: %3.6f +/- %3.6f km/h\n", pos->speed, pos->speed_error);
+   printf("  HDOP: %02.1f, VDOP: %02.1f;", pos->HDOP, pos->VDOP);
+   printf("  Error Ellipse: Long: %dm, Short: %dm\n", pos->long_error, pos->short_error);
+   printf("  Unknown use: %2x %2x %2x %2x\n", pos->unknown[0], pos->unknown[1],
+ 	pos->unknown[2], pos->unknown[3]);
  
    as_gps_print_sat_entries(pos->sat_entries);
  }
***************
*** 370,385 ****
--- 574,593 ----
  
    data[length-1] = 0xd; // terminate
  
+ #ifdef DEBUGWRITE
    printf("Sending: ");
+ #endif
  
    result = write(as_gps_file, data, length);
  
+ #if DEBUGWRITE
    for(count = 0; count < length; count++)
    {
      printf(" %02x", data[count]);
    }
  
    printf(" %d\n", result);
+ #endif
  
    return 0;
  }
*** as_gps.h.orig	Mon Sep 20 12:19:33 1999
--- as_gps.h	Tue Nov  2 23:25:46 1999
***************
*** 8,13 ****
--- 8,14 ----
  #include <sys/stat.h>
  #include <fcntl.h>
  #include <time.h>
+ #include <string.h>
  
  #define AS_GPS_SAT_CONDITION_SEARCH       0
  #define AS_GPS_SAT_CONDITION_TRACKING     1
***************
*** 77,82 ****
--- 78,84 ----
  
    double heading, heading_error;
    double speed, speed_error;
+   unsigned char unknown[4];
  
    AS_GPS_SatEntry sat_entries[8];
  } AS_GPS_PositionData;
***************
*** 97,103 ****
    double hgt;
  } AS_GPS_ReceiverMode;
  
! extern intas_gps_file;
  
  int as_gps_open(char *);
  int as_gps_close();
--- 99,141 ----
    double hgt;
  } AS_GPS_ReceiverMode;
  
! typedef struct
! {
!   unsigned char id;
!   unsigned char condition;
!   unsigned char level;
!   unsigned azimuth;
!   unsigned elevation;
! }AS_GPS_SatInfoEntry;
! 
! typedef struct
! {
!   unsigned seconds;
!   AS_GPS_SatInfoEntry sat_entries[8];
!   unsigned almanac_age;
!   char health[32];
! } AS_GPS_ReceiveSats;
! 
! typedef struct
! {
!   unsigned char id;
!   unsigned char level;
! } AS_GPS_SatCondition;
! 
! typedef struct
! {
!   unsigned char status;
!   unsigned char healthy;
!   unsigned char visible;
!   int height;
!   double lgt;
!   double lat;
!   time_t time;
!   AS_GPS_SatCondition id_lvl[8];
!   unsigned char diag[2];
! } AS_GPS_Condition;
! 
! extern int as_gps_file;
  
  int as_gps_open(char *);
  int as_gps_close();
***************
*** 106,114 ****
--- 144,154 ----
  int as_gps_send_cmd(unsigned char cmd, unsigned char *data, int length);
  
  int as_gps_parse_position_data(unsigned char *data, AS_GPS_PositionData *pos);
+ int as_gps_parse_receive_sats(unsigned char *data, AS_GPS_ReceiveSats *pos);
  
  void as_gps_print_position_data(const AS_GPS_PositionData *pos);
  void as_gps_print_sat_entries(const AS_GPS_SatEntry *sat_entries);
+ void as_gps_print_receive_sats(const AS_GPS_ReceiveSats *pos);
  
  unsigned char bcd2uchar(unsigned char);
  
*** gps_average.c.orig	Mon Sep 20 12:30:08 1999
--- gps_average.c	Fri Oct 29 21:00:14 1999
***************
*** 2,7 ****
--- 2,11 ----
  
  int main(int argc, char **argv)
  {
+   void *data;
+   double lat, lgt;
+   unsigned fix, read_count = 0;
+ 
    if(as_gps_open("/dev/gps"))
    {
      printf("Can't open device\n");
***************
*** 10,25 ****
  
    while(1)
    {
-     void *data;
-     double lat, lgt;
-     unsigned read_count = 0;
      unsigned char result = as_gps_handle_input(&data);
  
      if(result == AS_GPS_RCV_POSITION_DATA) 
      {
        AS_GPS_PositionData *pos = (AS_GPS_PositionData *)data;
  
!       if((pos->status & 0x03) || (pos->status & 0x04)) // atleast a 2D or 3D fix
        {
          lat = (pos->lat + ((double)read_count * lat)) /
                            ((double)read_count+1);
--- 14,27 ----
  
    while(1)
    {
      unsigned char result = as_gps_handle_input(&data);
  
      if(result == AS_GPS_RCV_POSITION_DATA) 
      {
        AS_GPS_PositionData *pos = (AS_GPS_PositionData *)data;
  
!       fix = pos->status & 0x0f;
!       if(fix == 3 || fix == 4) /* at least a 2D or 3D fix */
        {
          lat = (pos->lat + ((double)read_count * lat)) /
                            ((double)read_count+1);
***************
*** 27,33 ****
          lgt = (pos->lgt + ((double)read_count * lgt)) /
                            ((double)read_count+1);
  
!         printf("%5d: Lat: %3.16f, Lgt: %3.16f\n", read_count, lat, lgt);
          read_count++;
        }
      }
--- 29,35 ----
          lgt = (pos->lgt + ((double)read_count * lgt)) /
                            ((double)read_count+1);
  
!         printf("%5u: Lat: %3.16f, Lgt: %3.16f\n", read_count, lat, lgt);
          read_count++;
        }
      }
*** gps_printloc.c.orig	Sun Nov  7 23:09:11 1999
--- gps_printloc.c	Sun Nov  7 23:15:30 1999
***************
*** 0 ****
--- 1,56 ----
+ #include "as_gps.h"
+ 
+ /* Usage:  gps_printloc [#samples]
+    Prints UTCtime, lat, long, height in meters
+    until #samples lines are printed.  If #samples is zero, or missing,
+    gps_printloc continues until interrupted.  Also, repeated identical
+    samples are discarded (but a time discontinuity will be observed).
+    Normally one sample per second is printed.
+    Written 10-29-99 by jpd@usl.edu (adapted from gps_average.c).
+    Note: a neat way to show the effects of SA, is to graph via gnuplot:
+       gps_printloc > gps_printloc.out    [kill after sufficient samples written]
+       plot "gps_printloc.out" using ($2):($3)
+       pause -1 "Press CR to continue"
+       splot "gps_printloc.out" using ($2):($3):($4)
+       pause -1 "Press CR to continue"
+ */
+ int main(int argc, char *argv[])
+ {
+   unsigned fix, count=0, samples;
+   double lat,lgt,hgt;
+ 
+   if(as_gps_open("/dev/gps"))
+   {
+     printf("Can't open device\n");
+     exit(1);
+   }
+ 
+   if (argc > 1)
+     samples = atoi(argv[1]);
+   else
+     samples = 0;
+ 
+   while(!samples || count < samples)
+   {
+     void *data=NULL;
+     unsigned char result = as_gps_handle_input(&data);
+ 
+     if(result == AS_GPS_RCV_POSITION_DATA) 
+     {
+       AS_GPS_PositionData *pos = (AS_GPS_PositionData *)data;
+ 
+       fix = pos->status & 0x0f;
+       if((fix == 3 || fix == 4) /* at least a 2D or 3D fix */
+ 	&& (lat!=pos->lat || lgt!=pos->lgt || hgt!=pos->hgt))
+       {
+         printf("%ld, %3.16f, %3.16f, %5.1f\n", pos->time, pos->lat, pos->lgt, pos->hgt);
+ 	lat=pos->lat; lgt=pos->lgt; hgt=pos->hgt;
+         count++;
+       }
+     }
+     free(data);
+   }
+ 
+   as_gps_close(); 
+ }
+ 
*** gps_reset.c.orig	Sun Nov  7 23:08:58 1999
--- gps_reset.c	Sun Nov  7 20:43:39 1999
***************
*** 0 ****
--- 1,94 ----
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include "as_gps.h"
+ extern unsigned as_gps_snd_size[32];
+ #define sbsize(x) (as_gps_snd_size[x - 0xB0])
+ 
+ int main(int argc, char **argv)
+ {
+     extern char *optarg;
+     char *endp;
+     int option;
+     double latitude, longitude;
+     int Lopt=0, lopt=0;
+     char sndbuf[5];
+ 
+ 
+     while ((option = getopt(argc, argv, "L:h?l:")) != -1) {
+ 	switch (option) {
+ 	case 'L':
+ 	    longitude = strtod(optarg, &endp);
+ 	    if (endp != NULL && toupper(*endp) == 'W')
+ 	      longitude=-longitude;
+ 	    else if (endp == NULL || (*endp && toupper(*endp)!='E')) {
+ 		fprintf(stderr, "invalid longitude (-L) option;  %s\n", optarg);
+ 		exit(1);
+ 	    }
+ 	    Lopt++;
+ 	    break;
+ 	case 'l':
+ 	    latitude = strtod(optarg, &endp);
+ 	    if (endp != NULL && toupper(*endp) == 'S')
+ 	      latitude=-latitude;
+ 	    else if (endp == NULL || (*endp && toupper(*endp)!='N')) {
+ 		fprintf(stderr, "invalid latitude (-l) option;  %s\n", optarg);
+ 		exit(1);
+ 	    }
+ 	    lopt++;
+ 	    break;
+ 	case 'h':
+ 	case '?':
+ 	default:
+ 	    fputs("usage:  gps_reset [options] \n\
+   options include: \n\
+   -L longitude [ set longitude ] \n\
+   -h           [ help message ] \n\
+   -l latitude  [ set latitude ] \n\
+ ", stderr);
+ 	    exit(0);
+ 	}
+     }
+ 
+   if(as_gps_open("/dev/gps"))
+   {
+     printf("Can't open device\n");
+     exit(1);
+   }
+ 
+   as_gps_send_cmd(AS_GPS_SET_SYSTEM_RESET, sndbuf, sbsize(AS_GPS_SET_SYSTEM_RESET));
+   if(Lopt && lopt) {
+     option = (int)(latitude * 256.0 * 3600.0);
+     sndbuf[2] = (option>>24);
+     sndbuf[3] = (option>>16)&0xff;
+     sndbuf[4] = (option>>8)&0xff;
+     sndbuf[5] = (option)&0xff;
+ 
+     option = (int)(longitude * 256.0 * 3600.0);
+     sndbuf[6] = (option>>24);
+     sndbuf[7] = (option>>16)&0xff;
+     sndbuf[8] = (option>>8)&0xff;
+     sndbuf[9] = (option)&0xff;
+ 
+     as_gps_send_cmd(AS_GPS_SET_CURRENT_POSITION, sndbuf, sbsize(AS_GPS_SET_CURRENT_POSITION));
+   }
+ 
+   while(1)
+   {
+     void *data=NULL;
+     unsigned char result = as_gps_handle_input(&data);
+ 
+     if(result == AS_GPS_RCV_POSITION_DATA) // PositionData
+     {
+       as_gps_print_position_data((AS_GPS_PositionData *)data);  
+     }
+     else if(result == AS_GPS_RCV_RECEIVE_SAT) // SatPositionData
+     {
+       as_gps_print_receive_sats((AS_GPS_ReceiveSats *)data);  
+     }
+ 
+     free(data);
+   }
+ 
+   as_gps_close(); 
+ }
+ 
*** gps_settime.c.orig	Mon Sep 20 11:15:46 1999
--- gps_settime.c	Sun Nov  7 19:01:29 1999
***************
*** 14,20 ****
  
    while(1)
    {
!     void *data;
      double lat, lgt;
      unsigned read_count = 0;
      unsigned char result = as_gps_handle_input(&data);
--- 14,20 ----
  
    while(1)
    {
!     void *data=NULL;
      double lat, lgt;
      unsigned read_count = 0;
      unsigned char result = as_gps_handle_input(&data);
***************
*** 38,59 ****
  void set_time(const AS_GPS_PositionData *pos)
  {
    time_t time;
    struct timeval timeval;
    struct timezone timezone;
  
    time = pos->time;
  
    timeval.tv_sec = mktime(gmtime(&time));
    timeval.tv_usec = 0;
  
    timezone.tz_minuteswest = 0;
    timezone.tz_dsttime = 0;
  
!   printf("Setting time to %s", asctime(localtime(&time)));
!   printf("Setting time to %s", asctime(gmtime(&time)));
! 
    if(settimeofday(&timeval, &timezone))
    {
      printf("Error: Must be superuser to set time.\n");
    }
  }
--- 38,68 ----
  void set_time(const AS_GPS_PositionData *pos)
  {
    time_t time;
+ #if 0
    struct timeval timeval;
    struct timezone timezone;
+ #endif
  
    time = pos->time;
  
+ #if 0
    timeval.tv_sec = mktime(gmtime(&time));
    timeval.tv_usec = 0;
  
    timezone.tz_minuteswest = 0;
    timezone.tz_dsttime = 0;
  
! #endif
! #if 0
    if(settimeofday(&timeval, &timezone))
+ #else
+   if(stime(&time))
+ #endif
    {
      printf("Error: Must be superuser to set time.\n");
+     exit(1);
    }
+ 
+   printf("Setting time to %s", asctime(localtime(&time)));
+   printf("Setting time to %.24s UTC\n", asctime(gmtime(&time)));
  }
*** gps_test.c.orig	Mon Sep 20 11:15:52 1999
--- gps_test.c	Fri Nov  5 01:14:27 1999
***************
*** 8,22 ****
      exit(1);
    }
  
    while(1)
    {
!     void *data;
      unsigned char result = as_gps_handle_input(&data);
  
      if(result == AS_GPS_RCV_POSITION_DATA) // PositionData
      {
        as_gps_print_position_data((AS_GPS_PositionData *)data);  
      }
  
      free(data);
    }
--- 8,47 ----
      exit(1);
    }
  
+ #ifdef INCLUDE_GPS_CONDITION
+ #define sbsize(x) (as_gps_snd_size[x - 0xB0])
+   {
+       extern unsigned as_gps_snd_size[32];
+ 
+       char sndbuf[5];
+       as_gps_send_cmd(AS_GPS_REQ_CONDITION, sndbuf, sbsize(AS_GPS_REQ_CONDITION));
+   }
+ #endif
+ 
    while(1)
    {
!     void *data=NULL;
      unsigned char result = as_gps_handle_input(&data);
  
      if(result == AS_GPS_RCV_POSITION_DATA) // PositionData
      {
        as_gps_print_position_data((AS_GPS_PositionData *)data);  
      }
+     else if(result == AS_GPS_RCV_RECEIVE_SAT) // SatPositionData
+     {
+       as_gps_print_receive_sats((AS_GPS_ReceiveSats *)data);  
+     }
+ #ifdef INCLUDE_GPS_CONDITION
+     else if(result == AS_GPS_RCV_CONDITION) // req gps condition
+     {
+       extern unsigned as_gps_snd_size[32];
+       char sndbuf[5];
+ 
+       as_gps_print_gps_condition((AS_GPS_Condition *)data);
+ 
+ /*      as_gps_send_cmd(AS_GPS_REQ_CONDITION, sndbuf, sbsize(AS_GPS_REQ_CONDITION));*/
+     }
+ #endif
  
      free(data);
    }
*** gps_test_send.c.orig	Mon Sep 20 11:16:03 1999
--- gps_test_send.c	Sun Nov  7 14:07:20 1999
***************
*** 10,16 ****
  
    while(1)
    {
!     void *data;
      char send_data[50];
      unsigned char result = as_gps_handle_input(&data);
  
--- 10,16 ----
  
    while(1)
    {
!     void *data=NULL;
      char send_data[50];
      unsigned char result = as_gps_handle_input(&data);
  

--Drey_of_Squirrels_866_000
Content-Type: TEXT/plain; name="gpsd.diffs"; charset=us-ascii; x-unix-mode=0640
Content-Description: gpsd.diffs
Content-MD5: c5QoB1qOQqKv2PMWCQtCkw==

*** Makefile.orig	Thu Oct 28 22:26:54 1999
--- Makefile	Mon Nov  1 00:26:32 1999
***************
*** 94,100 ****
  X_INCLUDE =  -I/usr/X11R6/include
  
  ## Where to look for include files.
! INCLUDE = -I. $(X_INCLUDE)
  
  ## Implicit rules.
  .SUFFIXES: .c
--- 94,100 ----
  X_INCLUDE =  -I/usr/X11R6/include
  
  ## Where to look for include files.
! INCLUDE = -I. $(X_INCLUDE) -I../as-gps-0.1
  
  ## Implicit rules.
  .SUFFIXES: .c
***************
*** 103,109 ****
  
  
  ## Libraries and object files
! LIB_OBJECTS = netlib.o nmea_parse.o serial.o tm.o em.o $(MOTIF_OBJECTS)
  
  ## Programs
  PROGRAMS=gpsd
--- 103,109 ----
  
  
  ## Libraries and object files
! LIB_OBJECTS = netlib.o nmea_parse.o serial.o tm.o em.o aisin.o ../as-gps-0.1/as_gps.o $(MOTIF_OBJECTS)
  
  ## Programs
  PROGRAMS=gpsd
*** aisin.c.orig	Mon Nov  8 00:22:06 1999
--- aisin.c	Tue Nov  2 02:09:08 1999
***************
*** 0 ****
--- 1,99 ----
+ #include "config.h"
+ #include <stdio.h>
+ #include <math.h>
+ #include <string.h>
+ #include "nmea.h"
+ #include "as_gps.h"
+ 
+ AS_GPS_PositionData Pos;
+ AS_GPS_ReceiveSats Rcv;
+ extern unsigned as_gps_rcv_size[32];
+ extern struct OUTDATA gNMEAdata;
+ 
+ int aisin_checksum(unsigned char mode, unsigned char *sentence)
+ {
+   int count;
+   unsigned char checksum = 0;
+ 
+   for(count = 0; count <  as_gps_rcv_size[mode - 0xB0] - 1; count++)
+     checksum += sentence[count];
+ 
+   if(checksum)
+   {
+     printf("Checksum Error: Cmd:%02x, E:%d, E:%02x, A:%02x\n",
+       mode, checksum, checksum, sentence[as_gps_rcv_size[mode - 0xB0]-2]);
+     return 1;
+   }
+   return 0;
+ }
+   
+ void aisin2nmea(unsigned char *sentence)
+ {
+   unsigned char mode = *sentence;
+   int entry, i, mod;
+   struct tm *tm;
+ 
+   if(aisin_checksum(mode, sentence))  /* cksum error */
+     return;
+   if(mode == AS_GPS_RCV_POSITION_DATA) {
+     as_gps_parse_position_data(sentence, &Pos);
+     tm = gmtime(&Pos.time);
+     sprintf(gNMEAdata.utc, "%02d/%02d/%02d %02d:%02d:%02d  ",
+ 	    tm->tm_mon+1, tm->tm_mday, tm->tm_year%100,
+ 	    tm->tm_hour, tm->tm_min, tm->tm_sec);
+     if (gNMEAdata.latitude != Pos.lat)
+       gNMEAdata.cmask |= C_LATLON;
+     gNMEAdata.latitude = Pos.lat;
+     if (gNMEAdata.longitude != Pos.lgt)
+       gNMEAdata.cmask |= C_LATLON;
+     gNMEAdata.longitude = Pos.lgt;
+     gNMEAdata.altitude = Pos.hgt;  /* m */
+     gNMEAdata.speed = Pos.speed; /* knots !! */
+     gNMEAdata.track = Pos.heading;
+ 
+     gNMEAdata.satellites=0;
+     for(entry=0; entry<8; entry++) {
+       AS_GPS_SatEntry sat_entry = Pos.sat_entries[entry];
+       if (sat_entry.valid && sat_entry.condition==AS_GPS_SAT_CONDITION_DECODED_USED)
+ 	gNMEAdata.satellites ++;
+     }
+ 	
+     if(Pos.status&0xF == 3) { /* 2d fix */
+       gNMEAdata.status = 1;  /* fix via gps */
+       gNMEAdata.mode = 2;  /* 2d */
+     }
+     else if(Pos.status&0xF == 4) { /* 3d fix */
+       gNMEAdata.status = 1;  /* fix via gps */
+       gNMEAdata.mode = 3;  /* 3d */
+     }
+     else {
+       gNMEAdata.status = 0;  /* no fix */
+       gNMEAdata.mode = 1;  /* no fix */
+     }
+     gNMEAdata.pdop = 0.0; /* ?? */
+     gNMEAdata.hdop = Pos.HDOP;
+     gNMEAdata.vdop = Pos.VDOP;
+   }
+   else if (mode == AS_GPS_RCV_RECEIVE_SAT) {
+     as_gps_parse_receive_sats(sentence, &Rcv);
+    
+     for(mod=i=entry=0; entry<8; entry++) {
+       AS_GPS_SatInfoEntry  sat_entry = Rcv.sat_entries[entry];
+       if (sat_entry.id) {
+ 	if (gNMEAdata.PRN[i] != sat_entry.id) mod++;
+ 	gNMEAdata.PRN[i] = sat_entry.id;
+ 	if (gNMEAdata.elevation[i] != sat_entry.elevation) mod++;
+ 	gNMEAdata.elevation[i] = sat_entry.elevation;
+ 	if (gNMEAdata.azimuth[i] != sat_entry.azimuth) mod++;
+ 	gNMEAdata.azimuth[i] = sat_entry.azimuth;
+ 	if (gNMEAdata.ss[i] != sat_entry.level) mod++;
+ 	gNMEAdata.ss[i] = sat_entry.level; /* scale this? */
+ 	i++;
+       }
+     }
+     if (gNMEAdata.in_view != i) mod++;
+     gNMEAdata.in_view = i;
+ 
+     if (mod) gNMEAdata.cmask |= C_SAT;
+   }
+ }
*** gps.c.orig	Sat Feb  6 18:43:57 1999
--- gps.c	Tue Nov  2 01:13:39 1999
***************
*** 440,447 ****
                  case 'e':
                      device_type = DEVICE_EARTHMATE;
                      break;
                  default:
!                     fprintf(stderr,"Invalide device type \"%s\"\n"
                                     "Using GENERIC instead\n", device_type);
                      break;
              }
--- 440,450 ----
                  case 'e':
                      device_type = DEVICE_EARTHMATE;
                      break;
+ 		case 'a':
+ 		    device_type = DEVICE_AISIN;
+ 		    break;
                  default:
!                     fprintf(stderr,"Invalid device type \"%s\"\n"
                                     "Using GENERIC instead\n", device_type);
                      break;
              }
*** gpsd.c.orig	Tue Nov  2 00:58:24 1999
--- gpsd.c	Tue Nov  2 02:02:46 1999
***************
*** 42,47 ****
--- 42,48 ----
  #include "nmea.h"
  #include "gpsd.h"
  #include "version.h"
+ extern unsigned as_gps_rcv_size[32];
  
  #define QLEN		5
  #define BUFSIZE		4096
***************
*** 128,135 ****
  		case 'e':
  		    device_type = DEVICE_EARTHMATE;
  		    break;
  		default:
! 		    fprintf(stderr,"Invalide device type \"%s\"\n"
  				   "Using GENERIC instead\n", device_type);
  		    break;
  	    }
--- 129,139 ----
  		case 'e':
  		    device_type = DEVICE_EARTHMATE;
  		    break;
+ 		case 'a':
+ 		    device_type = DEVICE_AISIN;
+ 		    break;
  		default:
! 		    fprintf(stderr,"Invalid device type \"%s\"\n"
  				   "Using GENERIC instead\n", device_type);
  		    break;
  	    }
***************
*** 386,391 ****
--- 390,408 ----
      while (offset < BUFSIZE) {
  	if (read(input, buf + offset, 1) != 1)
  	    return 1;
+ 
+ 	if (device_type == DEVICE_AISIN) {
+ 	  if (offset == 1) {  /* first 2 bytes must be suitable cmd bytes */
+ 	    if (buf[0] != buf[1] || buf[0] < 0xB0 || buf[0] > 0xCC) {
+ 	      buf[0] = buf[1];
+ 	      continue;  /* read again */
+ 	    }
+ 	  }
+ 	  if (offset < as_gps_rcv_size[buf[0] - 0xB0]-1) {
+ 	    offset++;
+ 	    continue;
+ 	  }
+ 	}
  
  	if (buf[offset] == '\n' || buf[offset] == '\r') {
  	    buf[offset] = '\0';
*** gpsd.h.orig	Fri Jan 29 21:58:51 1999
--- gpsd.h	Sat Oct 30 13:05:32 1999
***************
*** 1,6 ****
  
  
! enum { DEVICE_GENERIC, DEVICE_TRIPMATE, DEVICE_EARTHMATE };
  
  extern int serial_open();
  extern void serial_close();
--- 1,6 ----
  
  
! enum { DEVICE_GENERIC, DEVICE_TRIPMATE, DEVICE_EARTHMATE, DEVICE_AISIN };
  
  extern int serial_open();
  extern void serial_close();
*** nmea_parse.c.orig	Tue Aug 18 17:56:12 1998
--- nmea_parse.c	Sat Oct 30 13:10:19 1999
***************
*** 31,37 ****
  
      strncpy(s + 3, d, 2);	// copy date
  
!     strncpy(s + 6, "19", 2);	// 20th century
  
      strncpy(s + 8, d + 4, 2);	// copy year
  
--- 31,37 ----
  
      strncpy(s + 3, d, 2);	// copy date
  
!     strncpy(s + 6, "19", 2);	// 20th century   Y2K FIXME!!jpd
  
      strncpy(s + 8, d + 4, 2);	// copy year
  
*** serial.c.orig	Sat Jan 30 00:51:10 1999
--- serial.c	Tue Nov  2 00:21:26 1999
***************
*** 83,89 ****
  
  #if defined (USE_TERMIO)
  	    ttyset.c_cflag = CBAUD & device_speed;
! 	    ttyset.c_cflag = CBAUD & B4800;
  #else
  	    ttyset.c_ispeed = device_speed;
  	    ttyset.c_ospeed = device_speed;
--- 83,89 ----
  
  #if defined (USE_TERMIO)
  	    ttyset.c_cflag = CBAUD & device_speed;
! 	    /* OMIT  ttyset.c_cflag = CBAUD & B4800;*/
  #else
  	    ttyset.c_ispeed = device_speed;
  	    ttyset.c_ospeed = device_speed;
*** tm.c.orig	Sat Feb  6 18:42:44 1999
--- tm.c	Tue Nov  2 00:43:37 1999
***************
*** 58,64 ****
  	    "$PRWIINIT,V,,,%s,%c,%s,%c,100.0,0.0,M,0.0,T,%02d%02d%02d,%02d%02d%02d*",
  	    latitude, latd, longitude, lond,
  	    tm->tm_hour, tm->tm_min, tm->tm_sec,
! 	    tm->tm_mday, tm->tm_mon + 1, tm->tm_year);
      add_checksum(buf + 1);	/* add c-sum + cr/lf */
      write(gNMEAdata.fdout, buf, strlen(buf));
      if (debug > 1) {
--- 58,64 ----
  	    "$PRWIINIT,V,,,%s,%c,%s,%c,100.0,0.0,M,0.0,T,%02d%02d%02d,%02d%02d%02d*",
  	    latitude, latd, longitude, lond,
  	    tm->tm_hour, tm->tm_min, tm->tm_sec,
! 	    tm->tm_mday, tm->tm_mon + 1, tm->tm_year%100); /* jpd: y2k mod */
      add_checksum(buf + 1);	/* add c-sum + cr/lf */
      write(gNMEAdata.fdout, buf, strlen(buf));
      if (debug > 1) {
***************
*** 97,105 ****
  
  	// Maybe we wait a bit and initialize in NMEA mode?
  
      } else if (debug > 1) {
! 	fprintf(stderr, "Unknown exception: \"%s\"",
! 		sentence);
      }
  }
  
--- 97,111 ----
  
  	// Maybe we wait a bit and initialize in NMEA mode?
  
+     } else if (*sentence == *(sentence+1) &&
+ 	       (unsigned char)*sentence >= 0xB0 &&
+ 	       (unsigned char)*sentence <= 0xCC) {
+         aisin2nmea(sentence); /* handle AISIN SEIKI gps */
+ 	device_type = DEVICE_AISIN;
      } else if (debug > 1) {
! 	fprintf(stderr, "Unknown exception: \"%s\" [%x %x %x ...]",
! 		sentence, (unsigned char)sentence[0],
! 		(unsigned char)sentence[1], (unsigned char)sentence[2]);
      }
  }
