Go to the documentation of this file.00001
00009 package org.rosmultimedia.player.onkyo;
00010
00011 import org.ros.exception.ServiceException;
00012 import org.ros.node.ConnectedNode;
00013 import org.ros.node.Node;
00014 import org.ros.node.service.ServiceResponseBuilder;
00015 import org.rosbuilding.common.BaseNodeMain;
00016 import org.rosbuilding.common.media.MediaMessageConverter;
00017 import org.rosbuilding.common.media.MediaStateDataComparator;
00018 import org.rosmultimedia.player.onkyo.eiscp.OnkyoEiscp;
00019
00020 import de.csmp.jeiscp.eiscp.EiscpCommmandsConstants;
00021 import smarthome_media_msgs.MediaAction;
00022 import smarthome_media_msgs.StateData;
00023 import smarthome_media_msgs.ToggleMuteSpeaker;
00024 import smarthome_media_msgs.ToggleMuteSpeakerRequest;
00025 import smarthome_media_msgs.ToggleMuteSpeakerResponse;
00026
00027
00034 public class OnkyoNode extends BaseNodeMain<OnkyoConfig, StateData, MediaAction> {
00035
00036 public static final String SRV_MUTE_SPEAKER_TOGGLE = "speaker_mute_toggle";
00037
00038 private OnkyoEiscp onkyoEiscp;
00039 private OnkyoSpeaker speaker;
00040
00041 public OnkyoNode() {
00042 super("onkyo",
00043 new MediaStateDataComparator(),
00044 new MediaMessageConverter(),
00045 MediaAction._TYPE,
00046 StateData._TYPE);
00047 }
00048
00049 @Override
00050 public void onStart(final ConnectedNode connectedNode) {
00051 super.onStart(connectedNode);
00052 this.startFinal();
00053 }
00054
00055 @Override
00056 public void onShutdown(Node node) {
00057 super.onShutdown(node);
00058 }
00059
00060 @Override
00061 protected void onConnected() {
00062 this.getStateData().setState(StateData.ENABLE);
00063 }
00064
00065 @Override
00066 protected void onDisconnected() {
00067 this.getStateData().setState(StateData.UNKNOWN);
00068 }
00069
00070 @Override
00071 public void onNewMessage(MediaAction message) {
00072 if (message != null) {
00073 this.logI(String.format("Command \"%s\"... for %s",
00074 message.getMethod(),
00075 message.getUri()));
00076
00077 super.onNewMessage(message);
00078 }
00079 }
00080
00081 @Override
00082 protected void initialize() {
00083 super.initialize();
00084
00085 this.onkyoEiscp = new OnkyoEiscp(this.configuration.getHost(), this.configuration.getPort());
00086
00087 this.addModule(new OnkyoPlayer(this.onkyoEiscp, this));
00088
00089 this.speaker = new OnkyoSpeaker(this.onkyoEiscp, this);
00090 this.addModule(new OnkyoSystem(this.onkyoEiscp, this));
00091 }
00092
00096 @Override
00097 protected boolean connect() {
00098 boolean isConnected = false;
00099 this.logI(String.format("Connecting to %s:%s...", this.configuration.getHost(), this.configuration.getPort()));
00100
00101 String response = this.onkyoEiscp.sendCommand(
00102 EiscpCommmandsConstants.SYSTEM_POWER_QUERY_ISCP);
00103
00104 if (response != null &&
00105 response.equals(EiscpCommmandsConstants.SYSTEM_POWER_ON_ISCP)) {
00106 this.getStateData().setState(StateData.INIT);
00107 isConnected = true;
00108 this.logI("\tConnected done.");
00109 } else {
00110 this.getStateData().setState(StateData.SHUTDOWN);
00111
00112 try {
00113 Thread.sleep(10000 / this.configuration.getRate());
00114 } catch (InterruptedException e) {
00115 this.logE(e);
00116 }
00117 }
00118
00119 return isConnected;
00120 }
00121
00125 protected void initServices() {
00126 this.getConnectedNode().newServiceServer(
00127 this.configuration.getPrefix() + SRV_MUTE_SPEAKER_TOGGLE,
00128 ToggleMuteSpeaker._TYPE,
00129 new ServiceResponseBuilder<ToggleMuteSpeakerRequest, ToggleMuteSpeakerResponse>() {
00130 @Override
00131 public void build(ToggleMuteSpeakerRequest request,
00132 ToggleMuteSpeakerResponse response) throws ServiceException {
00133 OnkyoNode.this.speaker.handleSpeakerMuteToggle(request, response);
00134 }
00135 });
00136 }
00137
00138 @Override
00139 protected OnkyoConfig getConfig() {
00140 return new OnkyoConfig(this.getConnectedNode());
00141 }
00142 }