-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathSocketTester.cpp
More file actions
49 lines (38 loc) · 1.34 KB
/
SocketTester.cpp
File metadata and controls
49 lines (38 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2021 Charles Tytler
#include "Utilities/UdpSocket.cpp"
#include <bitset>
#include <csignal>
#include <fstream>
#include <iomanip>
#include <iostream>
/**
* This tool is currently set up to connect to DCS-BIOS and print out received data in Hex format.
*/
void signalInteruptHandler(int sig)
{
std::cout << "Stopped." << std::endl;
std::exit(sig);
}
int main()
{
signal(SIGINT, signalInteruptHandler);
UdpSocket socket("127.0.0.1", "5010", "7778", "239.255.50.10");
std::ofstream log_file;
log_file.open("./socket_dump.log");
std::cout << "Logging data to ./socket_dump.log | Press CTRL+C to stop." << std::endl;
for (;;) {
constexpr int MAX_UDP_MSG_SIZE = 1024; // Maximum UDP buffer size to read.
char msg[MAX_UDP_MSG_SIZE] = {0};
const int num_bytes = socket.receive_bytes(msg, MAX_UDP_MSG_SIZE);
if (num_bytes != SOCKET_ERROR) {
log_file << std::dec << "Bytes recv: " << num_bytes << std::endl;
for (size_t byte = 0; byte < num_bytes; byte++) {
// Set format to "0x00"
log_file << "0x" << std::setfill('0') << std::setw(2) << std::right << std::hex;
log_file << static_cast<uint16_t>((unsigned char)(msg[byte])) << " ";
}
log_file << std::endl;
}
}
return 0;
}