public void discover()
        {
            logger.Debug("Starting discovery.");
            string[] ports = SerialPort.GetPortNames();
            foreach (string portName in ports)
            {
                logger.Debug("Checking port {0}", portName);
                SerialPort port = new SerialPort(portName);
                if (!port.IsOpen)
                {
                    logger.Debug("Port {0} is currently closed, attempting new connection.", portName);
                    MavLinkConnection connection = MavLinkConnection.createConnection(port);
                    if ((null != connection) && (connection.isOpen()))
                    {
                        // TODO: Look up existing record
                        logger.Debug("Connection established on port {0}", connection.portName());
                        logger.Debug("Mavlink device on port {0} is new, creating database entry.", connection.portName());

                        // create new business object around this record and assign it to connection
                        Drone drone = new Drone(connection);

                        // add this object to the list of active connections
                        this.connections.Add(drone);
                    }
                    else
                    {
                        logger.Debug("Discontinuing connection attempt on port {0}", portName);
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Constructor, takes a live MavLinkConnection object and begins monitoring device state
 /// </summary>
 /// <param name="connection">live, connected MavLinkConnection. Call MavLinkConnection.createConnection(port) and check port is open prior to calling this.</param>
 public Drone(MavLinkConnection connection)
 {
     this.id                     = Guid.NewGuid();
     this.connection             = connection;
     connection.MavLinkMessages += new MavLinkConnection.MavLinkEventHandler(messageRecieved);
 }
Пример #3
0
 void messageRecieved(MavLinkConnection connection, MavLinkEventArgs args)
 {
     logger.Debug("Received message {0} on native event channel", args.message.messid.ToString());
     processMessage(args.message);
 }
Пример #4
0
 public Commands(Drone droneObj)
 {
     connection = droneObj.connection;
     drone      = droneObj;
 }