diff options
author | 2019-05-21 20:01:08 +0300 | |
---|---|---|
committer | 2019-05-21 20:01:08 +0300 | |
commit | fe71239fc0d1e65e06ba9dcf2fb35239bff21466 (patch) | |
tree | e1e708310afc253ca006bb22558cc8cba67bdfb6 /src/device/udp.ino | |
parent | 5ca7e24e58f6bd657787b9235247149ffff420ae (diff) | |
download | usurpation-fe71239fc0d1e65e06ba9dcf2fb35239bff21466.tar.gz usurpation-fe71239fc0d1e65e06ba9dcf2fb35239bff21466.tar.bz2 usurpation-fe71239fc0d1e65e06ba9dcf2fb35239bff21466.zip |
Protocol: moved udp code out of main.
An effor was made to increase modularity of device code. It was a
partial success. IP adress, communications port, and wifi login
details had to be made static and visible in main.
Time is scarce and I am not about to push this further.
Signed-off-by: Ramūnas Mažeikis <ramunasnezinomas@gmail.com>
Diffstat (limited to 'src/device/udp.ino')
-rwxr-xr-x | src/device/udp.ino | 25 |
1 files changed, 25 insertions, 0 deletions
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();
+}
|