You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							38 lines
						
					
					
						
							916 B
						
					
					
				
			
		
		
	
	
							38 lines
						
					
					
						
							916 B
						
					
					
				| #!/usr/bin/env python3
 | |
| import os
 | |
| import datetime
 | |
| from panda import Panda
 | |
| 
 | |
| from common.time import MIN_DATE
 | |
| 
 | |
| def set_time(logger):
 | |
|   sys_time = datetime.datetime.today()
 | |
|   if sys_time > MIN_DATE:
 | |
|     logger.info("System time valid")
 | |
|     return
 | |
| 
 | |
|   try:
 | |
|     ps = Panda.list()
 | |
|     if len(ps) == 0:
 | |
|       logger.error("Failed to set time, no pandas found")
 | |
|       return
 | |
| 
 | |
|     for s in ps:
 | |
|       with Panda(serial=s) as p:
 | |
|         if not p.is_internal():
 | |
|           continue
 | |
| 
 | |
|         # Set system time from panda RTC time
 | |
|         panda_time = p.get_datetime()
 | |
|         if panda_time > MIN_DATE:
 | |
|           logger.info(f"adjusting time from '{sys_time}' to '{panda_time}'")
 | |
|           os.system(f"TZ=UTC date -s '{panda_time}'")
 | |
|         break
 | |
|   except Exception:
 | |
|     logger.exception("Failed to fetch time from panda")
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|   import logging
 | |
|   logging.basicConfig(level=logging.DEBUG)
 | |
| 
 | |
|   set_time(logging)
 | |
| 
 |