Skip to content

Commit b66c434

Browse files
committed
Created basic state message server
0 parents  commit b66c434

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

state_server.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import zmq
2+
import struct
3+
4+
class StateMsg(object):
5+
Attenuation = 0
6+
7+
def __init__(self, state_type):
8+
self.state_type = state_type
9+
10+
def __str__(self):
11+
return struct.pack("B", self.struct)
12+
13+
class AtennuationMsg(StateMsg):
14+
Roll = 0
15+
Pitch = 1
16+
Yaw = 2
17+
X = 3
18+
Y = 4
19+
Z = 5
20+
21+
def __init__(self, axis, value):
22+
StateMsg.__init__(self, StateMsg.Attenuation)
23+
self.axis = axis
24+
self.value = value
25+
26+
def __str__(self):
27+
return StateMsg.__str__(self) + struct.pack("Bf", self.axis, self.value)
28+
29+
class StateServer(object):
30+
def __init__(self, zmq_context):
31+
self.context = zmq_context
32+
self.socket = self.context.socket(zmq.PUB)
33+
34+
def bind(self, bind_address):
35+
self.socket.bind(bind_address)
36+
37+
if __name__ == "__main__":
38+
ss = StateServer(zmq.Context())
39+
ss.bind("tcp://127.0.0.1:5000")
40+

0 commit comments

Comments
 (0)