-
Notifications
You must be signed in to change notification settings - Fork 0
/
osibase.py
59 lines (48 loc) · 2.09 KB
/
osibase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
from siginterface import OsiBaseInterface, OsiBaseInterfaceTop, OsiBaseInterfaceBottom
from interface import implements
## A Basic block for building transceiver chains
#
# Blessed are the meek: for they shall inherit this class
class OsiBase(implements(OsiBaseInterface)):
## Constructor
## ctons
def __init__(self):
self.up = None ##! Points at next in rx chain
self.down = None ##! Points at next in tx chain
self.name = "noname" ##! Nicename for printing
## Traditionally the "TX" direction
# @param data rf: (list,np.array) data: (byte strings)
# transmit to the lower layer
def txdown(self, data, meta=None):
return self.down.rxup(data, meta)
## Transmit to the upper layer
# @param data same as txdown()
# @param meta is meta data usually a {}
def txup(self, data, meta=None):
return self.up.rxdown(data, meta)
## Receive from the lower layer VIRTUAL
# @param meta is meta data usually a {}
def rxdown(self, data, meta=None):
print("warning", self, "does not implement rxdown()")
return self.txup(data, meta)
## Receive from upper layer VIRTUAL
def rxup(self, data, meta=None):
print("warning", self, "does not implement rxup()")
return self.txdown(data, meta)
## Call this regularly on blocks which implement it. Dummy for now
def tick(self):
pass
## String classes together with this, Set the argument to become the parent of the object who calls this method.
def set_parent(self, parent):
self.up = parent
parent.down = self
return parent # this allows for stringing on one line
## Insert a parent to the object who calls this method
def insert_above(self, newparent):
oldparent = self.up
self.set_parent(newparent).set_parent(oldparent)
## Insert a child to the object who calls this method
def insert_below(self, newchild):
oldchild = self.down
oldchild.set_parent(newchild).set_parent(self)