Exemple #1
0
int
main (void)
{
    uart0_init ();

    while (1)
        proto_accept (uart0_getc ());
}
Exemple #2
0
int
main (void)
{
    spi_init (SPI_MASTER, SPI_MODE_0, SPI_MSB_FIRST, SPI_FOSC_DIV128);
    uart0_init ();
    sei ();
    proto_send0 ('z');
    while (1)
	proto_accept (uart0_getc ());
}
Exemple #3
0
int
main (int argc, char **argv)
{
    avr_init (argc, argv);
    sei ();
    uart0_init ();
    proto_send0 ('z');
    while (1)
    {
        uint8_t c = uart0_getc ();
        proto_accept (c);
    }
}
Exemple #4
0
int
main (void)
{
    uint8_t i;
#ifndef HOST
    uint8_t read_old = 0;
    uint8_t old_ind = 0;
    const int total = 5000;
#endif
    timer_init ();
    for (i = 0; i < AC_ENCODER_EXT_NB; i++)
	encoder_init (i, &encoder[i]);
    encoder_corrector_init (&encoder_corrector_right);
    uart0_init ();
    proto_send0 ('z');
    sei ();
    while (1)
      {
	timer_wait ();
	if (count)
	  {
	    encoder_update ();
	    encoder_corrector_update (&encoder_corrector_right, &encoder[1]);
	  }
#ifndef HOST
	if (read && !--read_cpt)
	  {
	    uint8_t r0, r1, r2, r3;
	    r0 = encoder_ext_read (0);
	    r1 = encoder_ext_read (1);
	    r2 = encoder_ext_read (2);
	    r3 = encoder_ext_read (3);
	    if (read_mode == 0 || (read_mode == 1 && r3 != read_old)
		|| (read_mode == 2
		    && (r0 == 0 || r1 == 0 || r2 == 0 || r3 == 0)))
	      {
		proto_send4b ('r', r0, r1, r2, r3);
		read_old = r3;
	      }
	    read_cpt = read;
	  }
	if (ind && !--ind_cpt)
	  {
	    i = encoder_ext_read (3);
	    if (!ind_init && i != old_ind)
	      {
		uint8_t eip = old_ind + total;
		uint8_t eim = old_ind - total;
		proto_send7b ('i', old_ind, i, eip, eim, i - eip, i - eim,
			      i == eip || i == eim);
	      }
	    old_ind = i;
	    ind_init = 0;
	    ind_cpt = ind;
	  }
#endif
	if (count && !--count_cpt)
	  {
	    proto_send4w ('C', encoder[0].cur, encoder[1].cur,
			  encoder[2].cur, encoder[3].cur);
	    count_cpt = count;
	  }
	while (uart0_poll ())
	    proto_accept (uart0_getc ());
      }
}
Exemple #5
0
static int
tls_accept(void *ctx, void **newctxp)
{
	struct tls_ctx *tlsctx = ctx;
	struct tls_ctx *newtlsctx;
	struct proto_conn *sock, *tcp;
	pid_t pid;
	int error;

	PJDLOG_ASSERT(tlsctx != NULL);
	PJDLOG_ASSERT(tlsctx->tls_magic == TLS_CTX_MAGIC);
	PJDLOG_ASSERT(tlsctx->tls_side == TLS_SIDE_SERVER_LISTEN);

	if (proto_connect(NULL, "socketpair://", -1, &sock) == -1)
		return (errno);

	/* Accept TCP connection. */
	if (proto_accept(tlsctx->tls_tcp, &tcp) == -1) {
		error = errno;
		proto_close(sock);
		return (error);
	}

	pid = fork();
	switch (pid) {
	case -1:
		/* Failure. */
		error = errno;
		proto_close(sock);
		return (error);
	case 0:
		/* Child. */
		pjdlog_prefix_set("[TLS sandbox] (server) ");
#ifdef HAVE_SETPROCTITLE
		setproctitle("[TLS sandbox] (server) ");
#endif
		/* Close listen socket. */
		proto_close(tlsctx->tls_tcp);
		tls_call_exec_server(sock, tcp);
		/* NOTREACHED */
		PJDLOG_ABORT("Unreachable.");
	default:
		/* Parent. */
		newtlsctx = calloc(1, sizeof(*tlsctx));
		if (newtlsctx == NULL) {
			error = errno;
			proto_close(sock);
			proto_close(tcp);
			(void)kill(pid, SIGKILL);
			return (error);
		}
		proto_local_address(tcp, newtlsctx->tls_laddr,
		    sizeof(newtlsctx->tls_laddr));
		PJDLOG_ASSERT(strncmp(newtlsctx->tls_laddr, "tcp://", 6) == 0);
		bcopy("tls://", newtlsctx->tls_laddr, 6);
		*strrchr(newtlsctx->tls_laddr, ':') = '\0';
		proto_remote_address(tcp, newtlsctx->tls_raddr,
		    sizeof(newtlsctx->tls_raddr));
		PJDLOG_ASSERT(strncmp(newtlsctx->tls_raddr, "tcp://", 6) == 0);
		bcopy("tls://", newtlsctx->tls_raddr, 6);
		*strrchr(newtlsctx->tls_raddr, ':') = '\0';
		proto_close(tcp);
		proto_recv(sock, NULL, 0);
		newtlsctx->tls_sock = sock;
		newtlsctx->tls_tcp = NULL;
		newtlsctx->tls_wait_called = true;
		newtlsctx->tls_side = TLS_SIDE_SERVER_WORK;
		newtlsctx->tls_magic = TLS_CTX_MAGIC;
		*newctxp = newtlsctx;
		return (0);
	}
}
Exemple #6
0
/** Main (and infinite) loop. */
static void
main_loop (void)
{
    while (1)
      {
	/* Wait until next cycle. */
	timer_wait ();
	/* Update chrono. */
	chrono_update ();
	/* Is match over? */
	if (chrono_is_match_over ())
	  {
	    /* Power off doors. */
	    pwm_set (BOT_PWM_DOOR_FRONT_BOTTOM, 0);
	    pwm_set (BOT_PWM_DOOR_FRONT_TOP, 0);
	    pwm_set (BOT_PWM_DOOR_BACK_BOTTOM, 0);
	    pwm_set (BOT_PWM_DOOR_BACK_TOP, 0);
	    pwm_set (BOT_PWM_CLAMP, 0);
	    /* End it and block here indefinitely. */
	    chrono_end_match (42);
	    return;
	  }
	/* Handle commands from UART. */
	while (uart0_poll ())
	    proto_accept (uart0_getc ());
	/* Update IO modules. */
	pwm_update ();
	contact_update ();
	pawn_sensor_update ();
	if (usdist_update ())
	  {
	    position_t robot_pos;
	    asserv_get_position (&robot_pos);
	    main_obstacles_nb = radar_update (&robot_pos, main_obstacles_pos);
	    move_obstacles_update ();
	    simu_send_pos_report (main_obstacles_pos, main_obstacles_nb, 0);
	  }
	/* Update AI modules. */
	logistic_update ();
	path_decay ();
	/* Only manage events if slaves are synchronised. */
	if (twi_master_sync ())
	    main_event_to_fsm ();
	/* Send stats if requested. */
	if (main_stats_asserv_ && !--main_stats_asserv_cpt_)
	  {
	    /* Get current position */
	    position_t cur_pos;
	    asserv_get_position (&cur_pos);
	    /* Send stats */
	    proto_send3w ('A', cur_pos.v.x, cur_pos.v.y, cur_pos.a);
	    /* Reset stats counter */
	    main_stats_asserv_cpt_ = main_stats_asserv_;
	  }
	if (main_stats_contact_ && !--main_stats_contact_cpt_)
	  {
	    proto_send1d ('P', contact_all () | (uint32_t) mimot_get_input () << 24);
	    main_stats_contact_cpt_ = main_stats_contact_;
	  }
	if (main_stats_codebar_ && !--main_stats_codebar_cpt_)
	  {
	    proto_send2b ('B', codebar_get (DIRECTION_FORWARD),
			  codebar_get (DIRECTION_BACKWARD));
	    main_stats_codebar_cpt_ = main_stats_codebar_;
	  }
	if (main_stats_usdist_ && !--main_stats_usdist_cpt_)
	  {
	    proto_send4w ('U', usdist_mm[0], usdist_mm[1], usdist_mm[2],
			  usdist_mm[3]);
	    main_stats_usdist_cpt_ = main_stats_usdist_;
	  }
      }
}