Skip to content

Instantly share code, notes, and snippets.

@vgrovestine
Created March 15, 2022 14:38
Show Gist options
  • Save vgrovestine/d9370c1bf1a2a6af29c60b7b6a49a510 to your computer and use it in GitHub Desktop.
Save vgrovestine/d9370c1bf1a2a6af29c60b7b6a49a510 to your computer and use it in GitHub Desktop.
Convert a spreadsheet to XML file compatible with SDRSharp's built-in frequency manager
<?php
ini_set('auto_detect_line_endings', true);
$xml = array();
$f_csv = fopen($argv[1], 'r');
$header_csv2xml = array(
'Group' => 'GroupName',
'Name' => 'Name',
'Frequency' => 'Frequency',
'Modulation' => 'DetectorType',
'Bandwidth' => 'FilterBandwidth',
'Shift' => 'Shift',
'Favorite' => 'IsFavourite',
'Notes' => false
);
$header_csv = array();
while(($r_csv = fgetcsv($f_csv)) !== false) {
if(empty($header_csv)) {
$header_csv = $r_csv;
}
else {
$xml[] = '<MemoryEntry>';
for($k = 0; $k < count($header_csv); $k++) {
$element_xml = $header_csv2xml[$header_csv[$k]];
if(!empty($element_xml)) {
/*
if($element_xml == 'IsFavourite') {
$r_csv[$k] = ($r_csv[$k] ? 'true' : 'false');
}
*/
$xml[] = ' <' . $element_xml . '>' . htmlspecialchars(trim($r_csv[$k])) . '</' . $element_xml . '>';
}
}
$xml[] = '</MemoryEntry>';
}
}
fclose($f_csv);
$xml = '<?xml version="1.0"?>'
. "\n" . '<ArrayOfMemoryEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'
. "\n" . implode("\n ", $xml)
. "\n" . '</ArrayOfMemoryEntry>';
file_put_contents('frequencies.xml', $xml);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment