static void startup()
{	
	location_init();
	loc = location_new(LOCATION_METHOD_GPS);

	loop = g_main_loop_new(NULL,FALSE);		
	g_main_loop_run (loop);

	tet_printf("\n TC startup");	
}
int
main (int argc, char *argv[])
{
	LocationObject *loc = NULL;
	
	location_init ();

	loop = g_main_loop_new (NULL, TRUE);

	loc  = location_new (LOCATION_METHOD_GPS);
	if (!loc) {
		g_debug("location_new failed");
		return -1;
	}

	LocationPosition *rb = location_position_new(0, 37.258, 127.056, 0, LOCATION_STATUS_2D_FIX);
	LocationPosition *lt = location_position_new(0, 37.260, 127.054, 0, LOCATION_STATUS_2D_FIX);
	LocationBoundary *bound = location_boundary_new_for_rect(lt, rb);
	location_position_free (rb);
	location_position_free (lt);
	if (bound) {
		g_object_set(loc, "boundary", bound, NULL);
		location_boundary_free(bound);
	} else g_warning("failed to location_boundary_new_for_rect()");	
	g_object_get(loc, "boundary", &bound, NULL);
	if (bound) {
		g_debug("Set property>> boundary> type: %d, (%f,%f),(%f,%f)", 
			bound->type,
			bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude,
			bound->rect.left_top->latitude, bound->rect.left_top->longitude);
		location_boundary_free (bound);
	} else 	g_warning("failed to set property> boundary");

	g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
	g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
	g_signal_connect (loc, "zone-in", G_CALLBACK(cb_zone_in), loc);
	g_signal_connect (loc, "zone-out", G_CALLBACK(cb_zone_out), loc);
	
	if( LOCATION_ERROR_NONE != location_start (loc) ){
		g_debug("location_start failed");
		return -1;
	}

	g_timeout_add_seconds (60, exit_program, NULL);
	g_main_loop_run (loop);

	location_stop (loc);
	location_free (loc);

	return 0;
}
示例#3
0
文件: prog10.c 项目: CARLEYBR/Classes
Location location_rand(Grid grid) {
    debug("Looking up random location");
    int y = 0;
    while (y == 0) {
        y = grid->height * ((float) rand() / (float) RAND_MAX);
    }
    
    int x = 0;
    while (x == 0) {
        x = grid->width * ((float) rand() / (float) RAND_MAX);
    }
    debug("Random location at %d,%d", x, y);

    return location_new(x, y);
}
static void startup()
{
	location_init();
	loc = location_new(LOCATION_METHOD_GPS);
	tet_printf("\n TC startup");
}
示例#5
0
文件: prog10.c 项目: CARLEYBR/Classes
Segment segment_new(Worm worm) {
    Segment retval = malloc(sizeof(struct _Segment));
    
    Node iterator = worm->front;
    Node prev = NULL;
    int i = 0;
    int xdirection = -1;
    int ydirection = 0;
    
    
    while (iterator != NULL) {
        Segment last = (Segment) iterator->data;

        if (prev != NULL) {
            Segment prevseg = (Segment) prev->data;
            if (prevseg->location->y > last->location->y) {
                ydirection = -1;
            }
            else {
                ydirection = 1;
            }
        }

        if (iterator->next == NULL) {
            iterator->next = ll_new(retval);

            int remaining = (worm->size - i);

            // Is there enough space?
            if (last->location->x > 1) {
                retval->location = location_new(last->location->x + xdirection, last->location->y);
            }
            else if (last->location->x < remaining + 1) { // Need more room.
                if (ydirection == 0) { // Have no direction
                    if (last->location->y + 1> remaining) {
                        ydirection = -1;
                    }
                    else {
                        ydirection = 1;
                    }
                }
                retval->location = location_new(last->location->x, last->location->y + ydirection);
            }

            debug("Created segment at %d,%d", retval->location->x, retval->location->y);
            move(retval->location->y, retval->location->x);
            addch('*');
            refresh();
            usleep(PAUSE);
            
            return retval;
        }
        
        prev = iterator;
        iterator = iterator->next;
        i++;
    }
    
    if (worm->front == NULL) {
        worm->front = ll_new(retval);
        retval->location = location_rand(worm->grid);
    }

    debug("Created segment at %d,%d", retval->location->x, retval->location->y);
    
    mvaddch(retval->location->y, retval->location->x, '*');
    refresh();
    usleep(PAUSE);

    return retval;
}
int main(int argc, char** argv)
{
	char strOpt[255];
	int ret;
	char str[STR_MAX];
	GError *gerr = NULL;

	// If application is executed by AUL, this is not needed.
	g_setenv("PKG_NAME", "com.samsung.location-api-test", 1);

	g_type_init();

#if !GLIB_CHECK_VERSION (2, 31, 0)
	if( !g_thread_supported() )
	{
		g_thread_init(NULL);
	}
#endif

	GThread *g_main;
	g_main = g_thread_create(GmainThread, NULL, TRUE, &gerr);
	if (!g_main) {
		g_printf("Error create gmain thread: Err domain[%d] Err code[%d] Err msg[%s]",
			gerr->domain, gerr->code, gerr->message);
		g_error_free(gerr);
		return 0;
	}

	json_util_init(LOCATION_API_TEST_JSON_FILE);
	g_printf("--- Start LBS Test App ---\n");
	while(1)
	{
		print_menu();
		g_printf("Select option: ");
		SelectOpt(strOpt);
		g_printf("======================================================================================\n");
		if (0 == g_strcmp0 ("x", strOpt)) {

		}
		else if (0 == g_strcmp0("1",strOpt)) {
			ret = location_init();
			GetLocationError(str, ret);
			g_printf("location_init: returned value [%s]\n", str);
		} else if (0 == g_strcmp0("2",strOpt)) {
			if (location_obj) {
				g_printf("Location object already existed: [0x%x]", (unsigned int)location_obj);
				continue;
			}
			g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_CPS[3]\n");
			g_printf("Select Location Method: ");
			LocationMethod method = PromptInt();
			location_obj = location_new(method);
			if(location_obj) g_printf("Success\n");
			else             g_printf("Failed\n");
		} else if (0 == g_strcmp0("3",strOpt)) {
			ret = location_free (location_obj);
			location_obj = NULL;

			g_sig_enable = 0;
			g_sig_disable = 0;
			g_sig_update = 0;
			g_sig_zonein = 0;
			g_sig_zoneout = 0;
			GetLocationError(str, ret);
			g_printf("location_free: returned value [%s]\n", str);
		} else if (0 == g_strcmp0("4",strOpt)) {
			ret = location_start(location_obj);
			GetLocationError(str, ret);
			g_printf("location_start: returned value [%s]\n", str);
		} else if (0 == g_strcmp0("5",strOpt)) {
			ret = location_stop(location_obj);
			GetLocationError(str, ret);
			g_printf("location_stop: returned value [%s]\n", str);
		} else if (0 == g_strcmp0("6",strOpt)) {
			LocationPosition *pos = NULL;
			LocationAccuracy *acc = NULL;
			ret = location_get_position(location_obj, &pos, &acc);
			GetLocationError(str, ret);
			g_printf("location_get_position: returned value [%s]\n", str);
			if (ret == LOCATION_ERROR_NONE) {
				g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f], status: [%d]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
				GetAccuracyLevel(str, acc->level);
				g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
			}
			if(pos) location_position_free(pos);
			if(acc) location_accuracy_free(acc);
		} else if (0 == g_strcmp0("6a",strOpt)) {
			LocationPosition *last_pos;
			LocationAccuracy *last_acc;
			int ret = 0;

			ret = location_get_last_position (location_obj, &last_pos, &last_acc);
			GetLocationError(str, ret);
			if (ret == LOCATION_ERROR_NONE) {
				g_printf ("SYNC>> Last position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
					last_pos->timestamp, last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->status);
				g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)",
					last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
				location_position_free(last_pos);
				location_accuracy_free(last_acc);
			} else g_warning ("SYNC>> Last position> failed. Error[%s]",str);

		}else if(0 == g_strcmp0("7",strOpt) ){
			LocationVelocity *vel = NULL;
			LocationAccuracy *acc = NULL;
			ret = location_get_velocity(location_obj, &vel, &acc);
			g_printf("location_get_velocity: returned value [%s]\n", str);
			if (ret == LOCATION_ERROR_NONE) {
				g_printf("time: [%d], speed: [%f], direction: [%f], climb: [%f]\n", vel->timestamp, vel->speed, vel->direction, vel->climb);
				GetAccuracyLevel(str, acc->level);
				g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
			}
			else {
				GetLocationError(str, ret);
				g_warning ("SYNC>> velocity> failed. Error[%s]", str);
			}
			if(vel) location_velocity_free(vel);
			if(acc) location_accuracy_free(acc);
		}else if(0 == g_strcmp0("7a",strOpt) ){
			LocationVelocity *last_vel = NULL;
			LocationAccuracy *last_acc = NULL;
			ret = location_get_last_velocity (location_obj, &last_vel, &last_acc);
			GetLocationError(str, ret);
			if (ret == LOCATION_ERROR_NONE) {
				g_printf ("SYNC>> Last velocity> time: %d, speed: %f, direction:%f, climb:%f",
					last_vel->timestamp, last_vel->speed, last_vel->direction, last_vel->climb);
				g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)",
					last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
				location_velocity_free(last_vel);
				location_accuracy_free(last_acc);
			} else g_warning ("SYNC>> Last velocity> failed. Error[%s]", str);
		}else if(0 == g_strcmp0("8",strOpt) ){
			int ret = 0, idx = 0;
			LocationSatellite *sat = NULL;
			guint prn;
			gboolean used;
			guint elevation;
			guint azimuth;
			gint snr;

			ret =  location_get_satellite (location_obj, &sat);
			GetLocationError(str, ret);
			if (ret == LOCATION_ERROR_NONE) {
				g_printf ("SYNC>> Current Sattelite> time = %d, satellite in view = %d, satellite in used = %d", sat->timestamp, sat->num_of_sat_inview, sat->num_of_sat_used);
				g_printf ("\tinview satellite information = ");
				for (idx=0; idx<sat->num_of_sat_inview; idx++) {
					location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
					g_printf ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
				}
				location_satellite_free (sat);
			} else g_warning ("SYNC>> Current satellite> failed. Error[%s]", str);
		}else if(0 == g_strcmp0("8a",strOpt) ){
			int ret = 0, idx = 0;
			LocationSatellite *last_sat = NULL;
			guint prn;
			gboolean used;
			guint elevation;
			guint azimuth;
			gint snr;

			ret = location_get_last_satellite (location_obj, &last_sat);
			GetLocationError(str, ret);
			if (ret == LOCATION_ERROR_NONE) {
				g_printf ("SYNC>> Last Sattelite> time = %d, satellite in view = %d, satellite in used = %d", last_sat->timestamp, last_sat->num_of_sat_inview, last_sat->num_of_sat_used);
				g_printf ("\tinview satellite information = ");
				for (idx=0; idx<last_sat->num_of_sat_inview; idx++) {
					location_satellite_get_satellite_details(last_sat, idx, &prn, &used, &elevation, &azimuth, &snr);
					g_printf ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
				}
				location_satellite_free (last_sat);
			} else g_warning ("SYNC>> Last satellite> failed. Error[%s]", str);
		}else if(0 == g_strcmp0("9",strOpt) ) {

			gulong distance;
			int ret = 0;
			char str[STR_MAX];
			LocationPosition pos1, pos2;

			pos1.latitude = 50.0663222;
			pos1.longitude = -5.71475;

			pos2.latitude = 58.6441;
			pos2.longitude = -3.070094;

			ret = location_get_distance(&pos1, &pos2, &distance);
			GetLocationError(str, ret);
			if(ret != LOCATION_ERROR_NONE) {
					g_printf("Fail to get position. Error[%s]\n", str);
			}
			else {
					g_printf("The approximate distance is [%lu]\n", distance);
					g_printf("cf.) It is approximately 969954.114 meter\n");
			}
		}else if(0 == g_strcmp0("10", strOpt)) {
			int method;
			char method_str[STR_MAX] = {0, };
			char input[8] = {0, };
			gboolean is_supported = FALSE;

			g_printf("0.Hybrid 1.GPS 2.WPS 3.CPS\n");
			g_printf("Select Method :");
			fgets(input, 8, stdin);
			method = atoi(input);
			switch(method) {
				case LOCATION_METHOD_HYBRID:
					is_supported = location_is_supported_method(LOCATION_METHOD_HYBRID);
					break;

				case LOCATION_METHOD_GPS:
					is_supported = location_is_supported_method(LOCATION_METHOD_GPS);
					break;

				case LOCATION_METHOD_WPS:
					is_supported = location_is_supported_method(LOCATION_METHOD_WPS);
					break;

				case LOCATION_METHOD_CPS:
					is_supported = location_is_supported_method(LOCATION_METHOD_CPS);
					break;

				default:
					break;

			}
			GetMethod(method_str, method);

			g_printf("Method[%s] is %s.", method_str, is_supported ? "supported" : "not supported");

		}else if(0 == g_strcmp0("11", strOpt)) {
			gboolean is_enabled = FALSE;
			is_enabled = location_is_enabled_gps(location_obj);
			if(is_enabled == TRUE) g_printf("GPS is turned on");
			else g_printf("GPS is turned off");
		}else if(0 == g_strcmp0("99", strOpt)) {
			int ret = 0;
			const *str = "command";
			ret = location_send_command(str);
			if(ret == 0)
				g_printf("Success to send command[%s]", str);
		}else if(0 == g_strcmp0("a1",strOpt)){
			if(location_obj && !g_sig_enable) {
				g_sig_enable = g_signal_connect (location_obj, "service-enabled", G_CALLBACK(cb_service_enabled), location_obj);
			}
		}else if(0 == g_strcmp0("a2",strOpt)){
			if(location_obj && !g_sig_disable){
				g_sig_disable = g_signal_connect (location_obj, "service-disabled", G_CALLBACK(cb_service_disabled), location_obj);
			}
		}else if(0 == g_strcmp0("a3",strOpt)){
			if(location_obj && !g_sig_update){
				g_sig_update = g_signal_connect (location_obj, "service-updated", G_CALLBACK(cb_service_updated), location_obj);
			}
		}else if(0 == g_strcmp0("a4",strOpt)){
			if(location_obj && !g_sig_zonein){
				g_sig_zonein = g_signal_connect (location_obj, "zone-in", G_CALLBACK(cb_zone_in), location_obj);
			}
		}else if(0 == g_strcmp0("a5",strOpt)){
			if(location_obj && !g_sig_zoneout){
				g_sig_zoneout = g_signal_connect (location_obj, "zone-out", G_CALLBACK(cb_zone_out), location_obj);
			}
		}else if(0 == g_strcmp0("b1",strOpt)){
			if(location_obj && g_sig_enable) {
				g_signal_handler_disconnect (location_obj, g_sig_enable);
				g_sig_enable = 0;
			}
		}else if(0 == g_strcmp0("b2",strOpt)){
			if(location_obj && g_sig_disable){
				g_signal_handler_disconnect (location_obj, g_sig_disable);
				g_sig_disable = 0;
			}
		}else if(0 == g_strcmp0("b3",strOpt)){
			if(location_obj && g_sig_update){
				g_signal_handler_disconnect (location_obj, g_sig_update);
				g_sig_update = 0;
			}
		}else if(0 == g_strcmp0("b4",strOpt)){
			if(location_obj && g_sig_zonein){
				g_signal_handler_disconnect (location_obj, g_sig_zonein);
				g_sig_zonein = 0;
			}
		}else if(0 == g_strcmp0("b5",strOpt)){
			if(location_obj && g_sig_zoneout){
				g_signal_handler_disconnect (location_obj, g_sig_zoneout);
				g_sig_zoneout = 0;
			}
		}else if(0 == g_strcmp0("c1",strOpt)){
			LocationBoundary* bound = NULL;
			int i = 0;
			int polygon_count = json_util_get_polygon_count();

			g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
			for(i = 0; i < polygon_count; i++)
				g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));

			g_printf("\nSelect Boundary: ");
			int opt = PromptInt();
			if (opt == 0) {
				LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
				LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
				bound = location_boundary_new_for_rect (lt, rb);
				location_position_free(rb);
				location_position_free(lt);

				location_boundary_add(location_obj, bound);

			} else if(opt == 1) {
				LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
				LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
				bound = location_boundary_new_for_rect (lt, rb);
				location_position_free(rb);
				location_position_free(lt);

				location_boundary_add(location_obj, bound);
			} else if(opt == 2) {
				LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
				double radius = 10.0;
				bound = location_boundary_new_for_circle(center, radius);

				location_boundary_add(location_obj, bound);
			} else if (opt > 2 && opt < 3 + polygon_count) {
				int index;
				int polygon_index = opt - 3;
				bound = json_util_get_polygon_boundary(polygon_index);
				location_boundary_add(location_obj, bound);

				LocationPosition * check_pos = NULL;
				gboolean ret = FALSE;
				int count = json_util_get_marker_position_count(polygon_index);
				for(index = 0; index < count; index++) {
					check_pos = json_util_get_marker_position(polygon_index, index);

					ret = location_boundary_if_inside(bound, check_pos);
					g_printf("[%s] is [%s] and the test result is [%s]\n", json_util_get_marker_name(polygon_index, index), json_util_result_zone_test(polygon_index, index), ret == TRUE? "inside": "outside");
					location_position_free(check_pos);
				}
			} else {
				g_printf("boundary is not set\n");
			}
			location_boundary_free(bound);

		}else if(0 == g_strcmp0("c2",strOpt)){
			g_printf("Get Boundary\n");
			location_boundary_foreach(location_obj, PrintBoundary, NULL);

		}else if(0 == g_strcmp0("c3",strOpt)){
			g_printf("Remove Boundary\n");
			LocationBoundary* bound = NULL;

			int i = 0;
			int polygon_count = json_util_get_polygon_count();

			g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
			for(i = 0; i < polygon_count; i++)
				g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));

			g_printf("\nSelect Boundary: ");
			int opt = PromptInt();
			if (opt == 0) {
				LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
				LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
				bound = location_boundary_new_for_rect (lt, rb);
				location_position_free(rb);
				location_position_free(lt);

			} else if(opt == 1) {
				LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
				LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
				bound = location_boundary_new_for_rect (lt, rb);
				location_position_free(rb);
				location_position_free(lt);

			} else if(opt == 2) {
				LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
				double radius = 10.0;
				bound = location_boundary_new_for_circle(center, radius);
				location_position_free(center);

			} else if (opt > 2 && opt < 3 + polygon_count) {
				int polygon_index = opt - 3;
				bound = json_util_get_polygon_boundary(polygon_index);
			} else {
				g_printf("Invalid value\n");
			}

			if(bound != NULL) location_boundary_remove(location_obj, bound);

		}else if(0 == g_strcmp0("c4",strOpt)){
			location_boundary_foreach(location_obj, RemoveBoundary, location_obj);
		}else if(0 == g_strcmp0("c5",strOpt)){
			char buf[255];
			g_printf("Input device name: ");
			fgets(buf, 255, stdin);
			buf[strlen(buf)-1]='\0';
			g_object_set(location_obj, "dev-name", buf, NULL);
		} else if (0 == g_strcmp0("c6", strOpt)) {
			guint interval = 1;
			g_printf("Input interval[1~120]:");
			scanf("%u", &interval);
			g_printf("changed interval to [%u]\n", interval);
			g_object_set(location_obj, "pos-interval", interval, NULL);
		} else if (0 == g_strcmp0("c7", strOpt)) {
			guint interval = 1;
			g_printf("Input interval[1~120]:");
			scanf("%u", &interval);
			g_printf("changed interval to [%u]\n", interval);
			g_object_set(location_obj, "vel-interval", interval, NULL);
		} else if (0 == g_strcmp0("c8", strOpt)) {
			guint interval = 1;
			g_printf("Input interval[1~120]:");
			scanf("%u", &interval);
			g_printf("changed interval to [%u]\n", interval);
			g_object_set(location_obj, "sat-interval", interval, NULL);
		}else if(0 == g_strcmp0("q",strOpt) ){
			g_main_loop_quit(g_mainloop);
			break;
		}
	}
	g_thread_join(g_main);
	g_printf("\n--- Exit LBS Test App ---\n");
	return 1;
}