/[mdap]/mdap-server.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /mdap-server.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8 by dpavlin, Sun Apr 22 16:06:03 2007 UTC revision 9 by dpavlin, Sun Apr 22 16:40:49 2007 UTC
# Line 9  use constant PORT  => '3235'; Line 9  use constant PORT  => '3235';
9    
10  my $debug = shift @ARGV;  my $debug = shift @ARGV;
11    
 my $local_port = 1000;  
   
12  my $resend_search_delay = 3;  my $resend_search_delay = 3;
13  my $tftp_path = '/srv/tftp/';  my $tftp_path = '/srv/tftp/';
14    
15    warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\n";
16    
17  sub fw {  sub fw {
18          my ($board, $offset,$len) = @_;          my ($board, $offset,$len) = @_;
19          open(my $fh, "$tftp_path/$board") || die "Can't open image $tftp_path/$board: $!";          open(my $fh, "$tftp_path/$board") || die "Can't open image $tftp_path/$board: $!";
# Line 54  sub ant2hash { Line 54  sub ant2hash {
54    
55  sub mdap_send {  sub mdap_send {
56          my $data = shift;          my $data = shift;
         warn ">> $data\n>>----------\n" if ($debug);  
57          $sock->mcast_send( "${data}", GROUP . ':' . PORT );          $sock->mcast_send( "${data}", GROUP . ':' . PORT );
58            if ($debug) {
59                    warn ">> ", dump( $data ), $/;
60            } else {
61                    $data =~ s/\s+/ /gi;
62                    warn ">> ", substr($data,0,70), $/;
63            }
64  }  }
65    
66  local $SIG{ALRM} = sub {  local $SIG{ALRM} = sub {
# Line 71  while (1) { Line 76  while (1) {
76          my $data;          my $data;
77          next unless $sock->recv($data,1024);          next unless $sock->recv($data,1024);
78    
79          if ( $data =~ m#^(REPLY-\S+)\s(MDAP/\d+\.\d+)# ) {          if ( $data =~ m#^(INFO|ANT-SEARCH|EXEC-CLI|REPLY-\S+)\s(MDAP)/(\d+\.\d+)# ) {
80    
81                  my ($type,$proto) = ($1,$2);                  my ($type,$proto,$mdap_ver) = ($1,$2,$3);
82    
83                  my $h = ant2hash($data);                  my $h = ant2hash($data);
84    
85                  my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h );                  my $client_version = $h->{'MDAP-VERSION'};
86                    $mdap_ver = $client_version if ($client_version);
87    
88                  print "<< $type $proto ", length($data), " bytes\n";                  print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n";
89    
90                  warn dump($h),$/ if ($debug);                  warn dump($h),$/ if ($debug);
91    
92                    # we are getting our own INFO messages
93                    next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# );
94    
95                    my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h );
96    
97                  if ($type eq 'REPLY-ANT-SEARCH') {                  if ($type eq 'REPLY-ANT-SEARCH') {
98                          mdap_send("INFO MDAP/1.2\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n22");                          mdap_send("INFO MDAP/$mdap_ver\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n22");
99                  } elsif ($type eq 'REPLY-INFO') {                  } elsif ($type eq 'REPLY-INFO') {
100                          my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?";                          my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?";
101                          if ( fw_exists( $board ) ) {                          if ( fw_exists( $board ) ) {
102                                  if ( $h->{'_BUILD'} ne fw_build( $board ) ) {                                  if ( $h->{'_BUILD'} ne fw_build( $board ) ) {
103                                          print "UPDATE STEP 1 on ant $ant\n";                                          print "UPDATE STEP 1 on ant $ant\n";
104                                          mdap_send("EXEC-CLI MDAP/1.2\r\nCLI-CMD:software upgrade\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n1F");                                          mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:software upgrade\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n1F");
105                                  } else {                                  } else {
106                                          print "OK ant $ant allready updated...\n";                                          print "OK ant $ant allready updated...\n";
107                                  }                                  }
# Line 99  while (1) { Line 110  while (1) {
110                          }                          }
111                  } elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) {                  } elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) {
112                                  print "UPDATE STEP 2 on ant $ant\n";                                  print "UPDATE STEP 2 on ant $ant\n";
113                                  mdap_send("EXEC-CLI MDAP/1.2\r\nSEQ-NR:2\r\nTO-ANT:$ant\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n5F");                                  mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nSEQ-NR:2\r\nTO-ANT:$ant\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n5F");
114                  } else {                  } else {
115                          print "!! reply ignored ", dump( $h ), $/;                          print "!! reply ignored ", dump( $h ), $/;
116                  }                  }

Legend:
Removed from v.8  
changed lines
  Added in v.9

  ViewVC Help
Powered by ViewVC 1.1.26