|
|
|
@ -20,19 +20,22 @@ Client client_new() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void client_connect(Client client) {
|
|
|
|
|
client->connection = connection_new();
|
|
|
|
|
client->sdk_conn = connection_new(0, 0, 30030, "192.168.2.1");
|
|
|
|
|
client->dev_conn = connection_new(10010, "192.168.2.24", 20020, "192.168.2.1");
|
|
|
|
|
|
|
|
|
|
set_sdk_connection(client, CONNECTION_WIFI_AP, 0, 10010);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void poll_message(Client client, union Message* resp) {
|
|
|
|
|
|
|
|
|
|
memset(resp, 0, sizeof(union Message));
|
|
|
|
|
|
|
|
|
|
// Poll for messages
|
|
|
|
|
static struct timeval timeout = {0, 0};
|
|
|
|
|
fd_set read_fds;
|
|
|
|
|
FD_ZERO(&read_fds);
|
|
|
|
|
FD_SET(client->connection->sockfd, &read_fds);
|
|
|
|
|
int result = select(client->connection->sockfd + 1, &read_fds, NULL, NULL, NULL);
|
|
|
|
|
FD_SET(client->sdk_conn->sockfd, &read_fds);
|
|
|
|
|
int result = select(client->sdk_conn->sockfd + 1, &read_fds, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
// Check for socket polling errors
|
|
|
|
|
if(result < 0) {
|
|
|
|
@ -47,8 +50,7 @@ void poll_message(Client client, union Message* resp) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read a message from the socket
|
|
|
|
|
// TODO: Use union to make all messages same size
|
|
|
|
|
int recvb = recvfrom(client->connection->sockfd, resp, sizeof(union Message), 0, (struct sockaddr*)&client->connection->remote_addr, &client->connection->addrlen);
|
|
|
|
|
int recvb = recvfrom(client->sdk_conn->sockfd, resp, sizeof(union Message), 0, (struct sockaddr*)&client->sdk_conn->remote_addr, &client->sdk_conn->addrlen);
|
|
|
|
|
|
|
|
|
|
// Check for socket read errors
|
|
|
|
|
if(recvb < 0) {
|
|
|
|
|