More limp home handling
authornorly <ny-git@enpas.org>
Sat, 18 Mar 2017 21:09:53 +0000 (22:09 +0100)
committernorly <ny-git@enpas.org>
Sat, 18 Mar 2017 21:46:18 +0000 (22:46 +0100)
vw-nm-tools.h
vw-nm.c
vw-nm.h

index e9e26c8d6e5d29e0fed5e8db8d8f94f2e7eabeec..426e778848f8894d3c94303b8d03675dc0b57f0a 100644 (file)
@@ -104,7 +104,7 @@ static struct NM_Main* nm_alloc(unsigned node_bits, NM_ID my_id, canid_t can_bas
        nm->nodes[nm->my_id].state = NM_MAIN_LOGIN;
 
        nm->tv.tv_sec = 0;
-       nm->tv.tv_usec = NM_USECS_OTHER_TURN;
+       nm->tv.tv_usec = NM_USECS_NODE_AWOL;
 
        return nm;
 }
diff --git a/vw-nm.c b/vw-nm.c
index e656e6847224c325845647d7792834684a9ed7c9..5afa9612738d6da7cb23bb10f9bfdce717e767e1 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) */
+       }
 }
 
 
@@ -142,7 +151,7 @@ static void nm_handle_can_frame(struct NM_Main *nm, struct can_frame *frame)
                                 * 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);
 }
diff --git a/vw-nm.h b/vw-nm.h
index 8237daee7ffcd642013793f750f8eaba0df11d4c..01f3c44a819ac6a2e9fd683deef9163a1b584365 100644 (file)
--- a/vw-nm.h
+++ b/vw-nm.h
@@ -49,13 +49,13 @@ struct NM_Main {
  *
  * We may reduce it since we're not on a real-time OS.
  */
-#define NM_USECS_MY_TURN 40000
+#define NM_USECS_MY_TURN 45000
 
 
-/* This timeout is 50 ms in:
+/* This timeout is 140 ms in:
  *  - 0x19 (RCD 310, Bosch)
  */
-#define NM_USECS_OTHER_TURN 50000
+#define NM_USECS_NODE_AWOL 140000
 
 
 /* This timeout is 500 ms in: