Skip to content

Commit

Permalink
Combined UDP and TCP socket functions into one socket.c and socket.h
Browse files Browse the repository at this point in the history
Signed-off-by: beegee-tokyo <bernd@giesecke.tk>
  • Loading branch information
beegee-tokyo committed Sep 16, 2016
1 parent e714be5 commit b46eca6
Show file tree
Hide file tree
Showing 7 changed files with 482 additions and 25 deletions.
10 changes: 3 additions & 7 deletions Makefile
Expand Up @@ -102,7 +102,7 @@ LED_SERIAL_PIN ?= 14
# --------------- esp-link modules config options ---------------

# Optional Modules mqtt
MODULES ?= mqtt rest tcp udp syslog
MODULES ?= mqtt rest socket syslog

# --------------- esphttpd config options ---------------

Expand Down Expand Up @@ -217,12 +217,8 @@ ifneq (,$(findstring rest,$(MODULES)))
CFLAGS += -DREST
endif

ifneq (,$(findstring tcp,$(MODULES)))
CFLAGS += -DTCP
endif

ifneq (,$(findstring udp,$(MODULES)))
CFLAGS += -DUDP
ifneq (,$(findstring socket,$(MODULES)))
CFLAGS += -DSOCKET
endif

ifneq (,$(findstring syslog,$(MODULES)))
Expand Down
7 changes: 2 additions & 5 deletions cmd/cmd.h
Expand Up @@ -49,11 +49,8 @@ typedef enum {
CMD_REST_REQUEST, // do REST request
CMD_REST_SETHEADER, // define header

CMD_TCP_SETUP = 30, // set-up callbacks
CMD_TCP_SEND, // send data over TCP socket

CMD_UDP_SETUP = 40, // set-up callbacks
CMD_UDP_SEND, // send data over UDP socket
CMD_SOCKET_SETUP = 30, // set-up callbacks
CMD_SOCKET_SEND, // send data over UDP socket
} CmdName;

typedef void (*cmdfunc_t)(CmdPacket *cmd);
Expand Down
17 changes: 5 additions & 12 deletions cmd/handlers.c
Expand Up @@ -12,11 +12,8 @@
#ifdef REST
#include <rest.h>
#endif
#ifdef TCP
#include <tcp.h>
#endif
#ifdef UDP
#include <udp.h>
#ifdef SOCKET
#include <socket.h>
#endif

#ifdef CMD_DBG
Expand Down Expand Up @@ -53,13 +50,9 @@ const CmdList commands[] = {
{CMD_REST_REQUEST, "REST_REQ", REST_Request},
{CMD_REST_SETHEADER, "REST_SETHDR", REST_SetHeader},
#endif
#ifdef TCP
{CMD_TCP_SETUP, "TCP_SETUP", TCP_Setup},
{CMD_TCP_SEND, "TCP_SEND", TCP_Send},
#endif
#ifdef UDP
{CMD_UDP_SETUP, "UDP_SETUP", UDP_Setup},
{CMD_UDP_SEND, "UDP_SEND", UDP_Send},
#ifdef SOCKET
{CMD_SOCKET_SETUP, "SOCKET_SETUP", SOCKET_Setup},
{CMD_SOCKET_SEND, "SOCKET_SEND", SOCKET_Send},
#endif
};

Expand Down
1 change: 1 addition & 0 deletions rest/rest.c
Expand Up @@ -116,6 +116,7 @@ tcpclient_recv(void *arg, char *pdata, unsigned short len) {
espconn_disconnect(client->pCon);
}

// Data is sent
static void ICACHE_FLASH_ATTR
tcpclient_sent_cb(void *arg) {
struct espconn *pCon = (struct espconn *)arg;
Expand Down

0 comments on commit b46eca6

Please sign in to comment.