summaryrefslogtreecommitdiff
path: root/code/esp32/components/eos/sock.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2019-12-07 17:13:23 +0100
committerUros Majstorovic <majstor@majstor.org>2019-12-07 17:13:23 +0100
commit040f4333678f46f3558e604014d460076244af6b (patch)
tree084b8a41eef67a9bf45a5c21124fc393061f88fb /code/esp32/components/eos/sock.c
parent8cdc7528c800a3f10bca3e875e76f6d9661ab88f (diff)
added net_alloc; fixed cell modem driver
Diffstat (limited to 'code/esp32/components/eos/sock.c')
-rw-r--r--code/esp32/components/eos/sock.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/code/esp32/components/eos/sock.c b/code/esp32/components/eos/sock.c
index 2ccfb65..ee3c6a3 100644
--- a/code/esp32/components/eos/sock.c
+++ b/code/esp32/components/eos/sock.c
@@ -25,7 +25,7 @@
#include "net.h"
#include "sock.h"
-static const char *TAG = "EOS";
+static const char *TAG = "EOS SOCK";
static SemaphoreHandle_t mutex;
static int _socks[EOS_SOCK_MAX_SOCK];
@@ -80,22 +80,25 @@ static ssize_t t_recvfrom(int sock, void *msg, size_t msg_size, EOSNetAddr *addr
static void sock_receiver(void *pvParameters) {
EOSNetAddr addr;
- unsigned char buffer[EOS_NET_SIZE_BUF];
uint8_t esock = (uint8_t)pvParameters;
int sock = _socks[esock-1];
+ unsigned char *buf;
- buffer[0] = EOS_SOCK_MTYPE_PKT;
- buffer[1] = esock;
do {
- ssize_t rv = t_recvfrom(sock, buffer+EOS_SOCK_SIZE_UDP_HDR, EOS_NET_SIZE_BUF-EOS_SOCK_SIZE_UDP_HDR, &addr);
+ ssize_t rv;
+
+ buf = eos_net_alloc();
+ rv = t_recvfrom(sock, buf+EOS_SOCK_SIZE_UDP_HDR, EOS_NET_SIZE_BUF-EOS_SOCK_SIZE_UDP_HDR, &addr);
if (rv < 0) {
sock = 0;
ESP_LOGE(TAG, "UDP RECV ERR:%d", rv);
continue;
}
- memcpy(buffer+2, addr.host, sizeof(addr.host));
- memcpy(buffer+2+sizeof(addr.host), &addr.port, sizeof(addr.port));
- eos_net_send(EOS_NET_MTYPE_SOCK, buffer, rv+EOS_SOCK_SIZE_UDP_HDR, 0);
+ buf[0] = EOS_SOCK_MTYPE_PKT;
+ buf[1] = esock;
+ memcpy(buf+2, addr.host, sizeof(addr.host));
+ memcpy(buf+2+sizeof(addr.host), &addr.port, sizeof(addr.port));
+ eos_net_send(EOS_NET_MTYPE_SOCK, buf, rv+EOS_SOCK_SIZE_UDP_HDR, 0);
} while(sock);
xSemaphoreTake(mutex, portMAX_DELAY);
_socks[esock-1] = 0;
@@ -105,9 +108,9 @@ static void sock_receiver(void *pvParameters) {
static void sock_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
EOSNetAddr addr;
- unsigned char ret[2];
uint8_t esock;
int sock, i;
+ unsigned char *rbuf;
if (size < 1) return;
@@ -119,6 +122,7 @@ static void sock_handler(unsigned char type, unsigned char *buffer, uint16_t siz
memcpy(&addr.port, buffer+2+sizeof(addr.host), sizeof(addr.port));
t_sendto(sock, buffer+EOS_SOCK_SIZE_UDP_HDR, size-EOS_SOCK_SIZE_UDP_HDR, &addr);
break;
+
case EOS_SOCK_MTYPE_OPEN_DGRAM:
sock = t_open_dgram();
esock = 0;
@@ -132,17 +136,20 @@ static void sock_handler(unsigned char type, unsigned char *buffer, uint16_t siz
}
xSemaphoreGive(mutex);
}
- ret[0] = EOS_SOCK_MTYPE_OPEN_DGRAM;
- ret[1] = esock;
// xTaskCreatePinnedToCore(&sock_receiver, "sock_receiver", 2048, NULL, EOS_IRQ_PRIORITY_UDP_RCVR, NULL, 1);
xTaskCreate(&sock_receiver, "sock_receiver", 2048, (void *)esock, EOS_IRQ_PRIORITY_UDP_RCVR, NULL);
- eos_net_send(EOS_NET_MTYPE_SOCK, ret, 2, 0);
+ rbuf = eos_net_alloc();
+ rbuf[0] = EOS_SOCK_MTYPE_OPEN_DGRAM;
+ rbuf[1] = esock;
+ eos_net_send(EOS_NET_MTYPE_SOCK, rbuf, 2, 0);
break;
+
case EOS_SOCK_MTYPE_CLOSE:
if (size < 2) return;
sock = _socks[buffer[1]-1];
t_close(sock);
break;
+
default:
break;
}