Esempio n. 1
0
 def connection(self, body):
     action = body["action"][0]
     if action == "save":
         # Save data
         i = int(body["index"][0])
         self.connection.save(i, body["name"][0], body["mode"][0], body["IP"][0], body["port"][0])
         active, data = self.connection.connection_data()
         out = json.dumps((i, data))
     elif action == "new":
         selected = self.connection.new()
         active, data = self.connection.connection_data()
         out = json.dumps((selected, data))
         # Replaced active with selected.. So new selected configuration is selected.
     # print body
     elif action == "delete":
         i = int(body["index"][0])
         selected = self.connection.delete(i)
         active, data = self.connection.connection_data()
         out = json.dumps((selected, data))
     elif action == "connect":
         i = int(body["index"][0])
         # Save just incase any changed made.
         self.connection.save(i, body["name"][0], body["mode"][0], body["IP"][0], body["port"][0])
         comm = FlightSim.comm.FS_Comm
         comm.disconnect()
         time.sleep(2)
         self.connection.set_active(i)
         comm.setup_sim(self.connection.active)
         out = "ok_connect"
     else:
         out = json.dumps(self.connection.connection_data())
     return out
Esempio n. 2
0
    def comm_update(self, body):

        # Check for status, disconnect or connect if applicable.
        comm = FlightSim.comm.FS_Comm
        status = self.get_key(body, "status")
        if status != None:
            status = status[0].lower()
            if status == "disconnect":

                comm.disconnect()
            elif status == "connect":
                comm.connect()

            return "ok"