Description
The class Network
is an abstraction that provides access to the CAN Bus. The current implementation is also assuming additional canopen roles in the same class. The user have no way to avoid that. It instantiates NmtMaster
, LssMaster
, SyncProducer
, TimeProducer
. All of them are in the current implementation passive, as in, they do not initiate any traffic on their own. This implementation is mixing the role of being a network interface class and providing canopen master functions. As an example, if network is going to be used for passive listening or slave nodes, one would not want NmtMaster
and LssMaster
.
I propose moving the initializations of SyncProducer
, TimeProducer
, NmtMaster
and LssMaster
to a separate method Network.create_manager()
(manager is the new official name for master in canopen) with a function argument to __init__()
to prevent creation of them. With this the user can opt out of the additional services.
Something like this:
# From class Network:
def __init__(self, bus: Optional[can.BusABC] = None, create_manager = True):
if create_manager:
self.create_manager()
def create_manager(self):
self.sync = SyncProducer(self)
self.time = TimeProducer(self)
self.nmt = NmtMaster(0)
self.nmt.network = self
self.lss = LssMaster()
self.lss.network = self
self.subscribe(self.lss.LSS_RX_COBID, self.lss.on_message_received)
Lines 31 to 55 in 48cca7c