altos: Send SPI message at flight state changes
[fw/altos] / src / ao-make-product.5c
1 #!/bin/sh
2
3 autoimport ParseArgs;
4
5 void
6 write_ucs2(string a, string description)
7 {
8         int len = String::length(a);
9
10         printf("/* %s */\n", description);
11         printf("#define AO_%s_LEN 0x%02x\n", description, len * 2 + 2);
12         printf("#define AO_%s_STRING \"%s\"\n", description, a);
13         printf("#define AO_%s_UCS2", description);
14         for (int i = 0; i < len; i++) {
15                 int     c = a[i];
16                 if (i > 0)
17                         printf(",");
18                 if (0x20 <= c && c < 128)
19                         printf(" '%c', 0", c);
20                 else
21                         printf(" LE_WORD(0x%04x),", c);
22         }
23         printf("\n\n");
24 }
25
26 void
27 write_string(string a, string description)
28 {
29         printf ("/* %s */\n", description);
30         printf ("#define AO_%s_STRING \"%s\"\n", description, a);
31 }
32
33 void
34 write_int(int a, string description)
35 {
36         printf ("/* %s */\n", description);
37         printf ("#define AO_%s_NUMBER %d\n\n", description, a);
38 }
39
40 void
41 write_hex(int a, string description)
42 {
43         printf ("/* %s */\n", description);
44         printf ("#define AO_%s_NUMBER 0x%04x\n\n", description, a);
45 }
46
47 string manufacturer = "altusmetrum.org";
48 string product = "TeleMetrum";
49 string version = "0.0";
50 int serial = 1;
51 int user_argind = 0;
52 int id_product = 0x000a;
53
54 argdesc argd = {
55         .args = {
56                 {
57                         .var = { .arg_string = &manufacturer },
58                         .abbr = 'm',
59                         .name = "manufacturer",
60                         .expr_name = "manf",
61                         .desc = "Manufacturer name." },
62                 {
63                         .var = { .arg_string = &product },
64                         .abbr = 'p',
65                         .name = "product",
66                         .expr_name = "prod",
67                         .desc = "Product name." },
68                 {
69                         .var = { .arg_int = &id_product },
70                         .abbr = 'i',
71                         .name = "id_product",
72                         .expr_name = "id_p",
73                         .desc = "Product ID." },
74                 {
75                         .var = { .arg_int = &serial },
76                         .abbr = 's',
77                         .name = "serial",
78                         .expr_name = "number",
79                         .desc = "Serial number." },
80                 {
81                         .var = { .arg_string = &version },
82                         .abbr = 'v',
83                         .name = "version",
84                         .expr_name = "string",
85                         .desc = "Program version." },
86         },
87         .prog_name = "usb descriptors",
88 };
89
90 void
91 main()
92 {
93         string[dim(argv)-1] nargv = {[n] = argv[n+1]};
94         parseargs(&argd, &nargv);
95         write_ucs2(manufacturer, "iManufacturer");
96         write_ucs2(product, "iProduct");
97         write_ucs2(sprintf("%06d", serial), "iSerial");
98         write_int(serial, "iSerial");
99         write_hex(id_product, "idProduct");
100         write_string(version, "iVersion");
101 }
102
103 main();