2018-01-31 08:46:55 +00:00
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import json
|
2018-02-01 21:07:26 +00:00
|
|
|
from telnetlib import Telnet
|
2018-01-31 08:46:55 +00:00
|
|
|
|
|
|
|
from adapt.intent import IntentBuilder
|
|
|
|
from mycroft import MycroftSkill, intent_handler
|
|
|
|
from mycroft.skills.core import MycroftSkill
|
|
|
|
from mycroft.util.log import getLogger
|
|
|
|
|
|
|
|
LOGGER = getLogger(__name__)
|
|
|
|
|
|
|
|
class FlightGearCopilotSkill(MycroftSkill):
|
|
|
|
def __init__(self):
|
|
|
|
super(FlightGearCopilotSkill, self).__init__()
|
2018-02-01 16:47:57 +00:00
|
|
|
self.settings['host'] = "localhost"
|
|
|
|
self.settings['port'] = 8081
|
|
|
|
# TODO add self.settings['profiles'] with default profiles (A32X and c172p)
|
2018-01-31 08:46:55 +00:00
|
|
|
|
|
|
|
# DEFINITION of the settings['profiles'] structure
|
2018-01-31 16:36:49 +00:00
|
|
|
# [
|
2018-01-31 08:46:55 +00:00
|
|
|
# {
|
|
|
|
# "name": "<profile-name>",
|
|
|
|
# "acid":
|
2018-01-31 16:36:49 +00:00
|
|
|
# [
|
2018-01-31 08:46:55 +00:00
|
|
|
# "<Aircraft-id> can be found in /???",
|
|
|
|
# ...
|
2018-01-31 16:36:49 +00:00
|
|
|
# ],
|
2018-01-31 08:46:55 +00:00
|
|
|
# flaps:
|
2018-01-31 16:36:49 +00:00
|
|
|
# [
|
2018-01-31 08:46:55 +00:00
|
|
|
# {
|
|
|
|
# "id": "<flaps-name> can be up|down|full|number",
|
|
|
|
# "min-spd": "<minimum speed for save retraction>",
|
2018-01-31 16:36:49 +00:00
|
|
|
# "max-spd": "<maximum speed for save extention>",
|
|
|
|
# "value": "<value in the prop tree>"
|
2018-01-31 08:46:55 +00:00
|
|
|
# },
|
|
|
|
# ...
|
2018-01-31 16:36:49 +00:00
|
|
|
# ]
|
2018-01-31 08:46:55 +00:00
|
|
|
# "flaps-path": "<path to current flaps-position>"
|
|
|
|
# "gear-retractable": "<true|false>"
|
2018-01-31 16:36:49 +00:00
|
|
|
# },
|
|
|
|
# ...
|
|
|
|
# ]
|
2018-01-31 08:46:55 +00:00
|
|
|
|
|
|
|
# might be useful
|
|
|
|
# make_active()
|
|
|
|
|
2018-01-31 16:36:49 +00:00
|
|
|
#########################
|
|
|
|
# #
|
|
|
|
# Flaps #
|
|
|
|
# #
|
|
|
|
#########################
|
|
|
|
|
2018-01-31 08:46:55 +00:00
|
|
|
@intent_handler(IntentBuilder('FlapsIntent').require('flaps'))
|
|
|
|
def handle_flaps_intent(self, message):
|
|
|
|
flaps_request = message.data['utterance']
|
|
|
|
if flaps_request == "flaps":
|
|
|
|
self.speak_dialog("no.setting")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
# extracting the flaps setting from the utterance
|
|
|
|
match = re.match(r'.*flaps.* (up|full|down|\d{1,2}).*', flaps_request, re.I)
|
2018-01-31 16:36:49 +00:00
|
|
|
if match == None:
|
|
|
|
self.speak_dialog("no.valid.flaps")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-01-31 08:46:55 +00:00
|
|
|
flaps_request = match.group(1)
|
|
|
|
|
2018-02-01 21:07:26 +00:00
|
|
|
try:
|
|
|
|
tn = Telnet(self.settings['host'], self.settings['port'])
|
|
|
|
except:
|
|
|
|
self.speak_dialog("no.telnet.con")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
tn.write("data\r\n")
|
2018-01-31 08:46:55 +00:00
|
|
|
|
|
|
|
# DEMO DATA
|
|
|
|
flaps = 2
|
|
|
|
# END DEMO DATA
|
|
|
|
|
2018-02-01 21:07:26 +00:00
|
|
|
# get acid
|
2018-02-01 21:09:27 +00:00
|
|
|
tn.write("get /sim/aircraft\r\n")
|
2018-02-01 21:07:26 +00:00
|
|
|
acid = tn.read_until("\n")
|
2018-01-31 08:46:55 +00:00
|
|
|
|
2018-02-01 21:07:26 +00:00
|
|
|
profile = None
|
2018-01-31 08:46:55 +00:00
|
|
|
|
2018-02-01 12:26:10 +00:00
|
|
|
# read acid to know which profile to use
|
2018-01-31 08:46:55 +00:00
|
|
|
for i_profiles in self.settings['profiles']:
|
2018-01-31 16:36:49 +00:00
|
|
|
for i_acid in i_profiles['acid']:
|
2018-01-31 08:46:55 +00:00
|
|
|
if i_acid == acid:
|
2018-01-31 16:36:49 +00:00
|
|
|
profile = i_profiles
|
2018-01-31 08:46:55 +00:00
|
|
|
break
|
2018-01-31 16:36:49 +00:00
|
|
|
if profile != None:
|
2018-01-31 08:46:55 +00:00
|
|
|
break
|
|
|
|
|
2018-01-31 16:36:49 +00:00
|
|
|
if profile == None:
|
|
|
|
# TODO when creation of profiles via voice is possible, add dialog how to
|
|
|
|
self.speak("Profile not found")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-02-01 21:07:26 +00:00
|
|
|
tn.write("get /velocities/airspeed-kt\r\n")
|
|
|
|
kias = float(tn.read_until("\n"))
|
|
|
|
|
|
|
|
# TODO read flaps
|
2018-01-31 08:46:55 +00:00
|
|
|
|
2018-01-31 16:36:49 +00:00
|
|
|
o_flaps = None
|
|
|
|
|
|
|
|
# find the flaps value for the flaps id
|
|
|
|
for i_flaps in profile['flaps']:
|
|
|
|
if str(i_flaps['id']) == str(flaps_request):
|
|
|
|
o_flaps = i_flaps
|
|
|
|
break
|
|
|
|
|
|
|
|
if o_flaps == None:
|
|
|
|
self.speak_dialog("flaps.setting.unknown")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-01-31 08:46:55 +00:00
|
|
|
# check if extend or retract flaps
|
2018-01-31 16:36:49 +00:00
|
|
|
# TODO add handling up|down|full is already set
|
|
|
|
if str(flaps_request) == "down" or str(flaps_request) == "full":
|
|
|
|
flaps_mov = "extend"
|
|
|
|
elif str(flaps_request) == "up":
|
|
|
|
flaps_mov = "retract"
|
2018-01-31 08:46:55 +00:00
|
|
|
else:
|
2018-01-31 16:36:49 +00:00
|
|
|
if int(flaps_request) > o_flaps:
|
2018-01-31 08:46:55 +00:00
|
|
|
flaps_mov = "extend"
|
2018-01-31 16:36:49 +00:00
|
|
|
elif int(flaps_request) < o_flaps:
|
2018-01-31 08:46:55 +00:00
|
|
|
flaps_mov = "retract"
|
|
|
|
else:
|
|
|
|
self.speak_dialog("keep.flaps")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-01-31 16:36:49 +00:00
|
|
|
# check if speed is high/low enough for retraction/extention
|
|
|
|
if flaps_mov == "extend":
|
|
|
|
if o_flaps['max-spd'] < kias:
|
|
|
|
self.speak_dialog("spd.high")
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
if o_flaps['min-spd'] > kias:
|
|
|
|
self.speak_dialog("spd.low")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-01-31 08:46:55 +00:00
|
|
|
# TODO set flaps in fg
|
|
|
|
|
|
|
|
self.speak("Speed checked. Flaps " + str(flaps_request))
|
|
|
|
|
2018-01-31 16:36:49 +00:00
|
|
|
|
|
|
|
#########################
|
|
|
|
# #
|
|
|
|
# Gear #
|
|
|
|
# #
|
|
|
|
#########################
|
|
|
|
|
2018-02-01 12:26:10 +00:00
|
|
|
@intent_handler(IntentBuilder('GearUpIntent').require('gearup'))
|
|
|
|
def handle_gear_up_intent(self, message):
|
|
|
|
|
|
|
|
# TODO add connection to fg
|
|
|
|
# TODO read acid from fg
|
|
|
|
|
|
|
|
# read acid to know which profile to use
|
|
|
|
for i_profiles in self.settings['profiles']:
|
|
|
|
for i_acid in i_profiles['acid']:
|
|
|
|
if i_acid == acid:
|
|
|
|
profile = i_profiles
|
|
|
|
break
|
|
|
|
if profile != None:
|
|
|
|
break
|
|
|
|
|
|
|
|
if profile == None:
|
|
|
|
# TODO when creation of profiles via voice is possible, add dialog how to
|
|
|
|
self.speak("Profile not found")
|
2018-01-31 16:36:49 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
2018-02-01 12:26:10 +00:00
|
|
|
if profile['gear-retractable'] == true:
|
|
|
|
# TODO set gear up in fg
|
|
|
|
self.speak("Gear up")
|
|
|
|
else:
|
|
|
|
self.speak_dialog("gear.not.retractable")
|
|
|
|
|
|
|
|
@intent_handler(IntentBuilder('GearDownIntent').require('geardown'))
|
|
|
|
def handle_gear_down_intent(self, message):
|
2018-01-31 16:36:49 +00:00
|
|
|
|
2018-02-01 12:26:10 +00:00
|
|
|
# TODO add connection to fg
|
|
|
|
# TODO read acid from fg
|
|
|
|
|
|
|
|
# read acid to know which profile to use
|
|
|
|
for i_profiles in self.settings['profiles']:
|
|
|
|
for i_acid in i_profiles['acid']:
|
|
|
|
if i_acid == acid:
|
|
|
|
profile = i_profiles
|
|
|
|
break
|
|
|
|
if profile != None:
|
|
|
|
break
|
|
|
|
|
|
|
|
if profile == None:
|
|
|
|
# TODO when creation of profiles via voice is possible, add dialog how to
|
|
|
|
self.speak("Profile not found")
|
2018-01-31 16:36:49 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
2018-02-01 12:26:10 +00:00
|
|
|
if profile['gear-retractable'] == true:
|
|
|
|
# TODO set gear down in fg
|
|
|
|
self.speak("Gear down")
|
|
|
|
else:
|
|
|
|
self.speak_dialog("gear.not.retractable")
|
2018-01-31 16:36:49 +00:00
|
|
|
|
2018-02-01 16:47:57 +00:00
|
|
|
|
|
|
|
#################################################################
|
|
|
|
# #
|
|
|
|
# Checklists #
|
|
|
|
# #
|
|
|
|
#################################################################
|
|
|
|
|
|
|
|
# TODO add all possible checklist
|
|
|
|
# TODO make it possible, to play a .mp3 file instead of tts
|
|
|
|
|
|
|
|
#########################
|
|
|
|
# #
|
|
|
|
# LDG Check #
|
|
|
|
# #
|
|
|
|
#########################
|
2018-01-31 16:36:49 +00:00
|
|
|
|
2018-02-01 16:47:57 +00:00
|
|
|
@intent_handler(IntentBuilder('LDGCheckIntent').require('ldgcheck'))
|
|
|
|
def handle_ldg_check_intent(self, message):
|
|
|
|
# TODO make checklist plane specific
|
|
|
|
self.speak("Landing no blue. . . Landing checklist completed")
|
2018-01-31 16:36:49 +00:00
|
|
|
|
2018-01-31 08:46:55 +00:00
|
|
|
def stop(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def create_skill():
|
|
|
|
return FlightGearCopilotSkill()
|