This application translates HTTP GET requests into the proper RS232 commands to control a Sharp Aquos TV

Dependencies:   EthernetInterface mbed-rtos mbed

Revision:
0:427a14ebab60
Child:
1:64bfc05e387d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AquosTV.cpp	Tue Jul 29 23:01:55 2014 +0000
@@ -0,0 +1,83 @@
+#include "AquosTV.h"
+
+AquosTV::AquosTV(DebugPort* dbg) {
+    m_dbg = dbg;
+    init();
+}
+
+AquosTV::~AquosTV() {
+    delete m_tv;
+}
+
+void AquosTV::init() {
+    m_tv = new Serial(PTC17,PTC16);
+    m_tv->baud(9600);
+    m_tv->format(8,SerialBase::None,1);
+    memset(httpcmd,0,sizeof(char)*BUF_SIZE);
+    memset(rs232cmd,0,sizeof(char)*BUF_SIZE);
+}
+        
+bool AquosTV::processCommand(const char* httpin) {
+    int i;
+    int j;
+    bool ret=false;
+    
+    char request[BUF_SIZE];
+    strncpy(httpcmd,httpin,BUF_SIZE-1);
+    httpcmd[AQUOSBUF-1] = '\0';
+    rs232cmd[0]='\0';
+    if(httpcmd[0] == 'G' && httpcmd[1] == 'E' && httpcmd[2]=='T' && httpcmd[3]==' ' && httpcmd[4]=='/') {
+        for(i=5;httpcmd[i]!=' '&&httpcmd[i]!='\0'&&i<AQUOSBUF-1;++i) {
+            request[i-5]=(httpcmd[i] | 0x20);  //make lower case
+        }
+        request[i-5]='\0';
+        m_dbg->send("\n\rReceived Command Request:  ");
+        m_dbg->send(request);
+        m_dbg->send("\n\r");
+            
+        if(strncmp(request,"poweron",BUF_SIZE-1)==0) {
+            strncpy(rs232cmd,"POWR1   \r",BUF_SIZE-1);
+            ret = true;
+        }
+        else if(strncmp(request,"poweroff",BUF_SIZE-1)==0) {
+            strncpy(rs232cmd,"POWR0   \r",BUF_SIZE-1);
+            ret = true;
+        }
+        else if(strncmp(request,"selecttv",BUF_SIZE-1)==0) {
+            strncpy(rs232cmd,"ITVD0   \r",BUF_SIZE-1);
+            ret = true;
+        }
+        else if(strncmp(request,"input",5)==0) {
+            i=request[5]-'0';
+            if(i>0 && i<10) {
+                 snprintf(rs232cmd,BUF_SIZE-1,"IAVD%i   \r",i);
+                ret = true;
+            }
+        }
+        else if(strncmp(request,"volume",6)==0) {
+            i=request[6]-'0';
+            j=request[7]-'0';
+            if(i>=0&&i<10) {
+                if(j>=0&&j<10) {
+                    i = 10*i + j;
+                }
+                snprintf(rs232cmd,BUF_SIZE-1,"VOLM%02i  \r",i);
+                ret = true;
+            }
+        }
+    }
+    
+    if(ret) {
+        m_dbg->send("\n\rCommand Interpreted:  ");
+        m_dbg->send(rs232cmd);
+        m_dbg->send("\n");
+        m_tv->printf(rs232cmd);
+    }
+    else {
+        m_dbg->send("Unknown Command Request\n\r");
+    }
+    return ret;
+}
+        
+const char* AquosTV::tvcmd()  { return rs232cmd; }
+const char* AquosTV::http() { return httpcmd; }
\ No newline at end of file