Linux fixes and updated run script to run main server

Former-commit-id: 8863d1403995e9ff8d7754928a60b32ed00ba9eb
This commit is contained in:
Ziver Koc 2016-01-04 23:04:00 +01:00
parent d117e344c2
commit 53ce5c0dce
2 changed files with 148 additions and 148 deletions

2
run.sh
View file

@ -4,7 +4,7 @@
#ant clean #ant clean
ant build ant build
screen -S hal -L -d -m ant run-remote-sensor screen -S hal -L -d -m ant run-main-server
echo "-----------------" echo "-----------------"
screen -list screen -list

View file

@ -1,147 +1,147 @@
package se.koc.hal; package se.koc.hal;
import se.koc.hal.bot.AliceBot; import se.koc.hal.bot.AliceBot;
import se.koc.hal.intf.HalBot; import se.koc.hal.intf.HalBot;
import se.koc.hal.intf.HalSpeachToText; import se.koc.hal.intf.HalSpeachToText;
import se.koc.hal.intf.HalTextToSpeach; import se.koc.hal.intf.HalTextToSpeach;
import se.koc.hal.struct.SwitchEvent; import se.koc.hal.struct.SwitchEvent;
import se.koc.hal.stt.ManualSTTClient; import se.koc.hal.stt.ManualSTTClient;
import se.koc.hal.tts.MaryRemoteTTSClient; import se.koc.hal.tts.MaryRemoteTTSClient;
import java.util.HashMap; import java.util.HashMap;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* Created with IntelliJ IDEA. * Created with IntelliJ IDEA.
* User: ezivkoc * User: ezivkoc
* Date: 2013-12-17 * Date: 2013-12-17
* Time: 10:59 * Time: 10:59
*/ */
public class HalClient { public class HalClient {
private static HashMap<String, SwitchEvent> switches = new HashMap<String, SwitchEvent>(); private static HashMap<String, SwitchEvent> switches = new HashMap<String, SwitchEvent>();
public static void main(String[] args){ public static void main(String[] args){
System.setProperty("org.apache.commons.logging.log", "org.apache.commons.logging.impl.NoOpLog"); System.setProperty("org.apache.commons.logging.log", "org.apache.commons.logging.impl.NoOpLog");
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF); org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
/********************************************************************/ /********************************************************************/
System.out.println("Initializing STT..."); System.out.println("Initializing STT...");
HalSpeachToText stt = HalSpeachToText stt =
new ManualSTTClient(); new ManualSTTClient();
// new GoogleSTTClient(); // new GoogleSTTClient();
// new Sphinx4STTClient(); // new Sphinx4STTClient();
stt.initSTT(); stt.initSTT();
/********************************************************************/ /********************************************************************/
System.out.println("Initializing TTS..."); System.out.println("Initializing TTS...");
final HalTextToSpeach tts = final HalTextToSpeach tts =
// new JarvisTTSClient(); // new JarvisTTSClient();
new MaryRemoteTTSClient(); new MaryRemoteTTSClient();
// new MaryLocalTTSClient(); // new MaryLocalTTSClient();
tts.initTTS(); tts.initTTS();
/********************************************************************/ /********************************************************************/
System.out.println("Initializing BOT..."); System.out.println("Initializing BOT...");
HalBot bot = new AliceBot(); HalBot bot = new AliceBot();
bot.initialize(); bot.initialize();
/********************************************************************/ /********************************************************************/
/* NexaSelfLearning nexa1 = new NexaSelfLearning(); /* NexaSelfLearning nexa1 = new NexaSelfLearning();
nexa1.setHouse(15087918); nexa1.setHouse(15087918);
nexa1.setUnit(0); nexa1.setUnit(0);
switches.put("livingroom", new SwitchEvent("livingroom", nexa1)); switches.put("livingroom", new SwitchEvent("livingroom", nexa1));
NexaSelfLearning nexa2 = new NexaSelfLearning(); NexaSelfLearning nexa2 = new NexaSelfLearning();
nexa2.setHouse(15087918); nexa2.setHouse(15087918);
nexa2.setUnit(1); nexa2.setUnit(1);
switches.put("bedroom", new SwitchEvent("bedroom", nexa2)); switches.put("bedroom", new SwitchEvent("bedroom", nexa2));
NexaSelfLearning nexa3 = new NexaSelfLearning(); NexaSelfLearning nexa3 = new NexaSelfLearning();
nexa3.setHouse(15087918); nexa3.setHouse(15087918);
nexa3.setUnit(3); nexa3.setUnit(3);
switches.put("kitchen", new SwitchEvent("kitchen", nexa3)); switches.put("kitchen", new SwitchEvent("kitchen", nexa3));
TellstickSerialComm.getInstance().setListener(new TellstickChangeListener() { TellstickSerialComm.getInstance().setListener(new TellstickChangeListener() {
@Override @Override
public void stateChange(TellstickProtocol protocol) { public void stateChange(TellstickProtocol protocol) {
for(SwitchEvent s : switches.values()) { for(SwitchEvent s : switches.values()) {
if(s.equals(protocol)) { if(s.equals(protocol)) {
String response = s.getName()+" window is "+(((NexaSelfLearning)protocol).isEnabled() ? "open": "closed"); String response = s.getName()+" window is "+(((NexaSelfLearning)protocol).isEnabled() ? "open": "closed");
System.out.println(">>> " + response); System.out.println(">>> " + response);
tts.speak(response); tts.speak(response);
return; return;
} }
} }
} }
}); });
*/ */
System.out.println("Listening..."); System.out.println("Listening...");
while(true){ while(true){
// Listen to input // Listen to input
System.out.print("<<< "); System.out.print("<<< ");
String request = stt.listen(); String request = stt.listen();
System.out.println(request); System.out.println(request);
String response = doActions(request); String response = doActions(request);
if(response == null) { if(response == null) {
// Bot answer // Bot answer
response = bot.respond(request); response = bot.respond(request);
} }
System.out.println(">>> " + response); System.out.println(">>> " + response);
// Cleanup response and Speak // Cleanup response and Speak
response = response.replaceAll("\\<.*?>",""); response = response.replaceAll("\\<.*?>","");
tts.speak(response); tts.speak(response);
} }
} }
private static Pattern pattern_isOn = Pattern.compile("\\bis (\\w*)\\b.*(on|off)"); private static Pattern pattern_isOn = Pattern.compile("\\bis (\\w*)\\b.*(on|off)");
private static Pattern pattern_turnOn = Pattern.compile("\\bturn on (\\w*)\\b"); private static Pattern pattern_turnOn = Pattern.compile("\\bturn on (\\w*)\\b");
private static Pattern pattern_turnOff = Pattern.compile("\\bturn off (\\w*)\\b"); private static Pattern pattern_turnOff = Pattern.compile("\\bturn off (\\w*)\\b");
private static String doActions(String request) { private static String doActions(String request) {
if(request == null) if(request == null)
return null; return null;
Matcher m = pattern_isOn.matcher(request); Matcher m = pattern_isOn.matcher(request);
if(m.find()){ if(m.find()){
String name = m.group(1); String name = m.group(1);
if(switches.containsKey(name)) if(switches.containsKey(name))
return "It is " + (switches.get(name).isOn() ? "on" : "off"); return "It is " + (switches.get(name).isOn() ? "on" : "off");
} }
m = pattern_turnOn.matcher(request); m = pattern_turnOn.matcher(request);
if(m.find()){ if(m.find()){
String name = m.group(1); String name = m.group(1);
if(name.equals("all")){ if(name.equals("all")){
for(SwitchEvent s : switches.values()) for(SwitchEvent s : switches.values())
s.turnOn(); s.turnOn();
return "I've turned everything on for you"; return "I've turned everything on for you";
} }
else if(switches.containsKey(name)) { else if(switches.containsKey(name)) {
switches.get(name).turnOn(); switches.get(name).turnOn();
return "Turned "+name+" on"; return "Turned "+name+" on";
} }
} }
m = pattern_turnOff.matcher(request); m = pattern_turnOff.matcher(request);
if(m.find()){ if(m.find()){
String name = m.group(1); String name = m.group(1);
if(name.equals("all")){ if(name.equals("all")){
for(SwitchEvent s : switches.values()) for(SwitchEvent s : switches.values())
s.turnOff(); s.turnOff();
return "I turned everything off"; return "I turned everything off";
} }
else if(switches.containsKey(name)) { else if(switches.containsKey(name)) {
switches.get(name).turnOff(); switches.get(name).turnOff();
return "I switched "+name+" off"; return "I switched "+name+" off";
} }
} }
return null; return null;
} }
} }