diff options
Diffstat (limited to 'src/device')
-rw-r--r-- | src/device/main.ino | 29 | ||||
-rwxr-xr-x | src/device/protocol_device.c | 14 | ||||
-rwxr-xr-x | src/device/protocol_device_private.h | 3 | ||||
-rwxr-xr-x | src/device/udp.ino | 25 |
4 files changed, 39 insertions, 32 deletions
diff --git a/src/device/main.ino b/src/device/main.ino index 1a34859..d4e092d 100644 --- a/src/device/main.ino +++ b/src/device/main.ino @@ -26,25 +26,17 @@ #include <stddef.h> #include "SSD1306Wire.h" #include "DejaVu_Sans_Mono_13.h" +#include "udp.h" -static char udppacketbuffer[32] = {0}; -static char *udppacketcursor = NULL; static const unsigned int internal_led = 2; static unsigned int led_state = 0; static const char servermagic[] = "I love coffee!"; static const char clientmagic[] = "I love tea!"; -static const int com_port = 6996; -IPAddress ip; /* Daemon IP */ -WiFiUDP Udp; SSD1306Wire display(0x3c, 4, 5, GEOMETRY_128_32); static void init_OLED(void); unsigned int toggle_led(const int ip); static int wifi_connect(const char * const ssid, const char * const password, const char doblink, const int ledpin); -static void discover_client(const int port); -static void udp_init_packet(IPAddress ip, const int port); -static void udp_push(const void * const data, const size_t size); -static int udp_flush(void); static void blink_led(const int pin, const int ontime, const int offtime); void setup(void) @@ -166,25 +158,6 @@ static void discover_client(const int port) } while (!done); } -static void udp_init_packet(IPAddress ip, const int port) -{ - Udp.beginPacket(ip, port); - memset(udppacketbuffer, 0, sizeof(udppacketbuffer)); - udppacketcursor = udppacketbuffer; -} - -static void udp_push(const void * const data, const size_t size) -{ - memcpy(udppacketcursor, data, size); - udppacketcursor += size; -} - -static int udp_flush(void) -{ - Udp.write((const uint8_t *) udppacketbuffer, udppacketcursor - udppacketbuffer); - return Udp.endPacket(); -} - static void blink_led(const int pin, const int ontime, const int offtime) { toggle_led(pin); diff --git a/src/device/protocol_device.c b/src/device/protocol_device.c index 3e38e19..5910546 100755 --- a/src/device/protocol_device.c +++ b/src/device/protocol_device.c @@ -18,9 +18,15 @@ cd_t protocol_init(void) return 0; } -void clear_data(void) +int clear_data(cd_t cd) { - connection.inp_crs = 0; + int ret = 0; + if (cd >= MAX_CONNECTIONS) { + ret = E_IVALID_DESCRIPTOR; + } else { + connection.inp_crs = 0; + } + return ret; } static int push_bytes(cd_t cd, char *data, size_t size) @@ -81,6 +87,10 @@ struct tlv * get_tlv(cd_t cd) return ret; } +int flush_data(cd_t cd) +{ + return 0; +} int get_last_data(cd_t cd) { diff --git a/src/device/protocol_device_private.h b/src/device/protocol_device_private.h index 29ff567..6754ecf 100755 --- a/src/device/protocol_device_private.h +++ b/src/device/protocol_device_private.h @@ -9,8 +9,7 @@ * bigger packets but memory is hard to come by and more won't be needed * anyway. * */ -#define MAX_PACKET_SIZE_IN (512) - +#define MAX_PACKET_SIZE_IN 512 /** * Device only gets one connection. Because daemon. */ diff --git a/src/device/udp.ino b/src/device/udp.ino new file mode 100755 index 0000000..3074b65 --- /dev/null +++ b/src/device/udp.ino @@ -0,0 +1,25 @@ +#include "udp.h"
+#include <ESP8266WiFi.h>
+#include <WiFiUdp.h>
+
+static char udppacketbuffer[32] = {0};
+static char *udppacketcursor = NULL;
+
+void udp_init_packet(IPAddress ip, const int port)
+{
+ Udp.beginPacket(ip, port);
+ memset(udppacketbuffer, 0, sizeof(udppacketbuffer));
+ udppacketcursor = udppacketbuffer;
+}
+
+void udp_push(const void * const data, const size_t size)
+{
+ memcpy(udppacketcursor, data, size);
+ udppacketcursor += size;
+}
+
+int udp_flush(void)
+{
+ Udp.write((const uint8_t *) udppacketbuffer, udppacketcursor - udppacketbuffer);
+ return Udp.endPacket();
+}
|