Ejemplo n.º 1
0
FILE *reinit_timer(FILE *port, char *name, int config, int lanes_expected)
{
	FILE *fd;
	char tmp[LINE_LEN];
	int lanes;

	printf("Wow, something's messed with your timer. Let's try again.\n");
	close_timer(port);
	printf("Please power cycle your timer.\n");
	printf("If you have a USB timer, just unplug it, wait a few seconds, and reconnect\n");
	printf("it to the SAME port.\n");
	printf("\nWhen you're done, press Enter and we'll try to get reconnected.\n");
retry:
	fgets(tmp, LINE_LEN, stdin);
	printf("Opening port.\n");
	fd = open_timer(name, config);
	if (!fd) {
		printf("Eek! Unable to open timer port! Please power cycle it again.\n");
		printf("Double-check that you plugged your USB timer into the same port!\n");
		printf("Press Enter to try again. (Ctrl-C to give up - you will lose all results.)\n");
		goto retry;
	}
	/* reset timer */
	lanes = init_timer(fd);
	if (lanes != lanes_expected) {
		close_timer(fd);
		printf("Eek! Invalid number of lanes! (Expected %d, got %d from timer.\n", lanes_expected, lanes);
		printf("Please power cycle your timer again and check all sensor connections.\n");
		printf("Press Enter to try again. (Ctrl-C to give up - you will lose all results.)\n");
		goto retry;
	}
	return fd;
}
Ejemplo n.º 2
0
int connector::connect_handler(file_io&, int type) {
    int n;
    socklen_t len;

    if (type & reactor::poll_close) {
        _fd.close();
        return fail;
    }

    if (type & (reactor::poll_out | reactor::poll_err)) {
        close_timer();

        len = sizeof(int);
        ll_sys_failed_return(getsockopt(_fd, SOL_SOCKET, SO_ERROR, &n, &len));

        if (n || (type & reactor::poll_err)) {
            if (ll_ok(do_emit(_fd, reactor::poll_err))) {
                if (_interval) {
                    _timer = _timermgr->schedule(_conntime + _interval, &connector::timer_handler, this);
                    return fail;
                }
            }
            return fail;
        } 
        else {
            _timer = _timermgr->idle(&connector::connect_ready, this);
            return ok;
        }
    }

    return ok;
}
Ejemplo n.º 3
0
void connector::close()
{
    if (!_emitting) {
        if (_fd.opened()) {
            _reactor->close(_fd);
        }
        close_timer();
    }
}
Ejemplo n.º 4
0
void tcpudp_act_cyc(uint8_t cycact)
{
	switch (cycact)
	{
		case 0:
			tcpip_flag_ = 0;
			close_timer();
			break;
		case 1:
			tcpip_flag_ = 1;
			open_timer();
			break;
		default:
			break;
	}
}
Ejemplo n.º 5
0
/* lua call spec:
Success:  status(true), nil = timer:start(timeout)
Failure:  status(false), error message = timer:start(timeout)
*/
static int start_user_timer(lua_State* l_thread) {
    LUA_GET_TIMER_OR_ERROR(l_thread, 1, timer);

    if (timer->state != INIT) {
        /* Timer is already started by another lua thread */
        return error_to_lua(l_thread, "Timer already in use by another thread");
    }

    int timeout = lua_tointeger(l_thread, 2);
    if (timeout <= 0) {
        return error_to_lua(l_thread, "Invalid timeout value %d specified", timeout);
    }

    int rc = uv_timer_start(&timer->handle, on_user_timer_timeout, timeout, 0);
    if (rc) {
        close_timer(timer);
        return error_to_lua(l_thread, "Error starting timer: %s", uv_strerror(rc));
    }

    timer->state = TICKING;
    lua_pushboolean(l_thread, 1);
    return 1;
}
Ejemplo n.º 6
0
LUA_OBJ_METHOD static int timer_gc(lua_State *L) {
    LUA_GET_TIMER_OR_RETURN(L, 1, timer);
    close_timer(timer);
    return 0;
}
Ejemplo n.º 7
0
LUA_OBJ_METHOD static int close_timer_lua(lua_State* l_thread) {
    LUA_GET_TIMER_OR_RETURN(l_thread, 1, timer);
    close_timer(timer);
    return 0;
}
Ejemplo n.º 8
0
/**
 * @brief Parses command line options and implements application logic
 *
 * @param argc number of arguments in the command line
 * @param argv table with command line argument strings
 *
 * @return Process exit code
 */
int main(int argc, char *argv[])
{
        const long long freq_nanosecs = freq_ms * 1000LL * 1000LL;
	int core_id, lock_data = 1, exit_val = EXIT_SUCCESS;

        if (argc < 3) {
                printf("Usage: %s <core_id> <lock|nolock>\n", argv[0]);
                exit(EXIT_FAILURE);
        }

        if (strcasecmp(argv[2], "nolock") != 0 &&
            strcasecmp(argv[2], "lock") != 0) {
                printf("Invalid data lock setting '%s'!\n", argv[2]);
                printf("Usage: %s <core_id> <lock|nolock>\n", argv[0]);
                exit(EXIT_FAILURE);
        }

        core_id = atoi(argv[1]);
        lock_data = (strcasecmp(argv[2], "nolock") == 0) ? 0 : 1;

        /* allocate memory blocks */
        main_data_ptr = init_memory(main_data_size);
        timer_data_ptr = init_memory(timer_data_size);
        if (main_data_ptr == NULL || timer_data_ptr == NULL) {
                exit_val = EXIT_FAILURE;
                goto error_exit1;
        }

        if (lock_data) {
                /* initialize PQoS and lock the data */
                if (init_pqos() != 0) {
                        exit_val = EXIT_FAILURE;
                        goto error_exit1;
                }

                /* lock the timer data */
                if (dlock_init(timer_data_ptr,
                               timer_data_size, 1 /* CLOS */, core_id) != 0) {
                        printf("Pseudo data lock error!\n");
                        exit_val = EXIT_FAILURE;
                        goto error_exit1;
                }
        }

        tsc_init(&timer_prof, "Timer Handler");

        if (init_timer(freq_nanosecs) != 0) {
                printf("Timer start error!\n");
                exit_val = EXIT_FAILURE;
                goto error_exit2;
        }

        main_thread((char *)main_data_ptr, main_data_size);

        (void) close_timer();

        tsc_print(&timer_prof);

 error_exit2:
        if (lock_data)
                dlock_exit();

 error_exit1:
        if (lock_data)
                (void) close_pqos();

        if (main_data_ptr != NULL)
                free(main_data_ptr);
        if (timer_data_ptr != NULL)
                free(timer_data_ptr);
	return exit_val;
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
	FILE *port;
	char *filename;
	int c, i, j, tmp;
	int debugmode = 0;
	int lanes;
    float times[MAX_LANES];
	float prev_times[MAX_LANES][4];
    int prev_head = 0;\
	char *tmpbuf[10];
    
	/* parse command line options */
	if (argc == 1) {
		usage();
		return 0;
	}

	opterr = 0;
	while ((c = getopt (argc, argv, "dp:")) != -1) {
		switch (c) {
		case 'd':
			printf("Debugging mode enabled\n");
			debugmode = 1;
			break;
		case 'p':
			filename = optarg;
			break;
		case '?':
		default:
			usage();
			return 1;
		}
	}

	/* open timer */
	port = open_timer(filename, !debugmode);
	if (!port) {
		fprintf(stderr, "Eek! Unable to open timer port! Cannot continue.\n");
		fprintf(stderr, "Possible problems:\n");
		fprintf(stderr, "\tbad filename for port (if USB timer, check dmesg for port id\n");
		fprintf(stderr, "\tno write access to device (check permissions or run as root)\n");
		fprintf(stderr, "\tUSB timer not connected\n");
		return 1;
	}
	/* reset timer */
	lanes = init_timer(port);
	if (!lanes) {
		fprintf(stderr, "Eek! Cannot initialize timer! Cannot continue!\n");
		fprintf(stderr, "Make sure your timer is supported by this program.\n");
		close_timer(port);
		return 1;
	}

	memset(prev_times, 0, sizeof(float) * 3 * MAX_LANES);
    printf("Press enter to continue.\n");
    fgets(tmpbuf, 10, stdin);

	/* main loop */
	while (1) {
		printf("Begin racing when ready.\n");
		tmp = get_times(port, lanes, times, debugmode);
		printf("Run is complete. Results:\n");
		if (tmp > 0) {
			/* good race! */
            display_winner(tmp);
            printf("\n");
            // save current time, drop last time
            display_times(lanes, times);
			for (j = 0; j < lanes; j++) {
                prev_times[j][prev_head] = times[j];
			}
			printf("\nPrevious results:\n");
            i = prev_head - 1;
            if (i < 0)
                i = 3;
            while (i != prev_head) {
                for (j = 0; j < lanes; j++)
                    printf("\t%1.4f", prev_times[j][i]);
                printf("\n");
                i--;
                if (i < 0)
                    i = 3;
            }

            prev_head++;
            if (prev_head == 4)
                prev_head = 0;
		}
		if (tmp == 0) {
			printf("Null race result! Please redo this run.\n");
		}
		if (tmp < 0) {
			port = reinit_timer(port, filename, !debugmode, lanes);
			/* if this returns, we've succeeded */
		}
        printf("Press enter to continue, X to exit.\n");
		fgets(tmpbuf, 10, stdin);
        if (strchr(tmpbuf, 'x') || strchr(tmpbuf, 'X'))
			break;
		rearm_timer(port, debugmode);
	}

	/* all done */
	printf("\nDone.\n");
	close_timer(port);
	return 0;
}