summaryrefslogtreecommitdiff
path: root/vw-nm-tools.h
diff options
context:
space:
mode:
Diffstat (limited to 'vw-nm-tools.h')
-rw-r--r--vw-nm-tools.h81
1 files changed, 76 insertions, 5 deletions
diff --git a/vw-nm-tools.h b/vw-nm-tools.h
index 426e778..f4126a6 100644
--- a/vw-nm-tools.h
+++ b/vw-nm-tools.h
@@ -76,6 +76,81 @@ static void can_tx(int socket, struct can_frame *frame)
+static int nm_is_rx_frame_valid(struct NM_Main *nm, struct can_frame *frame)
+{
+ if (frame->can_dlc < 2) {
+ printf("Skipping short frame from CAN ID %03x\n", frame->can_id);
+ return 0;
+ }
+
+ if ((frame->can_id & ~(nm->max_nodes - 1)) != nm->can_base) {
+ printf("Skipping non-NM from CAN ID %03x\n", frame->can_id);
+ return 0;
+ }
+
+ return 1;
+}
+
+
+
+
+
+
+
+
+
+
+static void nm_set_timer_now(struct NM_Main *nm)
+{
+ nm->tv.tv_sec = 0;
+ nm->tv.tv_usec = 0;
+ nm->timer_reason = NM_TIMER_NOW;
+}
+
+static void nm_set_timer_normal(struct NM_Main *nm)
+{
+ nm->tv.tv_sec = 0;
+ nm->tv.tv_usec = NM_USECS_NORMAL_TURN;
+ nm->timer_reason = NM_TIMER_NORMAL;
+}
+
+static void nm_set_timer_awol(struct NM_Main *nm)
+{
+ nm->tv.tv_sec = 0;
+ nm->tv.tv_usec = NM_USECS_NODE_AWOL;
+ nm->timer_reason = NM_TIMER_AWOL;
+}
+
+/*
+static void nm_set_timer_limphome(struct NM_Main *nm)
+{
+ nm->tv.tv_sec = 0;
+ nm->tv.tv_usec = NM_USECS_LIMPHOME;
+ nm->timer_reason = NM_TIMER_LIMPHOME;
+}
+*/
+
+
+
+
+
+
+static void nm_reset(struct NM_Main *nm)
+{
+ unsigned id;
+
+ for (id = 0; id < nm->max_nodes; id++) {
+ nm->nodes[id].next = 0xff;
+ nm->nodes[id].state = NM_MAIN_OFF;
+ }
+
+ nm->nodes[nm->my_id].next = nm->my_id;
+ nm->nodes[nm->my_id].state = NM_MAIN_LOGIN;
+
+ nm_set_timer_normal(nm);
+}
+
+
static struct NM_Main* nm_alloc(unsigned node_bits, NM_ID my_id, canid_t can_base)
{
@@ -100,11 +175,7 @@ static struct NM_Main* nm_alloc(unsigned node_bits, NM_ID my_id, canid_t can_bas
nm->my_id = my_id;
nm->can_base = can_base;
- nm->nodes[nm->my_id].next = nm->my_id;
- nm->nodes[nm->my_id].state = NM_MAIN_LOGIN;
-
- nm->tv.tv_sec = 0;
- nm->tv.tv_usec = NM_USECS_NODE_AWOL;
+ nm_reset(nm);
return nm;
}