]> Pileus Git - ~andy/csm213a-hw/blobdiff - hw2/control.c
Make slave mode configurable
[~andy/csm213a-hw] / hw2 / control.c
index ea10f9b9cff340510b2489276baac3ce0d1521c0..bae3e98fdda288b459f53d54166b929b4df71541 100644 (file)
@@ -30,7 +30,8 @@ int main(int argc, char **argv)
        char *opt_tty    = argv[1];
        int   opt_device = atoi(argv[2]);
        int   opt_sync   = argv[3] && !strcmp(argv[3], "sync") ?
-                          MSG_VALID_SYNC : 0;
+                          MSG_CTL_VALID_SYNC : 0;
+       int   opt_relay  = opt_device == 2;
 
        // Lookup current wall-clock time
        struct timespec ts;
@@ -41,17 +42,18 @@ int main(int argc, char **argv)
        init_msg_t body = {};
 
        // Set message header
-       head.header = MSG_HEADER;
-       head.msgid  = MSG_ID_INIT;
-       head.length = sizeof(init_msg_t);
-       head.cksum  = 0; // todo
+       head.header  = MSG_HEADER;
+       head.msgid   = MSG_ID_INIT;
+       head.length  = sizeof(init_msg_t);
+       head.cksum   = 0; // todo
 
        // Set valid flags
-       body.valid  = MSG_VALID_DEVICE
-                   | MSG_VALID_START
-                   | MSG_VALID_PERIOD
-                   | MSG_VALID_WORLD
-                   | opt_sync;
+       body.control = MSG_CTL_VALID_DEVICE
+                    | MSG_CTL_VALID_START
+                    | MSG_CTL_VALID_PERIOD
+                    | MSG_CTL_VALID_WORLD
+                    | opt_relay
+                    | opt_sync;
 
        // Set message body
        body.device         = opt_device;