int main(int argc, char **argv)
{
	catcierge_rfid_t rfidin;
	catcierge_rfid_t rfidout;
	catcierge_rfid_context_t ctx;

	catcierge_rfid_ctx_init(&ctx);

	catcierge_rfid_init("Inner", &rfidin, "/dev/ttyUSB0", rfid_read_cb, NULL);
	catcierge_rfid_ctx_set_inner(&ctx, &rfidin);
	catcierge_rfid_open(&rfidin);
	catcierge_rfid_init("Outer", &rfidout, "/dev/ttyUSB1", rfid_read_cb, NULL);
	catcierge_rfid_ctx_set_outer(&ctx, &rfidout);
	catcierge_rfid_open(&rfidout);

	while (1)
	{
		catcierge_rfid_ctx_service(&ctx);
		sleep(1);
	}

	catcierge_rfid_destroy(&rfidin);
	catcierge_rfid_destroy(&rfidout);
	catcierge_rfid_ctx_destroy(&ctx);

	return 0;
}
Пример #2
0
char *run_double_tests()
{
	char *return_message = NULL;
	int in_master = 0;
	int in_slave = 0;
	int out_master = 0;
	int out_slave = 0;
	char *in_slave_name = NULL;
	char *out_slave_name = NULL;
	int ret;
	char *e = NULL;
	ssize_t bytes_read;

	// Create inner pseudo terminal.
	{
		ret = openpty(&in_master, &in_slave, NULL, NULL, NULL);
		mu_assertf("Failed to create inner pseudo terminal", ret == 0);
	
		in_slave_name = strdup(ttyname(in_slave));
		mu_assertf("Failed to get inner slave name", in_slave_name);
		catcierge_test_STATUS("Inner slave tty: %s\n", in_slave_name);
	}

	// Create outer pseudo terminal.
	{
		ret = openpty(&out_master, &out_slave, NULL, NULL, NULL);
		mu_assertf("Failed to create outer pseudo terminal", ret == 0);

		out_slave_name = strdup(ttyname(out_slave));
		mu_assertf("Failed to get outer slave name", out_slave_name);
		catcierge_test_STATUS("Outer slave tty: %s\n", out_slave_name);
	}

	// Init RFID contexts.
	{
		catcierge_rfid_context_t ctx;
		catcierge_rfid_t rfidin;
		catcierge_rfid_t rfidout;

		catcierge_rfid_ctx_init(&ctx);

		catcierge_rfid_init("Test inner", &rfidin, in_slave_name, rfid_read_cb, NULL); 
		catcierge_rfid_ctx_set_inner(&ctx, &rfidin);
		catcierge_rfid_open(&rfidin);

		catcierge_rfid_init("Test inner", &rfidout, out_slave_name, rfid_read_cb, NULL);
		catcierge_rfid_ctx_set_outer(&ctx, &rfidout);
		catcierge_rfid_open(&rfidout);

		// TODO: Do some more tests here.
		catcierge_rfid_ctx_service(&ctx);

		catcierge_rfid_destroy(&rfidin);
		catcierge_rfid_destroy(&rfidout);
		catcierge_rfid_ctx_destroy(&ctx);	
	}

cleanup:
	if (in_master) close(in_master);
	if (out_master) close(out_master);
	if (in_slave) close(in_slave);
	if (out_slave) close(out_slave);

	if (out_slave_name) free(out_slave_name);
	if (in_slave_name) free(in_slave_name);

	return return_message;	
}
Пример #3
0
char *run_rfid_tests()
{
	int master;
	int slave;
	char *slave_name = NULL;
	int ret;
	char *e = NULL;
	ssize_t bytes_read;

	ret = openpty(&master, &slave, NULL, NULL, NULL);
	mu_assert("Failed to create pseudo terminal", ret == 0);

	slave_name = strdup(ttyname(slave));
	mu_assert("Failed to get slave name", slave_name);
	catcierge_test_STATUS("Slave tty: %s\n", slave_name);

	// Test OK RAT.
	{
		catcierge_rfid_context_t ctx;
		catcierge_rfid_t rfidin;
		init_rfid_stuff(&ctx, &rfidin, slave_name);

		catcierge_rfid_ctx_service(&ctx);
		mu_assert("Expected RFID state == CAT_CONNECTED",
			rfidin.state == CAT_CONNECTED);

		if ((e = read_rfid_master(&ctx, master, "Expected RAT", "RAT\r\n")))
			return e;

		write_rfid_master(master, "OK\r\n");
		catcierge_rfid_ctx_service(&ctx);
		mu_assert("Expected RFID state == CAT_AWAITING_TAG",
			rfidin.state == CAT_AWAITING_TAG);

		write_rfid_master(master, EXAMPLE_RFID_STR"\r\n");
		catcierge_rfid_ctx_service(&ctx);

		catcierge_rfid_destroy(&rfidin);
		catcierge_rfid_ctx_destroy(&ctx);

		catcierge_test_SUCCESS("Test OK RAT\n");
	}

	// Test failed RAT.
	{
		catcierge_rfid_context_t ctx;
		catcierge_rfid_t rfidin;
		init_rfid_stuff(&ctx, &rfidin, slave_name);

		catcierge_rfid_ctx_service(&ctx);
		mu_assert("Expected RFID state == CAT_CONNECTED",
			rfidin.state == CAT_CONNECTED);

		if ((e = read_rfid_master(&ctx, master, "Expected RAT", "RAT\r\n")))
			return e;

		write_rfid_master(master, "?1\r\n");
		catcierge_rfid_ctx_service(&ctx);
		mu_assert("Expected RFID state == CAT_AWAITING_TAG",
			rfidin.state == CAT_AWAITING_TAG);

		catcierge_rfid_destroy(&rfidin);
		catcierge_rfid_ctx_destroy(&ctx);

		catcierge_test_SUCCESS("Test failed RAT\n");
	}

	close(master);
	close(slave);
	free(slave_name);

	return NULL;
}
Пример #4
0
int main(int argc, char **argv)
{
	catcierge_args_t *args = &grb.args;

	fprintf(stderr, "\nCatcierge Grabber v" CATCIERGE_VERSION_STR " (" CATCIERGE_GIT_HASH_SHORT "");

	// Was this built with changes in the git sources?
	#ifdef CATCIERGE_GIT_TAINTED
	fprintf(stderr, "-tainted");
	#endif

	fprintf(stderr, ")\n(C) Joakim Soderberg 2013-2016\n\n");

	fprintf(stderr, "Library versions:\n");
	fprintf(stderr, " OpenCV v%d.%d.%d\n", CV_MAJOR_VERSION, CV_MINOR_VERSION, CV_SUBMINOR_VERSION);
	#ifdef WITH_ZMQ
	fprintf(stderr, "   CZMQ v%d.%d.%d\n", CZMQ_VERSION_MAJOR, CZMQ_VERSION_MINOR, CZMQ_VERSION_PATCH);
	#endif
	fprintf(stderr, "\n");

	// TODO: Enable specifying pid path on command line.
	#ifndef _WIN32
	pid_fd = create_pid_file(argv[0], PID_PATH, FD_CLOEXEC);
	#endif

	if (catcierge_grabber_init(&grb))
	{
		fprintf(stderr, "Failed to init\n");
		return -1;
	}

	if (catcierge_args_init(args, argv[0]))
	{
		fprintf(stderr, "Failed to init args\n");
		return -1;
	}

	if (catcierge_args_parse(args, argc, argv))
	{
		return -1;
	}

	if (args->nocolor)
	{
		catcierge_nocolor = 1;
	}

	catcierge_print_settings(args);

	setup_sig_handlers();

	if (args->log_path)
	{
		if (!(grb.log_file = fopen(args->log_path, "a+")))
		{
			CATERR("Failed to open log file \"%s\"\n", args->log_path);
		}
	}

	#ifdef RPI
	if (catcierge_setup_gpio(&grb))
	{
		CATERR("Failed to setup GPIO pins\n");
		return -1;
	}

	CATLOG("Initialized GPIO pins\n");
	#endif // RPI

	assert((args->matcher_type == MATCHER_TEMPLATE)
		|| (args->matcher_type == MATCHER_HAAR));

	if (catcierge_matcher_init(&grb.matcher, catcierge_get_matcher_args(args)))
	{
		CATERR("Failed to init %s matcher\n", grb.matcher->name);
		return -1;
	}

	CATLOG("Initialized catcierge image recognition\n");

	if (catcierge_output_init(&grb, &grb.output))
	{
		CATERR("Failed to init output template system\n");
		return -1;
	}

	if (catcierge_output_load_templates(&grb.output,
			args->inputs, args->input_count))
	{
		CATERR("Failed to load output templates\n");
		return -1;
	}

	CATLOG("Initialized output templates\n");

	#ifdef WITH_RFID
	catcierge_init_rfid_readers(&grb);
	#endif

	catcierge_setup_camera(&grb);

	#ifdef WITH_ZMQ
	catcierge_zmq_init(&grb);
	#endif

	CATLOG("Starting detection!\n");
	// TODO: Create a catcierge_grb_start(grb) function that does this instead.
	catcierge_fsm_start(&grb);

	// Run the program state machine.
	do
	{
		if (!catcierge_timer_isactive(&grb.frame_timer))
		{
			catcierge_timer_start(&grb.frame_timer);
		}

		// Always feed the RFID readers.
		#ifdef WITH_RFID
		if ((args->rfid_inner_path || args->rfid_outer_path) 
			&& catcierge_rfid_ctx_service(&grb.rfid_ctx))
		{
			CATERRFPS("Failed to service RFID readers\n");
		}
		#endif // WITH_RFID

		grb.img = catcierge_get_frame(&grb);

		catcierge_run_state(&grb);
		catcierge_print_spinner(&grb);
	} while (
		grb.running
		#ifdef WITH_ZMQ
		&& !zctx_interrupted
		#endif
		);

	catcierge_matcher_destroy(&grb.matcher);
	catcierge_output_destroy(&grb.output);
	catcierge_destroy_camera(&grb);
	#ifdef WITH_ZMQ
	catcierge_zmq_destroy(&grb);
	#endif
	catcierge_grabber_destroy(&grb);
	catcierge_args_destroy(&grb.args);

	if (grb.log_file)
	{
		fclose(grb.log_file);
	}

	#ifndef _WIN32
	if (pid_fd > 0)
	{
		close(pid_fd);
		unlink(PID_PATH);
	}
	#endif

	return 0;
}