mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 05:06:39 +01:00
udp wip
This commit is contained in:
18
ESP32_AP-Flasher/include/udp.h
Normal file
18
ESP32_AP-Flasher/include/udp.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "AsyncUDP.h"
|
||||
|
||||
class UDPcomm {
|
||||
public:
|
||||
UDPcomm();
|
||||
~UDPcomm();
|
||||
void init();
|
||||
void send(uint8_t* output);
|
||||
void processDataReq(struct espAvailDataReq* eadr);
|
||||
|
||||
private:
|
||||
AsyncUDP udp;
|
||||
void processPacket(AsyncUDPPacket packet);
|
||||
};
|
||||
|
||||
void init_udp();
|
||||
@@ -17,7 +17,7 @@
|
||||
#endif
|
||||
|
||||
#include "web.h"
|
||||
|
||||
#include "udp.h"
|
||||
#include "leds.h"
|
||||
|
||||
void timeTask(void* parameter) {
|
||||
@@ -66,6 +66,8 @@ void setup() {
|
||||
// https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
|
||||
|
||||
init_web();
|
||||
init_udp();
|
||||
|
||||
loadDB("/current/tagDB.json");
|
||||
|
||||
xTaskCreate(zbsRxTask, "zbsRX Process", 10000, NULL, 2, NULL);
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
#include "commstructs.h"
|
||||
#include "flasher.h"
|
||||
#include "newproto.h"
|
||||
#include "powermgt.h"
|
||||
#include "settings.h"
|
||||
#include "udp.h"
|
||||
#include "web.h"
|
||||
#include "zbs_interface.h"
|
||||
#include "powermgt.h"
|
||||
|
||||
#define ZBS_RX_WAIT_HEADER 0
|
||||
#define ZBS_RX_WAIT_PKT_LEN 1
|
||||
@@ -22,6 +23,8 @@
|
||||
#define ZBS_RX_WAIT_JOINNETWORK 10
|
||||
#define ZBS_RX_WAIT_XFERTIMEOUT 11
|
||||
|
||||
extern UDPcomm udpsync;
|
||||
|
||||
uint8_t restartBlockRequest = 0;
|
||||
|
||||
uint16_t sendBlock(const void* data, const uint16_t len) {
|
||||
@@ -196,6 +199,7 @@ void SerialRXLoop() {
|
||||
if (pktindex == sizeof(struct espAvailDataReq)) {
|
||||
struct espAvailDataReq* adr = (struct espAvailDataReq*)packetp;
|
||||
processDataReq(adr);
|
||||
udpsync.processDataReq(adr);
|
||||
free(packetp);
|
||||
RXState = ZBS_RX_WAIT_HEADER;
|
||||
}
|
||||
|
||||
62
ESP32_AP-Flasher/src/udp.cpp
Normal file
62
ESP32_AP-Flasher/src/udp.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#include "AsyncUDP.h"
|
||||
#include "commstructs.h"
|
||||
#include "newproto.h"
|
||||
|
||||
#define PKT_AVAIL_DATA_SHORTREQ 0xE3
|
||||
#define PKT_AVAIL_DATA_REQ 0xE5
|
||||
#define PKT_AVAIL_DATA_INFO 0xE6
|
||||
#define PKT_BLOCK_PARTIAL_REQUEST 0xE7
|
||||
#define PKT_BLOCK_REQUEST_ACK 0xE9
|
||||
#define PKT_BLOCK_REQUEST 0xE4
|
||||
#define PKT_BLOCK_PART 0xE8
|
||||
#define PKT_XFER_COMPLETE 0xEA
|
||||
#define PKT_XFER_COMPLETE_ACK 0xEB
|
||||
#define PKT_CANCEL_XFER 0xEC
|
||||
#define PKT_PING 0xED
|
||||
#define PKT_PONG 0xEE
|
||||
|
||||
UDPcomm udpsync;
|
||||
|
||||
void init_udp() {
|
||||
udpsync.init();
|
||||
}
|
||||
|
||||
UDPcomm::UDPcomm() {
|
||||
// Constructor
|
||||
}
|
||||
|
||||
UDPcomm::~UDPcomm() {
|
||||
// Destructor
|
||||
}
|
||||
|
||||
void UDPcomm::init() {
|
||||
if (udp.listenMulticast(IPAddress(239, 10, 0, 1), 16033)) {
|
||||
Serial.print("UDP Listening on IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
udp.onPacket([this](AsyncUDPPacket packet) {
|
||||
this->processPacket(packet);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void UDPcomm::send(uint8_t* output) {
|
||||
udp.writeTo(output, strlen((char*)output), IPAddress(239, 10, 0, 1), 16572);
|
||||
}
|
||||
|
||||
void UDPcomm::processPacket(AsyncUDPPacket packet) {
|
||||
if (packet.data()[0] == 0xFD) {
|
||||
espAvailDataReq* adr = (espAvailDataReq*)&packet.data()[1];
|
||||
processDataReq(adr);
|
||||
}
|
||||
}
|
||||
|
||||
void UDPcomm::processDataReq(struct espAvailDataReq* eadr) {
|
||||
uint8_t buffer[sizeof(struct espAvailDataReq) + 1];
|
||||
buffer[0] = PKT_AVAIL_DATA_INFO;
|
||||
memcpy(buffer + 1, eadr, sizeof(struct espAvailDataReq));
|
||||
udp.writeTo(buffer, sizeof(buffer), IPAddress(239, 10, 0, 1), 16572);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user