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;
}
Beispiel #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;	
}
Beispiel #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;
}