9
10
token_packet_t tp = token_packet_new(SETUP_PID, 0, 0);
10
uint8_t data_payload[8] = { /* Get device descriptor. */
11
uint8_t data_payload[] = { /* Get device descriptor. */
12
0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x12, 0x00,
20
14
data_packet_t dp = data_packet_new(DATA0_PID, data_payload, 64);
21
15
uint8_t tp_buffer_bit_count = -1;
22
16
uint8_t dp_buffer_bit_count = -1;
23
17
uint8_t *tp_buffer = NULL;
24
18
uint8_t *dp_buffer = NULL;
26
printf("DP payload bit count: %d\n",data_packet_get_payload_bit_count(dp));
21
/* Data packet payload bit count. */
23
uint8_t found = data_packet_get_payload_bit_count(dp);
25
bool verified = (found == target);
26
passing = passing && verified;
28
warn("Bad DP bit count; found: %d; target: %d\n",
28
32
token_packet_recalculate_crc5(tp);
29
33
data_packet_recalculate_crc16(dp);
31
35
tp_buffer = token_packet_bufferize(tp, &tp_buffer_bit_count);
36
dp_buffer = data_packet_bufferize(dp, &dp_buffer_bit_count);
37
passing = passing && tp_buffer && dp_buffer;
33
39
puts("TP buffer failed.");
34
dp_buffer = data_packet_bufferize(dp, &dp_buffer_bit_count);
36
41
puts("DP buffer failed.");
40
printf("TP buffer bit count: %d\n", tp_buffer_bit_count);
41
printf("DP buffer bit count: %d\n", dp_buffer_bit_count);
45
/* Buffer bit counts. */
48
uint8_t found, target;
50
found = tp_buffer_bit_count;
52
verified = (found == target);
53
passing = passing && verified;
55
printf("Bad TP buffer bit count; found: %d; target: %d\n",
58
found = dp_buffer_bit_count;
60
verified = (found == target);
61
passing = passing && verified;
63
printf("Bad DP buffer bit count; found: %d; target: %d\n",
43
67
token_packet_delete(tp);
44
68
data_packet_delete(dp);
51
76
uint8_t addresses[] = {0x15, 0x3a, 0x70};
52
77
uint8_t endpoints[] = {0x0e, 0x0a, 0x04};
53
78
uint8_t targets[] = {0x17, 0x1c, 0x0e};
56
82
for (iter = 0; iter < 3; iter++)
85
token_packet_new(SETUP_PID, addresses[iter], endpoints[iter]);
62
tp = token_packet_new(SETUP_PID, addresses[iter], endpoints[iter]);
63
89
token_packet_recalculate_crc5(tp);
64
90
found = token_packet_get_crc5(tp);
65
91
verified = (found == targets[iter]);
66
printf("CRC5 verified: %d; found: %d; target: %d\n",
67
verified, found, targets[iter]);
92
passing = passing && verified;
94
warn("Bad CRC5: found: 0x%x; target: 0x%x\n",
95
found, targets[iter]);
68
96
token_packet_delete(tp);
76
uint8_t sizes[] = {32, 32, 64, 64, 72};
77
105
packet_id_t pids[] = {DATA0_PID, DATA1_PID, DATA1_PID, DATA0_PID};
78
106
uint8_t payload0[] = {0x00, 0x01, 0x02, 0x03};
79
107
uint8_t payload1[] = {0x23, 0x45, 0x67, 0x89};
80
108
uint8_t payload2[] = {0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08};
81
109
uint8_t payload3[] = {0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x12, 0x00};
82
110
unsigned char payload4[] = "123456789";
111
uint8_t *payloads[] = {payload0, payload1, payload2, payload3, payload4};
112
uint8_t payload_sizes[] = {32, 32, 64, 64, 72};
83
113
uint16_t targets[] = {0xf75e, 0x7038, 0x88ee, 0x072f, 0x132d};
88
dp = data_packet_new(pids[0], payload0, sizes[0]);
89
found = data_packet_get_crc16(dp);
90
verified = (found == targets[0]);
91
printf("CRC16 verified: %d; found: 0x%x; target: 0x%x\n", verified,
93
data_packet_delete(dp);
95
dp = data_packet_new(pids[1], payload1, sizes[1]);
96
found = data_packet_get_crc16(dp);
97
verified = (found == targets[1]);
98
printf("CRC16 verified: %d; found: 0x%x; target: 0x%x\n", verified,
100
data_packet_delete(dp);
102
dp = data_packet_new(pids[2], payload2, sizes[2]);
103
found = data_packet_get_crc16(dp);
104
verified = (found == targets[2]);
105
printf("CRC16 verified: %d; found: 0x%x; target: 0x%x\n", verified,
107
data_packet_delete(dp);
109
dp = data_packet_new(pids[3], payload3, sizes[3]);
110
found = data_packet_get_crc16(dp);
111
verified = (found == targets[3]);
112
printf("CRC16 verified: %d; found: 0x%x; target: 0x%x\n", verified,
114
data_packet_delete(dp);
116
dp = data_packet_new(pids[4], payload4, sizes[4]);
117
found = data_packet_get_crc16(dp);
118
verified = (found == targets[4]);
119
printf("CRC16 verified: %d; found: 0x%x; target: 0x%x\n", verified,
121
data_packet_delete(dp);
117
for (iter = 0; iter < 5; iter++)
119
uint8_t *payload = payloads[iter];
121
data_packet_new(pids[iter], payload, payload_sizes[iter]);
122
uint16_t found = data_packet_get_crc16(dp);
123
bool verified = (found == targets[iter]);
124
passing = passing && verified;
126
warn("Bad CRC16: found: 0x%x; target: 0x%x\n",
127
found, targets[iter]);
128
data_packet_delete(dp);
137
TEST(bufferize_test);