-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
73 lines (54 loc) · 1.58 KB
/
main.c
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
#include <windows.h>
#include <stdio.h>
#include "runtime.h"
#include "stk.h"
err_t * run_exchange(const wchar_t *avrdoper_id, pool_t *pool) {
serial_t *avrdoper;
serial_t *comport;
pool_t *iterpool;
ERR(serial_open(&avrdoper, &avrdoper_hid, avrdoper_id, pool));
ERR(serial_open(&comport, &com, L"COM3", pool));
iterpool = pool_create(pool);
while (1) {
unsigned char *req, *resp;
pool_clear(iterpool);
ERR(stk_read_message(&req, comport, INFINITE, iterpool));
printf("Request:\n");
stk_dump_message(stdout, req);
ERR(stk_write_message(avrdoper, req, iterpool));
ERR(stk_read_message(&resp, avrdoper, INFINITE, iterpool));
printf("Response:\n");
stk_dump_message(stdout, resp);
ERR(stk_write_message(comport, resp, iterpool));
printf("\n");
}
pool_destroy(iterpool);
}
int print_dev(void *data, const wchar_t *id, pool_t *pool)
{
*(err_t **)data = run_exchange(id, pool);
return 0;
}
static err_t * start(pool_t *pool)
{
err_t *err = NULL;
ERR(serial_enum(&avrdoper_hid, print_dev, &err, pool));
return err;
}
int wmain()
{
pool_t *pool = pool_create(NULL);
err_t *err;
int exit_code;
err = start(pool);
if (!err) {
exit_code = EXIT_SUCCESS;
} else {
fwprintf(stderr, L"Error: %s\n", err_str(err, pool));
system("pause");
err_clear(err);
exit_code = EXIT_FAILURE;
}
pool_destroy(pool);
return exit_code;
}