-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsupparams.rb
executable file
·84 lines (68 loc) · 1.89 KB
/
supparams.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/ruby
$:.push File.dirname(__FILE__)
require 'parts'
module Supparams
def self.sep
return " :"
end
def self.process(fh, results, debug=false)
if $logger == nil then
$logger = Logger.new(STDOUT)
end
bname = "SupParams"
hsize = bname.length + 1 # include trailing '\0'
pname = "Supparams::process():"
ref = nil
status = 'nok'
begin
ref = results['blocks'][bname]
startpos = ref[:pos].to_i
fh.seek( startpos )
rescue
$logger.info (pname+" "+bname+"block starting position unknown")
return status
end
format = results['format']
if format == 2 then
mystr = fh.read(hsize).to_s[0..-2]
if mystr != bname then
$logger.info (pname+" incorrect header "+mystr)
return status
end
end
results[bname] = {}
xref = results[bname]
# version 1 and 2 are the same
status = Supparams::process_genparam(fh, results, debug=debug)
# read the rest of the block (just in case)
endpos = (results['blocks'][bname][:pos].to_i) + (results['blocks'][bname][:size].to_i)
fh.read( endpos - fh.tell() )
return 'ok'
end
# ================================================================
def self.process_genparam(fh, results, debug=false)
# process SupParams fields
bname = "SupParams"
xref = results[bname]
fields =
[
"supplier", # ............. 0
"OTDR", # ................. 1
"OTDR S/N", # ............. 2
"module", # ............... 3
"module S/N", # ........... 4
"software", # ............. 5
"other", # ................ 6
]
count = 0
fields.each do |field|
xstr = Parts::get_string(fh)
if debug then
$logger.info ("%s %d. %s: %s" % [sep, count, field, xstr] )
end
xref[field] = xstr
count += 1
end
return 'ok'
end
end