示例#1
0
int				parsing(t_env *data)
{
	char	*line;
	int		ret;

	line = NULL;
	while (!(data->ants))
		get_ants(data, line);
	while ((ret = get_next_line(0, &line)))
	{
		if (!check_line(&line, data))
		{
			if (!can_start(data))
				parsing_error(data, line);
			ft_strdel(&line);
			ft_putchar('\n');
			return (solve(data));
		}
		ft_putendl(line);
		ft_strdel(&line);
	}
	if (ret == -1)
		ft_error("read");
	ft_putchar('\n');
	if (!can_start(data))
		parsing_error(data, line);
	return (solve(data));
}
示例#2
0
errval_t default_start_function(coreid_t where,
                                struct module_info* mi,
                                char* record)
{
    assert(mi != NULL);
    errval_t err = SYS_ERR_OK;
    coreid_t core;
    /*
     *  XXX: there may be more device using this driver, so starting it a second time
     *       may be needed.
     */
    if (!can_start(mi)) {
        return KALUGA_ERR_DRIVER_ALREADY_STARTED;
    }

    core = where + get_core_id_offset(mi);

    if (!is_auto_driver(mi)) {
        return KALUGA_ERR_DRIVER_NOT_AUTO;
    }

    // Construct additional command line arguments containing pci-id.
    // We need one extra entry for the new argument.
    uint64_t vendor_id, device_id, bus, dev, fun;
    char **argv = mi->argv;
    bool cleanup = false;

    err = oct_read(record, "_ { bus: %d, device: %d, function: %d, vendor: %d, device_id: %d }",
                    &bus, &dev, &fun, &vendor_id, &device_id);

    if (err_is_ok(err)) {
        // We assume that we're starting a device if the query above succeeds
        // and therefore append the pci vendor and device id to the argument
        // list.
        argv = malloc((mi->argc+1) * sizeof(char *));
        memcpy(argv, mi->argv, mi->argc * sizeof(char *));
        char *pci_id = malloc(26);
        // Make sure pci vendor and device id fit into our argument
        assert(vendor_id < 0x9999 && device_id < 0x9999);
        snprintf(pci_id, 26, "%04"PRIx64":%04"PRIx64":%04"PRIx64":%04"
                        PRIx64":%04"PRIx64, vendor_id, device_id, bus, dev, fun);

        argv[mi->argc] = pci_id;
        argv[mi->argc+1] = NULL;
        cleanup = true;
    }
    err = spawn_program(core, mi->path, argv,
                    environ, 0, get_did_ptr(mi));

    if (err_is_fail(err)) {
        DEBUG_ERR(err, "Spawning %s failed.", mi->path);
    }
    if (cleanup) {
        // alloc'd string is the last of our array
        free(argv[mi->argc]);
        free(argv);
    }

    return err;
}
示例#3
0
void start_game() {
  if (!can_start()) {
    fprintf(stderr, "Couldn't start the game (not all players are online)\n");
    return;
  }

  save_state();
  server_message_t msg = { 0, { GAME_START }};
  broadcast_message(&msg);
  printf("Game has started!\n");
  start_resources_production();
}
示例#4
0
文件: lemipc.c 项目: noelq/EpiHistory
void		wait_for_player(t_ipc *my_ipc)
{
  t_map		*info;

  printf("[console] You got 20 second to conect some player\n");
  sleep(20);
  while (!can_start(info))
    {
      printf("[console] You got 10 second to adjust the team\n");
      printf("[console] there is %d players in team 1\n", info->nb_team1);
      printf("[console] there is %d players in team 2\n", info->nb_team2);
      sleep(10);
      info = get_info(my_ipc);
    }
  printf("[console] game is ready to begin");
  free(info);
}
示例#5
0
/*
* Show CAN errors as text, 
* in case of Bus-Off, try to recover
*/
static void displayerror(int device, canmsg_t *rx)
{
/* static int buffcnt = 0; */

	fprintf(stderr, "Flags 0x%02x,", rx->flags);
	if( 0 == (rx->flags & MSG_ERR_MASK)) {
		fprintf(stderr, " CAN Error Free");
	}
	if( rx->flags & MSG_WARNING) {
		fprintf(stderr, " CAN Warning Level,");
	}
	if( rx->flags & MSG_PASSIVE) {
		fprintf(stderr, " CAN Error Passive,");
	}
	if( rx->flags & MSG_BUSOFF) {
		fprintf(stderr, " CAN Bus Off,");
		can_reset(fd[device]);
		/* sleep 100ms */
		usleep (100000);
		can_start(fd[device]);
	}
	/* printf("\n"); */
}
示例#6
0
文件: cop_api.c 项目: mangOH/Demos
LONG cop_init(LONG board, LPVOID param, BYTE baudrate)
{
	// 1. Exit CAN if initialized or running
	if((cop_error = can_exit()) != CANERR_NOERROR)
	{
		//return cop_error;
	}
	// 2. Init CAN, operation status = initialized
	if((cop_error = can_init(board, param)) != CANERR_NOERROR)
	{
		can_exit();						// on error: exit CAN
		return cop_error;
	}
	// 3. Start CAN, operation status = running
	if((cop_error = can_start(baudrate)) != CANERR_NOERROR)
	{
		can_reset();					// on error: reset CAN
		can_exit();						//           exit CAN
		return cop_error;
	}
	cop_baudrate = baudrate;			// actual baudrate
	return cop_error;
}
示例#7
0
文件: cop_api.c 项目: mangOH/Demos
LONG cop_reset(BYTE baudrate)
{
	// 1. Reset CAN, operation status = stopped
	if((cop_error = can_reset()) != CANERR_NOERROR)
	{
		return cop_error;
	}
	// 2. Wait 100 milliseconds to continue
#if defined(_WIN32)
	Sleep(100);
#elif defined(__linux__)
	usleep(100000);
#else
	can_start_timer(100); while(!can_is_timeout()) {}
#endif
	// 3. Start CAN, operation status = running
	if((cop_error = can_start(baudrate)) != CANERR_NOERROR)
	{
		can_reset();					// on error: reset CAN
		return cop_error;
	}
	cop_baudrate = baudrate;			// actual baudrate
	return cop_error;
}