importstructimporttimefromtypingimportOptional# 1 Jan 1984OFFSET=441763200ONE_DAY=60*60*24TIME_OF_DAY_STRUCT=struct.Struct("<LH")
[docs]classTimeProducer:"""Produces timestamp objects."""#: COB-ID of the SYNC messagecob_id=0x100def__init__(self,network):self.network=network
[docs]deftransmit(self,timestamp:Optional[float]=None):"""Send out the TIME message once. :param float timestamp: Optional Unix timestamp to use, otherwise the current time is used. """delta=timestamportime.time()-OFFSETdays,seconds=divmod(delta,ONE_DAY)data=TIME_OF_DAY_STRUCT.pack(int(seconds*1000),int(days))self.network.send_message(self.cob_id,data)