00001 00009 package script.media.onkyo; 00010 00011 import org.ros.node.ConnectedNode; 00012 import org.ros.node.topic.Publisher; 00013 import org.rosbuilding.common.ISystem; 00014 import org.rosbuilding.common.media.CommandUtil; 00015 import org.rosbuilding.common.media.ISpeaker; 00016 00017 import com.rosalfred.core.ia.IaNode; 00018 import com.rosalfred.core.ia.RosRiveScript; 00019 00020 import smarthome_comm_msgs.Command; 00021 00027 public class Onkyo { 00028 00029 private static Object lockInstance = new Object(); 00030 private static ConnectedNode node; 00031 private static Publisher<Command> publisher; 00032 00033 private final RosRiveScript rivescript; 00034 00035 public Onkyo(RosRiveScript rivescript) { 00036 this.rivescript = rivescript; 00037 this.initialize(rivescript); 00038 } 00039 00040 private void initialize(RosRiveScript rivescript) { 00041 if (node == null) { 00042 synchronized (lockInstance) { 00043 if (node == null) { 00044 node = rivescript.getNode(); 00045 publisher = rivescript.getPublisherSay(); 00046 } 00047 } 00048 } 00049 } 00050 00051 private void publish(String method) { 00052 node.getLog().info("send sub command : " + method); 00053 00054 Command message = node.getTopicMessageFactory().newFromType(Command._TYPE); 00055 String user = this.rivescript.getCurrentUser(); 00056 message.getContext().setWho(IaNode.botname); 00057 message.getContext().setWhere( // TODO Mapping by knowedge relation 00058 this.rivescript.getUservar(user, IaNode.VAR_CONTEXT_WHERE)); 00059 message.setAction("::" + method); 00060 publisher.publish(message); 00061 00062 try { 00063 Thread.sleep(1); 00064 } catch (InterruptedException e) { 00065 // TODO Auto-generated catch block 00066 e.printStackTrace(); 00067 } 00068 } 00069 00070 public void startReceiver() { 00071 this.publish(ISystem.OP_POWER); 00072 00073 Command command = CommandUtil.toCommand( 00074 node, 00075 ISpeaker.OP_CHANNEL, 00076 "SLI10"); 00077 00078 publisher.publish(command); 00079 } 00080 00081 public void shutdownReceiver() { 00082 this.publish(ISystem.OP_SHUTDOWN); 00083 } 00084 00085 public void mute() { 00086 this.publish(ISpeaker.OP_MUTE); 00087 } 00088 }