Esempio n. 1
0
void mesh_init_from_cfg(tetmesh *mesh,mcconfig *cfg){
        mesh_init(mesh);
        mesh_loadnode(mesh,cfg);
        mesh_loadelem(mesh,cfg);
        mesh_loadfaceneighbor(mesh,cfg);
        mesh_loadmedia(mesh,cfg);
        mesh_loadelemvol(mesh,cfg);
	if(cfg->seed==SEED_FROM_FILE && cfg->seedfile[0]){
          mesh_loadseedfile(mesh,cfg);
        }
}
Esempio n. 2
0
bool wireless_init(void)
{
    mesh_driver_t driver;
    driver.app_recv   = nrf_driver_app_recv;
    driver.radio_init = nrf_driver_init;
    driver.radio_recv = nrf_driver_receive;
    driver.radio_send = nrf_driver_send;
    driver.get_timer  = nrf_driver_get_timer;

    /* Don't send broadcast message because node address may be changed by user after init() */
    return mesh_init(WIRELESS_NODE_ADDR, true, WIRELESS_NODE_NAME, driver, false);
}
Esempio n. 3
0
int main() {
	/* Enable the change of clock prescaler */
	CLKPR = (1 << CLKPCE);
	/* Within 4 clock cycles change the prescaler */
	CLKPR = (0 << CLKPS0 |
		 0 << CLKPS1 |
		 0 << CLKPS2 |
		 0 << CLKPS3);

	uart_init();
	systick_init();
	mesh_init(1);
	printf("Sink init!\n");
	/* unsigned long p_delay = systick; */
	for(;;){
		mesh_poll(systick);
		/* if(NRF24_get_register(0x09)){ */
		/* 	printf("."); */
		/* } */
		/* as(CONFIG,     0x0B); */
		/* as(EN_AA,      0x3F); */
		/* as(EN_RXADDR,  0x23); */
		/* as(SETUP_AW,   0x03); */
		/* as(SETUP_RETR, 0x35); */
		/* as(RF_CH,      0x78); */
		/* as(RF_SETUP,   0x27); */
		/* as(STATUS,     0x0E); */
		/* as(DYNPD,      0x00); */
		/* as(FEATURE,    0x01); */
		/* as(FIFO_STATUS,0x11); */
		/* as(RX_PW_P5,   0x10); */
		/* as(RX_ADDR_P5, 0xff); */
		/* if((systick - p_delay) > 10000){ */
		/* 	NRF24_print_registers(); */
		/* 	p_delay = systick; */
		/* } */
		/* printf("test %d %lu\n", mesh_is_connected(), systick); */
		_delay_ms(5);
	}
	return 0;
}
Esempio n. 4
0
int main(int argc, char **argv) {
	int exit_code = EXIT_FAILURE;
	int i;
	bool help = false;
	bool version = false;
	bool check_config = false;
	bool daemon = false;
	const char *debug_filter = NULL;
	int pid_fd = -1;
#ifdef BRICKD_WITH_LIBUDEV
	bool initialized_udev = false;
#endif

	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "--help") == 0) {
			help = true;
		} else if (strcmp(argv[i], "--version") == 0) {
			version = true;
		} else if (strcmp(argv[i], "--check-config") == 0) {
			check_config = true;
		} else if (strcmp(argv[i], "--daemon") == 0) {
			daemon = true;
		} else if (strcmp(argv[i], "--debug") == 0) {
			if (i + 1 < argc && strncmp(argv[i + 1], "--", 2) != 0) {
				debug_filter = argv[++i];
			} else {
				debug_filter = "";
			}
		} else {
			fprintf(stderr, "Unknown option '%s'\n\n", argv[i]);
			print_usage();

			return EXIT_FAILURE;
		}
	}

	if (help) {
		print_usage();

		return EXIT_SUCCESS;
	}

	if (version) {
		printf("%s\n", VERSION_STRING);

		return EXIT_SUCCESS;
	}

	if (prepare_paths() < 0) {
		return EXIT_FAILURE;
	}

	if (check_config) {
		return config_check(_config_filename) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
	}

	config_init(_config_filename);

	if (config_has_error()) {
		fprintf(stderr, "Error(s) occurred while reading config file '%s'\n",
		        _config_filename);

		goto error_config;
	}

	log_init();

	if (daemon) {
		pid_fd = daemon_start(_log_filename, &_log_file, _pid_filename, true);
	} else {
		pid_fd = pid_file_acquire(_pid_filename, getpid());

		if (pid_fd == PID_FILE_ALREADY_ACQUIRED) {
			fprintf(stderr, "Already running according to '%s'\n", _pid_filename);
		}
	}

	if (pid_fd < 0) {
		goto error_pid_file;
	}

	log_info("Brick Daemon %s started (pid: %u, daemonized: %d)",
	         VERSION_STRING, getpid(), daemon ? 1 : 0);

	if (debug_filter != NULL) {
		log_enable_debug_override(debug_filter);
	}

	if (config_has_warning()) {
		log_warn("Warning(s) in config file '%s', run with --check-config option for details",
		         _config_filename);
	}

	if (event_init() < 0) {
		goto error_event;
	}

	if (signal_init(handle_sighup, handle_sigusr1) < 0) {
		goto error_signal;
	}

	if (hardware_init() < 0) {
		goto error_hardware;
	}

	if (usb_init() < 0) {
		goto error_usb;
	}

#ifdef BRICKD_WITH_LIBUDEV
	if (!usb_has_hotplug()) {
		if (udev_init() < 0) {
			goto error_udev;
		}

		initialized_udev = true;
	}
#endif

	if (network_init() < 0) {
		goto error_network;
	}

	if (mesh_init() < 0) {
		goto error_mesh;
	}

#ifdef BRICKD_WITH_RED_BRICK
	if (gpio_init() < 0) {
		goto error_gpio;
	}

	if (redapid_init() < 0) {
		goto error_redapid;
	}

	if (red_stack_init() < 0) {
		goto error_red_stack;
	}

	if (red_extension_init() < 0) {
		goto error_red_extension;
	}

	if (red_usb_gadget_init() < 0) {
		goto error_red_usb_gadget;
	}

	red_led_set_trigger(RED_LED_GREEN, config_get_option_value("led_trigger.green")->symbol);
	red_led_set_trigger(RED_LED_RED, config_get_option_value("led_trigger.red")->symbol);
#endif

	if (event_run(network_cleanup_clients_and_zombies) < 0) {
		goto error_run;
	}

#ifdef BRICKD_WITH_RED_BRICK
	hardware_announce_disconnect();
	network_announce_red_brick_disconnect();
	red_usb_gadget_announce_red_brick_disconnect();
#endif

	exit_code = EXIT_SUCCESS;

error_run:
#ifdef BRICKD_WITH_RED_BRICK
	red_usb_gadget_exit();

error_red_usb_gadget:
	red_extension_exit();

error_red_extension:
	red_stack_exit();

error_red_stack:
	redapid_exit();

error_redapid:
	//gpio_exit();

error_gpio:
#endif
	network_exit();

error_mesh:
	mesh_exit();

error_network:
#ifdef BRICKD_WITH_LIBUDEV
	if (initialized_udev) {
		udev_exit();
	}

error_udev:
#endif
	usb_exit();

error_usb:
	hardware_exit();

error_hardware:
	signal_exit();

error_signal:
	event_exit();

error_event:
	log_info("Brick Daemon %s stopped", VERSION_STRING);

error_pid_file:
	if (pid_fd >= 0) {
		pid_file_release(_pid_filename, pid_fd);
	}

	log_exit();

error_config:
	config_exit();

	return exit_code;
}
Esempio n. 5
0
terrain* terrain_genDiamondSquare(int size, float range, float factor, const char* texturePath) {
    terrain* ret = (terrain*)malloc(sizeof(terrain));
    ret->model = NULL;
    ret->heightMap = (float**)malloc(sizeof(float) * size * size);
    ret->size = size;

	*((float*)ret->heightMap + 0 * size + 0) = 0;
	*((float*)ret->heightMap + 0 * size + (size-1)) = 0;
	*((float*)ret->heightMap + (size-1) * size + 0) = 0;
	*((float*)ret->heightMap + (size-1) * size + (size-1)) = 0;

    setRandSeed();
	int i, j, k;

	// NOTE: this is not correct, square values are not using the value of adjacent diamonds correctly
	for (i = size - 1; i >= 2; i /= 2, range *= pow(2,-factor)) {
		for (j = 0; j < size - 1; j += i) {
			for (k = 0; k < size - 1; k += i) {
				float a = access_2df_array(ret->heightMap, size, j, k);
				float b = access_2df_array(ret->heightMap, size, j, k+i);
				float c = access_2df_array(ret->heightMap, size, j+i, k);
				float d = access_2df_array(ret->heightMap, size, j+i, k+i);

				float e = access_2df_array(ret->heightMap, size, j + i/2, k + i/2) = (a + b + c + d)/4.0f + randomValue(range);

				access_2df_array(ret->heightMap, size, j, k+i/2) = (access_2df_array(ret->heightMap, size, j, k) + access_2df_array(ret->heightMap, size, j, k+i) + e)/3.0f + randomValue(range);
				access_2df_array(ret->heightMap, size, j+i/2, k) = (access_2df_array(ret->heightMap, size, j, k) + access_2df_array(ret->heightMap, size, j+i, k) + e)/3.0f + randomValue(range);
				access_2df_array(ret->heightMap, size, j+i, k+i/2) = (access_2df_array(ret->heightMap, size, j+i, k) + access_2df_array(ret->heightMap, size, j+i, k+i) + e)/3.0f + randomValue(range);
				access_2df_array(ret->heightMap, size, j+i/2, k+i) = (access_2df_array(ret->heightMap, size, j, k+i) + access_2df_array(ret->heightMap, size, j+i, k+i) + e)/3.0f + randomValue(range);
			}
		}
	}

	ret->model = (mesh*)malloc(sizeof(mesh));
		
	mesh_init(ret->model);
	ret->model->indexCount = 6 * (ret->size - 1) * (ret->size - 1);
	ret->model->vertexCount = ret->size * ret->size;

	GLfloat *vertices = (GLfloat*)malloc(sizeof(GLfloat) * ret->model->vertexCount * 8);
	GLuint *indices = (GLuint*)malloc(sizeof(GLuint) * ret->model->indexCount);

	for (i = 0, k = 0; i < ret->size; i++)
		for (j = 0; j < ret->size; j++, k+=8) {
			vertices[k] = (-ret->size/2 + i);
			vertices[k+1] = access_2df_array(ret->heightMap, ret->size, i, j);
			vertices[k+2] = (ret->size/2 - j);
			vertices[k+3] = (float)((int)j % 2);
			vertices[k+4] = (float)((int)i % 2);
			vertices[k+5] = 0;
			vertices[k+6] = 1;
			vertices[k+7] = 0;
			// TODO: fix normals
		}

	for (i = 0, k = 0; i < ret->size - 1; i++) {
		for (j = 0; j < ret->size - 1; j++, k+=6) {
			indices[k] = i + ret->size*j;
			indices[k+1] = i + ret->size + 1 + ret->size*j;
			indices[k+2] = i + 1 + ret->size*j;
		}
	}

	for (i = 0, k = 3; i < ret->size - 1; i++) {
		for (j = 0; j < ret->size - 1; j++, k+=6) {
			indices[k] = i + ret->size*j;
			indices[k+1] = ret->size + i + ret->size*j;
			indices[k+2] = i + ret->size + 1 + ret->size*j;
		}
	}

	mesh_loadToVAO(ret->model, vertices, indices);
	mesh_textureFromFile(ret->model, texturePath);

	free(indices);
	free(vertices);

    return ret;
}
struct net_device *softif_create(const char *name)
{
	struct net_device *soft_iface;
	struct bat_priv *bat_priv;
	int ret;

	soft_iface = alloc_netdev(sizeof(*bat_priv), name, interface_setup);

	if (!soft_iface)
		goto out;

	ret = register_netdevice(soft_iface);
	if (ret < 0) {
		pr_err("Unable to register the batman interface '%s': %i\n",
		       name, ret);
		goto free_soft_iface;
	}

	bat_priv = netdev_priv(soft_iface);

	atomic_set(&bat_priv->aggregated_ogms, 1);
	atomic_set(&bat_priv->bonding, 0);
	atomic_set(&bat_priv->bridge_loop_avoidance, 0);
	atomic_set(&bat_priv->ap_isolation, 0);
	atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
	atomic_set(&bat_priv->gw_mode, GW_MODE_OFF);
	atomic_set(&bat_priv->gw_sel_class, 20);
	atomic_set(&bat_priv->gw_bandwidth, 41);
	atomic_set(&bat_priv->orig_interval, 1000);
	atomic_set(&bat_priv->hop_penalty, 30);
	atomic_set(&bat_priv->log_level, 0);
	atomic_set(&bat_priv->fragmentation, 1);
	atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
	atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);

	atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
	atomic_set(&bat_priv->bcast_seqno, 1);
	atomic_set(&bat_priv->ttvn, 0);
	atomic_set(&bat_priv->tt_local_changes, 0);
	atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
	atomic_set(&bat_priv->bla_num_requests, 0);

	bat_priv->tt_buff = NULL;
	bat_priv->tt_buff_len = 0;
	bat_priv->tt_poss_change = false;

	bat_priv->primary_if = NULL;
	bat_priv->num_ifaces = 0;

	ret = bat_algo_select(bat_priv, bat_routing_algo);
	if (ret < 0)
		goto unreg_soft_iface;

	ret = sysfs_add_meshif(soft_iface);
	if (ret < 0)
		goto unreg_soft_iface;

	ret = debugfs_add_meshif(soft_iface);
	if (ret < 0)
		goto unreg_sysfs;

	ret = mesh_init(soft_iface);
	if (ret < 0)
		goto unreg_debugfs;

	return soft_iface;

unreg_debugfs:
	debugfs_del_meshif(soft_iface);
unreg_sysfs:
	sysfs_del_meshif(soft_iface);
unreg_soft_iface:
	unregister_netdevice(soft_iface);
	return NULL;

free_soft_iface:
	free_netdev(soft_iface);
out:
	return NULL;
}