-
Notifications
You must be signed in to change notification settings - Fork 2
/
flash-over-tcp.py
58 lines (45 loc) · 1.65 KB
/
flash-over-tcp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from aktos_dcs import *
from stm_flasher import StmFlasher
from gevent.queue import Queue
class ConnectionHandler(TcpHandlerActor):
def prepare(self):
self.flasher = StmFlasher()
self.flasher.setup_phy = self.setup_phy
self.flasher.read_phy = self.read_phy
self.flasher.write_phy = self.write_phy
self.read_queue = Queue()
def setup_phy(self):
print "Setup the physical connection"
def read_phy(self, count=1):
chunk = ""
while True:
chunk += self.read_queue.get()
print "Chunk: ", repr(chunk)
if len(chunk) == count:
break
return chunk
def write_phy(self, data):
print "Sending : ", repr(data)
self.socket_write(data)
def on_connect(self):
print "there is a connection!", self.client_id
print "Preparig to connect stm"
self.flasher.setup_hardware()
self.flasher.wait_setup_hardware()
self.read_queue = Queue()
self.flasher.upload_firmware('./ch.bin')
if self.flasher.upload_successful():
print "Upload is succesful"
else:
print "Problem while uploading firmware"
def on_disconnect(self):
print "client disconnected: ", self.client_id
def socket_read(self, data):
print "I got following data: ", repr(data)
self.read_queue.put(data)
def action(self):
pass
print "Started TcpServer on port 1235"
#TcpServerActor(address='0.0.0.0', port=22334)
TcpServerActor(address='0.0.0.0', port=1235, handler=ConnectionHandler)
wait_all()