#include "ggwave/ggwave.h" #include "ggwave-common.h" #include "ggwave-common-sdl2.h" #include #include #include #include #include int main(int argc, char** argv) { printf("Usage: %s [-cN] [-pN] [-tN]\n", argv[0]); printf(" -cN - select capture device N\n"); printf(" -pN - select playback device N\n"); printf(" -tN - transmission protocol:\n"); printf(" -t0 : Normal\n"); printf(" -t1 : Fast (default)\n"); printf(" -t2 : Fastest\n"); printf(" -t3 : Ultrasonic\n"); printf("\n"); auto argm = parseCmdArguments(argc, argv); int captureId = argm["c"].empty() ? 0 : std::stoi(argm["c"]); int playbackId = argm["p"].empty() ? 0 : std::stoi(argm["p"]); int txProtocol = argm["t"].empty() ? 1 : std::stoi(argm["t"]); if (GGWave_init(playbackId, captureId) == false) { fprintf(stderr, "Failed to initialize GGWave\n"); return -1; } auto ggWave = GGWave_instance(); ggWave->setTxMode(GGWave::TxMode::VariableLength); printf("Selecting Tx protocol %d\n", txProtocol); switch (txProtocol) { case 0: { printf("Using 'Normal' Tx Protocol\n"); ggWave->setParameters(1, 40, 9, 3, 50); } break; case 1: { printf("Using 'Fast' Tx Protocol\n"); ggWave->setParameters(1, 40, 6, 3, 50); } break; case 2: { printf("Using 'Fastest' Tx Protocol\n"); ggWave->setParameters(1, 40, 3, 3, 50); } break; case 3: { printf("Using 'Ultrasonic' Tx Protocol\n"); ggWave->setParameters(1, 320, 9, 3, 50); } break; default: { printf("Using 'Fast' Tx Protocol\n"); ggWave->setParameters(1, 40, 6, 3, 50); } }; printf("\n"); ggWave->init(0, ""); std::mutex mutex; std::thread inputThread([&]() { std::string inputOld = ""; while (true) { std::string input; std::cout << "Enter text: "; getline(std::cin, input); if (input.empty()) { std::cout << "Re-sending ... " << std::endl; input = inputOld; } else { std::cout << "Sending ... " << std::endl; } { std::lock_guard lock(mutex); ggWave->init(input.size(), input.data()); } inputOld = input; } }); while (true) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); { std::lock_guard lock(mutex); GGWave_mainLoop(); } } inputThread.join(); GGWave_deinit(); return 0; }