001package ca.bc.webarts.tools; 002 003import ca.bc.webarts.widgets.Util; 004import ca.bc.webarts.tools.ShawDirectLircCommands; 005 006import java.io.IOException; 007import java.net.UnknownHostException; 008 009class ShawDirectChannelChange extends TCPSocketClient 010{ 011 /** A holder This classes name (used when logging). **/ 012 private static String CLASSNAME = ca.bc.webarts.widgets.Util.getCurrentClassName(); 013 /** The string that gets tagged at the front of all debugging output messages.**/ 014 public static final String LOG_TAG = "ShawDirectLircApp"; 015 /** DEFAULT IP address for the Lirc server to usefor Shaw Direct commands.**/ 016 private static final String DEFAULT_LIRC_IP = "10.0.0.213"; // mythtv 017 018 /** flags the control of debugging output messages.**/ 019 public static boolean debugOut_ = true; 020 021 /** Helper Class var for passing the Shawdirect related message associated with the button that just gor pressed. **/ 022 private String activatedShawDirectCommand_=""; 023 024 /** IP address for the ShawDirect IR blaster Lirc server.**/ 025 private String lircServerIP_ = DEFAULT_LIRC_IP; 026 027 /** IP port for the ShawDirect IR blaster Lirc server.**/ 028 private int lircPort_ = 8765; 029 030 031 public ShawDirectChannelChange() 032 { 033 super(DEFAULT_LIRC_IP,8765); 034 } 035 036 /** Instatiates the client with custom IP and port.**/ 037 public ShawDirectChannelChange(String hostName, int portNum) 038 { 039 super(hostName,portNum); 040 } 041 042 043 public static void main (String [] args) 044 { 045 ShawDirectChannelChange instance= null; 046 System.out.println("Num="+args.length); 047 if (args.length < 1) 048 { 049 instance = new ShawDirectChannelChange(); 050 System.out.println("Usage: java ShawDirectChannelChange command [command...]\n" + 051 "Now using host=" + instance.host_ + ", portNumber=" + instance.port_); 052 } 053 else if (args[0].equals("-h") || args[0].equals("-?") || args[0].equalsIgnoreCase("--help") ) 054 { 055 System.out.println("Usage: java ShawDirectChannelChange command [command...]\n" + 056 "Now using host=" + DEFAULT_LIRC_IP + ", portNumber=" + "8765"); 057 System.out.println("ShawDirect (StarChoice) Lirc Command Strings:"); 058 System.out.println("SD1_POWER"); 059 System.out.println("SD1_UP"); 060 System.out.println("SD1_DOWN"); 061 System.out.println("SD1_LEFT"); 062 System.out.println("SD1_RIGHT"); 063 System.out.println("SD1_ENTER"); 064 System.out.println("SD1_GOBACK"); 065 System.out.println("SD1_EXIT"); 066 System.out.println("SD1_INFO"); 067 System.out.println("SD1_GUIDE"); 068 System.out.println("SD1_REWIND"); 069 System.out.println("SD1_PLAY"); 070 System.out.println("SD1_FORWARD"); 071 System.out.println("SD1_RECORD"); 072 System.out.println("SD1_PAUSE"); 073 System.out.println("SD1_STOP"); 074 System.out.println("SD1_CH_UP"); 075 System.out.println("SD1_CH_DOWN"); 076 System.out.println("SD1_LAST"); 077 System.out.println("SD1_INTERESTS"); 078 System.out.println("SD1_BROWSE"); 079 System.out.println("SD1_PPV"); 080 System.out.println("SD1_FUTURE"); 081 System.out.println("SD1_OPTIONS"); 082 System.out.println("SD1_1"); 083 System.out.println("SD1_2"); 084 System.out.println("SD1_3"); 085 System.out.println("SD1_4"); 086 System.out.println("SD1_5"); 087 System.out.println("SD1_6"); 088 System.out.println("SD1_7"); 089 System.out.println("SD1_8"); 090 System.out.println("SD1_9"); 091 System.out.println("SD1_0"); 092 System.out.println("SD1_HELP"); 093 } 094 else //if (args.length < 3) 095 { 096 instance = new ShawDirectChannelChange( ); 097 //host = args[0]; 098 //portNumber = Integer.valueOf(args[1]).intValue(); 099 System.out.println("Usage: java ShawDirectChannelChange command [command...]\n" + 100 "Now using host=" + instance.host_ + ", portNumber=" + instance.port_); 101 for (int i =0; i< args.length; i++) 102 { 103 instance.activatedShawDirectCommand_ = args[i]; 104 instance.sendShawDirectCommand(); 105 } 106 } 107 108 109 } 110 111 112 /** Called to send an Lirc message to the Shawdirect Lirc server when the user selects an ShawDirect command button. */ 113 private void sendShawDirectCommand() 114 { 115 String commandStr = ""; 116 117 if (activatedShawDirectCommand_!=null&&!activatedShawDirectCommand_.equals("")) 118 { 119 if(debug_>0) System.out.println(LOG_TAG+"."+Util.getCurrentMethodName()+" : "+activatedShawDirectCommand_); 120 121 try 122 { 123 initSocket(); 124 if (isInit()) 125 { 126 sendAndWait(ShawDirectLircCommands.getLircMessage(activatedShawDirectCommand_),1000); 127 closeSocket(); 128 } 129 else 130 System.out.println("Socket NOT init"); 131 } 132 catch (UnknownHostException e) 133 { 134 System.err.println("Don't know about lirc host " + lircServerIP_); 135 } 136 catch (IOException ioEx) 137 { 138 //ioEx.printStackTrace(); 139 System.err.println("Couldn't get I/O for the connection to the host " + lircServerIP_); 140 } 141 142 } 143 } 144 145 146}