handleConnected is called when a new client connects to the server.handleMessage is called whenever a client sends a message to the server. ![]() Server = SimpleWebSocketServer (hostname, websocket_server_port, SocketHandler ) address, 'connected' def handleClose (self ) : print self. dataĭef handleConnected (self ) : print self. Websocket_server_port = 8888 class SocketHandler (WebSocket ) : def handleMessage (self ) : # print the message when received print self. So, I used the SimpleWebSocketServer.pyclass from /dpallot/simple-websocket-server.Ī websocket server can be created by, from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket We would be using WebSockets for that so as to have a Real-time and an always on link to the bridge which would enable us to in turn communicate with FlightGear in realtime. Now that we have basic interface between python and FlightGear in place, the next step would be to setup a link between the user interface (a small web app) and the python bridge. Most of the commonly used properties are available over at Aircraft properties reference – FlightGear Wiki. The wrapper makes use of python’s magic methods _setitem_ and _getitem_ to make it easy for us to read or manipulate the property tree.įor example, getting the current altitude of the airplane is as easy as print fg /altitude-ft' ]Īnd setting the altitude is as simple as fg /altitude-ft' ] = 345.2īut the important thing here is, knowing the path to the data you want in the FlightGear property tree. from FlightGear import FlightGearįg = FlightGear (flightgear_server, flightgear_server_port ) The class will then make a connection to the telnet server. Initialize an instance of the class with the hostname and port. The wrapper can be obtained from the official repository at /p/flightgear/flightgear/ci/master/tree/scripts/python/FlightGear.py But FlightGear also provides us with a small wrapper class that makes retrieving and setting properties using the telnet server even more easier. (The argument is of format -telnet=medium,direction,speed_in_hertz,localhost,PORT,style.)Ĭommunication with that server can be done using any simple telnet interface.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |