@@ -0,0 +1,2476 @@
+%22%22%22A simple simulator for the OPC LED panels.%0A%0AUsage: python simulator.py%0A%0ATo make the LED-bot talk to this server, change the server address to%0A%60localhost:7890%60 in your configuration.%0A%0A%22%22%22%0A%0Afrom struct import unpack%0A%0Aimport SocketServer%0A%0AW = 64%0AH = 32%0Aled_num = W * H%0A%0Aled_width = led_height = led_spacing = 3%0A%0Ascreen_width = W * (led_width + led_spacing) + led_spacing%0Ascreen_height = H * (led_height + led_spacing) + led_spacing%0A%0Aheader = 'B' * 4%0Audp_format = header + ''.join('B' for _ in xrange(led_num * 3))%0A%0A%0Aclass OPCHandler(SocketServer.BaseRequestHandler):%0A    %22%22%22%0A    The RequestHandler class for our server.%0A%0A    It is instantiated once per connection to the server, and must%0A    override the handle() method to implement communication to the%0A    client.%0A    %22%22%22%0A%0A    def handle(self):%0A        # self.request is the TCP socket connected to the client%0A        data = self.request.recv(4096*32).strip()%0A%0A        values = unpack(udp_format, data)%0A%0A        # reverse the data, since we do the craziness in our client.%0A        values = values%5B::-1%5D%5B:-4%5D%0A%0A        screen = self.server.screen%0A%0A        for h in range(H):%0A            for w in range(W):%0A                i = (h*W + w) * 3%0A                fill = '#%2502x%2502x%2502x' %25 values%5Bi:i+3%5D%0A                left = led_spacing + w * (led_width + led_spacing)%0A                top = led_spacing + h * (led_height + led_spacing)%0A                screen.create_rectangle(%0A                    left, top, left+led_width, top+led_height, fill=fill%0A                )%0A%0A        screen.update()%0A%0A%0Aclass OPCServer(SocketServer.TCPServer):%0A%0A    allow_reuse_address = True%0A%0A    def __init__(self, server_address, RequestHandlerClass, bind_and_activate=True):%0A        SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass, bind_and_activate)%0A        self.screen = get_canvas()%0A        self.screen.update()%0A%0Adef get_canvas():%0A    %22%22%22 Creates a Tkinter canvas. %22%22%22%0A%0A    from Tkinter import Tk, Canvas, BOTH%0A%0A    root = Tk()%0A    root.title('LED bot simulator')%0A    root.geometry(%22%25sx%25s%22 %25 (screen_width, screen_height))%0A%0A    canvas = Canvas(root)%0A    canvas.pack(fill=BOTH, expand=1)%0A    canvas.create_rectangle(%0A        0, 0, screen_width, screen_height, outline=%22#000%22, fill=%22#000%22%0A    )%0A%0A    return canvas%0A%0A%0Aif __name__ == %22__main__%22:%0A    HOST, PORT = %22localhost%22, 7890%0A%0A    # Create the server%0A    server = OPCServer((HOST, PORT), OPCHandler)%0A%0A    # Start the server; Interrupt with Ctrl-C%0A    server.serve_forever()%0A

Add a Tkinter canvas based simulator.