Esempio n. 1
0
    def active(self,
               nwkskey,
               appskey=None,
               addr=None,
               fcnt_up=0,
               fcnt_down=0,
               dev_class=ClassType.a,
               adr=True,
               check_fcnt=False):
        self.nwkskey = nwkskey
        if appskey is None:
            appskey = b''
        self.appskey = appskey
        if self.active_mode == ActiveMode.abp:
            if addr is None:
                addr = AddrManger.dis_dev_addr()
        self.addr = addr
        AddrManger.addr_available(self.addr)
        self.fcnt_up = fcnt_up
        self.fcnt_down = fcnt_down
        self.dev_class = dev_class
        self.adr = adr
        self.check_fcnt = check_fcnt

        key_eui = ConstDB.dev + hexlify(self.dev_eui).decode()
        pipe = db0.pipeline()
        pipe.hmset(key_eui, self.__zip_vars())
        pipe.set(ConstDB.addr + hexlify(self.addr).decode(), key_eui)
        pipe.execute()
Esempio n. 2
0
 def delete(self):
     group_id_hex = hexlify(self.id).decode()
     group_key = ConstDB.group + group_id_hex
     """
     group_devs = db0.keys(ConstDB.group_dev + group_id_hex + ':*')
     """
     group_devs_list = self._get_device_list()
     group_devs = [
         (ConstDB.group_dev + group_id_hex + ':' + i_group_list).encode()
         for i_group_list in group_devs_list
     ]
     statistics_down = db0.keys(ConstDB.statistics_down + group_key + ':*')
     msg_down = db0.keys(ConstDB.msg_down + group_key + ':*')
     pipe = db0.pipeline()
     for key in group_devs:
         pipe.delete(key)
     for key in msg_down:
         pipe.delete(key)
     for key in statistics_down:
         pipe.delete(key)
     pipe.srem(ConstDB.app_groups + hexlify(self.app_eui).decode(), self.id)
     pipe.delete(ConstDB.que_down + group_key)
     pipe.delete(ConstDB.addr + hexlify(self.addr).decode())
     pipe.delete(group_key)
     pipe.execute()
     AddrManger.recycle_addr(self.addr)
Esempio n. 3
0
 def save(self):
     group_key = ConstDB.group + hexlify(self.id).decode()
     AddrManger.addr_available(self.addr)
     pipe = db0.pipeline()
     pipe.sadd(ConstDB.app_groups + hexlify(self.app_eui).decode(), self.id)
     pipe.hmset(group_key, self.__zip_vars())
     pipe.set(ConstDB.addr + hexlify(self.addr).decode(), group_key)
     pipe.execute()
Esempio n. 4
0
 def update(self):
     pipe = db0.pipeline()
     group_key = ConstDB.group + hexlify(self.id).decode()
     orignal_addr = db0.hget(group_key, FieldGroup.addr)
     if self.addr != orignal_addr:
         AddrManger.addr_available(self.addr)
         pipe.rename(ConstDB.addr + hexlify(orignal_addr).decode(),
                     ConstDB.addr + hexlify(self.addr).decode())
     pipe.hmset(group_key, self.__zip_vars_can_write())
     pipe.execute()
Esempio n. 5
0
 def delete(self):
     db_sql.session.delete(self)
     db_sql.session.flush()
     if self.active_at is not None:
         app_eui = hexlify(self.app_eui).decode()
         dev_eui = hexlify(self.dev_eui).decode()
         addr = hexlify(db0.hget(ConstDB.dev + dev_eui,
                                 FieldDevice.addr)).decode()
         msgs_up = db0.keys(ConstDB.msg_up + app_eui + ':' + dev_eui + ':*')
         msgs_down = db0.keys(ConstDB.msg_down + ConstDB.dev + dev_eui +
                              ':*')
         mac_cmds = db0.keys(ConstDB.mac_cmd + dev_eui + ':*')
         trans_params = db0.keys(ConstDB.trans_params + dev_eui + ':*')
         groups = db0.keys(ConstDB.group_dev + '*:' + dev_eui)
         statistics_up = db0.keys(ConstDB.statistics_up + dev_eui + ':*')
         statistics_down = db0.keys(ConstDB.statistics_down + ConstDB.dev +
                                    dev_eui + ':*')
         pipe = db0.pipeline()
         pipe.delete(ConstDB.dev_ack + dev_eui)
         pipe.delete(ConstDB.dev + dev_eui)
         pipe.srem(ConstDB.app_devs + app_eui, self.dev_eui)
         for key in groups:
             pipe.delete(key)
         pipe.delete(ConstDB.addr + addr)
         pipe.delete(ConstDB.dev_gateways + dev_eui)
         for key in mac_cmds:
             pipe.delete(key)
         for key in msgs_up:
             pipe.delete(key)
         for key in msgs_down:
             pipe.delete(key)
         pipe.delete(ConstDB.que_down + ConstDB.dev + dev_eui)
         pipe.delete(ConstDB.mac_cmd_que + dev_eui)
         for key in trans_params:
             pipe.delete(key)
         for key in statistics_down:
             pipe.delete(key)
         for key in statistics_up:
             pipe.delete(key)
         pipe.execute()
         AddrManger.recycle_addr(unhexlify(addr))
     db_sql.session.commit()