Ejemplo n.º 1
0
def Chaos_Func():
	print('CHAOS BEGINS !!!!!!!!!!!!!!!!!!!!!!!!!!!!')

	fs = FileStorage()
	fs.readJson("net.json")
	net = fs.db
	# pprint(self.db)
	# self.play(self.db['start'])

	fs.db = {}
	fs.readJson("clips.json")
	clips = fs.db

	# subs = []
	# for sub in net:
	# 	ip = net[sub]
	# 	s = zmq.Pub(bind_to=(ip[0], ip[1]))
	# 	subs.append(s)
	# 	print(' >> Subscribed to:', sub, '@', ip)

	subs = {}
	subs['sounds'] = zmq.Pub(bind_to=('localhost', 9000))
	subs['speak'] = subs['sounds']
	subs['servos'] = zmq.Pub(bind_to=('localhost', 9004))

	while True:
		for key in subs.keys():
			if key == 'sounds':
				clip = random.choice(clips.keys())
				msg = Messages.Dictionary()
				msg.dict['sound'] = clip
				subs['sounds'].pub('sounds', msg)
				# print('msg:', msg)
				time.sleep(7)
			elif key == 'speak':
				word = getnrandom()
				msg = Messages.Dictionary()
				msg.dict[key] = word
				subs[key].pub(key, msg)
				time.sleep(4)
			elif key == 'servos':
				num = random.choice(range(3))
				name = 'door{}'.format(num)
				msg = Messages.Dictionary()
				msg.dict['name'] = name
				msg.dict['angle'] = random.choice(range(30, 150, 10))
				subs[key].pub(key, msg)
				time.sleep(1)
			else:
				print('<<< Oops, unknown key:', key, '>>>')
Ejemplo n.º 2
0
def test_pub_sub_msgs():
    tcp = ('127.0.0.1', 9001)
    pub = zmq.Pub(tcp)
    sub = zmq.Sub(['test'], tcp)
    msgs = [
        Msgs.Vector(),
        Msgs.Quaternion(),
        Msgs.Array(),
        Msgs.IMU(),
        Msgs.Dictionary(),
        Msgs.Odom(),
        Msgs.Joystick(),
        Msgs.Twist(),
        Msgs.Wrench()
    ]
    for tmsg in msgs:
        while True:
            print(tmsg)
            pub.pub('test', tmsg)
            topic, msg = sub.recv()

            if msg:
                assert msg == tmsg
                assert topic == b'test'
                break
Ejemplo n.º 3
0
	def run(self):
		print('start pub')
		while True:
			# msg = Msg.Array()
			# msg.append(1)
			# msg.append(2)
			msg = Msg.Vector()
			msg.set(1, 2, 3)
			self.pub.pub('a', msg)
			print(msg)

			msg = Msg.Dictionary()
			msg.dict['bob'] = 1
			self.pub.pub('b', msg)
			print(msg)
			time.sleep(1)
Ejemplo n.º 4
0
def Pub():
    pub = zmq.Pub(('127.0.0.1', 9000))
    print('start pub')
    cnt = 0
    while True:
        # msg = Msg.Array()
        # msg.append(1)
        # msg.append(2)
        msg = Msg.Vector()
        cnt += 1
        msg.set(1, 2, cnt)
        pub.pub('a', msg)
        # print('>>', msg)

        msg = Msg.Dictionary()
        msg.dict['bob'] = 1
        pub.pub('b', msg)
        # print('>>', msg)
        time.sleep(.1)