-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.cc
153 lines (136 loc) · 4.63 KB
/
test.cc
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright (c) 2020 mumumusuc
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "controller.h"
#include "log.h"
#include "session2.h"
#include <assert.h>
#include <iostream>
#include <signal.h>
#include <unistd.h>
#define msleep(ms) std::this_thread::sleep_for(std::chrono::milliseconds((ms)))
std::future<int> test_future() {
std::promise<int> p;
auto f = p.get_future();
p.set_value(10);
return f;
}
static int test_l() {
int ret = 0;
try {
auto jc = new controller::JoyCon_L(nullptr);
//jc->Poll(POLL_STANDARD);
for (uint8_t j = 0; j < 0xff; j++)
for (uint8_t i = 0; i <= 0xf; ++i) {
ret = jc->SetPlayer(static_cast<Player>(i), PLAYER_FLASH_0);
msleep(32);
}
ret = jc->SetPlayer(PLAYER_0, PLAYER_FLASH_4);
delete jc;
} catch (std::exception &e) {
log_d(__func__, "%s", e.what());
}
return ret;
}
static int test_r() {
int ret = 0;
try {
auto jc = new controller::JoyCon_R(nullptr);
//jc->Poll(POLL_STANDARD);
for (uint8_t j = 0; j < 0xf; j++)
for (uint8_t i = 0; i <= 0xf; ++i) {
ret = jc->SetPlayer(static_cast<Player>(i), PLAYER_FLASH_0);
msleep(32);
}
ret = jc->SetPlayer(PLAYER_0, PLAYER_FLASH_4);
delete jc;
} catch (std::exception &e) {
log_d(__func__, "%s", e.what());
}
return ret;
}
static mac_address_le_t ns_mac = {0x62, 0x9a, 0x15, 0xeb, 0x68, 0xdc};
static int test_session() {
int ret = 0;
DeviceFunc dev_fun = {
.sender = [](const void *buffer, size_t size) -> ssize_t {
hex_d("SEND", buffer, size);
return size;
},
.recver = [](void *buffer, size_t size) -> ssize_t {
strcpy(reinterpret_cast<char *>(buffer), "test_session");
return size;
},
.send_size = OUTPUT_REPORT_SIZE,
.recv_size = INPUT_REPORT_STAND_SIZE,
};
session::Session sess(&dev_fun);
uint8_t buffer[OUTPUT_REPORT_SIZE] = "sess test";
auto f1 = std::async(
[&sess, buffer]() {
for (int i = 0; i < 10; i++) {
log_d(__func__, "time test %d -----ing", i);
auto f = sess.Transmit(
5, buffer, [](const void *input) {
//hex_dump("RECV", input, INPUT_PACKET_STAND_SIZE);
return session::WAITING;
});
assert(f.get() == session::TIMEDOUT);
log_d(__func__, "time test %d -----OK", i);
}
log_d(__func__, "time test over");
return 0;
});
auto f2 = std::async(
[&sess, buffer]() {
for (int i = 0; i < 10; i++) {
log_d(__func__, "done test %d -----ing", i);
auto f = sess.Transmit(
5, buffer, [](const void *input) {
//hex_dump("RECV", input, INPUT_PACKET_STAND_SIZE);
return session::DONE;
});
assert(f.get() == session::DONE);
log_d(__func__, "done test %d -----OK", i);
}
log_d(__func__, "done test over");
return 0;
});
ret = f1.get();
ret = f2.get();
return ret;
}
static int test_dual() {
int ret = 0;
auto jc = controller::JoyCon_Dual(nullptr);
jc.Pair();
jc.SetLowPower(false);
//jc.SetMcuMode(McuMode(0));
jc.SetImu(true);
for (uint8_t j = 0; j < 0x7f; j++) {
//jc.Poll(POLL_STANDARD);
for (uint8_t i = 0; i <= 0xf; ++i) {
ret = jc.SetPlayer(static_cast<Player>(i), PLAYER_FLASH_0);
msleep(32);
}
}
ret = jc.SetPlayer(PLAYER_0, PLAYER_FLASH_4);
return ret;
}
int main() {
std::cout << "hello test c++" << std::endl;
int ret = 0;
ret = test_session();
return ret;
}
// valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --undef-value-errors=no -s ./build/test_cpp