Ejemplo n.º 1
0
/* init_terminals
 * Description: Initializes the terminals and sets the storage field to point to its respective 4kb page
 * Inputs: none
 * Outputs: none
 * Returns: none
 * Side Effects: Initializes the terminal fields to 0 and ptrs to NULL
 */
void init_terminals()
{
	int i,j;
	for(i = 0; i< NUM_TERM; i++)
	{
		for(j=0;j<BUFF_SIZE;j++)
		{
			terminal[i].line_buf[i] = 0;
		}
		terminal[i].line_buf_index = 0;
		terminal[i].wrap_flag = 0;
		terminal[i].screen_x = 0;
		terminal[i].screen_y = 0;
		terminal[i].video_mem = (uint8_t*)VMEM_START;
		switch(i)
		{
			case 0:
			terminal[i].storage =  (uint8_t*)VIDEO_0;
			break;

			case 1:
			terminal[i].storage =  (uint8_t*)VIDEO_1;
			break;

			case 2:
			terminal[i].storage =  (uint8_t*)VIDEO_2;
			break;
		}
		clear_storage(&terminal[i]);
		terminal[i].term_read = 0;
		terminal[i].write_lock = 0;
		terminal[i].terminal_read_ret = 0;
	}
	curr_terminal = &terminal[0];
}
Ejemplo n.º 2
0
static void uart_input_handler(const char *data, int len)
{
	int i;
	if (len < 1) {
		return;
	}

	if (data[0] == 0x7f || data[0] == 0x08) {
		if (rcvMsg.pWritePos != rcvMsg.pRcvMsgBuff) {
			const char back = 0x08, space = ' ';
			uart_write_bytes(UART_NUM_0, &back, 1);
			uart_write_bytes(UART_NUM_0, &space, 1);
			//uart_write_bytes(UART_NUM_0, &back, 1);
			rcvMsg.pWritePos[0] = 0;
			rcvMsg.pWritePos -= 1;
		} else {
			// nothing to delete
			return;
		}
	}

	if (data[0] == '\r' || data[0] == '\n') {
		// enter key press
		rcvMsg.pWritePos[0] = 0;

		if (rcvMsg.pWritePos == rcvMsg.pRcvMsgBuff) {
			uart_write_bytes(UART_NUM_0, PROMPT, PROMPT_LEN);
		} else {
				int length = rcvMsg.pWritePos - rcvMsg.pRcvMsgBuff;
				uart_write_bytes(UART_NUM_0, PROMPT, PROMPT_LEN);
				if (status == INPUT_SSID) {
					memset(wifi_ssid, 0, WIFI_SSID_MAX_LEN);
					memcpy(wifi_ssid, rcvMsg.pRcvMsgBuff, length);
					status = NONE;
					ESP_LOGI(TAG, "you set ssid: %s", wifi_ssid);
					esp_err_t er = save_string(CMD_SSID, (char *)wifi_ssid);
					if (er != ESP_OK)
						ESP_LOGE(TAG, "save ssid error");
					goto set_end;
				} else if (status == INPUT_PASS) {
					memset(wifi_pass, 0, WIFI_PASS_MAX_LEN);
					memcpy(wifi_pass, rcvMsg.pRcvMsgBuff, length);
					status = NONE;
					ESP_LOGI(TAG, "you set password: %s", wifi_pass);
					esp_err_t er = save_string(CMD_PASS, (char *)wifi_pass);
					if (er != ESP_OK)
						ESP_LOGE(TAG, "save pass error");
					goto set_end;
				} else if (status == INPUT_IP) {
					memset(srv_ip, 0, SRV_IP_MAX_LEN);
					memcpy(srv_ip, rcvMsg.pRcvMsgBuff, length);
					status = NONE;
					ESP_LOGI(TAG, "you set server ip: %s", srv_ip);
					esp_err_t er = save_string(CMD_IP, (char *)srv_ip);
					if (er != ESP_OK)
						ESP_LOGE(TAG, "save ip error");
					goto set_end;
				} else if (status == INPUT_PORT) {
					if (!is_valid_port((const char *)rcvMsg.pRcvMsgBuff, length)) {
						rcvMsg.pWritePos = rcvMsg.pRcvMsgBuff;
						ESP_LOGE(TAG, "invalid server port, please input again");
						return;
					}
					srv_port = str2num((const char *)rcvMsg.pRcvMsgBuff, length);
					status = NONE;
					ESP_LOGI(TAG, "you set server port: %d", srv_port);
					//esp_err_t er = save_int32(CMD_PORT, srv_port);
					esp_err_t er = save_string(CMD_PORT, (char *)rcvMsg.pRcvMsgBuff);
					if (er != ESP_OK)
						ESP_LOGE(TAG, "save port error");
					goto set_end;
				}

				if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_SSID, length) == 0) {
					ESP_LOGI(TAG, "input your ssid [less than 32byte]:");
					status = INPUT_SSID;
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_PASS, length) == 0) {
					ESP_LOGI(TAG, "input your password [less than 32byte]:");
					status = INPUT_PASS;
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_IP, length) == 0) {
					ESP_LOGI(TAG, "input server IP:");
					status = INPUT_IP;
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_PORT, length) == 0) {
					ESP_LOGI(TAG, "input server port:");
					status = INPUT_PORT;
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_HELP, length) == 0) {
					show_help_info();
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_WIFI, length) == 0) {
					ESP_LOGI(TAG, "BLE scanning ......");
					close_nvs();
					ble_client_app_register();
					//initialise_wifi();
				} else if (strncmp((const char *)rcvMsg.pRcvMsgBuff, CMD_QUIT, length) == 0) {
					ESP_LOGI(TAG, "reset wifi info:");
					clear_storage();
					close_nvs();
					system_restart();
				} else {
					ESP_LOGI(TAG, "invalid command %s", rcvMsg.pRcvMsgBuff);
					show_help_info();
				}
		}
set_end:
		rcvMsg.pWritePos = rcvMsg.pRcvMsgBuff;
		memset(rcvMsg.pRcvMsgBuff, 0, RECV_BUF_SIZE);
		return;
	}

	*(rcvMsg.pWritePos) = data[0];
	uart_write_bytes(UART_NUM_0, &data[0], 1);
	rcvMsg.pWritePos += 1;

	if (rcvMsg.pWritePos - rcvMsg.pRcvMsgBuff >= RECV_BUF_SIZE - 1) {
		rcvMsg.pWritePos = rcvMsg.pRcvMsgBuff;		// overflow, restart
		ESP_LOGI(TAG, "overflow");
	}
}