Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sync_time(self):
- """Sync time on SmartScan."""
- # On a SmartScan time can be set only by the precision of seconds
- # So we need to wait for the next full second until we can send
- # the packet on it's way to the scanner.
- # It's not perfect, but the error should be more or less constant.
- message = Maint()
- message.state = message.OP_NO_CHANGE
- now = datetime.datetime.utcnow()
- epoch = datetime.datetime(1970, 1, 1)
- # int and datetime objects
- seconds = int((now - epoch).total_seconds()) + 1 # + sync second
- utctime = datetime.datetime.utcfromtimestamp(seconds)
- # wait until next full second
- # works only on Linux with good accuracy
- # Windows needs another approach
- time.sleep((utctime - datetime.datetime.utcnow()).total_seconds())
- command = MaintRfc()
- command.command = command.SET_CLOCK
- command.data = (seconds, )
- message.add_message(command)
- self._handler.sendto(message)
- LOG.debug("Time set to: %d = %s", seconds, utctime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement