libaltos: Test both bluetooth and USB APIs with cjnitest
[fw/altos] / libaltos / cjnitest.c
1 #include <stdio.h>
2 #include "libaltos.h"
3 #include <string.h>
4
5 #define HAS_BLUETOOTH   1
6 #define HAS_USB         1
7
8 static void
9 altos_puts(struct altos_file *file, char *string)
10 {
11         char    c;
12
13         while ((c = *string++))
14                 altos_putchar(file, c);
15 }
16
17 int
18 main (int argc, char **argv)
19 {
20         struct altos_device     device;
21         struct altos_list       *list;
22         struct altos_bt_device  bt_device;
23         struct altos_bt_list    *bt_list;
24
25         altos_init();
26 #if HAS_USB
27         list = altos_list_start();
28         while (altos_list_next(list, &device)) {
29                 struct altos_file       *file;
30                 int                     c;
31
32                 printf ("%04x:%04x %-20s %4d %s\n", device.vendor, device.product,
33                         device.name, device.serial, device.path);
34
35                 file = altos_open(&device);
36                 if (!file) {
37                         printf("altos_open failed\n");
38                         continue;
39                 }
40                 altos_puts(file,"v\nc s\n");
41                 altos_flush(file);
42                 while ((c = altos_getchar(file, 100)) >= 0) {
43                         putchar (c);
44                 }
45                 if (c != LIBALTOS_TIMEOUT)
46                         printf ("getchar returns %d\n", c);
47                 altos_close(file);
48         }
49         altos_list_finish(list);
50 #endif
51 #if HAS_BLUETOOTH
52         bt_list = altos_bt_list_start(8);
53         while (altos_bt_list_next(bt_list, &bt_device)) {
54                 printf ("%s %s\n", bt_device.name, bt_device.addr);
55                 if (strncmp(bt_device.name, "TeleBT", 6) == 0) {
56                         struct altos_file       *file;
57
58                         int                     c;
59                         file = altos_bt_open(&bt_device);
60                         if (!file) {
61                                 printf("altos_bt_open failed\n");
62                                 continue;
63                         }
64                         altos_puts(file,"v\nc s\n");
65                         altos_flush(file);
66                         while ((c = altos_getchar(file, 100)) >= 0) {
67                                 putchar(c);
68                         }
69                         if (c != LIBALTOS_TIMEOUT)
70                                 printf("getchar returns %d\n", c);
71                         altos_close(file);
72                 }
73         }
74         altos_bt_list_finish(bt_list);
75 #endif
76         altos_fini();
77         return 0;
78 }