Wizfi250 관련 질문 - 안드로이드 포팅 관련

현재 인증이나 기타 문제로 인해 Android 보드에 WIZFI250을 사용 예정에 있습니다.

H/W는 이미 설계를 끝냈고 S/W 적인 요청 사항이 있어 문의 드립니다.

Android 에 AT command script 를 포팅 할 수 있는 가이드 문서가 별도로 있는지요.

확인 부탁 드립니다.

감사합니다.

별도의 안드로이드용 소스는 없습니다만, 범용적으로 참고할만한 Host Demo 소스는 있습니다.

아래는 WizFi250를 제어하는 (Dos용) 예제 소스입니다.
몇몇 부분을 수정하시면 안드로이드 및 다른 플랫폼에서도 사용하실 수 있을 것으로 생각됩니다.
참고하시기 바랍니다.

// WizFi250-Host-Demo.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <conio.h>
#include <string.h>

#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

HANDLE g_file;
HANDLE g_keyboard;
HANDLE g_screen;

int uart_open(int nPort, int nBaudRate)
{
	DCB port;
	DWORD mode;
	COMMTIMEOUTS timeouts;
	char buffer[128] = {0,};

	sprintf(buffer, "\\\\.\\COM%d", nPort);

	g_keyboard = GetStdHandle(STD_INPUT_HANDLE);
	g_screen = GetStdHandle(STD_OUTPUT_HANDLE);

	// open the comm port.
	g_file = CreateFile(buffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

	if ( INVALID_HANDLE_VALUE==g_file )
	{
		printf("opening file\r\n");
		return 1;
	}

	// get the current DCB, and adjust a few bits to our liking.
	memset(&port, 0, sizeof(port));
	port.DCBlength = sizeof(port);
	if ( !GetCommState(g_file, &port))
		printf("getting comm state\r\n");
	sprintf(buffer, "baud=%d parity=n data=8 stop=1", nBaudRate);
	if (!BuildCommDCB(buffer, &port))
		printf("building comm DCB\r\n");
	if (!SetCommState(g_file, &port))
		printf("adjusting port settings\r\n");

	// set short timeouts on the comm port.
	timeouts.ReadIntervalTimeout = 1;
	timeouts.ReadTotalTimeoutMultiplier = 1;
	timeouts.ReadTotalTimeoutConstant = 1;
	timeouts.WriteTotalTimeoutMultiplier = 1;
	timeouts.WriteTotalTimeoutConstant = 1;
	if (!SetCommTimeouts(g_file, &timeouts))
		printf("setting port time-outs.\r\n");

	// set keyboard to raw reading.
	if (!GetConsoleMode(g_keyboard, &mode))
		printf("getting keyboard mode\r\n");
	mode &= ~ ENABLE_PROCESSED_INPUT;
	if (!SetConsoleMode(g_keyboard, mode))
		printf("setting keyboard mode\r\n");

	if (!EscapeCommFunction(g_file, CLRDTR))
		printf("clearing DTR\r\n");
	Sleep(200);
	if (!EscapeCommFunction(g_file, SETDTR))
		printf("setting DTR\r\n");

	return 0;
}


int uart_close()
{
	CloseHandle(g_keyboard);
	CloseHandle(g_file);

	return 0;
}

int uart_readbyte(char* buffer)
{
	DWORD read;
	ReadFile(g_file, buffer, 1, &read, NULL);
	return read;
}

int uart_readstring(char* buffer, int length)
{
	DWORD read;
	ReadFile(g_file, buffer, length, &read, NULL);
	return read;
}

int uart_writebyte(char* buffer)
{
	DWORD written;
	WriteFile(g_file, buffer, 1, &written, NULL);
	return written;
}

int uart_writestring(char* buffer)
{
	DWORD written;
	WriteFile(g_file, buffer, (DWORD)strlen(buffer), &written, NULL);
	return written;
}

#define LOCAL_MAX_COMMAND_BUFFER	1024
char g_uart_buffer[LOCAL_MAX_COMMAND_BUFFER+1] = {0,};

int send_and_check_command(char* send_command, unsigned char nCRLF, int nDelay, int nCount, char* szFind1, char* szFind2, char* szOK)
{
	int i;
	unsigned char bFind1=0, bFind2=0;
	int nResult = 0;
	int nReadData = 0;

	int n_total_read_data = 0;

	memset(g_uart_buffer, 0, sizeof(g_uart_buffer));

	uart_writestring(send_command);
	printf("<uart send>\r\n%s\r\n", send_command);

	if ( nCRLF==1 )			uart_writestring("\r");
	else if ( nCRLF==2 )	uart_writestring("\n");
	else if ( nCRLF==3 )	uart_writestring("\r\n");	

	if ( szFind1==0 ) bFind1 = 1;
	if ( szFind2==0 ) bFind2 = 1;

	for (i=0; i<nCount; i++)
	{
		nReadData = uart_readstring((char*)(g_uart_buffer + n_total_read_data), (LOCAL_MAX_COMMAND_BUFFER - n_total_read_data));
		if ( nReadData>0 )
		{			
		}
		n_total_read_data += nReadData;

		// check buffer overflow
		if ( (LOCAL_MAX_COMMAND_BUFFER - n_total_read_data)<1 )
		{
			nResult = 1;
			//while(uart_readstring(g_uart_buffer, LOCAL_MAX_COMMAND_BUFFER));
			break;
		}

		if ( bFind1==0 )
		{
			if ( strstr(g_uart_buffer, szFind1) ) bFind1 = 1;
		}
		if ( bFind2==0 )
		{
			if ( strstr(g_uart_buffer, szFind2) ) bFind2 = 1;
		}

		if ( bFind1 && bFind2 )			break;

		Sleep(nDelay);
	}

	if ( nResult==1 )
	{
		printf("g_uart_buffer overflow\r\n");
		return nResult;
	}

	if ( !(bFind1 && bFind2) )					nResult = 2;	// Timeout
	else if ( strstr(g_uart_buffer, szOK)==0 )	nResult = 3;	// Not Found Success String

	if ( strlen(g_uart_buffer)>0 )
	{
		printf("<uart recv>\r\n%s\r\n", g_uart_buffer);
	}

	return nResult;
}


int main(int argc, char **argv)
{
	int i = 0;
	int result = 0;
	int received_data = 0;

	if ( uart_open(3, 115200)!=0 )
	{
		printf("ERROR : uart_open\r\n");
		return 1;
	}

WizFi250_ASSOCIATION:

	// AP Association
	if ( send_and_check_command("AT",                      1, 100, 30, "[", "]", "[OK]")!=0 )	goto WizFi250_ERROR;
	if ( send_and_check_command("AT+WLEAVE",               1, 100, 30, "[", "]", "[OK]")!=0 )	goto WizFi250_ERROR;
	if ( send_and_check_command("AT+WNET=1",               1, 100, 30, "[", "]", "[OK]")!=0 )	goto WizFi250_ERROR;
	if ( send_and_check_command("AT+WSET=0,WizFiDemoAP",   1, 100, 30, "[", "]", "[OK]")!=0 )	goto WizFi250_ERROR;
	if ( send_and_check_command("AT+WSEC=0,wpa2,12345678", 1, 100, 30, "[", "]", "[OK]")!=0 )	goto WizFi250_ERROR;
	if ( send_and_check_command("AT+MPROF=S",              1, 100, 30, "[", "]", "[OK]")!=0 )	goto WizFi250_ERROR;
	for (i=0; i<3; i++)
	{
		if ( send_and_check_command("AT+WJOIN",                1, 100, 200,"[", "]", "[OK]")==0 )
		{
			result = 1;
			break;
		}
	}
	if ( result==0 )
	{
		printf("ERROR : Association\r\n");
		goto WizFi250_ERROR;
	}

WizFi250_TCPCONNECT:
	// TCP Connect
	if ( send_and_check_command("AT+SCON=O,TCN,192.168.3.106,5000,,1", 1, 100, 50, "[CONNECT", "]", "[OK]")!=0 )
	{
		printf("ERROR : TCP Connection\r\n");
		goto WizFi250_ERROR;
	}

	// Main Loop
	while(1)
	{
		memset(g_uart_buffer, 0, sizeof(g_uart_buffer));

		received_data = uart_readstring((char*)g_uart_buffer, LOCAL_MAX_COMMAND_BUFFER);
		if ( received_data<=0 )
		{
			continue;
		}

		// Exception handling
		if ( strstr(g_uart_buffer, "[DISCONNECT") )
		{
			printf("[TCP Disconnected Event]\r\n");
			goto WizFi250_TCPCONNECT;
		}
		else if ( strstr(g_uart_buffer, "[Link-Down Event]") )
		{
			printf("[AP Disassociated Event]\r\n");
			goto WizFi250_ASSOCIATION;
		}
		else if ( strstr(g_uart_buffer, "[Reset Event]") )
		{
			printf("[WizFi250 Reset Event]\r\n");
			goto WizFi250_ASSOCIATION;
		}

		if ( strlen(g_uart_buffer)>0 )
		{
			printf("<uart recv>\r\n%s\r\n", g_uart_buffer);
		}

		////////////////////////////////////////////////////////////////////////////////
		// Do something with <g_uart_buffer>, Send " : OK" to the TCP Server(just Test)
		strcat(g_uart_buffer, " ===> OK\r\n");
		uart_writestring(g_uart_buffer);
		printf("<uart send>\r\n%s\r\n", g_uart_buffer);
		////////////////////////////////////////////////////////////////////////////////
	}


WizFi250_ERROR:
	uart_close();

	printf("WizFi250 Demo is done......\r\n");
	getch();
}