Ejemplo n.º 1
0
const bool wifi(const struct ip_info *info) {
	uint8_t mac_address[6] ALIGNED;
	char *ap_password = NULL;
	struct ip_info ip_config;

	oled_info_t oled_info = { OLED_128x64_I2C_DEFAULT };
	const bool oled_connected =  oled_start(&oled_info);


	if (!wifi_detect()){
		(void) console_status(CONSOLE_YELLOW, WIFI_NOT_CONNECTED);
		OLED_CONNECTED(oled_connected, oled_puts(&oled_info, WIFI_NOT_CONNECTED));
		return false;
	}

	(void) ap_params_init();
	ap_password = (char *) ap_params_get_password();

	(void) console_status(CONSOLE_YELLOW, STARTING_WIFI);
	OLED_CONNECTED(oled_connected, oled_status(&oled_info, STARTING_WIFI));

	wifi_ap_init(ap_password);

	printf("ESP8266 information\n");
	printf(" SDK      : %s\n", system_get_sdk_version());
	printf(" Firmware : %s\n\n", wifi_get_firmware_version());

	if (network_params_init()) {
		(void) console_status(CONSOLE_YELLOW, CHANGING_TO_STATION_MODE);
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, CHANGING_TO_STATION_MODE));

		ssid = network_params_get_ssid();
		if (network_params_is_use_dhcp()) {
			wifi_station(ssid, network_params_get_password());
		} else {
			ip_config.ip.addr = network_params_get_ip_address();
			ip_config.netmask.addr = network_params_get_net_mask();
			ip_config.gw.addr = network_params_get_default_gateway();
			wifi_station_ip(ssid, network_params_get_password(), &ip_config);
		}
	}

	opmode = wifi_get_opmode();

	if (opmode == WIFI_STA) {
		printf("WiFi mode : Station (AP: %s)\n", network_params_get_ssid());
	} else {
		printf("WiFi mode : Access Point (authenticate mode: %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK");
	}

	if (wifi_get_macaddr(mac_address)) {
		printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address));
	} else {
		(void) console_error("wifi_get_macaddr");
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, "E: wifi_get_macaddr"));
	}

	printf(" Hostname    : %s\n", wifi_get_hostname());

	if (wifi_get_ip_info(&ip_config)) {
		printf(" IP-address  : " IPSTR "\n", IP2STR(ip_config.ip.addr));
		printf(" Netmask     : " IPSTR "\n", IP2STR(ip_config.netmask.addr));
		printf(" Gateway     : " IPSTR "\n", IP2STR(ip_config.gw.addr));

		if (opmode == WIFI_STA) {
			const _wifi_station_status status = wifi_station_get_connect_status();
			printf("      Status : %s\n", wifi_station_status(status));

			if (status != WIFI_STATION_GOT_IP) {
				(void) console_error("Not connected!");

				if (oled_connected) {
					oled_set_cursor(&oled_info, 2, 0);
					(void) oled_puts(&oled_info, wifi_station_status(status));
					oled_set_cursor(&oled_info, 5, 0);
					(void) oled_printf(&oled_info, "SSID : %s\n", network_params_get_ssid());
					oled_status(&oled_info, "E: Not connected!");
				}

				for (;;)
					;
			}
		}
	} else {
		(void) console_error("wifi_get_ip_info");
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, "E: wifi_get_ip_info"));
	}

	if (fota_params_init()) {
		OLED_CONNECTED(oled_connected, oled_status(&oled_info, "FOTA mode"));
		console_newline();
		fota(fota_params_get_server());
		for (;;)
			;
	}

	(void) console_status(CONSOLE_GREEN, WIFI_STARTED);
	OLED_CONNECTED(oled_connected, oled_status(&oled_info, WIFI_STARTED));

	memcpy((void *)info, (const void *)&ip_config, sizeof(struct ip_info));

	return true;
}
Ejemplo n.º 2
0
void notmain(void) {
	_output_type output_type = OUTPUT_TYPE_MONITOR;
	uint8_t mac_address[6] ALIGNED;
	struct ip_info ip_config;
	E131Params e131params;
	DMXParams dmxparams;
	uuid_t uuid;
	char uuid_str[UUID_STRING_LENGTH + 1] ALIGNED;

	hardware_init();

	(void) e131params.Load();

	if (e131params.isHaveCustomCid()) {
		memcpy(uuid_str, e131params.GetCidString(), UUID_STRING_LENGTH);
		uuid_str[UUID_STRING_LENGTH] = '\0';
		uuid_parse((const char *)uuid_str, uuid);
	} else {
		hardware_uuid(uuid);
		uuid_unparse(uuid, uuid_str);
	}

	output_type = e131params.GetOutputType();

	if (output_type == OUTPUT_TYPE_MONITOR) {
		//
	} else {
		output_type = OUTPUT_TYPE_DMX;
		(void) dmxparams.Load();
	}

	printf("[V%s] %s Compiled on %s at %s\n", SOFTWARE_VERSION, hardware_board_get_model(), __DATE__, __TIME__);
	printf("WiFi sACN E.131 DMX Out / Real-time DMX Monitor");

	console_set_top_row(3);

	(void) ap_params_init();
	const char *ap_password = ap_params_get_password();

	hardware_watchdog_init();

	console_status(CONSOLE_YELLOW, "Starting Wifi ...");

	wifi_init(ap_password);

	hardware_watchdog_stop();

	printf("ESP8266 information\n");
	printf(" SDK      : %s\n", system_get_sdk_version());
	printf(" Firmware : %s\n\n", wifi_get_firmware_version());

	if (network_params_init()) {
		console_status(CONSOLE_YELLOW, "Changing to Station mode ...");
		if (network_params_is_use_dhcp()) {
			wifi_station(network_params_get_ssid(), network_params_get_password());
		} else {
			ip_config.ip.addr = network_params_get_ip_address();
			ip_config.netmask.addr = network_params_get_net_mask();
			ip_config.gw.addr = network_params_get_default_gateway();
			wifi_station_ip(network_params_get_ssid(), network_params_get_password(), &ip_config);
		}
	}

	const _wifi_mode opmode = wifi_get_opmode();

	if (opmode == WIFI_STA) {
		printf("WiFi mode : Station\n");
	} else {
		printf("WiFi mode : Access Point (authenticate mode : %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK");
	}

	if (wifi_get_macaddr(mac_address)) {
		printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address));
	} else {
		console_error("wifi_get_macaddr");
	}

	printf(" Hostname    : %s\n", wifi_station_get_hostname());

	if (wifi_get_ip_info(&ip_config)) {
		printf(" IP-address  : " IPSTR "\n", IP2STR(ip_config.ip.addr));
		printf(" Netmask     : " IPSTR "\n", IP2STR(ip_config.netmask.addr));
		printf(" Gateway     : " IPSTR "\n", IP2STR(ip_config.gw.addr));
		if (opmode == WIFI_STA) {
			const _wifi_station_status status = wifi_station_get_connect_status();
			printf("      Status : %s\n", wifi_station_status(status));
			if (status != WIFI_STATION_GOT_IP){
				console_error("Not connected!");
				for(;;);
			}
		}
	} else {
		console_error("wifi_get_ip_info");
	}

	if (fota_params_init()) {
		console_newline();
		fota(fota_params_get_server());
		for(;;);
	}

	console_status(CONSOLE_YELLOW, "Starting UDP ...");
	udp_begin(E131_DEFAULT_PORT);

	console_status(CONSOLE_YELLOW, "Join group ...");

	uint32_t group_ip;
	(void)inet_aton("239.255.0.0", &group_ip);
	const uint16_t universe = e131params.GetUniverse();
	group_ip = group_ip | ((uint32_t)(((uint32_t)universe & (uint32_t)0xFF) << 24)) | ((uint32_t)(((uint32_t)universe & (uint32_t)0xFF00) << 8));
	udp_joingroup(group_ip);

	E131Bridge bridge;
	DMXSend dmx;
	DMXMonitor monitor;

	bridge.setCid(uuid);
	bridge.setUniverse(universe);
	bridge.setMergeMode(e131params.GetMergeMode());

	if (output_type == OUTPUT_TYPE_MONITOR) {
		bridge.SetOutput(&monitor);
		console_set_top_row(20);
	} else {
		bridge.SetOutput(&dmx);

		dmx.SetBreakTime(dmxparams.GetBreakTime());
		dmx.SetMabTime(dmxparams.GetMabTime());

		const uint8_t refresh_rate = dmxparams.GetRefreshRate();
		uint32_t period = (uint32_t) 0;

		if (refresh_rate != (uint8_t) 0) {
			period = (uint32_t) (1E6 / refresh_rate);
		}
		dmx.SetPeriodTime(period);
	}

	printf("\nBridge configuration\n");
	const uint8_t *firmware_version = bridge.GetSoftwareVersion();
	printf(" Firmware     : %d.%d\n", firmware_version[0], firmware_version[1]);
	printf(" CID          : %s\n", uuid_str);
	printf(" Universe     : %d\n", bridge.getUniverse());
	printf(" Merge mode   : %s\n", bridge.getMergeMode() == E131_MERGE_HTP ? "HTP" : "LTP");
	printf(" Multicast ip : " IPSTR "\n", IP2STR(group_ip));
	printf(" Unicast ip   : " IPSTR "\n\n", IP2STR(ip_config.ip.addr));

	if (output_type == OUTPUT_TYPE_DMX) {
		printf("DMX Send parameters\n");
		printf(" Break time   : %d\n", (int) dmx.GetBreakTime());
		printf(" MAB time     : %d\n", (int) dmx.GetMabTime());
		printf(" Refresh rate : %d\n", (int) (1E6 / dmx.GetPeriodTime()));
	}

	hardware_watchdog_init();

	console_status(CONSOLE_GREEN, "Bridge is running");

	for (;;) {
		hardware_watchdog_feed();
		(void) bridge.Run();
		led_blink();
	}
}
Ejemplo n.º 3
0
void notmain(void) {
	hardware_init();

	ltc_reader_params_init();

	output.console_output = ltc_reader_params_is_console_output();
	output.lcd_output = ltc_reader_params_is_lcd_output();
	output.midi_output = ltc_reader_params_is_midi_output();
	output.artnet_output = ltc_reader_params_is_artnet_output();

	if(output.midi_output) {
		midi_send_init();
	}

	if (output.lcd_output) {
		output.lcd_output = lcd_detect();
	}

	if (output.artnet_output) {
		output.artnet_output = wifi_detect();
	}

	ltc_reader_init(&output);

	printf("[V%s] %s Compiled on %s at %s\n", SOFTWARE_VERSION, hardware_board_get_model(), __DATE__, __TIME__);
	printf("SMPTE TimeCode LTC Reader / Converter");

	console_set_top_row(3);

	console_set_cursor(0, 12);
	console_puts("Console output : "); handle_bool(output.console_output); console_putc('\n');
	console_puts("LCD output     : "); handle_bool(output.lcd_output); console_putc('\n');
	console_puts("MIDI output    : "); handle_bool(output.midi_output); console_putc('\n');
	console_puts("ArtNet output  : "); handle_bool(output.artnet_output);console_puts(" (not implemented)\n");

	if (output.artnet_output) {
		uint8_t mac_address[6];
		struct ip_info ip_config;

		(void) ap_params_init();
		const char *ap_password = ap_params_get_password();

		console_status(CONSOLE_YELLOW, "Starting Wifi ...");

		wifi_init(ap_password);

		printf("\nESP8266 information\n");
		printf(" SDK      : %s\n", system_get_sdk_version());
		printf(" Firmware : %s\n\n", wifi_get_firmware_version());

		if (network_params_init()) {
			console_status(CONSOLE_YELLOW, "Changing to Station mode ...");
			if (network_params_is_use_dhcp()) {
				wifi_station(network_params_get_ssid(), network_params_get_password());
			} else {
				ip_config.ip.addr = network_params_get_ip_address();
				ip_config.netmask.addr = network_params_get_net_mask();
				ip_config.gw.addr = network_params_get_default_gateway();
				wifi_station_ip(network_params_get_ssid(), network_params_get_password(), &ip_config);
			}
		}

		const _wifi_mode opmode = wifi_get_opmode();

		if (opmode == WIFI_STA) {
			printf("WiFi mode : Station\n");
		} else {
			printf("WiFi mode : Access Point (authenticate mode : %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK");
		}

		if (wifi_get_macaddr(mac_address)) {
			printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address));
		} else {
			console_error("wifi_get_macaddr");
		}

		printf(" Hostname    : %s\n", wifi_station_get_hostname());

		if (wifi_get_ip_info(&ip_config)) {
			printf(" IP-address  : " IPSTR "\n", IP2STR(ip_config.ip.addr));
			printf(" Netmask     : " IPSTR "\n", IP2STR(ip_config.netmask.addr));
			printf(" Gateway     : " IPSTR "\n", IP2STR(ip_config.gw.addr));
			if (opmode == WIFI_STA) {
				const _wifi_station_status status = wifi_station_get_connect_status();
				printf("      Status : %s\n", wifi_station_status(status));
				if (status != WIFI_STATION_GOT_IP){
					console_error("Not connected!");
					for(;;);
				}
			}
		} else {
			console_error("wifi_get_ip_info");
		}

		console_status(CONSOLE_YELLOW, "Starting UDP ...");
		udp_begin(6454);

		console_status(CONSOLE_GREEN, "Wifi is started");
	}

	for (;;) {
		ltc_reader();
	}
}