コード例 #1
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::setImageSettings(Mode mode, PixelFormat format, 
					  unsigned int offsetX, unsigned int offsetY, unsigned int width, unsigned int height) {
    imgSettings.mode = mode;
    imgSettings.offsetX = 0;
    imgSettings.offsetY = 0;
    imgSettings.width = width;
    imgSettings.height = height;
    imgSettings.pixelFormat = format;

	bool valid;
    Format7PacketInfo fmt7PacketInfo;

    // Validate the settings to make sure that they are valid
    error = cam.ValidateFormat7Settings(&imgSettings, &valid, &fmt7PacketInfo);
    TEST_ERR(error);

	if ( !valid )
    {
        // Settings are not valid
		printf("Format7 settings are not valid\n");
        return false;
    }

	// Set the settings to the camera
    error = cam.SetFormat7Configuration(&imgSettings, fmt7PacketInfo.recommendedBytesPerPacket);
    TEST_ERR(error);

	return true;
}
コード例 #2
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::connectToCamera() {
	Error error;

	BusManager busMgr;
    unsigned int numCameras;
    error = busMgr.GetNumOfCameras(&numCameras);
    TEST_ERR(error);

    printf( "Number of PGR cameras detected: %u\n", numCameras );

    if ( numCameras < 1 )
    {
        printf( "Insufficient number of cameras... exiting\n" );
        return false;
    }

    PGRGuid guid;
    error = busMgr.GetCameraFromIndex(0, &guid);
    TEST_ERR(error);

    // Connect to a camera
    error = cam.Connect(&guid);
    TEST_ERR(error);

	return true;
}
コード例 #3
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::captureImage(Image &img) {
	// Retrieve an image
    error = cam.RetrieveBuffer( &img );
    TEST_ERR(error);

	return true;
}
コード例 #4
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::stopCapture() {
	// Stop capturing images
    error = cam.StopCapture();
    TEST_ERR(error);

	return true;
}
コード例 #5
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::startCapture(unsigned int frameRate) {
	//set the correct frame rate
	Property frProp;
    frProp.type = FRAME_RATE;
	frProp.absControl = true;
	frProp.onOff = true;
	frProp.absValue = (float) frameRate;
	error = cam.SetProperty(&frProp, false);
	TEST_ERR(error);

	// Start capturing images
    error = cam.StartCapture();
    TEST_ERR(error);

	return true;
}
コード例 #6
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::disconnectCamera() {
	// Disconnect the camera
	Error error;
    error = cam.Disconnect();
    TEST_ERR(error);

	return true;
}
コード例 #7
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::setGain(float gain) {
	//set the correct frame rate
	Property frProp;
	frProp.type = FlyCapture2::GAIN;
	frProp.absControl = true;
	frProp.onOff = false;
	frProp.absValue = gain;
	error = cam.SetProperty(&frProp, false);
	TEST_ERR(error);

	return true;
}
コード例 #8
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::setShutterSpeed(float shutterMillis) {
	//set the correct frame rate
	Property frProp;
    frProp.type = SHUTTER;
	frProp.absControl = true;
	frProp.onOff = true;
	frProp.absValue = (float) shutterMillis;
	error = cam.SetProperty(&frProp, false);
	TEST_ERR(error);

	return true;
}
コード例 #9
0
ファイル: sipreg.c プロジェクト: traviscross/libre-test
static int reg_test(enum sip_transp tp)
{
    struct test test;
    struct sip_server *srv = NULL;
    struct sipreg *reg = NULL;
    struct sip *sip = NULL;
    char reg_uri[256];
    int err;

    memset(&test, 0, sizeof(test));
    test.tp = tp;

    err = sip_server_alloc(&srv);
    if (err)
        goto out;

    err = sipstack_fixture(&sip);
    if (err)
        goto out;

    err = sip_server_uri(srv, reg_uri, sizeof(reg_uri), tp);
    if (err)
        goto out;

    err = sipreg_register(&reg, sip, reg_uri,
                          "sip:x@test",
                          "sip:x@test",
                          3600, "x", NULL, 0, 0, NULL, NULL, false,
                          sip_resp_handler, &test, NULL, NULL);
    if (err)
        goto out;

    err = re_main_timeout(800);
    if (err)
        goto out;

    TEST_ERR(test.err);

    TEST_ASSERT(srv->n_register_req > 0);
    TEST_ASSERT(test.n_resp > 0);

out:
    mem_deref(reg);

    sip_close(sip, true);
    mem_deref(sip);

    mem_deref(srv);

    return err;
}
コード例 #10
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::printCapabilities() {
	// Query for available Format 7 modes
	Error error;
    Format7Info fmt7Info;
    bool supported;
    fmt7Info.mode = imgSettings.mode;
    error = cam.GetFormat7Info( &fmt7Info, &supported );
    TEST_ERR(error);

    printf(
        "Max image pixels: (%u, %u)\n"
        "Image Unit size: (%u, %u)\n"
        "Offset Unit size: (%u, %u)\n"
        "Pixel format bitfield: 0x%08x\n",
        fmt7Info.maxWidth,
        fmt7Info.maxHeight,
        fmt7Info.imageHStepSize,
        fmt7Info.imageVStepSize,
        fmt7Info.offsetHStepSize,
        fmt7Info.offsetVStepSize,
        fmt7Info.pixelFormatBitField );
	return true;
}
コード例 #11
0
ファイル: PGRCamera.cpp プロジェクト: TLadd/SeniorDesign
bool PGRCamera::printInfo() {
	// Get the camera information
    CameraInfo camInfo;
    error = cam.GetCameraInfo(&camInfo);
    TEST_ERR(error);

    printf(
        "\n*** CAMERA INFORMATION ***\n"
        "Serial number - %u\n"
        "Camera model - %s\n"
        "Camera vendor - %s\n"
        "Sensor - %s\n"
        "Resolution - %s\n"
        "Firmware version - %s\n"
        "Firmware build time - %s\n\n",
        camInfo.serialNumber,
        camInfo.modelName,
        camInfo.vendorName,
        camInfo.sensorInfo,
        camInfo.sensorResolution,
        camInfo.firmwareVersion,
        camInfo.firmwareBuildTime );
	return true;
}
コード例 #12
0
ファイル: fio.c プロジェクト: Paul-Reed/daemon
int main(int ac, char **av)
{
	const char * const fifoname = "./fio.fifo";
	const char * const filename = "./fio.file";
	const mode_t mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
	FILE *file;
	char line[BUFSIZ];
	const int lock = 1;
	int errors = 0;
	int fd, wfd;

	if (ac == 2 && !strcmp(av[1], "help"))
	{
		printf("usage: %s\n", *av);
		return EXIT_SUCCESS;
	}

	printf("Testing: %s\n", "fio");

	umask(0);

	if ((fd = fifo_open(fifoname, mode, lock, &wfd)) == -1)
	{
		++errors, printf("Test1: fifo_open(\"%s\", %d, %d) failed (%s)\n", fifoname, (int)mode, lock, strerror(errno));
#ifndef HAVE_FCNTL_THAT_CAN_LOCK_FIFOS
		printf("\n      Can your system lock fifos?\n\n");
#endif
	}
	else
	{
		if ((fcntl_lock(fd, F_SETLK, F_WRLCK, SEEK_SET, 0, 0)) != -1)
			++errors, printf("Test2: fcntl_lock(wrlock) failed\n");

		/* Should really test that the following non-blocking changes do occur */

		if (nonblock_on(fd) == -1)
			++errors, printf("Test3: nonblock_on() failed (%s)\n", strerror(errno));

		if (nonblock_off(fd) == -1)
			++errors, printf("Test4: nonblock_off() failed (%s)\n", strerror(errno));

		if (fcntl_set_flag(fd, O_NONBLOCK) == -1)
			++errors, printf("Test5: fcntl_set_flag() failed (%s)\n", strerror(errno));

		if (fcntl_clear_flag(fd, O_NONBLOCK) == -1)
			++errors, printf("Test6: fcntl_clear_flag() failed (%s)\n", strerror(errno));

		close(fd);
		close(wfd);
		unlink(fifoname);
	}

#define CHECK_FGETLINE(i, size, expected) \
	if ((expected) && !fgetline(line, (size), file)) \
		++errors, printf("Test%d: fgetline() failed\n", (i)); \
	else if ((expected) && strcmp(line, ((expected) ? (expected) : ""))) \
		++errors, printf("Test%d: fgetline() read \"%s\", not \"%s\"\n", (i), line, (expected ? expected : "(null)"));

#define TEST_FGETLINE(i, buf, size, contents, line1, line2, line3) \
	if (!(file = fopen(filename, "wb"))) \
		++errors, printf("Test%d: failed to run test: failed to create test file\n", (i)); \
	else \
	{ \
		if (fwrite((contents), 1, strlen(contents), file) != strlen(contents)) \
			++errors, printf("Test%d: failed to run test: failed to write to test file\n", (i)); \
		else \
		{ \
			fclose(file); \
			if (!(file = fopen(filename, "r"))) \
				++errors, printf("Test%d: failed to run test: failed to open test file for reading\n", (i)); \
			else \
			{ \
				CHECK_FGETLINE((i), (size), (line1)) \
				CHECK_FGETLINE((i), (size), (line2)) \
				CHECK_FGETLINE((i), (size), (line3)) \
				if (fgetline(buf, BUFSIZ, file)) \
					++errors, printf("Test%d: fgetline() failed to return NULL at end of file\n", (i)); \
			} \
		} \
		fclose(file); \
		unlink(filename); \
	}

	TEST_FGETLINE(7, line, BUFSIZ, "abc\ndef\r\nghi\r", "abc\n", "def\n", "ghi\n")
	TEST_FGETLINE(8, line, BUFSIZ, "abc\rdef\nghi\r\n", "abc\n", "def\n", "ghi\n")
	TEST_FGETLINE(9, line, BUFSIZ, "abc\r\ndef\rghi\n", "abc\n", "def\n", "ghi\n")
	TEST_FGETLINE(10, line, BUFSIZ, "abc\ndef\rghi", "abc\n", "def\n", "ghi")
	TEST_FGETLINE(11, line, BUFSIZ, "", (char *)NULL, (char *)NULL, (char *)NULL)
	TEST_FGETLINE(12, line, 5, "abc", "abc", (char *)NULL, (char *)NULL)
	TEST_FGETLINE(13, line, 5, "abc\n", "abc\n", (char *)NULL, (char *)NULL)
	TEST_FGETLINE(14, line, 5, "abc\r\n", "abc\n", (char *)NULL, (char *)NULL)
	TEST_FGETLINE(15, line, 5, "abc\r", "abc\n", (char *)NULL, (char *)NULL)
	TEST_FGETLINE(16, line, 3, "abc\r", "ab", "c\n", (char *)NULL)
	TEST_FGETLINE(17, NULL, 0, "abc\r", (char *)NULL, (char *)NULL, (char *)NULL)

	/* Test read_timeout() and write_timeout() */

	if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, S_IRUSR | S_IWUSR)) == -1)
		++errors, printf("Test19: failed to create %s (%s)\n", filename, strerror(errno));
	else
	{
		char buf[12] = "0123456789\n";

		if (write_timeout(fd, 1, 0) == -1)
			++errors, printf("Test18: write_timeout(fd, 1, 0) failed (%s)\n", strerror(errno));
		else if (write(fd, buf, 11) != 11)
			++errors, printf("Test18: write(fd, \"0123456789\\n\", 11) failed (%s)\n", strerror(errno));
		else
		{
			close(fd);

			if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) == -1)
				++errors, printf("Test19: failed to open %s for reading (%s)\n", filename, strerror(errno));
			else if (read_timeout(fd, 1, 0) == -1)
				++errors, printf("Test19: read_timeout(fd, 1, 0) failed (%s)\n", strerror(errno));
			else if (read(fd, buf, 11) != 11)
				++errors, printf("Test19: read(fd) failed (%s)\n", strerror(errno));
		}

		close(fd);
	}

	unlink(filename);

	/* Test error handling */

#define TEST_ERR(i, func) \
	if ((func) != -1) \
		++errors, printf("Test%d: %s failed to return -1\n", (i), (#func)); \
	else if (errno != EINVAL) \
		++errors, printf("Test%d: %s failed (errno = %s, not %s)\n", (i), (#func), strerror(errno), strerror(EINVAL));

	TEST_ERR(20, read_timeout(-1, 0, 0))
	TEST_ERR(21, read_timeout(0, -1, 0))
	TEST_ERR(22, read_timeout(0, 0, -1))
	TEST_ERR(23, write_timeout(-1, 0, 0))
	TEST_ERR(24, write_timeout(0, -1, 0))
	TEST_ERR(25, write_timeout(0, 0, -1))
	TEST_ERR(26, rw_timeout(-1, 0, 0))
	TEST_ERR(27, rw_timeout(0, -1, 0))
	TEST_ERR(28, rw_timeout(0, 0, -1))
	TEST_ERR(29, nap(-1, 0))
	TEST_ERR(30, nap(0, -1))

	if (errors)
		printf("%d/30 tests failed\n", errors);
	else
		printf("All tests passed\n");

#ifndef HAVE_FCNTL_THAT_CAN_LOCK_FIFOS
	printf("\n");
	printf("    Note: Some systems (e.g. FreeBSD) can't lock fifos so fifo_open()\n");
	printf("    can't guarantee a unique reader.\n");
#endif

	return (errors == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
コード例 #13
0
ファイル: stun.c プロジェクト: traviscross/libre-test
static int test_stun_request(int proto, bool natted)
{
	struct stunserver *srv = NULL;
	struct stun_ctrans *ct = NULL;
	struct nat *nat = NULL;
	struct test test;
	struct sa laddr, public_addr;
	int err;

	memset(&test, 0, sizeof(test));

	err = stunserver_alloc(&srv);
	if (err)
		goto out;

	err = stun_alloc(&test.stun, NULL, NULL, NULL);
	if (err)
		goto out;

	if (proto == IPPROTO_UDP) {
		err = sa_set_str(&laddr, "127.0.0.1", 0);
		TEST_ERR(err);

		err = udp_listen(&test.us, &laddr, udp_recv_handler, &test);
		if (err)
			goto out;
		err = udp_local_get(test.us, &laddr);
		TEST_ERR(err);
	}

	if (natted) {
		err = sa_set_str(&public_addr, "4.5.6.7", 0);
		TEST_ERR(err);

		err = nat_alloc(&nat, srv->us, &public_addr);
		if (err)
			goto out;

		sa_set_port(&public_addr, sa_port(&laddr));
	}
	else {
		public_addr = laddr;
	}

	err = stun_request(&ct, test.stun, proto, test.us,
			   stunserver_addr(srv, proto), 0,
			   STUN_METHOD_BINDING, NULL, 0, true,
			   stun_resp_handler, &test, 0);
	if (err)
		goto out;

	TEST_ASSERT(ct != NULL);

	err = re_main_timeout(100);
	if (err)
		goto out;

	if (srv->err) {
		err = srv->err;
		goto out;
	}
	if (test.err) {
		err = test.err;
		goto out;
	}

	/* verify results */
	TEST_ASSERT(srv->nrecv >= 1);
	TEST_EQUALS(1, test.n_resp);

	if (proto == IPPROTO_UDP) {
		TEST_SACMP(&public_addr, &test.mapped_addr, SA_ALL);
	}

 out:
	mem_deref(test.stun);
	mem_deref(test.us);
	mem_deref(nat);
	mem_deref(srv);

	return err;
}