From 41df0f0e5410283ae16848f3f46ed11f77ccab92 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Sat, 26 Feb 2022 17:56:59 -0600 Subject: [PATCH] File transfer nonsense fixed! --- client/client.pro | 2 +- client/src/dos/vesa.c | 2 +- client/src/file.c | 13 ---------- client/src/gui/font.c | 32 ++++++++++++------------ client/src/gui/gui.c | 8 ++++-- client/src/gui/terminal.c | 5 +++- client/src/linux/linux.c | 5 ++-- client/src/system/comport.c | 3 +++ client/src/system/network.c | 3 ++- server/server.pro | 4 +-- server/src/client/file.c | 22 ++++------------ server/src/client/signup.c | 5 ++-- server/src/main.c | 3 ++- server/src/server.c | 2 ++ shared/packet.c | 50 ++++++++++++++++++++++++++----------- shared/packet.h | 5 ++-- 16 files changed, 86 insertions(+), 78 deletions(-) diff --git a/client/client.pro b/client/client.pro index fe4e7b7..203f831 100644 --- a/client/client.pro +++ b/client/client.pro @@ -21,7 +21,7 @@ TEMPLATE = app CONFIG -= qt -#CONFIG += ASAN +CONFIG += ASAN DESTDIR = $$OUT_PWD/bin SHARED = $$PWD/../shared diff --git a/client/src/dos/vesa.c b/client/src/dos/vesa.c index 91e7ded..d3ccba8 100644 --- a/client/src/dos/vesa.c +++ b/client/src/dos/vesa.c @@ -558,7 +558,7 @@ int16_t vbeInfoShow(void) { _vbeModeInfo.redMaskSize, _vbeModeInfo.greenMaskSize, _vbeModeInfo.blueMaskSize, - (_vbeModeInfo.memoryModel / 2) - 2 ? "DCOLOR" : "PACKED"); + ((_vbeModeInfo.memoryModel / 2) - 2) ? "DCOLOR" : "PACKED"); } } diff --git a/client/src/file.c b/client/src/file.c index 3e6c15d..354789d 100644 --- a/client/src/file.c +++ b/client/src/file.c @@ -109,7 +109,6 @@ static void fileCheckNext(void) { if (_current == NULL) { // End of queue? if (arrlen(_fileList) == 0) { - logWrite("End of queue.\n"); arrfree(_fileList); if (_dialogVisible) guiDelete(D(_winFile)); netChannelRelease(_channel); @@ -117,7 +116,6 @@ static void fileCheckNext(void) { } // Get next queue entry. - logWrite("Next queue entry.\n"); _currentLength = 0; _current = _fileList[0]; arrdel(_fileList, 0); @@ -127,7 +125,6 @@ static void fileCheckNext(void) { // End of current queue file list? if (arrlen(_current->files) == 0) { - logWrite("End of files.\n"); // End of list! arrfree(_current->files); _current->callback(); @@ -136,7 +133,6 @@ static void fileCheckNext(void) { doRecheck = 1; } else { // No. Get next file. - logWrite("Next file.\n"); _file = _current->files[0]; arrdel(_current->files, 0); } @@ -147,7 +143,6 @@ static void fileCheckNext(void) { shaPointer = cacheSha256Get(_file); if (!shaPointer) shaPointer = badSHA; packetData = packetContentPack(&length, "iss", temp, shaPointer, _file); - logWrite("Checking [%d] [%s] [%s]\n", temp, shaPointer, _file); encoded.control = PACKET_CONTROL_DAT; encoded.packetType = PACKET_TYPE_FILE_REQUEST; encoded.channel = _channel; @@ -204,29 +199,24 @@ static void packetHandler(PacketDecodeDataT *packet) { packetContentUnpack(packet->data, "i", &response); switch (response) { case FILE_RESPONSE_UNKNOWN: - logWrite("Unknown file transfer response.\n"); fileShowError("Unknown file transfer response."); break; case FILE_RESPONSE_OKAY: // This file is already up-to-date, move on to next. - logWrite("Got FILE_RESPONSE_OKAY\n"); fileCheckNext(); break; case FILE_RESPONSE_SEND: // Start of new file. Get SHA and length. - logWrite("Got FILE_RESPONSE_SEND\n"); packetContentUnpack(packet->data, "iis", &response, &_currentLength, &_currentSha256); break; case FILE_RESPONSE_DATA: - logWrite("Got FILE_RESPONSE_DATA\n"); // Receive new file data. if (!_dialogVisible) fileShowDialog(); // Are we starting a new file? if (_handle == NULL) { - logWrite("Opening [%s]\n", _file); _handle = cacheFOpen(_file, "wb"); if (!_handle) { fileShowError("Unable to write to cache."); @@ -234,11 +224,9 @@ static void packetHandler(PacketDecodeDataT *packet) { } } // Write data to file, skipping first integer stored in packet. - logWrite("Writing %d bytes to [%s]\n", packet->length - 4, _file); fwrite(&packet->data[4], packet->length - 4, 1, _handle); // Is this file complete? if (ftell(_handle) >= _currentLength) { - logWrite("Closing [%s]\n", _file); // Close this file. cacheFClose(_handle); _handle = NULL; @@ -248,7 +236,6 @@ static void packetHandler(PacketDecodeDataT *packet) { // Next file! fileCheckNext(); } else { - logWrite("Sending FILE_REQUEST_NEXT\n"); // Tell the server we got this bit of data, send the next. temp = FILE_REQUEST_NEXT; packetData = packetContentPack(&length, "i", temp); diff --git a/client/src/gui/font.c b/client/src/gui/font.c index 6be67e3..07bde38 100644 --- a/client/src/gui/font.c +++ b/client/src/gui/font.c @@ -123,15 +123,15 @@ void fontRender(FontT *font, char *string, ColorT foreground, ColorT background, offset += (font->span / 2); if (odd) { - surfacePutPixel(x, yp, data & 0x08 ? foreground : background); - surfacePutPixel(x + 1, yp, data & 0x04 ? foreground : background); - surfacePutPixel(x + 2, yp, data & 0x02 ? foreground : background); - surfacePutPixel(x + 3, yp, data & 0x01 ? foreground : background); + surfacePutPixel(x, yp, (data & 0x08) ? foreground : background); + surfacePutPixel(x + 1, yp, (data & 0x04) ? foreground : background); + surfacePutPixel(x + 2, yp, (data & 0x02) ? foreground : background); + surfacePutPixel(x + 3, yp, (data & 0x01) ? foreground : background); } else { - surfacePutPixel(x, yp, data & 0x80 ? foreground : background); - surfacePutPixel(x + 1, yp, data & 0x40 ? foreground : background); - surfacePutPixel(x + 2, yp, data & 0x20 ? foreground : background); - surfacePutPixel(x + 3, yp, data & 0x10 ? foreground : background); + surfacePutPixel(x, yp, (data & 0x80) ? foreground : background); + surfacePutPixel(x + 1, yp, (data & 0x40) ? foreground : background); + surfacePutPixel(x + 2, yp, (data & 0x20) ? foreground : background); + surfacePutPixel(x + 3, yp, (data & 0x10) ? foreground : background); } yp++; @@ -149,14 +149,14 @@ void fontRender(FontT *font, char *string, ColorT foreground, ColorT background, data = font->bits[offset]; offset += font->span; - surfacePutPixel(x, yp, data & 0x80 ? foreground : background); - surfacePutPixel(x + 1, yp, data & 0x40 ? foreground : background); - surfacePutPixel(x + 2, yp, data & 0x20 ? foreground : background); - surfacePutPixel(x + 3, yp, data & 0x10 ? foreground : background); - surfacePutPixel(x + 4, yp, data & 0x08 ? foreground : background); - surfacePutPixel(x + 5, yp, data & 0x04 ? foreground : background); - surfacePutPixel(x + 6, yp, data & 0x02 ? foreground : background); - surfacePutPixel(x + 7, yp, data & 0x01 ? foreground : background); + surfacePutPixel(x, yp, (data & 0x80) ? foreground : background); + surfacePutPixel(x + 1, yp, (data & 0x40) ? foreground : background); + surfacePutPixel(x + 2, yp, (data & 0x20) ? foreground : background); + surfacePutPixel(x + 3, yp, (data & 0x10) ? foreground : background); + surfacePutPixel(x + 4, yp, (data & 0x08) ? foreground : background); + surfacePutPixel(x + 5, yp, (data & 0x04) ? foreground : background); + surfacePutPixel(x + 6, yp, (data & 0x02) ? foreground : background); + surfacePutPixel(x + 7, yp, (data & 0x01) ? foreground : background); yp++; } diff --git a/client/src/gui/gui.c b/client/src/gui/gui.c index da7cf55..bb04632 100644 --- a/client/src/gui/gui.c +++ b/client/src/gui/gui.c @@ -815,10 +815,14 @@ void guiWidgetPositionOnScreenGet(WidgetT *widget, RectT *pos) { *pos = widget->pos; } else { *pos = p->clip; - pos->x += widget->pos.x + widget->window->base.pos.x; - pos->y += widget->pos.y + widget->window->base.pos.y; + pos->x += widget->pos.x; + pos->y += widget->pos.y; pos->w = widget->pos.w; pos->h = widget->pos.h; + if (widget->window) { + pos->x += widget->window->base.pos.x; + pos->y += widget->window->base.pos.y; + } } } diff --git a/client/src/gui/terminal.c b/client/src/gui/terminal.c index 9ba7f60..421a9e0 100644 --- a/client/src/gui/terminal.c +++ b/client/src/gui/terminal.c @@ -706,6 +706,8 @@ void terminalScreenClear(TerminalT *terminal) { static void terminalSequenceReset(TerminalT *terminal) { + char *parms = NULL; + terminal->escFound = 0; terminal->inEscape = 0; terminal->number[0] = 0; @@ -713,7 +715,8 @@ static void terminalSequenceReset(TerminalT *terminal) { if (terminal->parameters != NULL) { while (arrlen(terminal->parameters) > 0) { - free(arrpop(terminal->parameters)); + parms = arrpop(terminal->parameters); + free(parms); } terminal->parameters = NULL; } diff --git a/client/src/linux/linux.c b/client/src/linux/linux.c index f6085b7..025b3d4 100644 --- a/client/src/linux/linux.c +++ b/client/src/linux/linux.c @@ -34,7 +34,7 @@ #define TIMER_INTERVAL (1000 / TICKS_PER_SECOND) -#define COM_BUFFER_SIZE 2048 +#define COM_BUFFER_SIZE (32 * 1024) #define MODEM_RESULT_OK 1 #define MODEM_RESULT_ERROR 2 #define MODEM_RESULT_NOTHING 3 @@ -142,7 +142,7 @@ static void comModem(uint8_t c) { x = strlen(_command); // Room in buffer? - if (x > COM_BUFFER_SIZE - 1) { + if (x > COM_BUFFER_SIZE - 2) { // No. Clear buffer. _command[0] = 0; } else { @@ -496,6 +496,7 @@ static void processNetworkEvent(void) { break; case ENET_EVENT_TYPE_RECEIVE: + //logWrite(" IN: "); packetDebugPrint((uint8_t *)event.packet->data, event.packet->dataLength); comAddToBuffer((char *)event.packet->data, event.packet->dataLength); break; diff --git a/client/src/system/comport.c b/client/src/system/comport.c index dd7a76d..c03fe42 100644 --- a/client/src/system/comport.c +++ b/client/src/system/comport.c @@ -17,6 +17,7 @@ * */ + #include "comport.h" #include "timer.h" #include "config.h" @@ -25,6 +26,8 @@ void comPacketSender(uint8_t *data, uint32_t length, void *userData) { (void)userData; + //logWrite("OUT: "); packetDebugPrint((uint8_t *)data, length); + comWrite(__configData.serialCom - 1, (char *)data, length); } diff --git a/client/src/system/network.c b/client/src/system/network.c index 3685fb1..f32ab20 100644 --- a/client/src/system/network.c +++ b/client/src/system/network.c @@ -117,7 +117,7 @@ void netProcess(void) { r = comRead(__configData.serialCom - 1, (char *)buffer, 1024); // New data or not, process anything in the queue. if (packetDecode(__packetThreadData, &decoded, buffer, r)) { - //logWrite("Packet In: %d\n", decoded.packetType); + logWrite("network.c - Packet In: %d Length: %d Channel: %d\n", decoded.packetType, decoded.length, decoded.channel); //packetDebugPrint((uint8_t *)decoded.data, decoded.length); switch (decoded.packetType) { case PACKET_TYPE_PING: @@ -158,6 +158,7 @@ void netProcess(void) { packet->data = (uint8_t *)malloc(decoded.length); memcpy(packet->data, decoded.data, decoded.length); // Send it to the subscriber. + logWrite("Delivering to subscriber %p\n", _channels[r].value); _channels[r].value(packet); } } diff --git a/server/server.pro b/server/server.pro index 648fe47..7f5c246 100644 --- a/server/server.pro +++ b/server/server.pro @@ -21,8 +21,8 @@ TEMPLATE = app CONFIG -= qt CONFIG += \ console \ - c11 -# ASAN + c11 \ + ASAN DESTDIR = $$OUT_PWD/bin SHARED = $$PWD/../shared diff --git a/server/src/client/file.c b/server/src/client/file.c index 5a3f1b3..9b11102 100644 --- a/server/src/client/file.c +++ b/server/src/client/file.c @@ -49,7 +49,6 @@ void clientApiFileRequest(ClientThreadT *client, PacketDecodeDataT *data) { break; default: - logWrite("Got FILE_REQUEST_UNKNOWN [%d] %d\n\r", request, data->length); // No idea what they want. packetData = packetContentPack(&length, "i", FILE_RESPONSE_UNKNOWN); // Build packet. @@ -80,8 +79,6 @@ static void clientApiFileRequestCheck(ClientThreadT *client, PacketDecodeDataT * char buffer2[2048] = { 0 }; uint32_t temp = 0; - logWrite("Got FILE_REQUEST_CHECK\n\r"); - // Is something still open? if (client->handle) { fclose(client->handle); @@ -90,12 +87,10 @@ static void clientApiFileRequestCheck(ClientThreadT *client, PacketDecodeDataT * // Extract the request. packetContentUnpack(data->data, "iss", &request, &sha256, &path); - logWrite("[%s] [%s]\n\r", sha256, path); // Look up the entry and compare SHA256. dbFileSha256Get(path, shaInDB, 128); if (strcasecmp(sha256, shaInDB) == 0) { - logWrite("File is current. Sending FILE_RESPONSE_OKAY.\n\r"); // File is already current on client. temp = FILE_RESPONSE_OKAY; packetData = packetContentPack(&length, "i", temp); @@ -107,14 +102,12 @@ static void clientApiFileRequestCheck(ClientThreadT *client, PacketDecodeDataT * packetSend(client->packetThreadData, &encoded); DEL(packetData); } else { - logWrite("File needs updated.\n\r"); // Get real path. dbFileRealPathGet(path, buffer, FILE_VIRTUAL_PATH_MAX); snprintf(buffer2, 2048, "%s%s", __settingsFile, buffer); // Open file & get file size. client->handle = fopen(buffer2, "rb"); if (!client->handle) { - logWrite("Unable to open [%s]\n", buffer2); DEL(sha256); DEL(path); // ***TODO*** Handle error @@ -123,10 +116,8 @@ static void clientApiFileRequestCheck(ClientThreadT *client, PacketDecodeDataT * fseek(client->handle, 0, SEEK_END); client->fileSize = ftell(client->handle); fseek(client->handle, 0, SEEK_SET); - logWrite("Size is %d\n\r", client->fileSize); // Send file metadata to start transfer - logWrite("Sending FILE_RESPONSE_SEND.\n\r"); temp = FILE_RESPONSE_SEND; packetData = packetContentPack(&length, "iis", temp, client->fileSize, shaInDB); encoded.control = PACKET_CONTROL_DAT; @@ -135,7 +126,6 @@ static void clientApiFileRequestCheck(ClientThreadT *client, PacketDecodeDataT * encoded.encrypt = 0; packetEncode(client->packetThreadData, &encoded, packetData, length); packetSend(client->packetThreadData, &encoded); - //packetDebugPrint((uint8_t *)encoded.dataPointer, encoded.length); DEL(packetData); DEL(sha256); @@ -155,7 +145,6 @@ static void clientApiFileRequestNext(ClientThreadT *client, PacketDecodeDataT *d // Do we have an open file? if (client->handle) { - logWrite("Sending FILE_RESPONSE_DATA.\n\r"); // Add response type. temp = FILE_RESPONSE_DATA; memcpy(&packetData[0], &temp, sizeof(int32_t)); @@ -163,24 +152,23 @@ static void clientApiFileRequestNext(ClientThreadT *client, PacketDecodeDataT *d // Add file data. // ***TODO*** We can't send quite a full packet for some reason. length = client->fileSize - ftell(client->handle); - if (length > PACKET_MAX - 14) { + if (length > PACKET_MAX - (10 + sizeof(int32_t))) { // File is larger than a packet size. - length = PACKET_MAX - 14; // 4 for integer of response type. 10 more because a full PACKET_MAX causes issues. - fread(&packetData[4], length, 1, client->handle); + length = PACKET_MAX - (10 + sizeof(int32_t)); // 4 for integer of response type. 10 more because a full PACKET_MAX causes issues. + fread(&packetData[sizeof(int32_t)], length, 1, client->handle); } else { // File remains will fit in this packet. - fread(&packetData[4], length, 1, client->handle); + fread(&packetData[sizeof(int32_t)], length, 1, client->handle); fclose(client->handle); client->handle = NULL; } - logWrite("Sending %d bytes of file\n\r", length); // Build packet. encoded.control = PACKET_CONTROL_DAT; encoded.packetType = PACKET_TYPE_FILE_RESPONSE; encoded.channel = data->channel; encoded.encrypt = 0; - packetEncode(client->packetThreadData, &encoded, packetData, length + 4); + packetEncode(client->packetThreadData, &encoded, packetData, length + sizeof(int32_t)); // Send it. packetSend(client->packetThreadData, &encoded); } diff --git a/server/src/client/signup.c b/server/src/client/signup.c index 61b8222..0c87f9d 100644 --- a/server/src/client/signup.c +++ b/server/src/client/signup.c @@ -40,17 +40,16 @@ void clientApiSignup(ClientThreadT *client, PacketDecodeDataT *data) { // This only makes sense if they're not logged in. if (!client->authenticated) { - - packetDebugPrint((uint8_t *)data->data, data->length); - // Get info for the user. packetContentUnpack(data->data, "sssss", &email, &first, &last, &pass, &user); + /* logWrite("Email: %s\n\r", email); logWrite("First: %s\n\r", first); logWrite(" Last: %s\n\r", last); logWrite(" Pass: %s\n\r", pass); logWrite(" User: %s\n\r", user); + */ // See if they already exist in the database. if (dbUserNameExists(user)) { diff --git a/server/src/main.c b/server/src/main.c index e9de36d..1e77270 100644 --- a/server/src/main.c +++ b/server/src/main.c @@ -84,7 +84,7 @@ static void configWrite(char *file) { "USER=%s\n" "PASS=%s\n", _configServer, - _configPort, + (int)_configPort, _configDatabase, _configUser, _configPassword @@ -157,6 +157,7 @@ int main(int argc, char *argv[]) { restShutdown(); configWrite(configFile); DEL(configFile); + dbDisconnect(); logWrite("Shutdown complete.\n"); logClose(); memoryShutdown(); diff --git a/server/src/server.c b/server/src/server.c index 87f30a3..38b8702 100644 --- a/server/src/server.c +++ b/server/src/server.c @@ -63,6 +63,8 @@ static void serverPacketSender(uint8_t *data, uint32_t length, void *userData) { ENetPeer *peer = (ENetPeer *)userData; ENetPacket *packet = NULL; + //logWrite("OUT: "); packetDebugPrint((uint8_t *)data, length); + // Send packet. packet = enet_packet_create(data, length, ENET_PACKET_FLAG_RELIABLE); enet_peer_send(peer, 0, packet); diff --git a/shared/packet.c b/shared/packet.c index 244e082..a6d1e71 100644 --- a/shared/packet.c +++ b/shared/packet.c @@ -51,6 +51,7 @@ #include "thirdparty/tiny-AES128-C/pkcs7_padding.h" +static uint8_t _packetLogging = 0; // Do we want to write all packets to disk? static packetSender _packetSender = NULL; static uint8_t _encryptionReady = 0; @@ -184,13 +185,6 @@ static uint8_t packetCRC(uint8_t *data, uint16_t length, uint8_t startAt) { } -void packetDebugPrint(uint8_t *data, uint16_t length) { - uint16_t i; - for (i=0; i 0) { for (x=0; xdecodeQueue[threadData->decodeQueueHead++] = input[x]; - if (threadData->decodeQueueHead >= PACKET_INPUT_QUEUE_SIZE) threadData->decodeQueueHead = 0; + if (threadData->decodeQueueHead >= PACKET_BUFFER_SIZE) threadData->decodeQueueHead = 0; } } @@ -215,7 +209,7 @@ uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeDat // Get next byte. c = threadData->decodeQueue[threadData->decodeQueueTail++]; - if (threadData->decodeQueueTail >= PACKET_INPUT_QUEUE_SIZE) threadData->decodeQueueTail = 0; + if (threadData->decodeQueueTail >= PACKET_BUFFER_SIZE) threadData->decodeQueueTail = 0; // New packet? if (threadData->newPacket) { @@ -235,6 +229,8 @@ uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeDat // Yes! Process it and set up for the next packet. threadData->newPacket = 1; + packetLog(" IN:", threadData->decodeBuffer, threadData->length); + /* // Check CRC. x = packetCRC(threadData->decodeBuffer, threadData->length - 1, 0); @@ -305,7 +301,7 @@ uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeDat // Copy packet data to new buffer, if any. if (threadData->length - 4 > 0) { decodeData->data = (uint8_t *)malloc(threadData->length - 4); // 4 for 3 byte header and 1 byte CRC. - if (!decodeData) continue; + if (!decodeData->data) continue; memcpy(decodeData->data, &threadData->decodeBuffer[3], threadData->length - 4); // Skip header and CRC. decodeData->length = threadData->length - 4; } else { @@ -316,9 +312,6 @@ uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeDat // Fix length to remove header and checksum. threadData->length -= 4; - logWrite("Packet In: %d Length: %d\n\r", decodeData->packetType, decodeData->length); - //packetDebugPrint((uint8_t *)decodeData->data, decodeData->length); - // Is this a DH_REQUEST? if (decodeData->packetType == PACKET_TYPE_DH_REQUEST) { memcpy(threadData->dhModulus, decodeData->data, PACKET_ENCRYPT_KEY_SIZE * sizeof(uint16_t)); @@ -529,12 +522,39 @@ void packetEncryptionSetup(PacketThreadDataT *threadData) { } +void packetLog(char *message, uint8_t *packet, uint32_t length) { + FILE *log = NULL; + uint16_t i = 0; + static uint8_t firstCall = 1; + + if (!_packetLogging) return; + + if (firstCall) { + log = fopen("packet.log", "wt"); + firstCall = 0; + } else { + log = fopen("packet.log", "at"); + } + if (log) { + fprintf(log, "%s %05u ", message, length); + for (i=0; i 32) && (packet[i] < 255) && (packet[i] != 127)) { + fprintf(log, "%02x [%c] ", packet[i], packet[i]); + } else { + fprintf(log, "%02x [ ] ", packet[i]); + } + } + fprintf(log, "\n-------------------------------------------------------------------------------\n"); + fclose(log); + } +} + + void packetSend(PacketThreadDataT *threadData, PacketEncodeDataT *data) { // Valid control type? if (data->control != PACKET_CONTROL_BAD && data->control <= PACKET_CONTROL_COUNT) { + packetLog("OUT:", data->dataPointer, data->length); _packetSender(data->dataPointer, data->length, threadData->senderData); - logWrite("Packet Out: %d Length: %d\n\r", data->packetType, data->length); - //packetDebugPrint((uint8_t *)data->dataPointer, data->length); } else { logWrite("Invalid PACKET_CONTROL!\n\r"); } diff --git a/shared/packet.h b/shared/packet.h index 568d994..70700fa 100644 --- a/shared/packet.h +++ b/shared/packet.h @@ -43,7 +43,6 @@ #define PACKET_MAX 4096 // Maximum number of bytes per packet. #define PACKET_SEQUENCE_MAX 32 // Five bits of data, 32 max. Represents size of replay history. Also maximum number of packets on the wire at a time. -#define PACKET_INPUT_QUEUE_SIZE 8192 #define PACKET_BUFFER_SIZE (PACKET_MAX * 2 + 2 + 8) // Worst case, every byte is a PACKET_FRAME. Add two for ending frame. Add 8 for worst case header and CRC. #define PACKET_FRAME 0x7e @@ -98,7 +97,7 @@ typedef struct PacketThreadDataS { */ uint8_t decodeBuffer[PACKET_MAX]; uint8_t encodeBuffer[PACKET_BUFFER_SIZE]; - uint8_t decodeQueue[PACKET_INPUT_QUEUE_SIZE]; + uint8_t decodeQueue[PACKET_BUFFER_SIZE]; uint16_t decodeQueueHead; uint16_t decodeQueueTail; uint8_t inEscape; @@ -121,13 +120,13 @@ typedef void (*packetSender)(uint8_t *data, uint32_t length, void *userData); uint8_t *packetContentPack(uint16_t *length, char *format, ...); void packetContentUnpack(uint8_t *buffer, char *format, ...); -void packetDebugPrint(uint8_t *data, uint16_t length); uint8_t packetDecode(PacketThreadDataT *threadData, PacketDecodeDataT *decodeData, uint8_t *input, uint16_t inputLength); void packetDecodeDataDestroy(PacketDecodeDataT **packet); void packetDecodeDataStaticDestroy(PacketDecodeDataT *packet); uint8_t packetEncode(PacketThreadDataT *threadData, PacketEncodeDataT *data, uint8_t *input, uint16_t length); uint8_t packetEncryptionReady(void); void packetEncryptionSetup(PacketThreadDataT *threadData); +void packetLog(char *message, uint8_t *packet, uint32_t length); void packetSend(PacketThreadDataT *threadData, PacketEncodeDataT *data); void packetSenderRegister(packetSender sender); PacketThreadDataT *packetThreadDataCreate(void *senderData);