def neighbors_update(self): """ update neigh_dict from cli:'neighbor table' """ """ >>> print(lora.cli("neighbor table")) | Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|S|D|N| Extended MAC | +------+--------+-----+----------+-----------+-+-+-+-+------------------+ | C | 0x2801 | 219 | 0 | 0 |1|1|1|1| 0000000000000005 | | R | 0x7400 | 9 | 0 | 0 |1|0|1|1| 0000000000000002 | """ x = self.mesh.neighbors() print_debug(3, "Neighbors Table: %s" % x) if x is None: # bad read, just keep previous neigbors return # clear all pre-existing neigbors self.router_data = RouterData() self.router_data.mac = self.MAC self.router_data.rloc16 = self.rloc16 self.router_data.role = self.state self.router_data.ts = time.time() self.router_data.coord = Gps.get_location() for nei_rec in x: # nei_rec = (role=3, rloc16=10240, rssi=0, age=28, mac=5) age = nei_rec.age if age > 300: continue # shouln't add neighbors too old role = nei_rec.role rloc16 = nei_rec.rloc16 # maybe we shouldn't add Leader (because this info is already available at Leader) # if rloc16 == self.leader_rloc(): # continue rssi = nei_rec.rssi mac = nei_rec.mac neighbor = NeighborData(( mac, age, rloc16, role, rssi, )) self.router_data.add_neighbor(neighbor) #print("new Neighbor: %s"%(neighbor.to_string())) #except: # pass # add own info in dict #self.neigh_dict[self.MAC] = (0, self.rloc16, self.state, 0) print_debug(3, "Neighbors: %s" % (self.router_data.to_string())) return
def __init__(self, data=None): self.mac = 0 self.rloc16 = 0 self.role = 0 self.ts = 0 self.dict = {} self.pack_index_last = 0 self.coord = Gps.get_location() if data is None: return datatype = str(type(data)) if datatype == "<class 'bytes'>": self._init_bytes(data) elif datatype == "<class 'NeighborData'>": self._init_neighbordata(data)