Add version command to show product information
authorKeith Packard <keithp@keithp.com>
Sat, 9 May 2009 17:24:10 +0000 (10:24 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 9 May 2009 17:24:10 +0000 (10:24 -0700)
Makefile
ao-make-product.5c
ao.h
ao_cmd.c
ao_product.c

index a570be7b40c268c92a2bb94a27302709fbef7f3c..ab72b413472073c2cb797072708cd912a9bc2ed3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,8 @@
 # 
 CC=sdcc
 
+VERSION=$(shell git describe)
+
 CFLAGS=--model-small --debug --opt-code-speed 
 
 LDFLAGS=--out-fmt-ihx --code-loc 0x0000 --code-size 0x8000 \
@@ -238,21 +240,22 @@ ao_product-tidongle-$(SERIAL).rel: ao_product.c $(TIDONGLE_DEFS)
        $(CC) -c $(CFLAGS) -D PRODUCT_DEFS='\"$(TIDONGLE_DEFS)\"' -o$@ ao_product.c
 
 $(TELEMETRUM_DEFS): ao-make-product.5c
-       nickle ao-make-product.5c -m altusmetrum.org -p TeleMetrum -s $(SERIAL) > $@
+       nickle ao-make-product.5c -m altusmetrum.org -p TeleMetrum -s $(SERIAL) -v $(VERSION) > $@
 
 $(TELETERRA_DEFS): ao-make-product.5c
-       nickle ao-make-product.5c -m altusmetrum.org -p TeleTerra -s $(SERIAL) > $@
+       nickle ao-make-product.5c -m altusmetrum.org -p TeleTerra -s $(SERIAL) -v $(VERSION) > $@
 
 $(TELEDONGLE_DEFS): ao-make-product.5c
-       nickle ao-make-product.5c -m altusmetrum.org -p TeleDongle -s $(SERIAL) > $@
+       nickle ao-make-product.5c -m altusmetrum.org -p TeleDongle -s $(SERIAL) -v $(VERSION) > $@
 
 $(TIDONGLE_DEFS): ao-make-product.5c
-       nickle ao-make-product.5c -m altusmetrum.org -p TIDongle -s $(SERIAL) > $@
+       nickle ao-make-product.5c -m altusmetrum.org -p TIDongle -s $(SERIAL) -v $(VERSION) > $@
 
 clean:
        rm -f $(ADB) $(ASM) $(LNK) $(LST) $(REL) $(RST) $(SYM)
        rm -f $(PROGS) $(PCDB) $(PLNK) $(PMAP) $(PMEM) $(PAOM)
        rm -f $(ALL_DEFS) $(HOST_PROGS)
+       rm -f $(TELEMETRUM_DEFS) $(TELETERRA_DEFS) $(TELEDONGLE_DEFS) $(TIDONGLE_DEFS)
 
 install:
 
index 4f5bcba92ec1288c18856bca4d5db34b60326842..933032dd6344f3835bfe88d8066ba1c2c508d724 100644 (file)
@@ -3,13 +3,14 @@
 autoimport ParseArgs;
 
 void
-write_string(string a, string description)
+write_ucs2(string a, string description)
 {
        int len = String::length(a);
 
        printf("/* %s */\n", description);
        printf("#define AO_%s_LEN 0x%02x\n", description, len * 2 + 2);
-       printf("#define AO_%s_STRING", description);
+       printf("#define AO_%s_STRING \"%s\"\n", description, a);
+       printf("#define AO_%s_UCS2", description);
        for (int i = 0; i < len; i++) {
                int     c = a[i];
                if (i > 0)
@@ -22,6 +23,13 @@ write_string(string a, string description)
        printf("\n\n");
 }
 
+void
+write_string(string a, string description)
+{
+       printf ("/* %s */\n", description);
+       printf ("#define AO_%s_STRING \"%s\"\n", description, a);
+}
+
 void
 write_int(int a, string description)
 {
@@ -31,6 +39,7 @@ write_int(int a, string description)
 
 string manufacturer = "altusmetrum.org";
 string product = "TeleMetrum";
+string version = "0.0";
 int serial = 1;
 int user_argind = 0;
 
@@ -54,6 +63,12 @@ argdesc argd = {
                        .name = "serial",
                        .expr_name = "number",
                        .desc = "Serial number." },
+               {
+                       .var = { .arg_string = &version },
+                       .abbr = 'v',
+                       .name = "version",
+                       .expr_name = "string",
+                       .desc = "Program version." },
        },
        .prog_name = "usb descriptors",
 };
@@ -63,10 +78,11 @@ main()
 {
        string[dim(argv)-1] nargv = {[n] = argv[n+1]};
        parseargs(&argd, &nargv);
-       write_string(manufacturer, "iManufacturer");
-       write_string(product, "iProduct");
-       write_string(sprintf("%06d", serial), "iSerial");
+       write_ucs2(manufacturer, "iManufacturer");
+       write_ucs2(product, "iProduct");
+       write_ucs2(sprintf("%06d", serial), "iSerial");
        write_int(serial, "iSerial");
+       write_string(version, "iVersion");
 }
 
 main();
diff --git a/ao.h b/ao.h
index 12948ed3c55a422f1b48bce8cf536ec33d96a946..aa7163fc141342850d0c97b1a1e19a378ca4b7ac 100644 (file)
--- a/ao.h
+++ b/ao.h
@@ -841,5 +841,8 @@ ao_config_init(void);
 
 extern const uint8_t ao_usb_descriptors [];
 extern const uint16_t ao_serial_number;
+extern const char ao_version[];
+extern const char ao_manufacturer[];
+extern const char ao_product[];
 
 #endif /* _AO_H_ */
index f0459a73fd4976b17b6077328d2c2b2c8ea13516..827545d0ee8842a94ed41fb376e1d0da38cc0de9 100644 (file)
--- a/ao_cmd.c
+++ b/ao_cmd.c
@@ -212,6 +212,15 @@ echo(void)
        lex_echo = ao_cmd_lex_i != 0;
 }
 
+static void
+version(void)
+{
+       printf("manufacturer     %s\n", ao_manufacturer);
+       printf("product          %s\n", ao_product);
+       printf("serial-number    %u\n", ao_serial_number);
+       printf("software-version %s\n", ao_version);
+}
+
 static const char help_txt[] = "All numbers are in hex";
 
 #define NUM_CMDS       11
@@ -297,6 +306,7 @@ __code struct ao_cmds       ao_base_cmds[] = {
        { 'T', ao_task_info,    "T                                  Show task states" },
        { 'E', echo,            "E <0 off, 1 on>                    Set command echo mode" },
        { 'd', dump,            "d <start> <end>                    Dump memory" },
+       { 'v', version,         "v                                  Show version" },
        { 0,    help,   NULL },
 };
 
index b743e9f00a28de491f1d4d858594864d103bb548..b42e62c09a800c92644542a63795d59cb537c017 100644 (file)
@@ -22,6 +22,9 @@
 /* Defines which mark this particular AltOS product */
 
 const uint16_t ao_serial_number = AO_iSerial_NUMBER;
+const char ao_version[] = AO_iVersion_STRING;
+const char ao_manufacturer[] = AO_iManufacturer_STRING;
+const char ao_product[] = AO_iProduct_STRING;
 
 #define LE_WORD(x)    ((x)&0xFF),((uint8_t) (((uint16_t) (x))>>8))
 
@@ -134,17 +137,17 @@ const uint8_t ao_usb_descriptors [] =
        /* iManufacturer */
        AO_iManufacturer_LEN,
        AO_USB_DESC_STRING,
-       AO_iManufacturer_STRING,
+       AO_iManufacturer_UCS2,
 
        /* iProduct */
        AO_iProduct_LEN,
        AO_USB_DESC_STRING,
-       AO_iProduct_STRING,
+       AO_iProduct_UCS2,
 
        /* iSerial */
        AO_iSerial_LEN,
        AO_USB_DESC_STRING,
-       AO_iSerial_STRING,
+       AO_iSerial_UCS2,
 
        /* Terminating zero */
        0