3dscontroller-ng/3DS/source/wireless.c

38 lines
854 B
C
Raw Normal View History

2014-12-05 20:00:27 +00:00
#include "wireless.h"
int sock;
struct sockaddr_in sain, saout;
2014-12-08 17:34:52 +00:00
struct packet outBuf, rcvBuf;
2014-12-05 20:00:27 +00:00
bool openSocket(int port) {
sock = socket(AF_INET, SOCK_DGRAM, 0);
saout.sin_family = sain.sin_family = AF_INET;
saout.sin_port = sain.sin_port = htons(port);
sain.sin_addr.s_addr = INADDR_ANY;
bind(sock, (struct sockaddr *)&sain, sizeof(sain));
fcntl(sock, F_SETFL, O_NONBLOCK);
return true;
}
void sendBuf(int length) {
2014-12-08 17:34:52 +00:00
sendto(sock, (char *)&outBuf, length, 0, (struct sockaddr *)&saout, sizeof(saout));
2014-12-05 20:00:27 +00:00
}
void sendConnectionRequest(void) {
2014-12-08 17:34:52 +00:00
outBuf.command = CONNECT;
2014-12-05 20:00:27 +00:00
sendBuf(1);
}
2014-12-08 17:34:52 +00:00
void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch) {
2014-12-08 18:29:08 +00:00
outBuf.command = KEYS;
2014-12-08 17:34:52 +00:00
memcpy(&outBuf.keys, &keys, 4);
memcpy(&outBuf.circlePad, &circlePad, 4);
memcpy(&outBuf.touch, &touch, 4);
2014-12-05 20:00:27 +00:00
sendBuf(sizeof(struct packet));
}