Skip to content

Commit 88e8514

Browse files
committed
removed v1 support
1 parent 6898dd9 commit 88e8514

File tree

2 files changed

+3
-146
lines changed

2 files changed

+3
-146
lines changed

src/EventDispatcher/EventDispatcher.cpp

Lines changed: 3 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -502,146 +502,6 @@ bool EventDispatcher::handleV2Frame() {
502502
return processV2Frame(v2Buffer, payloadBytes);
503503
}
504504

505-
bool EventDispatcher::handleLegacyFrame() {
506-
if (hwSerial->available() < 7) {
507-
return false;
508-
}
509-
510-
bool success = false;
511-
512-
byte startByte = hwSerial->read();
513-
if (startByte == 255) {
514-
byte sourceId = hwSerial->read();
515-
if (sourceId != 0) {
516-
if (sourceId == EVENT_CONFIGURATION) {
517-
// Config Event has 12 bytes, 2 bytes are already parsed above.
518-
while (hwSerial->available() < 10) {
519-
}
520-
521-
// We have a ConfigEvent.
522-
byte boardId = hwSerial->read();
523-
byte topic = hwSerial->read();
524-
byte index = hwSerial->read();
525-
byte key = hwSerial->read();
526-
uint32_t value = (((uint32_t)hwSerial->read()) << 24) +
527-
(((uint32_t)hwSerial->read()) << 16) +
528-
(((uint32_t)hwSerial->read()) << 8) +
529-
hwSerial->read();
530-
byte stopByte = hwSerial->read();
531-
if (stopByte == 0b10101010) {
532-
stopByte = hwSerial->read();
533-
if (stopByte == 0b01010101) {
534-
success = true;
535-
callListeners(new ConfigEvent(boardId, topic, index, key, value),
536-
true);
537-
}
538-
}
539-
} else {
540-
word eventId = word(hwSerial->read(), hwSerial->read());
541-
if (eventId != 0) {
542-
byte value = hwSerial->read();
543-
byte stopByte = hwSerial->read();
544-
if (stopByte == 0b10101010) {
545-
stopByte = hwSerial->read();
546-
if (stopByte == 0b01010101) {
547-
success = true;
548-
callListeners(new Event((char)sourceId, eventId, value), true,
549-
false);
550-
551-
if (sourceId == EVENT_POLL_EVENTS && board == value) {
552-
digitalWrite(rs485Pin, HIGH); // Write.
553-
// Wait until the RS485 converter switched to write mode.
554-
delayMicroseconds(RS485_MODE_SWITCH_DELAY);
555-
556-
while (!eventQueue.empty()) {
557-
Event *e = eventQueue.front();
558-
eventQueue.pop();
559-
callListeners(e, true, true);
560-
}
561-
562-
// Send NULL event to indicate that transmission is complete.
563-
callListeners(new Event(EVENT_NULL, 1, board), false, true);
564-
565-
lastPoll = millis();
566-
567-
// Flush the serial buffer and wait until done.
568-
hwSerial->flush();
569-
digitalWrite(rs485Pin, LOW); // Read.
570-
// Wait until the RS485 converter switched back to read mode.
571-
delayMicroseconds(RS485_MODE_SWITCH_DELAY);
572-
} else if (sourceId == EVENT_RUN) {
573-
running = true;
574-
}
575-
576-
} else {
577-
if (Serial) {
578-
rp2040.idleOtherCore();
579-
Serial.print("Received wrong second stop byte ");
580-
Serial.println(stopByte, DEC);
581-
rp2040.resumeOtherCore();
582-
}
583-
}
584-
} else {
585-
if (Serial) {
586-
rp2040.idleOtherCore();
587-
Serial.print("Received wrong first stop byte ");
588-
Serial.println(stopByte, DEC);
589-
rp2040.resumeOtherCore();
590-
}
591-
}
592-
} else {
593-
if (Serial) {
594-
rp2040.idleOtherCore();
595-
Serial.print("Received invalid event id ");
596-
Serial.println(eventId, DEC);
597-
rp2040.resumeOtherCore();
598-
}
599-
}
600-
}
601-
} else {
602-
if (Serial) {
603-
rp2040.idleOtherCore();
604-
Serial.print("Received invalid source id ");
605-
Serial.println(sourceId, DEC);
606-
rp2040.resumeOtherCore();
607-
}
608-
}
609-
} else {
610-
if (Serial) {
611-
rp2040.idleOtherCore();
612-
Serial.print("Received wrong start byte ");
613-
Serial.println(startByte, DEC);
614-
rp2040.resumeOtherCore();
615-
}
616-
// We didn't receive a start byte. Fake "success" to start over with the
617-
// next byte.
618-
success = true;
619-
}
620-
621-
if (success) {
622-
if (error) {
623-
error = false;
624-
dispatch(new Event(EVENT_NO_ERROR, 1, board));
625-
}
626-
} else {
627-
error = true;
628-
dispatch(new Event(EVENT_ERROR, 1, board));
629-
630-
while (hwSerial->available()) {
631-
byte bits = hwSerial->read();
632-
if (bits == 0b10101010 && hwSerial->available()) {
633-
bits = hwSerial->read();
634-
if (bits == 0b01010101) {
635-
// Now we should be back in sync.
636-
break;
637-
}
638-
}
639-
}
640-
}
641-
642-
return success;
643-
}
644-
645505
void EventDispatcher::update() {
646506
if (!rs485) { // We're on Core1, the EffectController. Transmit stacked
647507
// events to Core0.
@@ -660,16 +520,15 @@ void EventDispatcher::update() {
660520
if (v2UartDmaActive) {
661521
serviceV2UartDmaRx();
662522
} else {
523+
// Fallback parser is still needed for V2 bootstrap and fault handling:
524+
// - bootstrap: receive initial V2 setup frame before DMA cutover
525+
// - fault path: continue operating if UART DMA transport cannot start
663526
while (hwSerial->available() > 0) {
664527
int firstByte = hwSerial->peek();
665528
if (firstByte == ppuc::v2::kSyncByte) {
666529
if (!handleV2Frame()) {
667530
break;
668531
}
669-
} else if (firstByte == 255) {
670-
if (!handleLegacyFrame()) {
671-
break;
672-
}
673532
} else {
674533
// Desync/noise, consume one byte and continue.
675534
hwSerial->read();

src/EventDispatcher/EventDispatcher.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class EventDispatcher {
5353

5454
private:
5555
bool readBytes(byte* buffer, size_t len);
56-
bool handleLegacyFrame();
5756
bool handleV2Frame();
5857
bool startV2UartDmaTransport();
5958
void stopV2UartDmaTransport();
@@ -115,7 +114,6 @@ class EventDispatcher {
115114
bool rs485 = false;
116115
uint8_t rs485Pin = 0;
117116
byte board = 255;
118-
bool error = false;
119117
uint32_t lastPoll;
120118
bool running = false;
121119

0 commit comments

Comments
 (0)