Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created April 7, 2010 16:01
Show Gist options
  • Save Mon-Ouie/359058 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/359058 to your computer and use it in GitHub Desktop.
VALUE Wlan_connect(VALUE self, VALUE config, VALUE timeout) {
if (sceNetApctlConnect(FIX2INT(config)))
rb_raise(rb_eRuntimeError, "Failled to connect to acces point %d",
FIX2INT(config));
time_t startTime, currTime;
time(&startTime);
int last_state = -1;
while (true) {
time(&currTime);
if (currTime - startTime >= FIX2INT(timeout)) {
sceNetApctlDisconnect();
rb_raise(rb_eTimeoutError, "Connection timeouted after %d seconds",
FIX2INT(timeout));
break;
}
int state;
if (sceNetApctlGetState(&state)) {
rb_raise(rb_eRuntimeError,
"Error occured while getting connection state");
break;
}
if (state > last_state) {
last_state = state;
}
if (state == PSP_NET_APCTL_STATE_GOT_IP)
break;
sceKernelDelayThread(50 * 1000);
}
return Qnil;
}
VALUE Wlan_configs(VALUE self) {
VALUE ret = rb_ary_new();
for (int i = 1; i < 20; ++i) {
if (sceUtilityCheckNetParam(i))
break;
VALUE entry = rb_ary_new();
netData data;
sceUtilityGetNetParam(i, PSP_NETPARAM_IP, &data);
rb_ary_push(entry, rb_str_new2(data.asString));
sceUtilityGetNetParam(i, PSP_NETPARAM_NAME, &data);
rb_ary_push(entry, rb_str_new2(data.asString));
rb_ary_push(ret, entry);
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment