static void Main(string[] args) { Stream strm = null; if (args.Length == 0) { strm = Console.OpenStandardInput(); } else if (args.Length == 1) { Console.WriteLine("Usage '" + FileUsage + "' OR '" + SerialUsage + "' Use no arguments for stdin"); Console.ReadKey(); Environment.Exit(0); } else if (args[0] == "-S" ) { if (args.Length != 3) { Console.WriteLine("Error - argument syntax should be: '" + SerialUsage + "'"); Environment.Exit(1); } var comport = args[1]; var baud = Convert.ToInt32(args[2]); var port = new SerialPort(comport, baud); port.Open(); strm = port.BaseStream; } else { strm = File.OpenRead(args[1]); } var link = new Mavlink_Link(strm); var net = new MavlinkNetwork(link); var consoledumper = new ConsoleDumper(net); Console.ReadKey(); }
static void Main(string[] args) { _mavStream = ExampleCommon.GetMavStreamFromArgs(args); _link = new Mavlink_Link(_mavStream); _net = new MavlinkNetwork(_link); var packetsReceived = Observable.FromEvent<PacketReceivedEventHandler, MavlinkPacket>( handler => (sender, e) => handler.Invoke(e), d => _net.PacketReceived += d, d => _net.PacketReceived -= d); var heartbeats = packetsReceived.Where(p => p.Message is MAVLink_heartbeat_message); Console.WriteLine("Waiting For hearbeat (10 second timeout)..."); var paramsReceived = from hb in heartbeats .Take(1) .Do(SendParamListRequest) .Timeout(TimeSpan.FromSeconds(10)) from message in packetsReceived .Where(m => m.SystemId == hb.SystemId) .Where(m => m.ComponentId == hb.ComponentId) .Select(p => p.Message) .OfType<MAVLink_param_value_message>() .TakeWhile(p => p.param_index < p.param_count - 1 ) select message; paramsReceived.Subscribe( DumpPacket, e => Console.WriteLine("Error: " + e.Message), () => Console.WriteLine("Complete")); _link.Start(); Console.ReadKey(); _link.Stop(); _mavStream.Close(); }
public ConsoleDumper(MavlinkNetwork mavNet) { _mavNet = mavNet; _mavNet.PacketReceived += NetworkLayerPacketReceived; }