Skip to content

Commit 550b4d9

Browse files
committed
fix comments for usermod hooks "onUdpPacket"
1 parent f3e3f58 commit 550b4d9

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

usermods/udp_name_sync/udp_name_sync.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class UdpNameSync : public Usermod {
3434

3535
IPAddress broadcastIp = ~uint32_t(Network.subnetMask()) | uint32_t(Network.gatewayIP());
3636
byte udpOut[WLED_MAX_SEGNAME_LEN + 2];
37-
udpOut[0] = 2; // 0: wled notifier protocol, 1: warls protocol, 2 is free
37+
udpOut[0] = 200; // 0: wled notifier protocol, 1: warls protocol, 2 is free
3838

3939
if (strlen(segmentName) && !mainseg.name) { // name cleared
4040
notifierUdp.beginPacket(broadcastIp, udpPort);
@@ -46,8 +46,13 @@ class UdpNameSync : public Usermod {
4646
return;
4747
}
4848

49-
const char* curName = mainseg.name ? mainseg.name : "";
50-
if (strcmp(curName, segmentName) == 0) return; // same name, do nothing
49+
char checksumSegName = 0;
50+
char checksumCurName = 0;
51+
for(int i=0; i++; mainseg.name[i]==0 || segmentName[i]==0) {
52+
checksumSegName+=segmentName[i];
53+
checksumCurName+=mainseg.name[i];
54+
}
55+
if (checksumCurName == checksumSegName) return; // same name, do nothing
5156

5257
notifierUdp.beginPacket(broadcastIp, udpPort);
5358
DEBUG_PRINT(F("UdpNameSync: saving segment name "));
@@ -61,9 +66,10 @@ class UdpNameSync : public Usermod {
6166
DEBUG_PRINTLN(segmentName);
6267
}
6368

64-
bool onUdpPacket(uint8_t * payload, uint8_t len) override {
69+
bool onUdpPacket(uint8_t * payload, size_t len) override {
6570
DEBUG_PRINT(F("UdpNameSync: Received packet"));
66-
if (payload[0] != 2) return false;
71+
if (receiveDirect) return false;
72+
if (payload[0] != 200) return false;
6773
//else
6874
Segment& mainseg = strip.getMainSegment();
6975
mainseg.setName((char *)&payload[1]);

wled00/fcn_declare.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class Usermod {
442442
virtual void onMqttConnect(bool sessionPresent) {} // fired when MQTT connection is established (so usermod can subscribe)
443443
virtual bool onMqttMessage(char* topic, char* payload) { return false; } // fired upon MQTT message received (wled topic)
444444
virtual bool onEspNowMessage(uint8_t* sender, uint8_t* payload, uint8_t len) { return false; } // fired upon ESP-NOW message received
445-
virtual bool onUdpPacket(uint8_t* payload, uint8_t len) { return false; } //fired upon UDP packet received
445+
virtual bool onUdpPacket(uint8_t* payload, size_t len) { return false; } //fired upon UDP packet received
446446
virtual void onUpdateBegin(bool) {} // fired prior to and after unsuccessful firmware update
447447
virtual void onStateChange(uint8_t mode) {} // fired upon WLED state change
448448
virtual uint16_t getId() {return USERMOD_ID_UNSPECIFIED;}
@@ -482,7 +482,7 @@ namespace UsermodManager {
482482
#ifndef WLED_DISABLE_ESPNOW
483483
bool onEspNowMessage(uint8_t* sender, uint8_t* payload, uint8_t len);
484484
#endif
485-
bool onUdpPacket(uint8_t* payload, uint8_t len);
485+
bool onUdpPacket(uint8_t* payload, size_t len);
486486
void onUpdateBegin(bool);
487487
void onStateChange(uint8_t);
488488
Usermod* lookup(uint16_t mod_id);

0 commit comments

Comments
 (0)