blob: 1e994840e35b76d62da30e18444aab395033559d [file] [log] [blame]
Talustus3019a912013-04-06 11:50:07 +02001#!/usr/bin/python
2
3import socket
4import sys
5import struct
6import time
7
8# debug
9VERBOSE = True
10
11def D(msg):
12 if VERBOSE: print(msg)
13
14# "struct fbinfo" is defined in $T/system/core/adb/framebuffer_service.c
15def fbinfo_unpack(data):
16 keys = ("version",
17 "bpp",
18 "size",
19 "width",
20 "height",
21 "red_offset",
22 "red_length",
23 "blue_offset",
24 "blue_length",
25 "green_offset",
26 "green_length",
27 "alpha_offset",
28 "alpha_length"
29 )
30 # the data is little-endian
31 values = struct.unpack("<IIIIIIIIIIIII",data)
32
33 D("dump struct fbinfo")
34 i = 0
35 for key in keys:
36 D("%14s: %-12d" % (key, values[i]))
37 i = i + 1
38
39
40
41def save():
42 f = open('dump', 'w')
43 while True:
44 data = s.recv(4096 * 16)
45 if data == "":
46 break
47 f.write(data)
48 f.close()
49
50
51def communicate(cmd=None):
52 if cmd != None:
53 buf = "%04x%s" % (len(cmd), cmd)
54 D("<< " + buf)
55 s.send(buf)
56 data = s.recv(4096)
57
58 D(">> [%s]" % len(data))
59 D(data)
60
61 if data[0:4] == 'FAIL':
62 return False
63 else:
64 return True
65
66
67target = ''
68# use getopt module in future
69for arg in sys.argv:
70 if arg == '-q':
71 VERBOSE = False
72 if target != 'any':
73 # compatiable with "adb -d", redirect commands to usb
74 if arg == '-d':
75 target = 'usb'
76 # compatiable with "adb -e", redirect commands to emulator
77 elif arg == '-e':
78 target = 'local'
79
80if target == '': target ='any'
81
82s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
83
84D("connecting")
85try:
86 s.connect(("localhost", 5037))
87except socket.error:
88 print 'Cannot connect to localhost:5037'
89 print socket.error
90 sys.exit(0)
91
92D("connected")
93
94if not communicate("host:transport-%s" % target):
95 sys.exit(1)
96#communicate("host:transport-usb:shell:ls /data")
97communicate("framebuffer:")
98
99data = s.recv(52)
100fbinfo_unpack(data)
101
102t0 = float(time.time())
103save()
104t1 = float(time.time())
105print t1 - t0
106