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

Last change on this file since 8136 was 8057, checked in by rick, 15 years ago

Extra values does no hurt, saves me from getting the values from the section key

  • 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 'nodename' => $nodename,
63 'interface' => $if,
64 );
65 foreach $line (split('\n',$config{$if})) {
66 ($key, $value) = split(/=/,$line);
67 if ($key and (lc($key) =~ /^[a-z].*/)) {
68 #print "$key : $value\n";
69 $value = lc($value);
70 if ($key =~ /^type$/i) {
71 if ($value eq 'ethernet') {
72 $value = 'eth';
73 } else {
74 $value = '11b';
75 }
76 } elsif ($key =~ /^mode$/i) {
77 if ($value eq 'master') {
78 $value = 'ms';
79 } else { # managed
80 $value = 'mn';
81 }
82 } elsif ($key =~ /^polar$/i) {
83 if ($value eq 'hor') {
84 $value = 'hr';
85 } else {
86 $value = 'vr';
87 }
88 } elsif ($key =~ /^essid$/i) {
89 $key = 'ssid';
90
91 # Dirty hack to fetch compass direction of essid
92 $value =~ /[a-z]+-([a-z]+)\..*/;
93 $direction = $1;
94 # Translate into English
95 if ($direction ne "omni") {
96 $direction =~ tr/oz/es/;
97 }
98 # node AMwtrt1 and 'test' directions
99 if ($direction eq "wtrtr" or $direction eq "test") {
100 $direction = '';
101 }
102 $tmp{'compass-direction'} = $direction;
103 } elsif ($key =~ /^gain$/i) {
104 $value =~ s/dbi//;
105 }
106 $tmp{lc($key)} = $value;
107 }
108 }
109# ethernet2wifi bridges
110 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
111 $tmp{type} = '11b';
112 }
113# 11a
114 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
115 $tmp{type} = '11a';
116 }
117
118 foreach $key (keys %tmp) {
119 print "$key=$tmp{$key}\n";
120 }
121 print "\n";
122}
Note: See TracBrowser for help on using the repository browser.