Go to the documentation of this file.00001
00009 package org.rosmultimedia.player.samsung;
00010
00011 import java.io.IOException;
00012
00013 import org.ros.node.ConnectedNode;
00014 import org.ros.node.Node;
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.samsung.driver.LcdTvC650;
00019 import org.rosmultimedia.player.samsung.driver.SamsungRemoteSession;
00020 import org.rosmultimedia.player.samsung.internal.SamsungMonitor;
00021 import org.rosmultimedia.player.samsung.internal.SamsungPlayer;
00022 import org.rosmultimedia.player.samsung.internal.SamsungSystem;
00023
00024 import smarthome_media_msgs.MediaAction;
00025 import smarthome_media_msgs.StateData;
00026
00033 public class SamsungTvNode extends BaseNodeMain<SamsungConfig, StateData, MediaAction> {
00034
00035 protected SamsungRemoteSession tvIp;
00036
00037 public SamsungTvNode() {
00038 super("samsungtv",
00039 new MediaStateDataComparator(),
00040 new MediaMessageConverter(),
00041 MediaAction._TYPE,
00042 StateData._TYPE);
00043 }
00044
00045 @Override
00046 public void onStart(ConnectedNode connectedNode) {
00047 super.onStart(connectedNode);
00048 this.tvIp = new LcdTvC650(this);
00049 this.startFinal();
00050 }
00051
00052 @Override
00053 public void onShutdown(Node node) {
00054 this.tvIp.destroy();
00055 super.onShutdown(node);
00056 }
00057
00058 @Override
00059 protected void onConnected() {
00060 this.getStateData().setState(StateData.ENABLE);
00061 }
00062
00063 @Override
00064 protected void onDisconnected() {
00065 this.getStateData().setState(StateData.UNKNOWN);
00066 }
00067
00068 @Override
00069 public void onNewMessage(MediaAction message) {
00070 if (message != null) {
00071 this.logI(String.format("Command \"%s\"... for %s",
00072 message.getMethod(),
00073 message.getUri()));
00074
00075 super.onNewMessage(message);
00076 }
00077 }
00078
00079 @Override
00080 protected boolean connect() {
00081 boolean isConnected = false;
00082 this.logI(String.format("Connecting to %s:%s...", this.configuration.getHost(), this.configuration.getPort()));
00083
00084 try {
00085 this.tvIp = SamsungRemoteSession.create(
00086 this,
00087 SamsungRemoteSession.APP,
00088 SamsungRemoteSession.REMOTE,
00089 this.configuration.getHost(),
00090 this.configuration.getPort() );
00091
00092 this.getStateData().setState(StateData.INIT);
00093 isConnected = true;
00094 this.logI("\tConnected done.");
00095 } catch (Exception e) {
00096 this.getStateData().setState(StateData.SHUTDOWN);
00097 try {
00098 Thread.sleep(10000 / this.configuration.getRate());
00099 } catch (InterruptedException ex) {
00100 this.logE(ex);
00101 }
00102 }
00103
00104 return isConnected;
00105 }
00106
00107 @Override
00108 protected void initialize() {
00109 super.initialize();
00110
00111
00112
00113
00114 this.addModule(new SamsungMonitor(this));
00115 this.addModule(new SamsungPlayer(this));
00116 this.addModule(new SamsungSystem(this));
00117 }
00118
00119 public void pushEnum (final SamsungCommand key, final float timeout )
00120 throws IOException, InterruptedException {
00121 this.logD("Send to Samsung : " + key.getValue() );
00122 this.tvIp.sendKey( key );
00123 Thread.sleep((long) (1000l*timeout));
00124
00125 }
00126
00127 public void pushEnum (final SamsungCommand key)
00128 throws IOException, InterruptedException {
00129 this.pushEnum( key, 0.250f );
00130 }
00131
00132 public void sendText (final String text, final float timeout )
00133 throws IOException, InterruptedException {
00134 this.tvIp.sendText(text);
00135 Thread.sleep((long) (1000l*timeout));
00136 }
00137
00138 public void sendText (final String text)
00139 throws IOException, InterruptedException {
00140 this.sendText( text, 0.250f );
00141 }
00142
00143 public static boolean isInteger(final String str) {
00144 if (str == null) {
00145 return false;
00146 }
00147 int length = str.length();
00148 if (length == 0) {
00149 return false;
00150 }
00151 int i = 0;
00152 if (str.charAt(0) == '-') {
00153 if (length == 1) {
00154 return false;
00155 }
00156 i = 1;
00157 }
00158 for (; i < length; i++) {
00159 char c = str.charAt(i);
00160 if (c <= '/' || c >= ':') {
00161 return false;
00162 }
00163 }
00164 return true;
00165 }
00166
00167 @Override
00168 protected SamsungConfig getConfig() {
00169 return new SamsungConfig(this.getConnectedNode());
00170 }
00171 }