rendered paste body#!/usr/bin/perl -w
use IO::Socket;
local $/ = "\r";
$remote = IO::Socket::INET->new( Proto => "tcp",
PeerAddr => "10.2.1.85",
PeerPort => "1000",
);
unless ($remote) { die "cannot connect to http daemon on 10.2.1.85" }
$remote->autoflush(1);
ParseS();
ParseCDR();
ParseCSR();
close $remote;
sub ParseS
{
print $remote "\002S\r\n";
my $str = <$remote>;
chomp($str);
print STDOUT $str . "\r\n";
my @resp = split(/,/,$str);
$sensorCount = $resp[1];
}
sub ParseCDR
{
print $remote "\002CDR\r\n";
my $str = <$remote>;
chomp($str);
print STDOUT $str . "\r\n";
my @resp = split(/,/,$str);
$mac = $resp[1];
$serverName = $resp[2];
}
sub ParseCSR {
@sensors = ();
for ($i = 1; $i <= $sensorCount; $i++)
{
print $remote "\002CSR$i\r\n";
my $str = <$remote>;
chomp($str);
print STDOUT $str . "\r\n";
my @resp = split(/,/,$str);
my %record = (
"sensorType" => $resp[1],
"serialNumber" => $resp[2]
);
push(@sensors, \%record);
}
}