diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-01 17:20:19 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-01 17:20:19 +0200 |
commit | ffe81214b6bd99544d072545be47dac745786794 (patch) | |
tree | a2ae6f2f65c91a54becf6738e36e8da2e981015c /src | |
parent | 562964df547e9cdbb3ee32edae5592ab5a513b25 (diff) |
add package fiddling + editorconfig + preprocessor options
Diffstat (limited to 'src')
-rw-r--r-- | src/frontend/qt_sdl/LocalMP.cpp | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index cc42706..b2e307e 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -16,6 +16,11 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +// VSR-specific experiments + +// #define VSR_MESSAGE_FIDDLING 1 +#define VSR_DUMP_MESSAGES 1 + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -39,13 +44,18 @@ #include "LocalMP.h" #include "Platform.h" -#include <pcap/pcap.h> -#include <time.h> -#include <vector> #include <stdint.h> +#ifdef VSR_DUMP_MESSAGES +#include <pcap/pcap.h> +#include <vector> pcap_dumper_t* dumper; +#endif + +#ifdef VSR_MESSAGE_FIDDLING +#include <time.h> unsigned long test_start = time(NULL); +#endif using namespace melonDS; using namespace melonDS::Platform; @@ -241,10 +251,12 @@ void SemReset(int num) bool Init() { +#ifdef VSR_DUMP_MESSAGES pcap_t* handle = pcap_open_dead(DLT_USER0, 1 << 16); char filename[80]; snprintf(filename, 79, "melon_%lu.pcap", time(NULL)); dumper = pcap_dump_open(handle, filename); +#endif MPQueue = new QSharedMemory("melonNIFI"); @@ -307,7 +319,9 @@ bool Init() void DeInit() { +#ifdef VSR_DUMP_MESSAGES pcap_dump_close(dumper); +#endif if (MPQueue) { @@ -447,16 +461,18 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) u16 mask = header->ConnectedBitmask; - // // packet dropping test - // unsigned long now = time(NULL); - // static bool first = true; - // bool dropping = false; - // if (now - test_start > 20 && InstanceID == 0) { - // if (first == true) - // printf("[INSTANCE %d] started dropping packets!\n", InstanceID); - // first = false; - // dropping = true; - // } +#ifdef VSR_MESSAGE_FIDDLING + // fiddle the packets after 20 seconds + unsigned long now = time(NULL); + static bool first = true; + bool fiddle = false; + if (now - test_start > 20 && InstanceID == 0) { + if (first == true) + printf("[INSTANCE %d] started fiddling!\n", InstanceID); + first = false; + fiddle = true; + } +#endif // TODO: check if the FIFO is full! @@ -467,30 +483,47 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) pktheader.Length = len; pktheader.Timestamp = timestamp; +#ifdef VSR_DUMP_MESSAGES std::vector<uint8_t> buf; +#endif type &= 0xFFFF; int nfifo = (type == 2) ? 1 : 0; // NOTE: this is the ni-fi packet header, altering this header in any way // seems to consistently trigger PACKET FIFO OVERFLOW errors FIFOWrite(nfifo, &pktheader, sizeof(pktheader)); +#ifdef VSR_DUMP_MESSAGES buf.insert(buf.end(), (uint8_t*) &pktheader, (uint8_t*) &pktheader + sizeof(pktheader)); +#endif if (len) { - // // replace packet content with random noise while dropping - // if (dropping) - // for (size_t i = 0; i < len; i++) - // packet[i] = rand(); +#ifdef VSR_MESSAGE_FIDDLING + if (fiddle && len == 0xde) { + // NOTE: packet indexes are after NIFI header! + packet[0x80] = 0x11; + packet[0x81] = 0x11; + packet[0x82] = 0x11; + packet[0x83] = 0x11; + packet[0x84] = 0x11; + packet[0x85] = 0x11; + packet[0x86] = 0x11; + packet[0x87] = 0x11; + } +#endif +#ifdef VSR_DUMP_MESSAGES buf.insert(buf.end(), (uint8_t*) packet, (uint8_t*) packet + len); +#endif FIFOWrite(nfifo, packet, len); } +#ifdef VSR_DUMP_MESSAGES struct pcap_pkthdr p; p.len = buf.size(); p.caplen = buf.size(); gettimeofday(&p.ts, NULL); pcap_dump((u_char*) dumper, &p, buf.data()); +#endif if (type == 1) { |