Skip to content

Commit 3ef6cbc

Browse files
committed
Buffer streamer. Decodes incoming packets,replays.
1 parent fd6bbd4 commit 3ef6cbc

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
def main():
1515

1616
p1 = VirtualDac(
17-
host='255.255.255.255'
17+
host='255.255.255.255'
1818
)
19-
q = p1.get_queue()
2019
p1.start()
2120

22-
p2 = RepeaterProcess(DEVICE_MAC)
21+
p2 = RepeaterProcess(DEVICE_MAC, p1.get_queue())
2322
p2.start()
2423

2524
p1.join()

repeater/repeater.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from stream import QueueStream
88

99
class RepeaterProcess(Process):
10-
def __init__(self, macObj):
10+
def __init__(self, macObj, queue=None):
1111
self._isRunning = False # XXX: A locked resource
1212
self._lock = RLock()
1313
self._macObj = macObj
14-
self._queueStream = QueueStream()
14+
self._queueStream = QueueStream(queue=queue)
1515

1616
super(RepeaterProcess, self).__init__()
1717

repeater/stream.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import math
2+
import struct
23
from multiprocessing import Process, Queue, RLock
34

45
class QueueStream(object):
6+
7+
def __init__(self, queue=None):
8+
if not queue:
9+
queue = Queue()
10+
11+
self.called = False
12+
self._queue = queue
13+
self.stream = self.produce()
14+
515
def produce_circle(self):
616
RESIZE_SPEED_INV = 200
717
CMAX = 30000
@@ -73,13 +83,30 @@ def produce(self):
7383
while True:
7484
data = self.get_nowait()
7585

76-
if not data:
77-
for pt in self.produce_circle():
78-
yield pt
86+
if data:
87+
# Index of instructions
88+
l = len(data)
89+
numPoints = (l - 3)/18
90+
off = 3
91+
for i in xrange(numPoints):
92+
93+
d = data[off:off+18]
94+
off += 18
95+
96+
f, x, y, r, g, b, i, u1, u2 = struct.unpack("<HhhHHHHHH", d)
97+
#print f, x, y, r, g, b, i, u1, u2
98+
yield (x, y, r, g, b)
99+
#flags, x, y, r, g, b, i, u1, u2)
100+
101+
102+
103+
#print 'Len data: ', l, m, type(data)
104+
#for pt in self.produce_circle2():
105+
# yield pt
79106
continue
80107

81-
if data:
82-
for pt in self.produce_circle2():
108+
if not data:
109+
for pt in self.produce_circle():
83110
yield pt
84111
continue
85112

@@ -88,11 +115,6 @@ def produce(self):
88115
#print cmd, length
89116

90117

91-
def __init__(self):
92-
self.called = False
93-
self._queue = Queue()
94-
self.stream = self.produce()
95-
96118
def read(self, n):
97119
d = [self.stream.next() for i in xrange(n)]
98120
return d

0 commit comments

Comments
 (0)