Subversion Repositories HomeAutomation

Rev

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

Rev Author Line No. Line
1666 runge 1
#!/usr/bin/perl
2
 
3
# Written by Mattias Runge 2008-2010
4
 
5
use Cwd 'abs_path';
1885 arune 6
use File::Basename;
1890 arune 7
use Time::HiRes qw( usleep );
1666 runge 8
 
9
$| = 1;
10
 
11
$numArgs = $#ARGV + 1;
12
 
13
my $hostname = "localhost";
14
my $port = 1201;
15
my $filename = "";
16
my $hwid = "";
17
my $bios = 0;
18
my $reset = "false";
19
 
20
foreach $argnum (0 .. $#ARGV)
21
{
22
	if ($ARGV[$argnum] eq "-h")
23
	{
24
		$hostname = $ARGV[$argnum+1];
25
		next;
26
 
27
	}
28
	elsif ($ARGV[$argnum] eq "-p")
29
	{
30
		$port = $ARGV[$argnum+1];
31
		next;
32
 
33
	}
34
	elsif ($ARGV[$argnum] eq "-i")
35
	{
36
		$hwid = $ARGV[$argnum+1];
37
		next;
38
 
39
	}
40
	elsif ($ARGV[$argnum] eq "-f")
41
	{
42
		$filename = abs_path($ARGV[$argnum+1]);
43
		next;
44
 
45
	}
46
	elsif ($ARGV[$argnum] eq "-b")
47
	{
48
		$bios = 1;
49
	}
50
	elsif ($ARGV[$argnum] eq "-r")
51
	{
52
		$reset = "true";
53
	}
54
}
55
 
56
if ($hwid eq "")
57
{
58
	die "You must specify a hardware id!\n";
59
	exit 1;
60
}
61
 
1885 arune 62
my $path = dirname(abs_path($0));
63
 
64
# Read atom functions from separate file
65
if (-e $path."/setConfig/AtomLib.pl") {
66
	require $path."/setConfig/AtomLib.pl";
67
} else {
68
	print "Error: No AtomLib.pl was found in ".$path.". \n\n";
69
	exit 1;
70
}
71
 
1666 runge 72
#0x14f90d1f to 0x1f0df914
73
@hwidChars = split(//, $hwid);
1877 arune 74
$hwid = $hwidChars[0]. $hwidChars[1]. uc($hwidChars[8]. $hwidChars[9]. $hwidChars[6]. $hwidChars[7]. $hwidChars[4]. $hwidChars[5]. $hwidChars[2]. $hwidChars[3]);
1666 runge 75
 
76
print "atomDude settings:\n";
77
print "Hardware id: " . $hwid . "\n";
78
print "Atom address: " . $hostname . ":" . $port . "\n";
79
print "Hexfile: " . $filename . "\n";
80
print "Parameters: " . "\n";
81
 
82
if ($reset eq "true" && $filename eq "")
83
{
1913 arune 84
	$socket = atomd_initialize($hostname, $port);
2157 arune 85
	usleep(100000);
86
	atomd_kill_promt($socket);
87
#	atomjs_write("Node_Reset('".$hwid."')");
1913 arune 88
	atomd_send_command($socket, "Node_Reset $hwid");
89
	print atomd_read_command_response($socket);
90
	exit(0);
91
	#my $result = system("atomic -s $hostname -p $port -c \"Node_Reset $hwid\"");
92
	#exit($result);
1666 runge 93
}
94
else
95
{
1967 arune 96
	open (FP, "+<".$filename) or die "Error: Cannot open file $filename\n";
97
	@filecontents = <FP>;
98
	close FP;
1890 arune 99
 
1967 arune 100
	$socket = atomd_initialize($hostname, $port);
2157 arune 101
	usleep(100000);
102
	atomd_kill_promt($socket);
1890 arune 103
 
104
	#print "Sending Node_ClearHex\n";
1967 arune 105
	atomd_send_command($socket, "Node_ClearHex");
106
	atomd_kill_promt($socket);
107
 
108
	my $linenums = 0;
109
	foreach $filerow (@filecontents) {
1890 arune 110
		#print "Sending Node_AppendHex $filerow \n";
1967 arune 111
		atomd_send_command($socket, "Node_AppendHex $filerow");
112
		atomd_kill_promt($socket);
113
		$linenums += 1;
114
	}
115
	#print "Sending Node_ProgramHex $hwid $bios $linenums \n";
116
	atomd_send_command($socket, "Node_ProgramHex $hwid $bios $linenums");
1913 arune 117
#	atomd_kill_promt($socket);
1890 arune 118
 
119
	#atomd_send_command($socket, "Node_Program $hwid $bios $filename");
1913 arune 120
 
1967 arune 121
	print atomd_read_command_response($socket);
122
	exit(0);
123
 
124
#	my $result = system("atomic -s $hostname -p $port -c \"Node_Program $hwid $bios $filename\"");
125
#	exit($result);
1666 runge 126
}
127
 
128
exit(0);