Skip to content

Commit 458e76c

Browse files
committed
fixed image/animation through TCP
1 parent dcd97b2 commit 458e76c

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/input/tcp.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ void TcpInput::setup() {
1515
tcpServer.begin();
1616

1717
parsePacketQueue = xQueueCreate(10, sizeof(data_packet_t));
18+
xTaskCreatePinnedToCore(queue, "ParsePacketTask", 4096, NULL, 1, &parsePacketHandle, 1);
1819
}
1920

2021
/**
2122
* loop functionality
2223
*/
2324
void TcpInput::loop() {
24-
TcpInput::queue();
25+
// no additional handling needed
2526
}
2627

2728
/**
@@ -125,24 +126,27 @@ void TcpInput::disconnect(void *arg, AsyncClient *client) {
125126
/**
126127
* the queue handler
127128
*/
128-
void TcpInput::queue() {
129+
void TcpInput::queue(void *parameter) {
129130
//TODO: if there are multiple packets (like for a GIF), get all packets and split them into 210 byte pieces. currently only the first packet gets split, which breaks bigger GIFs
130-
//TODO: only split into 210 byte pieces, if it can be parsed as a frame. otherwise pass it through unchanged to make single images work
131131

132-
data_packet_t dataPacket;
133-
if (xQueueReceive(parsePacketQueue, &dataPacket, (TickType_t)10) == pdPASS) {
134-
size_t off = 0;
135-
size_t max = 210;
136-
size_t len = dataPacket.size;
137-
uint8_t *buffer = dataPacket.data;
138-
139-
while (len > 0) {
140-
size_t use = len > max ? max : len;
141-
TcpInput::parse(buffer, use);
142-
143-
off += use;
144-
buffer += use;
145-
len = dataPacket.size - off;
132+
while (true) {
133+
data_packet_t dataPacket;
134+
if (xQueueReceive(parsePacketQueue, &dataPacket, (TickType_t)10) == pdPASS) {
135+
size_t off = 0;
136+
size_t maxImage = 274;
137+
size_t maxAnimation = 210;
138+
size_t len = dataPacket.size;
139+
uint8_t *buffer = dataPacket.data;
140+
141+
while (len > 0) {
142+
size_t max = buffer[0] == 0x01 && buffer[3] == 0x49 ? maxAnimation : maxImage;
143+
size_t use = len > max ? max : len;
144+
TcpInput::parse(buffer, use);
145+
146+
off += use;
147+
buffer += use;
148+
len = dataPacket.size - off;
149+
}
146150
}
147151
}
148152
}

src/input/tcp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525

2626
private:
2727
inline static QueueHandle_t parsePacketQueue = NULL;
28+
inline static TaskHandle_t parsePacketHandle = NULL;
2829

29-
static void queue();
30+
static void queue(void *parameter);
3031
static void parse(const uint8_t *buffer, size_t size);
3132
static void write(const uint8_t *buffer, size_t size);
3233
};

0 commit comments

Comments
 (0)