static unsigned char mavlink_get_route(unsigned char ch, mavlink_message_t *msg) { int target_sys, target_comp; unsigned char i, route = active_channel_mask; /* if the message wasn't generated by us * mask out source channel * and learn the route */ if (ch != 255) { route &= ~(1 << ch); mavlink_learn_route(ch, msg); } /* heartbeats goes to all channels except origin */ if (msg->msgid == MAVLINK_MSG_ID_HEARTBEAT) return route; get_targets(msg, &target_sys, &target_comp); /* its for us - don't route */ if ((target_sys == config.mav.osd_sysid) && (target_comp == MAV_COMP_ID_OSD)) return 0; /* broadcast message - route to all active ports*/ if (target_sys <= 0) return route; /* selective routing - try match sysid and compid */ route = 0; for (i = 0; i < total_routes; i++) { if (target_sys == routes[i].sysid && (target_comp <= 0 || target_comp == routes[i].compid) && routes[i].ch != ch) { route |= 1 << routes[i].ch; } } if (route) return route; /* try forwarding to any route that match the sysid */ route = 0; for (i = 0; i < total_routes; i++) { if (target_sys == routes[i].sysid && routes[i].ch != ch) { route |= 1 << routes[i].ch; } } return route; }
static unsigned char mavlink_get_route(unsigned char ch, mavlink_message_t *msg) { int target_sys, target_comp; unsigned char i; unsigned char route = active_channel_mask; /* if the message wasn't generated by us, mask out source channel */ if (ch != 255) { route &= ~(1 << ch); mavlink_learn_route(ch, msg); } /* heartbeats goes to all channels except origin */ if (msg->msgid == MAVLINK_MSG_ID_HEARTBEAT) return route; get_targets(msg, &target_sys, &target_comp); /* destination is us - done */ if ((target_sys == osd_sysid) && (target_comp == MAV_COMP_ID_ALCEOSD)) return 0; route = 0; for (i = 0; i < total_routes; i++) { if ((target_sys <= 0) || (target_sys == routes[i].sysid && (target_comp <= 0 || target_comp == routes[i].compid))) { if (routes[i].ch != ch) { route |= 1 << routes[i].ch; #ifdef ROUTING_DEBUG /*printf("fwd msg %u from chan %u to chan %u sysid=%d compid=%d\n", msg->msgid, (unsigned)ch, (unsigned)routes[i].ch, (int)target_sys, (int)target_comp);*/ #endif } } } return route; }