Esempio n. 1
0
    def iterate_from_node(self, tx_node: Node):
        for preamble_len in PREAMBLES:
            for modulation in lwb_slot.RADIO_MODULATIONS:
                for power in POWERS:  # lwb_slot.POWERS:
                    self.logger.info(
                        "Tx on Node {}: Mod: {}, Power: {}, Preamble_Length: {}"
                        .format(tx_node.id, modulation, power, preamble_len))

                    config = RadioConfiguration(modulation,
                                                preamble=preamble_len)
                    math = RadioMath(config)

                    message = "Hello World! from FlockLab Node {}: Mod: {}, Pow: {}, Prmbl: {}".format(
                        tx_node.id, modulation, power, preamble_len)

                    for node in self.nodes:
                        self.configure_node(node, (node.id == tx_node.id),
                                            modulation, power, preamble_len)
                        if node.id != tx_node.id:
                            self.receive(node)
                    time.sleep(0.1)
                    self.send(tx_node, message=message)
                    time.sleep(
                        math.get_message_toa(len(message) + 1) * 1.5 + 0.1)
Esempio n. 2
0
class SimMessage:
    def __init__(self,
                 timestamp,
                 source: 'sim_node.SimNode',
                 payload,
                 modulation,
                 destination=None,
                 type=SimMessageType.DATA,
                 content=None,
                 power_level=0,
                 id=None,
                 band=None,
                 tx_start=None):
        self.timestamp = timestamp
        if id is not None:
            self.id = id
        else:
            self.id = np.random.randint(1024)
        self.source = source
        self.destination = destination
        self.type = type
        self.payload = payload
        self.content = content
        self.modulation = modulation
        self.band = band
        self.tx_start = tx_start

        if id is not None:
            self.id = id
        else:
            self.id = np.random.randint(256)

        self.power_level = power_level

        self.hop_count = 0
        self.radio_configuration = RadioConfiguration(
            lwb_slot.RADIO_MODULATIONS[modulation],
            lwb_slot.RADIO_POWERS[self.power_level],
            tx=True,
            preamble=(2 if self.modulation > 7 else 3))
        self.radio_math = RadioMath(self.radio_configuration)

        self.freeze_hop_count = self.hop_count
        self.freeze_power_level = self.power_level
        self.freeze_timestamp = None

    def __copy__(self):
        message = SimMessage(timestamp=self.timestamp,
                             source=self.source,
                             payload=self.payload,
                             destination=self.destination,
                             type=self.type,
                             content=self.content,
                             power_level=self.power_level,
                             modulation=self.modulation,
                             band=self.band,
                             id=self.id)

        message.hop_count = self.hop_count
        message.tx_start = self.tx_start
        self.freeze_hop_count = self.hop_count
        self.freeze_power_level = self.power_level
        return message

    def copy(self):
        return self.__copy__()

    def __str__(self):
        return "<SimMessage {:f},{:d},{:d},{},{},{},{}>".format(
            self.timestamp, self.modulation, self.power_level, self.type,
            self.source, self.destination, self.payload)

    def increase_timestamp(self, offset):
        self.timestamp += offset

    def freeze(self):
        self.freeze_hop_count = self.hop_count
        self.freeze_power_level = self.power_level
        self.freeze_timestamp = self.timestamp

    @property
    def tx_end(self):
        return self.tx_start + self.radio_math.get_message_toa(
            payload_size=self.payload)

    @property
    def hash(self):
        return "{timestamp},{source},{destination},{type},{power_level},{hop_count},{id}".format(
            timestamp=self.timestamp,
            source=self.source,
            destination=self.destination,
            type=self.type,
            content=self.content,
            power_level=self.power_level,
            hop_count=self.hop_count,
            id=self.id)
Esempio n. 3
0
    def reconstruct_receptions(df, csv_path):
        receptions = [
            pd.DataFrame(columns=[
                'tx_node', 'rx_node', 'modulation', 'power', 'preamble',
                'rssi', 'snr', 'timestamp'
            ],
                         dtype='float')
        ]

        nodes = df.node_id.sort_values().unique()

        for node in nodes:

            subset = df[(df.node_id == node) & (df.rx == True)]

            counter = 0

            for index, row in subset.iterrows():
                counter += 1
                if (counter % 100) == 0:
                    print("{}@{}".format(counter, node), end=',')

                if (type(row['output']) is dict and 'type' in row['output']
                        and row['output']['type'] == 'radio_cfg'
                        and 'power' in row['output']):

                    modulation = row['output']['modulation']
                    power = row['output']['power']
                    preamble = row['output']['preamble']

                    config = RadioConfiguration(modulation, preamble=preamble)
                    math = RadioMath(config)

                    message = "Hello World! from FlockLab Node {}: Mod: {:d}, Pow: {:d}, Prmbl: {:d}".format(
                        node, modulation, power, preamble)

                    offset = math.get_message_toa(len(message) + 1) * 1.5 + 0.3

                    rx_subset = df[(df.timestamp > row.timestamp)
                                   & (df.timestamp < (row.timestamp + offset))
                                   & (df.node_id != node)
                                   & (df.rx == True)]

                    receptions.append(
                        pd.DataFrame({
                            'tx_node': [node],
                            'rx_node': [None],
                            'modulation': [modulation],
                            'power': [power],
                            'preamble': [preamble],
                            'rssi': [None],
                            'snr': [None],
                            'timestamp': [row.timestamp],
                        }))

                    for rx_index, rx_row in rx_subset.iterrows():
                        if (type(rx_row['output']) is dict
                                and 'type' in rx_row['output']
                                and rx_row['output']['type'] == 'radio_rx_msg'
                                and 'text' in rx_row['output']
                                and rx_row['output']['text'] == message):
                            receptions.append(
                                pd.DataFrame({
                                    'tx_node': [node],
                                    'rx_node': [rx_row['node_id']],
                                    'modulation': [modulation],
                                    'power': [power],
                                    'preamble': [preamble],
                                    'rssi': [rx_row['output']['rssi']],
                                    'snr': [rx_row['output']['snr']],
                                    'timestamp': [row.timestamp],
                                }))

        receptions = pd.concat(receptions, ignore_index=True)

        receptions.to_csv(csv_path)
        return receptions