Skip to content

Instantly share code, notes, and snippets.

@Commifreak
Last active July 7, 2022 15:58
Show Gist options
  • Save Commifreak/72a754c5fb07840d69fcac32c75bcbc8 to your computer and use it in GitHub Desktop.
Save Commifreak/72a754c5fb07840d69fcac32c75bcbc8 to your computer and use it in GitHub Desktop.
VCDS AutoScan parser for PHP
/**
* Takes a AutoScan as input and gives back an array with infos
* @param $path
* @return array The data [ECU#, PartNo, ComponentVersion]
* @note This code is part of vag-flashinfo.de ;)
*/
public static function processVCDSFile($path) {
$vcdsData = [];
$file = file($path);
$file = str_replace(["\r", "\n"], '', $file);
$sections = array_keys($file, "-------------------------------------------------------------------------------");
foreach ($sections as $sectionMarker) {
$addressLine = $file[$sectionMarker+1];
$hwSwLine = $file[$sectionMarker+2];
/**
* Address
*/
$address = explode(":", $addressLine)[0];
$address = explode(" ", $address)[1];
/**
* HW/SW
*/
$hwSw = trim(explode(":", explode(" ", $hwSwLine)[1])[1]);
if(empty($hwSw) || strpos($hwSw, ' ') === false) {
continue;
}
/**
* Version
*/
$sw = array_reverse(explode(" ", $file[$sectionMarker+3]));
$sw = array_diff($sw, [""]);
#ArrayHelper::removeValue($sw, ""); Yii2 version
$sw = reset($sw);
$vcdsData[] = [$address, $hwSw, $sw];
}
return $vcdsData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment