From 21045b1beecbfc80c84484d8e955ac364ac65432 Mon Sep 17 00:00:00 2001 From: Ollo Date: Wed, 3 May 2023 21:39:15 +0200 Subject: [PATCH] Refactored packet length, UDP parser fixed --- src/LED-Board.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/LED-Board.cpp b/src/LED-Board.cpp index a755c1e..96ee3fc 100644 --- a/src/LED-Board.cpp +++ b/src/LED-Board.cpp @@ -24,9 +24,8 @@ Panel panel5(47, 53, 49, 4 * PANEL_WIDTH, 0 * PANEL_HEIGHT); /** * 800 Byte describing all 5 panels in bits */ -/* uint8_t packetBuffer[(PANEL_WIDTH * PANEL_HEIGHT * MAXIMUM_PANELSIZE) / sizeof(uint8_t)]; // buffer to hold incoming packet,*/ -const uint16_t packetBufferSize = (PANEL_WIDTH * PANEL_HEIGHT * MAXIMUM_PANELSIZE) / BITS_OF_BYTE + 1; -uint8_t packetBuffer[packetBufferSize]; +#define PACKET_LENGTH (((PANEL_WIDTH * PANEL_HEIGHT * MAXIMUM_PANELSIZE) / BITS_OF_BYTE) + 1) +uint8_t packetBuffer[PACKET_LENGTH]; /* Reply with error messages*/ char ReplyBuffer[UDP_TX_PACKET_MAX_SIZE]; // a string to send back @@ -62,40 +61,40 @@ void receiveUDP() { Serial.print(", port "); Serial.println(Udp.remotePort()); someOneIsConnected = true; - if (packetSize < ((int) sizeof(packetBuffer)) ) { + if (packetSize < ((int) PACKET_LENGTH) ) { // read the packet into packetBufffer Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); } - if (packetSize == sizeof(packetBuffer)) { + if (packetSize == PACKET_LENGTH) { auto brightness = packetBuffer[0]; //OCR5A = brightness; int offset = 0; - for(uint16_t i = 0; i < packetBufferSize;i++){ + for(int i = 0; i < PACKET_LENGTH; i++){ uint8_t value = packetBuffer[i]; - uint8_t a = (value | 0xb00000001) > 0 ? 1 : 0; + uint8_t a = (value & 0xb00000001) > 0 ? 1 : 0; image.set_pixel_offset(offset, a); offset++; - uint8_t b = (value | 0xb00000010) > 0 ? 1 : 0; + uint8_t b = ((value & 0xb00000010) > 0) ? 1 : 0; image.set_pixel_offset(offset, b); offset++; - uint8_t c = (value | 0xb00000100) > 0 ? 1 : 0; + uint8_t c = ((value & 0xb00000100) > 0) ? 1 : 0; image.set_pixel_offset(offset, c); offset++; - uint8_t d = (value | 0xb00001000) > 0 ? 1 : 0; + uint8_t d = ((value & 0xb00001000) > 0) ? 1 : 0; image.set_pixel_offset(offset, d); offset++; - uint8_t e = (value | 0xb00010000) > 0 ? 1 : 0; + uint8_t e = ((value & 0xb00010000) > 0) ? 1 : 0; image.set_pixel_offset(offset, e); offset++; - uint8_t f = (value | 0xb00100000) > 0 ? 1 : 0; + uint8_t f = ((value & 0xb00100000) > 0) ? 1 : 0; image.set_pixel_offset(offset, f); offset++; - uint8_t g = (value | 0xb01000000) > 0 ? 1 : 0; + uint8_t g = ((value & 0xb01000000) > 0) ? 1 : 0; image.set_pixel_offset(offset, g); offset++; - uint8_t h = (value | 0xb10000000) > 0 ? 1 : 0; + uint8_t h = ((value & 0xb10000000) > 0) ? 1 : 0; image.set_pixel_offset(offset, h); offset++; }