-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSDHRNetworking.h
More file actions
101 lines (82 loc) · 2.85 KB
/
SDHRNetworking.h
File metadata and controls
101 lines (82 loc) · 2.85 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
//////////////////////////////////////////////////////////////////////////
//
// Utility header file to provide cross-platform initialization of networking
// It just sets up the server file descriptor given a server sockaddr
//
//////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <cstring>
#include <atomic>
#include <vector>
#include <SDL.h>
#include "common.h"
#define PKT_BUFSZ 2048
#pragma pack(push, 1)
struct Packet {
uint8_t data[PKT_BUFSZ];
uint32_t size;
Packet() : size(1) {
memset(data, 0, 1);
}
};
struct SDHRPacketHeader {
uint32_t seqno;
uint32_t cmdtype;
};
#pragma pack(pop)
struct SDHREvent {
bool is_iigs; // 2gs == 1, 2e == 0
bool m2b0;
bool m2sel;
bool rw; // read == 1, write == 0
uint16_t addr;
uint8_t data;
SDHREvent(bool is_iigs_, bool m2b0_, bool m2sel_, bool rw_, uint16_t addr_, uint8_t data_) :
is_iigs(is_iigs_), m2b0(m2b0_), m2sel(m2sel_), rw(rw_), addr(addr_), data(data_) {}
};
enum class ENET_RES
{
OK = 0,
ERR = 1
};
enum class BusEventFlags : uint32_t {
EventEnable = 1u << 0,
Overflow = 1u << 1,
};
constexpr bool state_has_flag(uint32_t value, BusEventFlags flag);
std::string bus_event_state_to_string(uint32_t state);
#define CXSDHR_CTRL 0xC0A0 // SDHR command
#define CXSDHR_DATA 0xC0A1 // SDHR data
// Call this method as a new thread
// It loops infinitely and waits for packets
// And puts it in an events queue
int usb_server_thread(std::atomic<bool>* shouldTerminateNetworking);
// Call this method as a new thread
// It loops indefinitely and processes the packets queue
// Each packet contains a minumum of 64 events.
// If the events are SDHR data, it appends them to a command_buffer
// When it parses a SDHR_PROCESS_EVENTS event, it calls SDHRManager
// which itself processes the command_buffer
int process_usb_events_thread(std::atomic<bool>* shouldTerminateProcessing);
void process_single_event(SDHREvent& e);
void terminate_processing_thread();
void clear_queues();
const uint64_t get_number_packets_processed();
const uint64_t get_duration_packet_processing_ns();
const uint64_t get_duration_network_processing_ns();
const size_t get_packet_pool_count();
const size_t get_max_incoming_packets();
const bool tini_is_ok();
const bool client_is_connected();
const std::string get_tini_name_string();
const uint32_t get_tini_last_error();
const std::string get_tini_last_error_string();
const std::string get_tini_last_error_string_async(); // Replaces async IO Pending "error" as OK
// Sends data to the tini via the register API
uint32_t usb_write_register(uint32_t addressStart, const std::vector<uint32_t>* vData, bool setIncrement);
// Mouse interface (temporary!)
uint32_t usb_mouse_send_event(SDL_Event event);
void usb_mouse_set_sensitivity(float s);
float usb_mouse_get_sensitivity();
void usb_display_imgui_window(bool* p_open);