This commit is contained in:
Nic Limper
2023-03-28 11:26:36 +02:00
parent 1a6d3d6408
commit faf2d4cc19
4 changed files with 88 additions and 2 deletions

View 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();

View File

@@ -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);

View File

@@ -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;
}

View 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);
}