X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=vw-nm.c;h=e656e6847224c325845647d7792834684a9ed7c9;hb=65531f9a117392b6858eec9435830ef168119064;hp=689cf694db56450e12bd639c60d77b4636bb1d0c;hpb=0aa4c34efd1890654cbdc946790737312f2f630d;p=revag-nm.git diff --git a/vw-nm.c b/vw-nm.c index 689cf69..e656e68 100644 --- a/vw-nm.c +++ b/vw-nm.c @@ -60,7 +60,7 @@ static void nm_update_my_next_id(struct NM_Main *nm) { state = nm->nodes[id].state & NM_MAIN_MASK; if (state == NM_MAIN_ON || state == NM_MAIN_LOGIN) { - /* TODO: Check for limp home nodes? */ + /* We skip limp home nodes */ nm->nodes[nm->my_id].next = id; break; } @@ -108,21 +108,27 @@ static void nm_handle_can_frame(struct NM_Main *nm, struct can_frame *frame) nm->tv.tv_sec = 0; nm->tv.tv_usec = 0; /* IMPORTANT: The caller needs to check for - * timeouts first, so no other NM frames are - * received until our correcting login has - * been sent. + * timeouts first, i.e. no other NM frames + * are received until our correcting login + * has been sent. */ } else if (next == nm->nodes[nm->my_id].next) { - /* where nm->nodes[nm->my_id].next == nm->my_id */ - - /* TODO: Is this a case we need to handle? */ + /* where (nm->nodes[nm->my_id].next == nm->my_id) */ /* It can happen when: * - our sent frames don't go anywhere * - we just logged in and immediately * afterwards another ECU sent a regular - * NM frame without knowing that we exist. + * NM frame. + */ + + /* Let's handle this just like a LOGIN, since + * we're learning about a new device. + * See case NM_MAIN_LOGIN below for details. */ + + nm_update_my_next_id(nm); + nm->nodes[nm->my_id].state = NM_MAIN_ON; } else if (next == nm->my_id) { /* It's our turn. * Reset the timeout so anyone we missed @@ -142,22 +148,23 @@ static void nm_handle_can_frame(struct NM_Main *nm, struct can_frame *frame) case NM_MAIN_LOGIN: /* Note: sender != nm->my_id */ - printf("Handling LOGIN\n"); - nm_update_my_next_id(nm); /* We're not alone anymore, so let's change state. */ nm->nodes[nm->my_id].state = NM_MAIN_ON; - /* We don't reset the timeout when somebody logs in. + /* We don't reset the timeout when somebody logs in, + * i.e. (next == sender). * Instead, we'll simply include them in the next * round. */ /* Actually, when a login is done as a correction, * we do reset the timeout. - * - * TODO. */ + if (next != sender) { + nm->tv.tv_sec = 0; + nm->tv.tv_usec = NM_USECS_OTHER_TURN; + } break; }