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.
		
		
		
		
			
				
					27 lines
				
				848 B
			
		
		
			
		
	
	
					27 lines
				
				848 B
			| 
								 
											2 years ago
										 
									 | 
							
								# Utilities for sanitizing routes of only essential data for testing car ports and doing validation.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								from openpilot.tools.lib.logreader import LogIterable, LogMessage
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								def sanitize_vin(vin: str):
							 | 
						||
| 
								 | 
							
								  # (last 6 digits of vin are serial number https://en.wikipedia.org/wiki/Vehicle_identification_number)
							 | 
						||
| 
								 | 
							
								  VIN_SENSITIVE = 6
							 | 
						||
| 
								 | 
							
								  return vin[:-VIN_SENSITIVE] + "X" * VIN_SENSITIVE
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								def sanitize_msg(msg: LogMessage) -> LogMessage:
							 | 
						||
| 
								 | 
							
								  if msg.which() == "carParams":
							 | 
						||
| 
								 | 
							
								    msg = msg.as_builder()
							 | 
						||
| 
								 | 
							
								    msg.carParams.carVin = sanitize_vin(msg.carParams.carVin)
							 | 
						||
| 
								 | 
							
								    msg = msg.as_reader()
							 | 
						||
| 
								 | 
							
								  return msg
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								PRESERVE_SERVICES = ["can", "carParams", "pandaStates", "pandaStateDEPRECATED"]
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								def sanitize(lr: LogIterable) -> LogIterable:
							 | 
						||
| 
								 | 
							
								  filtered = filter(lambda msg: msg.which() in PRESERVE_SERVICES, lr)
							 | 
						||
| 
								 | 
							
								  sanitized = map(sanitize_msg, filtered)
							 | 
						||
| 
								 | 
							
								  return sanitized
							 |