inital rx
This commit is contained in:
parent
a3a11a5078
commit
9d6e7c5e0d
@ -32,6 +32,7 @@ def onMessage(message):
|
|||||||
if(data[0] == boat):
|
if(data[0] == boat):
|
||||||
sendData(data)
|
sendData(data)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
async def run(ws, path):
|
async def run(ws, path):
|
||||||
async for message in ws:
|
async for message in ws:
|
||||||
|
|||||||
74
rx_esp2866/rx_esp2866.ino
Normal file
74
rx_esp2866/rx_esp2866.ino
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
|
||||||
|
#define WIFI_SSID "MBCBootjes"
|
||||||
|
#define WIFI_PASS "hetgrootedok"
|
||||||
|
#define UDP_PORT 1234
|
||||||
|
|
||||||
|
WiFiUDP UDP;
|
||||||
|
#define RX_BUFFER_SIZE 255
|
||||||
|
char rxBuffer[RX_BUFFER_SIZE];
|
||||||
|
uint8_t rxBuffer_writePointer = 0;
|
||||||
|
uint8_t rxBuffer_readPointer = 0;
|
||||||
|
|
||||||
|
class Buffer
|
||||||
|
{
|
||||||
|
void *buffer_start;
|
||||||
|
void *buffer_end;
|
||||||
|
int size;
|
||||||
|
|
||||||
|
void *write_p;
|
||||||
|
void *read_p;
|
||||||
|
|
||||||
|
Buffer(void *buffer, size)
|
||||||
|
{
|
||||||
|
this->buffer_start = buffer;
|
||||||
|
this->buffer_end = buffer + size - 1;
|
||||||
|
|
||||||
|
this->write_p = this->buffer_start;
|
||||||
|
this->read_p = this->buffer_start;
|
||||||
|
|
||||||
|
this->size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void put(void *data, size_t len)
|
||||||
|
{
|
||||||
|
if (this->write_p + len > buffer_end)
|
||||||
|
{
|
||||||
|
size_t leftToEnd = (size_t)(buffer_end - this->write_p)
|
||||||
|
this->put(data, leftToEnd);
|
||||||
|
this->put(data + leftToEnd, len - leftToEnd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(this->write_p, data, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||||
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
|
delay(100);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
UDP.begin(UDP_PORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
int packetSize = UDP.parsePacket();
|
||||||
|
if (packetSize) {
|
||||||
|
int len = UDP.read(&rxBuffer[rxBuffer_writePointer], RX_BUFFER_SIZE-rxBuffer_writePointer);
|
||||||
|
if (rxBuffer_writePointer >= RX_BUFFER_SIZE)
|
||||||
|
{
|
||||||
|
rxBuffer_writePointer -= RX_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rxBuffer_writePointer != rxBuffer_readPointer)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user