11#include " include/DuckNet.h"
22#include < cstring>
33#include < ArduinoJson.h>
4+ #include < regex>
45
56DuckNet::DuckNet (BloomFilter *filter): bloomFilter(filter) {
67}
@@ -188,21 +189,21 @@ int DuckNet::setupWebServer(bool createCaptivePortal, std::string html) {
188189 // }
189190 // });
190191
191- webServer.on (" /atakHistory" , HTTP_GET, [&](AsyncWebServerRequest* request) {
192- size_t atakSize;
192+ // webServer.on("/atakHistory", HTTP_GET, [&](AsyncWebServerRequest* request) {
193+ // size_t atakSize;
193194
194- uint8_t * atakBytes = DuckNet::serializeAtakHistoryToBytes (&atakMessageBuffer, &atakSize);
195+ // uint8_t* atakBytes = DuckNet::serializeAtakHistoryToBytes(&atakMessageBuffer, &atakSize);
195196
196- // std::shared_ptr<uint8_t> atakData(atakBytes, [](uint8_t* p) { delete[] p; });
197+ // // std::shared_ptr<uint8_t> atakData(atakBytes, [](uint8_t* p) { delete[] p; });
197198
198- AsyncWebServerResponse *response = request->beginResponse_P (200 , " application/octet-stream" , atakBytes, atakSize);
199+ // AsyncWebServerResponse *response = request->beginResponse_P(200, "application/octet-stream", atakBytes, atakSize);
199200
200- loginfo_ln (" sending atak history" );
201- // response->addHeader("Content-Disposition", "attachment; filename=\"atakHistory.bin\"");
202- request->send (response);
203- });
201+ // loginfo_ln("sending atak history");
202+ // // response->addHeader("Content-Disposition", "attachment; filename=\"atakHistory.bin\"");
203+ // request->send(response);
204+ // });
204205
205- webServer.on (" /atakChatHistory " , HTTP_GET, [&](AsyncWebServerRequest* request){
206+ webServer.on (" /atakHistory " , HTTP_GET, [&](AsyncWebServerRequest* request){
206207 std::string response = DuckNet::serializeAtakHistoryToJSON (&atakMessageBuffer);
207208 const char * res = response.c_str ();
208209 request->send (200 , " text/json" , res);
@@ -358,7 +359,7 @@ int DuckNet::setupInternet(std::string ssid, std::string password)
358359
359360void DuckNet::addToAtakBuffer (std::vector<byte> message) {
360361 txPacket->prepareForSending (bloomFilter, BROADCAST_DUID, DuckType::UNKNOWN, topics::achat, message);
361- auto atakBuffer = txPacket->getBuffer (); // TODO: no auto
362+ auto atakBuffer = txPacket->getBuffer ();
362363 CdpPacket atakPacket (atakBuffer);
363364
364365 if (atakMessageBuffer.findMuid (atakPacket.muid ) < 0 ){
@@ -384,10 +385,28 @@ std::string DuckNet::serializeAtakHistoryToJSON(CircularBuffer* buffer) {
384385 CdpPacket packet = buffer->getMessage (tail);
385386 unsigned long messageAge = millis () - packet.timeReceived ;
386387 std::string messageAgeString = String (messageAge).c_str ();
387- std::string messageBody (packet.data .begin (),packet.data .end ());
388388 std::string sduid (packet.sduid .begin (), packet.sduid .end ());
389389 std::string muid (packet.muid .begin (), packet.muid .end ());
390390
391+ // fill in placeholder body info
392+ std::string rawBody (packet.data .begin (),packet.data .end ());
393+
394+ // Default placeholders
395+ std::string LAT = " 0.0000" ;
396+ std::string LNG = " 0.0000" ;
397+
398+ // Extract lat/lng from format: "Lat: <val>, Lng: <val>"
399+ std::regex coordRegex (R"( Lat:\s*([-+]?\d*\.\d+|\d+),\s*Lng:\s*([-+]?\d*\.\d+|\d+))" );
400+ std::smatch match;
401+ if (std::regex_search (rawBody, match, coordRegex)) {
402+ if (match.size () >= 3 ) {
403+ LAT = match[1 ].str ();
404+ LNG = match[2 ].str ();
405+ }
406+ }
407+
408+ std::string messageBody = " {\" body\" :\" i: 14GU t: 1 s: 0 r: t b: TEST,TEST," + LAT + " ," + LNG + " ," + " a-n-G,TEST,All,-2`&\" ,\" username\" :\" GRAND SLAM CTL\" }" ;
409+
391410 json = json + " {\" sduid\" :\" " + sduid + " \" , \" muid\" :\" " + muid + " \" , \" title\" :\" PLACEHOLDER TITLE\" , \" body\" :" + messageBody + " , \" messageAge\" :\" " + messageAgeString + " \" }" ;
392411 tail++;
393412 if (tail == buffer->getBufferEnd ()){
0 commit comments