Subversion Repositories HomeAutomation

Rev

Rev 950 | Rev 1046 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
945 runge 1
#!/usr/bin/perl
2
 
3
# Written by Mattias Runge 2008
4
 
5
use XML::Twig;
6
use Getopt::Long;
7
 
8
$binaryname = "makeCanId.pl";
9
if (@ARGV > 0)
10
{
11
	GetOptions(	"xmlfile=s" 	=> \$xmlfile,
12
			"cfile=s" 	=> \$cfile);
13
}
14
else
15
{
16
	$help = 1;
17
}
18
 
19
if ($help)
20
{
21
	print "Usage ./$binaryname [options]\n";
22
	print "Options:\n";
23
	print "  -x <xmlfile>			Choose xmlfile to parse\n";
24
	print "  -c <headerfile> 		Choose header file to write\n";
25
	print "  -h 				Shows this usage\n";
26
	print "\n";
947 runge 27
	print "example: ./$binaryname -x data.xml -c moduleid.h\n";
945 runge 28
 
29
	exit 0;
30
}
31
 
32
my $now = localtime time;
33
my $twig = XML::Twig->new();
34
 
35
$twig->parsefile($xmlfile);
36
 
37
my $root = $twig->root;
38
 
947 runge 39
open (MYFILE, '>' . $cfile);
945 runge 40
 
947 runge 41
print MYFILE "// Built on $now by $binaryname\n";
42
print MYFILE "// DO NOT CHANGE MANUALLY\n\n";
945 runge 43
 
965 runge 44
 
45
print MYFILE "#ifndef MODULEID_H_\n";
46
print MYFILE "#define MODULEID_H_\n\n";
47
 
945 runge 48
print MYFILE "//------------------ //\n";
49
print MYFILE "// Class definitions //\n";
50
print MYFILE "//------------------ //\n";
51
print MYFILE "\n";
52
 
53
foreach my $class ($root->first_child('classes')->children('class'))
54
{
950 runge 55
	my $className = $class->att('name');
945 runge 56
	$className =~ tr/a-z/A-Z/;
947 runge 57
	print MYFILE "#define CAN_MODULE_CLASS_$className " . $class->att('id') . "\n";
945 runge 58
}
59
 
60
print MYFILE "\n";
61
print MYFILE "//-------------------- //\n";
62
print MYFILE "// Command definitions //\n";
63
print MYFILE "//-------------------- //\n";
64
print MYFILE "\n";
65
 
66
foreach my $command ($root->first_child('commands')->children('command'))
67
{
950 runge 68
	my $commandName = $command->att('name');
945 runge 69
	$commandName =~ tr/a-z/A-Z/;
950 runge 70
	my $commandType = $command->att('type');
945 runge 71
	$commandType =~ tr/a-z/A-Z/;
950 runge 72
 
73
	if ($commandType eq "SPECIFIC")
74
	{
75
		$commandType = $command->att('module');
76
		$commandType =~ tr/a-z/A-Z/;
77
	}
78
 
947 runge 79
	print MYFILE "#define CAN_MODULE_CMD_" . $commandType . "_" . $commandName . " " . $command->att('id') . "\n";
945 runge 80
}
81
 
82
print MYFILE "\n";
83
print MYFILE "//------------------- //\n";
84
print MYFILE "// Module definitions //\n";
85
print MYFILE "//------------------- //\n";
86
print MYFILE "\n";
87
 
88
foreach my $module ($root->first_child('modules')->children('module'))
89
{
950 runge 90
	my $className = $module->att('class');
945 runge 91
	$className =~ tr/a-z/A-Z/;
950 runge 92
	my $moduleName = $module->att('name');
945 runge 93
	$moduleName =~ tr/a-z/A-Z/;
947 runge 94
	print MYFILE "#define CAN_MODULE_TYPE_" . $className . "_" . $moduleName . " " . $module->att('id') . "\n";
945 runge 95
}
96
 
97
print MYFILE "\n";
98
print MYFILE "//----------------- //\n";
99
print MYFILE "// Misc definitions //\n";
100
print MYFILE "//----------------- //\n";
101
print MYFILE "\n";
102
 
103
foreach my $define ($root->first_child('defines')->children('define'))
104
{
950 runge 105
	my $groupName = $define->att('group');
945 runge 106
	$groupName =~ tr/a-z/A-Z/;
950 runge 107
	my $defineName = $define->att('name');
945 runge 108
	$defineName =~ tr/a-z/A-Z/;
947 runge 109
	print MYFILE "#define " . $groupName . "_" . $defineName . " " . $define->att('id') . "\n";
945 runge 110
}
111
 
112
print MYFILE "\n";
113
 
965 runge 114
print MYFILE "#endif /*MODULEID_H_*/\n";
115
 
945 runge 116
close (MYFILE);
117
 
118
print "Successfully wrote " . $cfile . "\n";