X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=host%2Fget_performance.rb;h=43096f267c39c9bda5a5fb18452025f193540228;hb=b022a029def51d63f330c12bf07156db294c8958;hp=a307005554c9de1b6eabf85e3196edb84c2c16c1;hpb=4787ed5e9896fad4256f7b119b2fdfbcfef1cc88;p=avr-crypto-lib.git diff --git a/host/get_performance.rb b/host/get_performance.rb index a307005..43096f2 100644 --- a/host/get_performance.rb +++ b/host/get_performance.rb @@ -18,10 +18,54 @@ along with this program. If not, see . =end +$debug = false +require 'rubygems' require 'serialport' +require 'getopt/std' +$conffile_check = Hash.new +$conffile_check.default = 0 + +################################################################################ +# readconfigfile # +################################################################################ + +def readconfigfile(fname, conf) + return conf if $conffile_check[fname]==1 + $conffile_check[fname]=1 + section = "default" + if not File.exists?(fname) + return conf + end + file = File.open(fname, "r") + until file.eof + line = file.gets() + next if /[\s]*#/.match(line) + if m=/\[[\s]*([^\s]*)[\s]*\]/.match(line) + section=m[1] + conf[m[1]] = Hash.new + next + end + next if not /=/.match(line) + m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line) + if m[1]=="include" + Dir.glob(m[2]){ |fn| conf = readconfigfile(fn, conf) } + else + conf[section][m[1]] = m[2] + end + end + file.close() + return conf +end + +################################################################################ +# read_line # +################################################################################ def read_line(error_msg=true) - s = $sp.gets() + i=$extended_wait + begin + s = $sp.gets() + end until s or i==0 if s==nil puts("ERROR: read timeout!\n") if error_msg return nil @@ -29,6 +73,10 @@ def read_line(error_msg=true) s.gsub(/\006/, ''); end +################################################################################ +# readPerformanceVector # +################################################################################ + def readPerformanceVector(param) lb="" buffer="" @@ -55,22 +103,58 @@ def readPerformanceVector(param) end while true end +################################################################################ +# MAIN # +################################################################################ + + +opts = Getopt::Std.getopts("f:c:t:a:d") -if ARGV.size < 5 +conf = Hash.new +conf = readconfigfile("/etc/testport.conf", conf) +conf = readconfigfile("~/.testport.conf", conf) +conf = readconfigfile("testport.conf", conf) +conf = readconfigfile(opts["f"], conf) if opts["f"] + +#puts conf.inspect + +puts("serial port interface version: " + SerialPort::VERSION); +$linewidth = 64 +params = { "baud" => conf["PORT"]["baud"].to_i, + "data_bits" => conf["PORT"]["databits"].to_i, + "stop_bits" => conf["PORT"]["stopbits"].to_i, + "parity" => SerialPort::NONE } +params["paraty"] = SerialPort::ODD if conf["PORT"]["paraty"].downcase == "odd" +params["paraty"] = SerialPort::EVEN if conf["PORT"]["paraty"].downcase == "even" +params["paraty"] = SerialPort::MARK if conf["PORT"]["paraty"].downcase == "mark" +params["paraty"] = SerialPort::SPACE if conf["PORT"]["paraty"].downcase == "space" + +puts("\nPort: "+conf["PORT"]["port"]+"@" + + params["baud"].to_s + + " " + + params["data_bits"].to_s + + conf["PORT"]["paraty"][0,1].upcase + + params["stop_bits"].to_s + + "\n") + +$sp = SerialPort.new(conf["PORT"]["port"], params) + +$sp.read_timeout=1000; # 5 minutes +$sp.flow_control = SerialPort::SOFT +=begin +if ARGV.size < 1 STDERR.print <=6)?ARGV[5]:""; -param=(ARGV.size>=7)?ARGV[6]:""; +command=opts['c']+"\r"; +$dir=(opts['t'])?opts['t']:""; +param=(opts['a'])?opts['a']:""; -puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n"); $linewidth = 16 -$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE); -$sp.read_timeout=1000; # 1 secound $extended_wait=100; $sp.write(command);