Ejemplo n.º 1
0
 def callback(self, ch, method, properties, body):
     Mesh.consummed += 1
     if Mesh.consummed % 100 == 0:  #display mesh status each 100 models received
         Mesh.required_amount = SchedulerState.get_amount()
         Mesh.print_mesh_info()
     # uncommment to reduce the amount of frames send during the esp declaration phase
     # if Mesh.comp < Mesh.required_amount :
     #     print_flush("Not enough pixels on the mesh network to display the model")
     #     return
     if Websock.should_get_deco():
         Listen.deco = json.loads(Websock.get_deco())
     b = body.decode('ascii')
     self.model.set_from_json(b)
     tmp = Websock.get_esp_state()
     if tmp != None and eval(tmp) != self.previous_state:
         Mesh.change_esp_state = True
         print_flush("tmp != None, tmp = {}".format(tmp))
         self.previous_state = eval(tmp)
     else:
         Mesh.change_esp_state = False
     if Mesh.change_esp_state:  # A procedure has started (ie AMA.py is launched) and both the mesh network and the serveur have to be ready
         self.procedures_manager()
     elif (Mesh.ama == 1):  # A procedure is running
         self.ama_care()
     elif (Mesh.addressed):
         # Production mod : all pixels are addressed
         Mesh.sequence = (Mesh.sequence + 1) % 65536
         array = slef.msg.color(self.model._model, Mesh.sequence,
                                Mesh.pixels, Listen.unk)
         self.mesh_conn.send(array)
     else:  # Temporisation required between the launching of AMA.py and the frist model matching the procedure arrives
         print_flush("{} : It is not the time to send colors".format(
             Mesh.consummed))
Ejemplo n.º 2
0
 def reattributing_indexes(self):
     self.deco = loads(
         Websock.get_deco())  #retrieves the disconnected cards.
     for mac in self.pos_unknown.keys():
         if len(self.deco) > 0:
             # dummy security, should do something in the case of it happenning but dunno what (yet)
             pixel_deco = self.deco.popitem()
             self.pos_unknown[mac] = (
                 (-1, -1), pixel_deco[1][1]
             )  #associate the disconnected card index to the unknown card.
     self.pixels = loads(
         Websock.get_pixels())  #retrieves the current pixel list
     self.pixels['default'] = ((-1, -1), -1)  #adds the fake pixel security.
Ejemplo n.º 3
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()