source: genesis/nodes/genesis-to-py.pl@ 8050

Last change on this file since 8050 was 8048, checked in by rick, 15 years ago

upport is always nice, but can be a bit tricky sometimes. Hence the little hack around it

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#!/usr/bin/env perl
2use Geo::Coordinates::RDNAP qw/from_rd to_rd dms/;
3
4
5# RD X,Y -> RD Noorderbreedte, Oosterbreedte
6# http://web.inter.nl.net/users/F.Kissels/gps/conversie.html
7
8# Little perl to convert genesis files into python config files,
9# Which gonna be used for more logic stuff ;-)
10
11$argc = $#ARGV + 1;
12if ($argc == 0) {
13 print "Usage $_ <wleiden.conf> ...\n";
14 exit 1;
15# Hack to easy support multiple files without remembering any variable in between
16} elsif ($argc > 1) {
17 foreach $file (@ARGV) {
18 print `perl $ENV{_} $file`;
19 }
20 exit 0;
21}
22
23
24do($ARGV[0]) || die;
25
26my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
27
28$interfaces = join(',',keys %config);
29if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
30 ($lat, $lon, $h) = from_rd( $X, $Y, 0);
31} else {
32 $lat = $lon = $h = 0;
33}
34
35$status = $status_labels{$status} || 'up'; # ensure reporting a correct status
36
37print <<EOF;
38[$nodename]
39location = $location
40status = $status
41latitude = $lat
42longitude = $lon
43interfaces = $interfaces
44x = $X
45y = $Y
46masterip = $master_ip
47nodetype = $nodetype
48name = $nodename
49configtype = node
50
51EOF
52
53
54foreach $if (keys %config) {
55 print <<EOF;
56[$nodename/$if]
57EOF
58 %tmp = (
59 'configtype' => 'interface',
60 'dhcp' => 'no',
61 'compass-direction' => '',
62 );
63 foreach $line (split('\n',$config{$if})) {
64 ($key, $value) = split(/=/,$line);
65 if ($key and (lc($key) =~ /^[a-z].*/)) {
66 #print "$key : $value\n";
67 $value = lc($value);
68 if ($key =~ /^type$/i) {
69 if ($value eq 'ethernet') {
70 $value = 'eth';
71 } else {
72 $value = '11b';
73 }
74 } elsif ($key =~ /^mode$/i) {
75 if ($value eq 'master') {
76 $value = 'ms';
77 } else { # managed
78 $value = 'mn';
79 }
80 } elsif ($key =~ /^polar$/i) {
81 if ($value eq 'hor') {
82 $value = 'hr';
83 } else {
84 $value = 'vr';
85 }
86 } elsif ($key =~ /^essid$/i) {
87 $key = 'ssid';
88
89 # Dirty hack to fetch compass direction of essid
90 $value =~ /[a-z]+-([a-z]+)\..*/;
91 $direction = $1;
92 # Translate into English
93 if ($direction ne "omni") {
94 $direction =~ tr/oz/es/;
95 }
96 # node AMwtrt1 and 'test' directions
97 if ($direction eq "wtrtr" or $direction eq "test") {
98 $direction = '';
99 }
100 $tmp{'compass-direction'} = $direction;
101 } elsif ($key =~ /^gain$/i) {
102 $value =~ s/dbi//;
103 }
104 $tmp{lc($key)} = $value;
105 }
106 }
107# ethernet2wifi bridges
108 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
109 $tmp{type} = '11b';
110 }
111# 11a
112 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
113 $tmp{type} = '11a';
114 }
115
116 foreach $key (keys %tmp) {
117 print "$key=$tmp{$key}\n";
118 }
119 print "\n";
120}
Note: See TracBrowser for help on using the repository browser.