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

51 lines
1.3 KiB
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
//char outBuf[sizeof(struct packet)], rcvBuf[sizeof(struct packet)];
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) {
//outBuf[0] = KEYS;
outBuf.command = keys;
2014-12-05 20:00:27 +00:00
//memcpy(outBuf + 1, &keys, 4);
//memcpy(outBuf + 5, &cstick, 4);
2014-12-08 17:34:52 +00:00
//#pragma GCC diagnostic push
//#pragma GCC diagnostic ignored "-Wstrict-aliasing"
//memcpy(&((struct packet *)outBuf)->keys, &keys, 4);
//memcpy(&((struct packet *)outBuf)->cstick, &cstick, 4);
//memcpy(&((struct packet *)outBuf)->touch, &touch, 4);
//sendBuf(sizeof(struct packet));
//#pragma GCC diagnostic pop
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));
}