Attachment 'tOnkyo.py'

Download

   1 import socket
   2 import select
   3 import sys
   4 import traceback
   5 class Onkyo:
   6     def __init__(self):
   7         HOST = '10.0.2.137'
   8         PORT = 60128
   9         self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  10         self.socket.connect((HOST, PORT))
  11     def mycolors(self):
  12         self.cred = '\033[91m'
  13         self.creset = '\033[0m'
  14         self.cgreen = '\033[92m'
  15         self.cblue = '\033[94m'
  16         self.cyellow = '\033[33m'
  17 
  18     def myError(self, message="No message"):
  19         #self.printDebug()
  20         print self.cred + "Error: %s" % (message) + self.creset
  21         print traceback.print_exc(file=None)
  22         print "---End of traceback---\n"
  23 
  24     def myclean(self):
  25         if self.socket:
  26             self.socket.close()
  27     def makeMessage(self, cmd=None):
  28         if not cmd:
  29             self.myError("makeMessage: no message")
  30             
  31         o = 'ISCP\x00\x00\x00\x10\x00\x00\x00\n\x01\x00\x00\x00!1%s\r\n' % (cmd)
  32         return o
  33     def Iscp2Humans(self, i=None):
  34         if not i:
  35             self.myError("parseIscp: nothing to parse")
  36             return None
  37         else:
  38             i = i.replace("\x00", "").replace("\x01", "").replace("\x1a", "")
  39             i = i.replace("\x10", "").replace("!1", ": ").replace("\n", "").replace("\r","")
  40             i = i.replace("\x0b", "")
  41             return i
  42 
  43     def validcase(self):
  44         self.socket.send("ISCP\x00\x00\x00\x10\x00\x00\x00\n\x01\x00\x00\x00!1SLIQSTN\x1a\r\n")
  45         
  46     def main(self):
  47         self.mycolors()
  48         print self.cgreen + "Turmio Onkyo Magick v0.1 > " + self.creset
  49         self.validcase()
  50         while True:
  51             data = select.select([self.socket, sys.stdin],[],[],5)[0]
  52             if self.socket in data:
  53                 d = self.socket.recv(1024)
  54                 #print repr(d)
  55                 #print repr(dstrip)
  56                 print '<-- ' + self.cgreen + self.Iscp2Humans(d) + self.creset
  57             
  58             if sys.stdin in data:
  59                 try:
  60                     i = sys.stdin.readline()
  61                     if i[0] == "!":
  62                         o = i[1:]
  63                         self.socket.send(o)
  64                         print "--> " + self.cyellow + \
  65                                 "RAW: %s" % self.Iscp2Humans(o) + self.creset
  66                         self.validcase()
  67                     else:
  68                         o = self.makeMessage(i)
  69                         self.socket.send(o)
  70                         print "--> " + self.cyellow + \
  71                             "%s" % self.Iscp2Humans(o) + self.creset
  72                 
  73                 except:
  74                     self.myError("Something wrong while sending")
  75                     print "fail"
  76 
  77 
  78     #print "raw: %s" % data
  79     #print 'Received', repr(data)
  80 if __name__ == "__main__":
  81     try:
  82         remote = Onkyo()
  83         remote.main()
  84 
  85     except KeyboardInterrupt:
  86         remote.myclean()
  87         sys.exit(1)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view | diff] (2012-01-18 22:54:15, 2170.7 KB) [[attachment:IMG_2403.JPG]]
  • [get | view | diff] (2012-01-18 22:54:06, 2823.3 KB) [[attachment:IMG_2405.JPG]]
  • [get | view | diff] (2011-09-08 19:54:21, 89.4 KB) [[attachment:configpage.png]]
  • [get | view | diff] (2011-09-06 15:16:09, 108.8 KB) [[attachment:customer.png]]
  • [get | view | diff] (2011-09-06 15:15:13, 111.5 KB) [[attachment:info.png]]
  • [get | view | diff] (2012-01-16 08:18:45, 86.6 KB) [[attachment:jtag-rs232.png]]
  • [get | view | diff] (2012-08-07 16:34:59, 70.2 KB) [[attachment:libupdater.so.symbols]]
  • [get | view | diff] (2012-12-08 19:38:39, 1424.0 KB) [[attachment:mtdblcok11-etc]]
  • [get | view | diff] (2011-09-06 15:15:50, 88.8 KB) [[attachment:network.png]]
  • [get | view | diff] (2011-09-13 21:03:49, 256.5 KB) [[attachment:onkyo.xls]]
  • [get | view | diff] (2012-01-16 07:53:49, 7805.3 KB) [[attachment:onkyo_repair-tips_[ET].pdf]]
  • [get | view | diff] (2012-01-16 07:54:08, 1639.6 KB) [[attachment:onkyo_tx-nr1000-service_tips-av-receiver_[ET].pdf]]
  • [get | view | diff] (2012-01-16 07:53:28, 10471.0 KB) [[attachment:onkyo_tx-nr509_[ET].pdf]]
  • [get | view | diff] (2012-12-08 16:35:34, 9728.0 KB) [[attachment:squashfs-mtdblock10]]
  • [get | view | diff] (2011-09-06 15:15:31, 129.7 KB) [[attachment:station.png]]
  • [get | view | diff] (2011-09-06 15:59:40, 88.2 KB) [[attachment:strange.png]]
  • [get | view | diff] (2011-09-06 15:30:03, 2.9 KB) [[attachment:tOnkyo.py]]
  • [get | view | diff] (2012-01-16 10:06:38, 46.6 KB) [[attachment:uart-rs232-net.png]]
 All files | Selected Files: delete move to page
Normal Sort Sort + uniq Sort + uniq + count

You are not allowed to attach a file to this page.