def __init__(self, **kwargs): """Constructor.""" self.fc = None self.Gtx, self.Grx = None, None self.Ltx, self.Lrx = None, None self.Ntx, self.Nrx = None, None self.fomax = None self.__cfo = None self.bandwidth = None ChannelInterface.__init__(self, **kwargs)
def log_drop(self, p, *args, **kwargs): """Overload to log 'cif-txpower', 'rxpower', and 'pathloss' annotation.""" if p.hasanno('cif-txpower'): txpower = p.getanno('cif-txpower') kwargs['cif-txpower'] = "%.2f dBm"%(txpower) if p.hasanno('rxpower'): rxpower = p.getanno('rxpower') kwargs['rxpower'] = "%.2f dBm"%(rxpower) if p.hasanno('noisepower'): noisepower = p.getanno('noisepower') kwargs['noisepower'] = "%.2f dBm"%(noisepower) if p.hasanno('pathloss'): pathloss = p.getanno('pathloss') kwargs['pathloss'] = "%.2f dB"%(pathloss) ChannelInterface.log_drop(self, p, *args, **kwargs)
def set_sendanno(self, p): """Set radio annotations for transmitted packet. :return: Modified packet. If the 'cif-txpower' annotation has not already been set by another protocol, this method will use the local `txpower` value. The transmit power is then adjusted by the transmit antenna gain `Grx` and the transmitter system loss `Lrx`, such that the new transmit power is: Ptx (dBm) = Pold (dBm) + Gtx (dB) - Ltx (dB) The 'cif-txpower' annotation is then set to this new value. Finally, the method calls `ChannelInterface.set_sendanno()`. Overload this method as necessary. """ Gtx = self.Gtx Ltx = self.Ltx Ptx = self.txpower if p.hasanno('cif-txpower'): Ptx = p.getanno('cif-txpower') # adjust transmit power txpower = Ptx + Gtx - Ltx p.setanno('cif-txpower', txpower) # update and set local cfo self.set_cfo() p.setanno('tx-cfo', self.cfo) return ChannelInterface.set_sendanno(self, p)
def configure(self, fc=None, Gtx=None, Grx=None, \ Ltx=None, Lrx=None, Ntx = None, Nrx = None, fomax=None, \ txpower = None, bandwidth=None, **kwargs): """Set up radio parameters. :param fc: Center frequency of `Radio` (in Hz). :param Gtx: Transmit antenna gain (in dB). :param Grx: Receive antenna gain (in dB). :param Ltx: System loss associated with transmitter (in dB). :param Lrx: System loss associated with receiver (in dB). :param Ntx: Number of transmit antennas. :param Nrx: Number of receive antennas. :param fomax: Maximum frequency offset of local oscillator (in ppm). :param txpower: Transmit power (in dBm). :param bandwidth: System bandwidth (in Hz). :param kwargs: Keywords passed to `ChannelInterface.configure()`. All parameters not specified will be set to their default values as specified by the class. """ # get parameters cls = self.__class__ if fc is None: fc = cls.fc if Gtx is None: Gtx = cls.Gtx if Grx is None: Grx = cls.Grx if Ltx is None: Ltx = cls.Ltx if Lrx is None: Lrx = cls.Lrx if bandwidth is None: bw = cls.bandwidth if txpower is None: txpower = cls.txpower if Ntx is None: Ntx = cls.Ntx if Nrx is None: Nrx = cls.Nrx if fomax is None: fomax = cls.fomax # set parameters self.fc = fc self.Gtx, self.Grx = Gtx, Grx self.Ltx, self.Lrx = Ltx, Lrx self.bandwidth = bw self.txpower = txpower self.Ntx, self.Nrx = Ntx, Nrx self.fomax = fomax self.set_cfo() ChannelInterface.configure(self, **kwargs)
def set_recvanno(self, p): """Set radio annotations for received packet. :return: Modified packet. This method sets the 'rxpower' annotation to the value returned by `rxpower()`, sets the 'noisepower' annotation using `thermalnoise()` and `bandwidth`, and then calls ChannelInterface.set_recvanno()`. Overload this method as needed. :note: This method is called immediately after the packet `p` has been inserted in the `rxbuffer`. """ r = ChannelInterface.set_recvanno(self, p) rxpower = self.rxpower(r, self.Grx, self.Lrx) noisepower = self.noisepower() r.setanno('rxpower', rxpower) r.setanno('noisepower', noisepower) # update and set local cfo self.set_cfo() r.setanno('rx-cfo', self.cfo) return r
def log_send(self, p, *args, **kwargs): """Overloaded to log 'cif-txpower' annotation.""" if p.hasanno('cif-txpower'): txpower = p.getanno('cif-txpower') kwargs['cif-txpower'] = "%.2f dBm"%(txpower) ChannelInterface.log_send(self, p, *args, **kwargs)