Change timeout name
[revag-nm.git] / vw-nm.c
diff --git a/vw-nm.c b/vw-nm.c
index e656e6847224c325845647d7792834684a9ed7c9..9ca640044b493c0f010be7c412b4a4d7e483763d 100644 (file)
--- a/vw-nm.c
+++ b/vw-nm.c
@@ -65,6 +65,15 @@ static void nm_update_my_next_id(struct NM_Main *nm) {
                        break;
                }
        } while (id != nm->my_id);
+
+       if (nm->nodes[nm->my_id].next == nm->my_id) {
+               /* Uh oh, we're the only one left. */
+
+               /* TODO */
+               nm->nodes[nm->my_id].state = NM_MAIN_LOGIN;
+
+               /* TODO: Timeout 140ms (RCD 310) */
+       }
 }
 
 
@@ -135,14 +144,14 @@ static void nm_handle_can_frame(struct NM_Main *nm, struct can_frame *frame)
                                 * can send its login frame to correct us.
                                 */
                                nm->tv.tv_sec = 0;
-                               nm->tv.tv_usec = NM_USECS_MY_TURN;
+                               nm->tv.tv_usec = NM_USECS_NORMAL_TURN;
                        } else {
                                /* We just got some random ON message.
                                 * Reset the timer looking out for broken
                                 * connectivity.
                                 */
                                nm->tv.tv_sec = 0;
-                               nm->tv.tv_usec = NM_USECS_OTHER_TURN;
+                               nm->tv.tv_usec = NM_USECS_NODE_AWOL;
                        }
                        break;
                case NM_MAIN_LOGIN:
@@ -163,9 +172,11 @@ static void nm_handle_can_frame(struct NM_Main *nm, struct can_frame *frame)
                         */
                        if (next != sender) {
                                nm->tv.tv_sec = 0;
-                               nm->tv.tv_usec = NM_USECS_OTHER_TURN;
+                               nm->tv.tv_usec = NM_USECS_NODE_AWOL;
                        }
                        break;
+               case NM_MAIN_LIMPHOME:
+                       nm_update_my_next_id(nm);
        }
 
        nm_dump_all(nm);
@@ -190,7 +201,7 @@ static void nm_buildframe(struct NM_Main *nm, struct can_frame *frame)
 static void nm_timeout_callback(struct NM_Main *nm, struct can_frame *frame)
 {
        nm->tv.tv_sec = 0;
-       nm->tv.tv_usec = NM_USECS_OTHER_TURN;
+       nm->tv.tv_usec = NM_USECS_NODE_AWOL;
 
        nm_buildframe(nm, frame);
 }
@@ -201,7 +212,7 @@ static void nm_timeout_callback(struct NM_Main *nm, struct can_frame *frame)
 static void nm_start(struct NM_Main *nm, struct can_frame *frame)
 {
        nm->tv.tv_sec = 0;
-       nm->tv.tv_usec = 50000;
+       nm->tv.tv_usec = NM_USECS_NODE_AWOL;
 
 
 
@@ -264,13 +275,16 @@ int main(int argc, char **argv)
        struct NM_Main *nm;
        fd_set rdfs;
        int s;
+       NM_ID my_id;
 
-       if (argc != 2) {
-               printf("syntax: %s IFNAME\n", argv[0]);
+       if (argc != 3) {
+               printf("syntax: %s IFNAME MY_ID\n", argv[0]);
                return 1;
        }
 
-       nm = nm_alloc(5, 0x0b, 0x420);
+       my_id = strtoul(argv[2], NULL, 0);
+
+       nm = nm_alloc(5, my_id, 0x420);
        if (!nm) {
                printf("Out of memory allocating NM struct.\n");
                return 1;
@@ -320,6 +334,7 @@ int main(int argc, char **argv)
        }
 
        nm_free(nm);
+       close(s);
 
        return 0;
 }