static const GpsInterface* GetGpsInterface(JNIEnv* env, jobject obj) {
    // this must be set before calling into the HAL library
    if (!mCallbacksObj)
        mCallbacksObj = env->NewGlobalRef(obj);

    if (!sGpsInterface) {
        sGpsInterface = get_gps_interface();
        if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0) {
            sGpsInterface = NULL;
            return NULL;
        }
    }
    return sGpsInterface;
}
예제 #2
0
파일: test_gps.c 프로젝트: kgunn/libhybris
int main(int argc, char *argv[])
{
  int sleeptime = 6000, opt, initok = 0;
  struct timeval tv;
  int agps = 0, agpsril = 0, injecttime = 0;

  while ((opt = getopt(argc, argv, "art")) != -1)
  {
               switch (opt) {
               case 'a':
		   agps = 1;
		   fprintf(stdout, "*** Using agps\n");
                   break;
               case 'r':
		   agpsril = 1;
		   fprintf(stdout, "*** Using agpsril\n");
                   break;
	       case 't':
		   injecttime = 1;
		   fprintf(stdout, "*** Timing info will be injected\n");
                   break;
               default:
                   fprintf(stderr, "\n Usage: %s \n \
			   \t-a for agps,\n \
		           \t-r for agpsril,\n \
			   \t-t to inject time,\n \
			   \tnone for standalone gps\n",
                           argv[0]);
                   exit(1);
               }
  }


  fprintf(stdout, "*** setup signal handler\n");
  signal(SIGINT, sigint_handler);

  fprintf(stdout, "*** get gps interface\n");
  Gps = get_gps_interface();

  fprintf(stdout, "*** init gps interface\n");
  initok = Gps->init(&callbacks);
  fprintf(stdout, "*** setting positioning mode\n");
  /* need to be done before starting gps or no info will come out */
  if((agps||agpsril) && !initok)
	Gps->set_position_mode(GPS_POSITION_MODE_MS_BASED, GPS_POSITION_RECURRENCE_PERIODIC, 100, 0, 0);
  else
	Gps->set_position_mode(GPS_POSITION_MODE_STANDALONE, GPS_POSITION_RECURRENCE_PERIODIC, 100, 0, 0);

  if (Gps && !initok && (agps||agpsril))
  {
    fprintf(stdout, "*** get agps interface\n");
    AGps = get_agps_interface(Gps);
    if (AGps)
    {
	fprintf(stdout, "*** set up agps interface\n");
	AGps->init(&callbacks2);
	fprintf(stdout, "*** set up agps server\n");
	AGps->set_server(AGPS_TYPE_SUPL, "supl.google.com", 7276);
    }

    fprintf(stdout, "*** get agps ril interface\n");

    AGpsRil = get_agps_ril_interface(Gps);
    if (AGpsRil)
    {
	AGpsRil->init(&callbacks3);
    }

    fprintf(stdout, "*** delete aiding data\n");
    Gps->delete_aiding_data(GPS_DELETE_ALL);
  }

  if(injecttime)
  {
    fprintf(stdout, "*** aiding gps by injecting time information\n");
    gettimeofday(&tv, NULL);
    Gps->inject_time(tv.tv_sec, tv.tv_sec, 0);
  }

  fprintf(stdout, "*** start gps track\n");
  Gps->start();

  fprintf(stdout, "*** gps tracking started\n");

  while(sleeptime > 0)
  {
    fprintf(stdout, "*** tracking.... \n");
    sleep(100);
    sleeptime = sleeptime - 100;
  }

  fprintf(stdout, "*** stop tracking\n");
  Gps->stop();
  fprintf(stdout, "*** cleaning up\n");
  Gps->cleanup();

  return 0;
}
static jboolean android_location_GpsLocationProvider_is_supported(JNIEnv* env, jclass clazz) {
    return (sGpsInterface != NULL || get_gps_interface() != NULL);
}
예제 #4
0
파일: test_gps.c 프로젝트: 8l/libhybris
int main(int argc, char *argv[])
{
  int sleeptime = 6000, opt, initok = 0;
  int coldstart = 0, extra = 0, ulp = 0;
  struct timeval tv;
  int agps = 0, agpsril = 0, injecttime = 0, injectlocation = 0;
  char *location = 0, *longitude, *latitude;
  float accuracy = 100; /* Use 100m as location accuracy by default */

  while ((opt = getopt(argc, argv, "acl:p:s:rtux")) != -1)
  {
	switch (opt) {
		case 'a':
		   agps = 1;
		   fprintf(stdout, "*** Using agps\n");
                   break;
		case 'c':
		   coldstart = 1;
		   fprintf(stdout, "*** Using cold start\n");
		   break;
		case 'l':
		   injectlocation = 1;
		   location = optarg;
		   fprintf(stdout, "*** Location info %s will be injected\n", location);
                   break;
		case 'r':
		   agpsril = 1;
		   fprintf(stdout, "*** Using agpsril\n");
                   break;
		case 't':
		   injecttime = 1;
		   fprintf(stdout, "*** Timing info will be injected\n");
                   break;
		case 'p':
		   apn = optarg;
		   break;
		case 's':
		   agps_server = optarg;
		   break;
		case 'u':
		   ulp = 1;
		   break;
		case 'x':
                   extra = 1;
                   fprintf(stdout, "*** Allowing for Xtra downloads\n");
                   break;
		default:
                   fprintf(stderr, "\n Usage: %s \n \
			   \t-a for agps,\n \
			   \t-c for coldstarting the gps,\n \
			   \t-p <apn name> to specify an apn name,\n \
			   \t-s <agps_server:port> to specify a different supls server.\n \
		           \t-r for agpsril,\n \
			   \t-t to inject time,\n \
			   \t-u to use ULP (if available,\n \
                           \t-x deal with Xtra gps data.\n \
			   \tnone for standalone gps\n",
                           argv[0]);
                   exit(1);
               }
  }

  if(!apn)
  {
        apn = strdup("Internet");
  }

  fprintf(stdout, "*** setup signal handler\n");
  signal(SIGINT, sigint_handler);

  fprintf(stdout, "*** get gps interface\n");
  Gps = get_gps_interface();

  fprintf(stdout, "*** init gps interface\n");
  initok = Gps->init(&callbacks);
  fprintf(stdout, "*** setting positioning mode\n");
  /* need to be done before starting gps or no info will come out */
  if((agps||agpsril) && !initok)
	Gps->set_position_mode(GPS_POSITION_MODE_MS_BASED, GPS_POSITION_RECURRENCE_PERIODIC, 1000, 0, 0);
  else
	Gps->set_position_mode(GPS_POSITION_MODE_STANDALONE, GPS_POSITION_RECURRENCE_PERIODIC, 1000, 0, 0);

  if (Gps && !initok && (agps||agpsril))
  {
    fprintf(stdout, "*** get agps interface\n");
    AGps = get_agps_interface(Gps);
    if (AGps)
    {
	fprintf(stdout, "*** set up agps interface\n");
	AGps->init(&callbacks2);
	fprintf(stdout, "*** set up agps server\n");
	if(agps_server)
	{
		char *server,*port = 0;

		server =  strdup(agps_server);
		strtok_r (server, ":", &port);

		fprintf(stdout, "SUPL server: %s at port number: %s\n", server, port);
		AGps->set_server(AGPS_TYPE_SUPL, server, atoi(port));
		free(server);
	}
	else
		AGps->set_server(AGPS_TYPE_SUPL, "supl.google.com", 7276);
    }

    if(agpsril)
    {
	fprintf(stdout, "*** get agps ril interface\n");

	AGpsRil = get_agps_ril_interface(Gps);
	if (AGpsRil)
	{
		AGpsRil->init(&callbacks3);
	}
    }
    /* if coldstart is requested, delete all location info */
    if(coldstart)
    {
      fprintf(stdout, "*** delete aiding data\n");
      Gps->delete_aiding_data(GPS_DELETE_ALL);
    }
    
    if(extra)
    {
      fprintf(stdout, "*** xtra aiding data init\n");
      GpsExtra = get_gps_extra_interface(Gps);
      if(GpsExtra)
        GpsExtra->init(&callbacks5);
    }

    fprintf(stdout, "*** setting up network notification handling\n");
    GpsNi = get_gps_ni_interface(Gps);
    if(GpsNi)
    {
      GpsNi->init(&callbacks4);
    }

#ifdef HAVE_ULP
    if(ulp)
    {
        UlpNetwork = get_ulp_network_interface(Gps);
        if (UlpNetwork) {
        fprintf(stdout, "*** got ulp network interface\n");
            if (UlpNetwork->init(&callbacks6) != 0) {
                fprintf(stdout, "*** FAILED to init ulp network interface\n");
                UlpNetwork = NULL;
            }
        }
        else
            fprintf(stdout, "*** ULP failed!\n");

        UlpPhoneContext = get_ulp_phone_context_interface(Gps);
        if (UlpPhoneContext) {
            fprintf(stdout, "*** got ulp phone context interface\n");
            UlpPhoneContext->init(&callbacks7);
        }
    }
#endif /* HAVE_ULP */
  }
  if(injecttime)
  {
    fprintf(stdout, "*** aiding gps by injecting time information\n");
    gettimeofday(&tv, NULL);
    Gps->inject_time(tv.tv_sec, tv.tv_sec, 0);
  }

  if(injectlocation)
  {
    fprintf(stdout, "*** aiding gps by injecting location information\n");
    //Gps->inject_location(double latitude, double longitude, float accuracy);
    latitude = strtok(location, ",");
    longitude = strtok(NULL, ",");
    Gps->inject_location(strtod(latitude, NULL), strtod(longitude, NULL), accuracy);
  }

  fprintf(stdout, "*** start gps track\n");
  Gps->start();

  fprintf(stdout, "*** gps tracking started\n");

  while(sleeptime > 0)
  {
    fprintf(stdout, "*** tracking.... \n");
    sleep(100);
    sleeptime = sleeptime - 100;
  }

  if (AGps)
	AGps->data_conn_closed(AGPS_TYPE_SUPL);
  fprintf(stdout, "*** stop tracking\n");
  Gps->stop();
  fprintf(stdout, "*** cleaning up\n");
  Gps->cleanup();

  return 0;
}
예제 #5
0
const GpsInterface* gps__get_gps_interface(struct gps_device_t* dev)
{
    return get_gps_interface();
}
예제 #6
0
int main(int argc, char *argv[])
{
  int sleeptime = 6000, opt, initok = 0;
  int coldstart = 0, extra = 0;
  struct timeval tv;
  int agps = 0, agpsril = 0, injecttime = 0;

  while ((opt = getopt(argc, argv, "acrtx")) != -1)
  {
               switch (opt) {
               case 'a':
		   agps = 1;
		   fprintf(stdout, "*** Using agps\n");
                   break;
	       case 'c':
		   coldstart = 1;
		   fprintf(stdout, "*** Using cold start\n");
		   break;
               case 'r':
		   agpsril = 1;
		   fprintf(stdout, "*** Using agpsril\n");
                   break;
	       case 't':
		   injecttime = 1;
		   fprintf(stdout, "*** Timing info will be injected\n");
                   break;
               case 'x':
                   extra = 1;
                   fprintf(stdout, "*** Allowing for Xtra downloads\n");
                   break;
               default:
                   fprintf(stderr, "\n Usage: %s \n \
			   \t-a for agps,\n \
			   \t-c for coldstarting the gps,\n \
		           \t-r for agpsril,\n \
			   \t-t to inject time,\n \
                           \t-x deal with Xtra gps data.\n \
			   \tnone for standalone gps\n",
                           argv[0]);
                   exit(1);
               }
  }


  fprintf(stdout, "*** setup signal handler\n");
  signal(SIGINT, sigint_handler);

  fprintf(stdout, "*** get gps interface\n");
  Gps = get_gps_interface();

  fprintf(stdout, "*** init gps interface\n");
  initok = Gps->init(&callbacks);
  fprintf(stdout, "*** setting positioning mode\n");
  /* need to be done before starting gps or no info will come out */
  if((agps||agpsril) && !initok)
	Gps->set_position_mode(GPS_POSITION_MODE_MS_BASED, GPS_POSITION_RECURRENCE_PERIODIC, 1000, 0, 0);
  else
	Gps->set_position_mode(GPS_POSITION_MODE_STANDALONE, GPS_POSITION_RECURRENCE_PERIODIC, 1000, 0, 0);

  if (Gps && !initok && (agps||agpsril))
  {
    fprintf(stdout, "*** get agps interface\n");
    AGps = get_agps_interface(Gps);
    if (AGps)
    {
	fprintf(stdout, "*** set up agps interface\n");
	AGps->init(&callbacks2);
	fprintf(stdout, "*** set up agps server\n");
	AGps->set_server(AGPS_TYPE_SUPL, "supl.google.com", 7276);
	fprintf(stdout, "*** Trying to open connection\n");
	AGps->data_conn_open(AGPS_TYPE_ANY, "internet", AGPS_APN_BEARER_IPV4V6);
    }

    fprintf(stdout, "*** get agps ril interface\n");

    AGpsRil = get_agps_ril_interface(Gps);
    if (AGpsRil)
    {
	AGpsRil->init(&callbacks3);
    }

    /* if coldstart is requested, delete all location info */
    if(coldstart)
    {
      fprintf(stdout, "*** delete aiding data\n");
      Gps->delete_aiding_data(GPS_DELETE_ALL);
    }
    
    if(extra)
    {
      fprintf(stdout, "*** xtra aiding data init\n");
      GpsExtra = get_gps_extra_interface(Gps);
      if(GpsExtra)
        GpsExtra->init(&callbacks5);
    }

    fprintf(stdout, "*** setting up network notification handling\n");
    GpsNi = get_gps_ni_interface(Gps);
    if(GpsNi)
    {
      GpsNi->init(&callbacks4);
    }
  }

  UlpNetwork = get_ulp_network_interface(Gps);
  if (UlpNetwork) {
    fprintf(stdout, "*** got ulp network interface\n");
    if (UlpNetwork->init(&callbacks6) != 0) {
      fprintf(stdout, "*** FAILED to init ulp network interface\n");
      UlpNetwork = NULL;
    }
  }

  UlpPhoneContext = get_ulp_phone_context_interface(Gps);
  if (UlpPhoneContext) {
    fprintf(stdout, "*** got ulp phone context interface\n");
    UlpPhoneContext->init(&callbacks7);
  }

  if(injecttime)
  {
    fprintf(stdout, "*** aiding gps by injecting time information\n");
    gettimeofday(&tv, NULL);
    Gps->inject_time(tv.tv_sec, tv.tv_sec, 0);
  }

  fprintf(stdout, "*** start gps track\n");
  Gps->start();

  fprintf(stdout, "*** gps tracking started\n");

  while(sleeptime > 0)
  {
    fprintf(stdout, "*** tracking.... \n");
    sleep(100);
    sleeptime = sleeptime - 100;
  }

  fprintf(stdout, "*** stop tracking\n");
  Gps->stop();
  fprintf(stdout, "*** cleaning up\n");
  Gps->cleanup();

  return 0;
}