@@ -171,6 +171,7 @@ int DuckNet::setupWebServer(bool createCaptivePortal, std::string html) {
171171 switch (err) {
172172 case DUCK_ERR_NONE:
173173 {
174+ loginfo_ln (" success sending packer" );
174175 request->send (200 , " text/html" , " OK." );
175176 }
176177 break ;
@@ -187,19 +188,21 @@ int DuckNet::setupWebServer(bool createCaptivePortal, std::string html) {
187188 });
188189
189190 webServer.on (" /atakHistory" , HTTP_GET, [&](AsyncWebServerRequest* request) {
190- uint8_t * atakBytes = DuckNet::serializeAtakHistoryToBytes (&atakBuffer);
191- size_t atakSize = sizeof (atakBytes);
192- // Use shared_ptr for safe cleanup
193- std::shared_ptr<uint8_t > atakData (atakBytes, [](uint8_t * p) { delete[] p; });
191+ size_t atakSize;
194192
195- AsyncWebServerResponse* response = request->beginResponse (" application/octet-stream" , atakSize,???
196- });
193+ uint8_t * atakBytes = DuckNet::serializeAtakHistoryToBytes (&atakBuffer, &atakSize);
197194
198- response->addHeader (" Content-Disposition" , " attachment; filename=\" atakHistory.bin\" " );
195+ // std::shared_ptr<uint8_t> atakData(atakBytes, [](uint8_t* p) { delete[] p; });
196+
197+ AsyncWebServerResponse *response = request->beginResponse_P (200 , " application/octet-stream" , atakBytes, atakSize);
198+
199+ loginfo_ln (" sending atak history" );
200+ // response->addHeader("Content-Disposition", "attachment; filename=\"atakHistory.bin\"");
199201 request->send (response);
200202});
201203
202204 webServer.on (" /atakChatHistory" , HTTP_GET, [&](AsyncWebServerRequest* request){
205+ loginfo_ln (" this is what should be called in captive portal" );
203206 std::string response = DuckNet::serializeAtakHistoryToJSON (&atakBuffer);
204207 const char * res = response.c_str ();
205208 request->send (200 , " text/json" , res);
@@ -357,6 +360,7 @@ void DuckNet::addToAtakBuffer(CdpPacket message) {
357360 if (atakBuffer.findMuid (message.muid ) < 0 ){
358361 message.timeReceived = millis ();
359362 atakBuffer.push (message);
363+ loginfo_ln (" pushed new packet to buffer" );
360364 }
361365}
362366
@@ -391,38 +395,28 @@ std::string DuckNet::serializeAtakHistoryToJSON(CircularBuffer* buffer) {
391395
392396}
393397
394- uint8_t * DuckNet::serializeAtakHistoryToBytes (CircularBuffer* buffer) {
398+ uint8_t * DuckNet::serializeAtakHistoryToBytes (CircularBuffer* buffer, size_t * totalAtakBytes ) {
395399 // int atakBytes = buffer->getCount();
396400 // size_t dataSize = atakBytes * sizeof(CdpPacket);
397- // outSize = dataSize + sizeof(uint32_t);
398-
399- uint8_t * result = new uint8_t [dataSize];
400-
401- // // First 4 bytes = count (little endian)
402- // result[0] = atakBytes & 0xFF;
403- // result[1] = (atakBytes >> 8) & 0xFF;
404- // result[2] = (atakBytes >> 16) & 0xFF;
405- // result[3] = (atakBytes >> 24) & 0xFF;
401+ // totalAtakBytes = dataSize + sizeof(uint32_t);
402+ std::vector<byte> packetArr;
406403
407404 // Serialize packets
408405 int tail = buffer->getTail ();
409- // for (int i = 0; i < atakBytes; i++) {
410- // CdpPacket packet = buffer->getMessage(tail);
411- // memcpy(result + 4 + i * sizeof(CdpPacket), &packet, sizeof(CdpPacket));
412- // tail = (tail + 1) % buffer->getBufferEnd();
413- // }
414406
415407 while (tail != buffer->getHead ()){
416408 CdpPacket packet = buffer->getMessage (tail);
417- // get the size of this specific packet
418- // copy the bytes into result
419- memcpy (result + 4 + i * sizeof (CdpPacket), &packet, sizeof (CdpPacket));
409+ packetArr.insert (packetArr.end (), packet.muid .begin (), packet.muid .end ());
410+ packetArr.insert (packetArr.end (), packet.data .begin (), packet.data .end ());
420411 tail++;
421412 if (tail == buffer->getBufferEnd ()){
422413 tail = 0 ;
423414 }
424415 }
425-
416+ *totalAtakBytes = packetArr.size ();
417+ uint8_t * result = new uint8_t [*totalAtakBytes];
418+ memcpy (result, packetArr.data (), *totalAtakBytes);
419+ loginfo_ln (" complete serialize" );
426420 return result;
427421}
428422
0 commit comments