int * find_sequences(int *arr, int len){
	//Return final array which has 6indexes [AP1_S,AP1_E,AP2_S,AP2_E,GP1_S,GP2_E]
	if (arr == NULL || len <= 3)
		return NULL;

	int i, start = 0, end = 0, *res;
	res = (int *)malloc(6 * sizeof(int));

	findAP(arr, len, &start, &end);
	res[0] = start;
	res[1] = end;
	
	start = end;
	findAP(arr, len, &start, &end);
	res[2] = start;
	res[3] = end;

	start = 0;
	end = 0;

	for (i = 0; i < len - 1; i++){
		if ((arr[start + 1] * 1.0) / arr[start] == (arr[i + 1] * 1.0) / arr[i])
			end = i + 1;
		else{
			if (end - start > 1)
				break;
			else
				start = end = i;

		}
	}

	res[4] = start;
	res[5] = end;

	return res;
}
Esempio n. 2
0
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	Wifi_InitDefault(false);
	
	consoleDemoInit(); 

	Keyboard* kb = keyboardDemoInit();
	kb->OnKeyPressed = keyPressed;

	while(1) {
		int status = ASSOCSTATUS_DISCONNECTED;

		consoleClear();
		consoleSetWindow(NULL, 0,0,32,24);

		Wifi_AccessPoint* ap = findAP();

		consoleClear();
		consoleSetWindow(NULL, 0,0,32,10);

		iprintf("Connecting to %s\n", ap->ssid);

		//this tells the wifi lib to use dhcp for everything
		Wifi_SetIP(0,0,0,0,0);	
		char wepkey[64];
		int wepmode = WEPMODE_NONE;
		if (ap->flags & WFLAG_APDATA_WEP) {
			iprintf("Enter Wep Key\n");
			while (wepmode == WEPMODE_NONE) {
				scanf("%s",wepkey);
				if (strlen(wepkey)==13) {
					wepmode = WEPMODE_128BIT;
				} else if (strlen(wepkey) == 5) {
					wepmode = WEPMODE_40BIT;
				} else {
					iprintf("Invalid key!\n");
				}
			}
			Wifi_ConnectAP(ap, wepmode, 0, (u8*)wepkey);
		} else {
			Wifi_ConnectAP(ap, WEPMODE_NONE, 0, 0);
		}
		consoleClear();
		while(status != ASSOCSTATUS_ASSOCIATED && status != ASSOCSTATUS_CANNOTCONNECT) {

			status = Wifi_AssocStatus();
			int len = strlen(ASSOCSTATUS_STRINGS[status]);
			iprintf("\x1b[0;0H\x1b[K");
			iprintf("\x1b[0;%dH%s", (32-len)/2,ASSOCSTATUS_STRINGS[status]);

			scanKeys();

			if(keysDown() & KEY_B) break;
			
			swiWaitForVBlank();
		}

		char url[256];

		if(status == ASSOCSTATUS_ASSOCIATED) {
			u32 ip = Wifi_GetIP();

			iprintf("\nip: [%i.%i.%i.%i]\n", (ip ) & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, (ip >> 24) & 0xFF);
			while(1) {

				scanf("%s", url);

				if ( 0 == strcmp(url,"quit")) break;

				struct hostent *host = gethostbyname(url);

				if(host)
					iprintf("IP (%s) : %s\n",  url, inet_ntoa(*(struct in_addr *)host->h_addr_list[0]));
				else
					iprintf("Could not resolve\n");

				swiWaitForVBlank();
			}
		} else {
Esempio n. 3
0
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	Wifi_InitDefault(false);
	
	consoleDemoInit(); 

	//Keyboard* kb = keyboardDemoInit();
	//kb->OnKeyPressed = keyPressed;

	while(1);

	{
		int status = ASSOCSTATUS_DISCONNECTED;

		consoleClear();

		Wifi_AccessPoint* ap = findAP();

		iprintf("Connecting to %s\n", ap->ssid);

		//this tells the wifi lib to use dhcp for everything
		Wifi_SetIP(0,0,0,0,0);	

		Wifi_ConnectAP(ap, WEPMODE_NONE, 0, 0);

		while(status != ASSOCSTATUS_ASSOCIATED && status != ASSOCSTATUS_CANNOTCONNECT) {
			int oldStatus = status;

			status = Wifi_AssocStatus();

			iprintf("%s", oldStatus != status ? ASSOCSTATUS_STRINGS[status] : ".");

			scanKeys();

			if(keysDown() & KEY_B) break;
			
			swiWaitForVBlank();
		}
		consoleClear();
		consoleSetWindow(NULL, 0,0,32,10);

		char url[256];

		if(status == ASSOCSTATUS_ASSOCIATED) {
			while(1) {
				u32 ip = Wifi_GetIP();

				iprintf("ip: [%i.%i.%i.%i]", (ip ) & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, (ip >> 24) & 0xFF);

				scanf("%s", url);

				struct hostent *host = gethostbyname(url);

				if(host)
					iprintf("IP (%s) : %s\n",  url, inet_ntoa(*(struct in_addr *)host->h_addr_list[0]));
				else
					iprintf("Could not resolve\n");

				scanKeys();

				if(keysDown() & KEY_B) break;

				swiWaitForVBlank();
			}
		}
	}
	return 0;
}