1 static char* nm_main_to_string(NM_State state)
3 switch(state & NM_MAIN_MASK) {
10 case NM_MAIN_LIMPHOME:
17 static char* nm_sleep_to_string(NM_State state)
19 switch(state & NM_SLEEP_MASK) {
22 case NM_SLEEP_REQUEST:
25 return "Acknowledged";
33 static void nm_dump_all(struct NM_Main *nm)
38 printf(" Node | next | Main | Sleep\n");
39 printf("----------------------------------------\n");
41 for (id = 0; id < nm->max_nodes; id++) {
42 struct NM_Node *node = &nm->nodes[id];
44 if (node->state & NM_MAIN_MASK) {
45 printf(" %02x %02x %9s %s\n",
48 nm_main_to_string(node->state),
49 nm_sleep_to_string(node->state));
62 static void can_tx(int socket, struct can_frame *frame)
66 ret = write(socket, frame, sizeof(*frame));
67 if (ret != sizeof(*frame)) {
68 perror("write to CAN socket");
80 static struct NM_Main* nm_alloc(unsigned node_bits, NM_ID my_id, canid_t can_base)
84 if (node_bits < 1 || node_bits > 6) {
88 nm = malloc(sizeof(*nm));
93 nm->max_nodes = 1 << node_bits;
94 nm->nodes = malloc(nm->max_nodes * sizeof(*nm->nodes));
101 nm->can_base = can_base;
103 nm->nodes[nm->my_id].next = nm->my_id;
104 nm->nodes[nm->my_id].state = NM_MAIN_LOGIN;
107 nm->tv.tv_usec = NM_USECS_OTHER_TURN;
115 static void nm_free(struct NM_Main *nm)