4 This file is part of the ARM-Crypto-Lib.
5 Copyright (C) 2008, 2009 Daniel Otte (daniel.otte@rub.de)
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 $conffile_check = Hash.new
26 $conffile_check.default = 0
28 ################################################################################
30 ################################################################################
32 def readconfigfile(fname, conf)
33 return conf if $conffile_check[fname]==1
34 $conffile_check[fname]=1
36 if not File.exists?(fname)
39 file = File.open(fname, "r")
42 next if /[\s]*#/.match(line)
43 if m=/\[[\s]*([^\s]*)[\s]*\]/.match(line)
48 next if not /=/.match(line)
49 m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line)
51 Dir.glob(m[2]){ |fn| conf = readconfigfile(fn, conf) }
53 conf[section][m[1]] = m[2]
60 ################################################################################
62 ################################################################################
64 def read_line(error_msg=true)
70 puts("ERROR: read timeout!\n") if error_msg
76 ################################################################################
77 # readPerformanceVector #
78 ################################################################################
80 def readPerformanceVector(param)
86 if lb.match(/End of performance figures/)
89 if m=lb.match(/=== (.*) performance ===/)
92 fname+="."+param if param != ""
94 fout = File.open(fname, "w+")
95 printf("> %s \n", fname)
105 ################################################################################
107 ################################################################################
110 opts = Getopt::Std.getopts("f:c:t:a:d")
113 conf = readconfigfile("/etc/testport.conf", conf)
114 conf = readconfigfile("~/.testport.conf", conf)
115 conf = readconfigfile("testport.conf", conf)
116 conf = readconfigfile(opts["f"], conf) if opts["f"]
120 puts("serial port interface version: " + SerialPort::VERSION);
122 params = { "baud" => conf["PORT"]["baud"].to_i,
123 "data_bits" => conf["PORT"]["databits"].to_i,
124 "stop_bits" => conf["PORT"]["stopbits"].to_i,
125 "parity" => SerialPort::NONE }
126 params["paraty"] = SerialPort::ODD if conf["PORT"]["paraty"].downcase == "odd"
127 params["paraty"] = SerialPort::EVEN if conf["PORT"]["paraty"].downcase == "even"
128 params["paraty"] = SerialPort::MARK if conf["PORT"]["paraty"].downcase == "mark"
129 params["paraty"] = SerialPort::SPACE if conf["PORT"]["paraty"].downcase == "space"
131 puts("\nPort: "+conf["PORT"]["port"]+"@" +
132 params["baud"].to_s +
134 params["data_bits"].to_s +
135 conf["PORT"]["paraty"][0,1].upcase +
136 params["stop_bits"].to_s +
139 $sp = SerialPort.new(conf["PORT"]["port"], params)
141 $sp.read_timeout=1000; # 5 minutes
142 $sp.flow_control = SerialPort::SOFT
146 Usage: ruby #{$0} -c command [-t target_dir] [-a additional specifier]
152 command=opts['c']+"\r";
153 $dir=(opts['t'])?opts['t']:"";
154 param=(opts['a'])?opts['a']:"";
160 while(readPerformanceVector(param))