Tutorials/g0WmLTE/Tutorial2: wmxstat

File wmxstat, 2.3 KB (added by ffund01, 5 years ago)

wmxstat program

Line 
1#!/usr/bin/ruby1.8
2#
3# Copyright (c) 2011 Polytechnic Institute of New York University
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21# THE SOFTWARE.
22#
23# Contact: ffund01@students.poly.edu
24
25
26
27require "/usr/bin/oml4r.rb"
28
29APPNAME = "wmxstat"
30APPPATH = "/usr/bin/wimaxcu"
31APPVERSION = "1.2"
32
33class MPStat < OML4R::MPBase
34    name :status_link
35    param :freq, :type => :long
36    param :signal
37    param :rssi, :type => :long
38    param :cinr, :type => :long
39end
40
41class Wrapper
42
43  def process(output)
44    lines = output.split("\n")
45    lines=lines.drop(1)
46    lines=lines.reverse.drop(2).reverse
47    vals=lines.collect { |row|
48      column = row.split(" ")
49      column[2]
50    }
51
52    # Inject the measurements into OML
53    MPStat.inject(vals[0],vals[1],vals[2],vals[3])
54  end
55
56  def initialize(args)
57   
58    # Initialize variables
59    @interval = 5
60
61    # Initialize OML4R
62    OML4R::init(args, :appID => APPNAME)
63
64  end
65   
66  def start()
67    while true
68      # Run 'wimaxcu scan'; capture its output and process it
69      cmd = "#{APPPATH} status link"
70      output = `#{cmd}`
71      process(output)
72      # Wait for a given duration and loop again
73      sleep @interval.to_i
74    end
75  end
76
77end
78
79begin
80  app = Wrapper.new(ARGV)
81  app.start()
82rescue Exception => ex
83  puts "Received an Exception when executing the wrapper!"
84  puts "The Exception is: #{ex}\n"
85end
86