Ejemplo n.º 1
0
def main():
    nb_connection = 0
    Websock.send_esp_state(1)
    while True:
        Mesh.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        while True:
            try:
                Mesh.socket.bind((c.HOST, c.PORT))
                Mesh.socket.listen(5)
            except socket.error as msg:
                print_flush("Socket has failed :", msg)
                time.sleep(0.1)
                continue
            break
        socket_thread = None
        while True:
            print_flush("Socket opened, waiting for connection...")
            conn, addr = Mesh.socket.accept()
            print_flush("Connection accepted with {0}".format(addr))
            if (socket_thread != None):
                socket_thread.close_socket()
                print_flush("The previous connection has been closed")
            socket_thread = Mesh(conn, addr)
            Mesh.print_mesh_info()
            socket_thread.start()
Ejemplo n.º 2
0
 def run(self, params, expires_at=None):
     self.start_socket()
     # get necessary informations
     self.rows = SchedulerState.get_rows()
     self.cols = SchedulerState.get_cols()
     # get the pixels to address
     self.pos_unknown = loads(
         Websock.get_pos_unk())  #format {'@mac1' : ((x,j), index), ...}}
     self.params = params
     print_flush("Launched AMA app with {0} parameter".format(
         self.params['mode']))
     if (self.params['mode'] == 'ama'
         ):  # assisted manual addressing : reset the position of all pixels
         Websock.send_pixels({})
     elif (self.params['mode'] == 'rac'):
         # hot assisted readdressing : reattribute the unusued pixel indexes (get from deconnected pixels) without changing already addressed pixels
         self.deco = loads(Websock.get_deco())
         array = []
         for key in self.deco.keys(
         ):  #Generate the list of all free cells for the frontend
             value = self.deco[key]
             array += [value[0]]
         self.send_pixel_down(array)  #sends this list to the frontend
         self.reattributing_indexes()  #update the dictionnaries
     #Put esp root in ADDR or CONF state, depending on the current state of the server : indicate start of procedure
     Websock.send_esp_state(0)
     if self.params['mode'] == 'skip':
         self.skip_procedure()
         sleep(1)
     else:
         self.addressing_procedure()
     #publish on REDIS and save in DB the new pixels dictionary
     self.update_DB()
     #Put ESPs in COLOR state
     Websock.send_esp_state(1)
     self.visual_verification()
     self.wait_to_be_kill()