def __init__(self, mac_master, own_mac, face_id, BROKER_IP): own_mac = own_mac.upper() LogThread.__init__(self, "MQTT") # init MQTT as slave self.client = mqtt.Client(client_id=own_mac) self.client.username_pw_set(username="******", password="******") # start socket towards c++ code self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.connection.connect(('localhost', 6666)) self.log("Connected to socket") # connect to MQTT self.client.connect(BROKER_IP, 1884, 60) self.client.on_connect = self.on_connect # pair to master topic = "directions/effector/pair/{}".format(mac_master) payload = "{}${}".format(own_mac, face_id) self.client.publish(topic, payload)
def __init__( self, parent, id=wx.ID_ANY, title="MapFrame", pos=wx.DefaultPosition, size=(512, 512), style=wx.DEFAULT_FRAME_STYLE, ): wx.Frame.__init__(self, parent, id, title, pos, size, style) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse) self.Bind(EVT_LOCATION_CHANGED, self.OnLocationChanged) self.image = None self.loc = None self.log_thread = LogThread(self) self.log_thread.start()
class MapFrame(wx.Frame): def __init__( self, parent, id=wx.ID_ANY, title="MapFrame", pos=wx.DefaultPosition, size=(512, 512), style=wx.DEFAULT_FRAME_STYLE, ): wx.Frame.__init__(self, parent, id, title, pos, size, style) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse) self.Bind(EVT_LOCATION_CHANGED, self.OnLocationChanged) self.image = None self.loc = None self.log_thread = LogThread(self) self.log_thread.start() def OnLocationChanged(self, event): log.debug("OnLocationChanged()") self.loc = event.loc self.Draw() def OnMouse(self, event): if not event.LeftDown(): return log.debug("OnMouse!") ex = get_last_location() log.debug("map_name: %s, loc: %s" % (ex.map_name, ex.loc)) # ~ doc = etree.ElementTree(file='map.xml') # ~ map_xml = doc.xpath('//map[@name="%s"]' % ex.map_name) map_xml = map_info.load_by_alias(ex.map_name) if not map_xml: log.warn("unkown map '%s'" % ex.map_name) else: bg_image_path = os.path.expanduser("~/bin/el_linux/maps") bg_image_path = os.path.join(bg_image_path, map_xml.get("image")) self.image = wx.Image(bg_image_path, wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.loc = ex.loc size = map_xml.get("size").split(",") self.map_size = (int(size[0]), int(size[1])) self.Draw() def OnSize(self, event): log.debug("OnSize!") self.Width, self.Height = self.GetClientSizeTuple() self._Buffer = wx.EmptyBitmap(self.Width, self.Height) self.Draw() def OnPaint(self, event): log.debug("OnPaint()") self.Draw() def Draw(self): log.debug("Draw()") dc = wx.BufferedPaintDC(self, self._Buffer) dc.Clear() if self.image: png_dc = wx.MemoryDC() png_dc.SelectObject(self.image) dc.Blit(0, 0, self.image.GetWidth(), self.image.GetHeight(), png_dc, 0, 0) if self.loc: dc.SetPen(wx.Pen("blue")) scale = self.image.GetSize()[0] * 1.0 / self.map_size[0] log.debug("scale: %s" % scale) dc.DrawCircle(self.loc[0] * scale, (self.map_size[1] - self.loc[1]) * scale, 10)
def __init__(self, name, mac): LogThread.__init__(self, name) self.mac = mac self.sniffer_thread = SnifferThread('Sniffer')
def __init__(self, name, color, direction, execution_time, connection): LogThread.__init__(self, name) self.process = None self.connection = connection # socket towards c++ self.direction, self.color, self.execution_time = direction, color, execution_time
def __init__(self, name): LogThread.__init__(self, name) self.process = None