use an array for messages
authorFelix Fietkau <nbd@openwrt.org>
Thu, 30 May 2013 17:06:05 +0000 (19:06 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 30 May 2013 17:06:05 +0000 (19:06 +0200)
convert-modeswitch.pl
switch.c

index f7ac9ff574a6410eb84660d43f45d74d736da69f..97f1d7b9f764066e66ffbd0528e119a0742d9432 100644 (file)
@@ -153,12 +153,13 @@ sub dev_opt {
                my @val = @$val;
                undef $val;
                foreach my $elem (@val) {
+                       my $json = json_val($elem, $type);
+                       next unless defined $json;
                        if (defined $val) {
-                               $val = "$val, "
+                               $val = "$val, $json"
                        } else {
-                               $val = "";
+                               $val = $json;
                        }
-                       $val .= json_val($elem, $type);
                }
                $val = "[ $val ]";
        } else {
@@ -205,9 +206,12 @@ foreach my $devid (sort keys %devices) {
                dev_opt($cur->{Mode}, "mode", "string", \$sep);
                dev_opt($cur->{NoDriverLoading}, "no_driver", "bool", \$sep);
                dev_opt($cur->{MessageEndpoint}, "msg_endpoint", "int", \$sep);
-               dev_opt($cur->{MessageContent}, "msg", "int", \$sep);
-               dev_opt($cur->{MessageContent2}, "msg2", "int", \$sep);
-               dev_opt($cur->{MessageContent3}, "msg3", "int", \$sep);
+               my $msg = [
+                       $cur->{MessageContent},
+                       $cur->{MessageContent2},
+                       $cur->{MessageContent3}
+               ];
+               dev_opt($msg, "msg", "array:int", \$sep);
                dev_opt($cur->{WaitBefore}, "wait", "int", \$sep);
                dev_opt($cur->{ReleaseDelay}, "release_delay", "int", \$sep);
                dev_opt($cur->{NeedResponse}, "response", "bool", \$sep);
index 3f1e3f38a62431f9fcba128f0c37e1eac9d6a1b2..b73fe018f978861d143c5cd450694d959b8d222c 100644 (file)
--- a/switch.c
+++ b/switch.c
@@ -84,9 +84,7 @@ void handle_switch(struct usbdev_data *data)
 {
        static const struct blobmsg_policy data_policy[__DATA_MAX] = {
                [DATA_MODE] = { .name = "mode", .type = BLOBMSG_TYPE_STRING },
-               [DATA_MSG] = { .name = "msg", .type = BLOBMSG_TYPE_INT32 },
-               [DATA_MSG2] = { .name = "msg2", .type = BLOBMSG_TYPE_INT32 },
-               [DATA_MSG3] = { .name = "msg3", .type = BLOBMSG_TYPE_INT32 },
+               [DATA_MSG] = { .name = "msg", .type = BLOBMSG_TYPE_ARRAY },
        };
        struct blob_attr *tb[__DATA_MAX];
        int mode = MODE_GENERIC;