cycle_analyst_logger 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8478f82cab17da96da04e8c35ed5aa6750e64c0c
4
+ data.tar.gz: 3af24ab892c6e44a41437e7fa102ea3353d3312c
5
+ SHA512:
6
+ metadata.gz: 20df1ddea9c110826aaa289fcee22a225754a396f3716fb7dd8aed38d50dcaac024931d0621e1a66c07040541175f320eb7a80313ecb3d44446b5516a8983edd
7
+ data.tar.gz: 9d23d596fd87c9c8b598ee994ddf550e25a6067813c2d98e4f92c5849137aaa1827ce5e36d2978ab33bd9a192f455aeab5c3f72610fc4b9bdc8a2ed0fd9b7ad3
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ /html/
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ # .env
16
+
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ Gemfile.lock
32
+ .ruby-version
33
+ .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
38
+ *.csv
39
+ *.log
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = cycle_analyst_logger
2
+
3
+ == NAME
4
+ cycle_analyst_logger - Store the streaming data log output of a Grin Cycle Analyst V3
5
+
6
+ == SYNOPSIS
7
+ cycle_analyst_logger [global options] command [command options] [arguments...]
8
+
9
+ == GLOBAL OPTIONS
10
+ -t, --tty=arg - Serial (USB) device (default: /dev/ttyUSB1)
11
+ -b, --baudrate=arg - Serial port baudrate (default: 9600)
12
+ --version - Display the program version
13
+ -q, --[no-]quiet - Do not output to stdout
14
+ --help - Show this message
15
+
16
+ == COMMANDS
17
+ help - Shows a list of commands or help for one command
18
+ log - Capture the logging output of the CA to a file
19
+
20
+ === log - Capture the logging output of the CA to a file
21
+ cycle_analyst_logger [global options] log [command options] [tty] [baudrate]
22
+
23
+ === COMMAND OPTIONS
24
+ -l, --line_count=arg - How many lines to read (default: forever)
25
+
26
+ :include:cycle_analyst_logger.rdoc
27
+
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+ Rake::RDocTask.new do |rd|
8
+ rd.main = "README.rdoc"
9
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
+ rd.title = 'Your application title'
11
+ end
12
+
13
+ spec = eval(File.read('cycle_analyst_logger.gemspec'))
14
+
15
+ Gem::PackageTask.new(spec) do |pkg|
16
+ end
17
+ CUKE_RESULTS = 'results.html'
18
+ CLEAN << CUKE_RESULTS
19
+ desc 'Run features'
20
+ Cucumber::Rake::Task.new(:features) do |t|
21
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
+ t.cucumber_opts = opts
24
+ t.fork = false
25
+ end
26
+
27
+ desc 'Run features tagged as work-in-progress (@wip)'
28
+ Cucumber::Rake::Task.new('features:wip') do |t|
29
+ tag_opts = ' --tags ~@pending'
30
+ tag_opts = ' --tags @wip'
31
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32
+ t.fork = false
33
+ end
34
+
35
+ task :cucumber => :features
36
+ task 'cucumber:wip' => 'features:wip'
37
+ task :wip => 'features:wip'
38
+ require 'rake/testtask'
39
+ Rake::TestTask.new do |t|
40
+ t.libs << "test"
41
+ t.test_files = FileList['test/*_test.rb']
42
+ end
43
+
44
+ task :default => [:test,:features]
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cycle_analyst_logger/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cycle_analyst_logger"
8
+ spec.version = CycleAnalystLogger::VERSION
9
+ spec.authors = ["Robert J. Berger"]
10
+ spec.email = ["rberger@ibd.com"]
11
+
12
+ spec.summary = %q{Read and store log output from the Grin Cycle Analyst}
13
+ spec.description = %q{Read and store log output from the Grin Cycle Analyst}
14
+ spec.homepage = "https://github.com/rberger/cycle_analyst_logger"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.has_rdoc = true
25
+ spec.extra_rdoc_files = ['README.rdoc', 'cycle_analyst_logger.rdoc']
26
+ spec.rdoc_options << '--title' << 'cycle_analyst_logger' << '--main' << 'README.rdoc' << '-ri'
27
+
28
+ spec.add_runtime_dependency 'gli', '~> 2.17'
29
+ spec.add_runtime_dependency 'serialport', '~> 1.3'
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.16'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rdoc'
35
+ spec.add_development_dependency 'aruba', '~> 0.14'
36
+ spec.add_development_dependency 'yard', '~> 0.9'
37
+ end
@@ -0,0 +1,57 @@
1
+ == cycle_analyst_logger - Describe your application here
2
+
3
+ v0.0.1
4
+
5
+ === Global Options
6
+ === -b|--baudrate arg
7
+
8
+ Serial port baudrate
9
+
10
+ [Default Value] 9600
11
+
12
+
13
+ === -t|--tty arg
14
+
15
+ Serial (USB) device
16
+
17
+ [Default Value] /dev/ttyUSB1
18
+
19
+
20
+ === --help
21
+ Show this message
22
+
23
+
24
+
25
+ === -q|--[no-]quiet
26
+ Do not output to stdout
27
+
28
+
29
+
30
+ === --version
31
+ Display the program version
32
+
33
+
34
+
35
+ === Commands
36
+ ==== Command: <tt>help command</tt>
37
+ Shows a list of commands or help for one command
38
+
39
+ Gets help for the application or its commands. Can also list the commands in a way helpful to creating a bash-style completion function
40
+ ===== Options
41
+ ===== -c
42
+ List commands one per line, to assist with shell completion
43
+
44
+
45
+
46
+ ==== Command: <tt>log </tt>
47
+ Capture the logging output of the CA to a file
48
+
49
+
50
+ ===== Options
51
+ ===== -l|--line_count arg
52
+
53
+ How many lines to read
54
+
55
+ [Default Value] forever
56
+
57
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'cycle_analyst_logger'
4
+
5
+ cli = CycleAnalystLogger::Cli.new
6
+ cli.main
@@ -0,0 +1,7 @@
1
+ # Add requires for other files you add to your project here, so
2
+ # you just need to require this one file in your bin file
3
+
4
+ require 'cycle_analyst_logger/gli_patch.rb'
5
+ require 'cycle_analyst_logger/version.rb'
6
+ require 'cycle_analyst_logger/main.rb'
7
+ require 'cycle_analyst_logger/cycle_analyst.rb'
@@ -0,0 +1,70 @@
1
+ require 'time'
2
+ require 'serialport'
3
+
4
+ module CycleAnalystLogger
5
+ class CycleAnalyst
6
+ attr_reader :baudrate
7
+ attr_reader :tty
8
+ attr_reader :dict
9
+ attr_reader :serial_io
10
+
11
+ CA_DICT = {
12
+ 0 => {address: 0, name: "Amp Hours", units: "Ah", scale: 1},
13
+ 1 => { address: 1, name: "Volts", units: "V", scale: 1 },
14
+ 2 => { address: 2, name: "Current", units: "A", scale: 1},
15
+ 3 => { address: 3, name: "Speed", units: "Kph", scale: 1},
16
+ 4 => { address: 4, name: "Distance", units: "Km", scale: 1},
17
+ 5 => { address: 5, name: "Motor Temp", units: "DegC", scale: 1},
18
+ 6 => { address: 6, name: "Human Cadence", units: "RPM", scale: 1},
19
+ 7 => { address: 7, name: "Human Power", units: "W", scale: 1},
20
+ 8 => { address: 8, name: "Human Torque", units: "Nm", scale: 1},
21
+ 9 => { address: 9, name: "Throttle In", units: "V", scale: 1},
22
+ 10 => { address: 10, name: "Throttle Out", units: "V", scale: 1},
23
+ 11 => { address: 11, name: "AuxA", units: "", scale: 1},
24
+ 12 => { address: 11, name: "AuxD", units: "", scale: 1},
25
+ 13 => { address: 12, name: "Limit Flags", units: "bit flags", scale: 1}
26
+ }
27
+
28
+ def initialize(opts)
29
+ @baudrate = opts[:baudrate]
30
+ @tty = opts[:tty]
31
+ @dict = CA_DICT
32
+ @serial_io = SerialPort.new @tty, @baudrate, 8, 1
33
+ end
34
+
35
+ def logs_header
36
+ dict.map do |(address, node)|
37
+ "#{node[:name]} (#{node[:units]})"
38
+ end.join(",")
39
+ end
40
+
41
+ def tsv2array(line)
42
+ line.split("\t")
43
+ end
44
+
45
+ # Get line from serial port and send to file
46
+ # @param output_fd [File] File Descriptor of the output file to write to. Don't write to file if nil
47
+ # @param line_count [Integer, Symbol] Number of lines to output, or forever if :forever
48
+ # @param quite [Boolean] Don't output to stdout if true
49
+ def get_logs(output_fd, line_count, quiet)
50
+ line_number = 0
51
+ hdr = %Q(Timestamp,#{logs_header})
52
+
53
+ puts hdr if not quiet
54
+ output_fd.puts hdr if output_fd
55
+
56
+ serial_io.each_line do |line|
57
+ output_line = %Q(#{Time.now.utc.round(10).iso8601(6)},#{tsv2array(line).join(",")})
58
+ puts output_line if not quiet
59
+ output_fd.puts output_line if output_fd
60
+
61
+ # Determine if we go forever
62
+ if (line_count != :forever)
63
+ # If not, then quit when we reach count lines
64
+ line_number +=1
65
+ break if line_number >= line_count
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,13 @@
1
+ # Work around a bug with the RdocDocumentListener
2
+ # Fix rdoc formatter #201
3
+ # https://github.com/davetron5000/gli/pull/201#issuecomment-195385509
4
+ require 'gli'
5
+ module RdocDocumentListenerAppFix
6
+ def initialize(_global_options,_options,_arguments,app)
7
+ super
8
+ @app = app
9
+ end
10
+ end
11
+ class GLI::Commands::RdocDocumentListener
12
+ prepend RdocDocumentListenerAppFix
13
+ end
@@ -0,0 +1,70 @@
1
+ require 'gli'
2
+
3
+ module CycleAnalystLogger
4
+
5
+ class Cli
6
+ attr_reader :ca
7
+
8
+ include GLI::App
9
+
10
+ def main
11
+ program_desc 'Store the streaming data log output of a Grin Cycle Analyst V3'
12
+
13
+ version CycleAnalystLogger::VERSION
14
+
15
+ subcommand_option_handling :normal
16
+ arguments :strict
17
+ sort_help :manually
18
+
19
+ desc 'Serial (USB) device'
20
+ default_value '/dev/ttyUSB1'
21
+ arg 'tty', :optional
22
+ flag [:t, :tty]
23
+
24
+ desc 'Serial port baudrate'
25
+ default_value 9600
26
+ arg 'baudrate', :optional
27
+ flag [:b, :baudrate]
28
+
29
+ desc 'Do not output to stdout'
30
+ switch [:q, :quiet]
31
+
32
+ desc 'Capture the logging output of the CA to a file'
33
+ command :log do |log|
34
+ log.desc "How many lines to read"
35
+ log.default_value :forever
36
+ log.flag [:l, :line_count]
37
+
38
+ log.action do |global_options, options, args|
39
+ quiet = global_options[:quiet]
40
+ line_count = options[:line_count]
41
+ output_fd = File.open("cycle_analyst.#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}.csv", 'w')
42
+ ca.get_logs(output_fd, line_count, quiet)
43
+ end
44
+ end
45
+
46
+ pre do |global,command,options,args|
47
+ # Pre logic here
48
+ # Return true to proceed; false to abort and not call the
49
+ # chosen command
50
+ # Use skips_pre before a command to skip this block
51
+ # on that command only
52
+ @ca = CycleAnalyst.new(global)
53
+ end
54
+
55
+ post do |global,command,options,args|
56
+ # Post logic here
57
+ # Use skips_post before a command to skip this
58
+ # block on that command only
59
+ end
60
+
61
+ on_error do |exception|
62
+ # Error logic here
63
+ # return false to skip default error handling
64
+ true
65
+ end
66
+
67
+ exit run(ARGV)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module CycleAnalystLogger
2
+ VERSION = '0.1.1'
3
+ end
data/todo.txt ADDED
@@ -0,0 +1,14 @@
1
+ Ah
2
+ Volts
3
+ Amps
4
+ Speed (Kph)
5
+ Distance (Km)
6
+ Motor Temp (DegC)
7
+ Human RPM (cadence)
8
+ Human Power (Watts)
9
+ Human Torque (Nm)
10
+ Throtle In (Volts)
11
+ Throtle Out (Volts)
12
+ Acceleration
13
+ Limit Flags (preset #, Thr Fault, Ebrake, LVC, Limit flags)
14
+
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cycle_analyst_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert J. Berger
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.17'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: serialport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: aruba
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ description: Read and store log output from the Grin Cycle Analyst
126
+ email:
127
+ - rberger@ibd.com
128
+ executables:
129
+ - cycle_analyst_logger
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - README.rdoc
133
+ - cycle_analyst_logger.rdoc
134
+ files:
135
+ - ".gitignore"
136
+ - Gemfile
137
+ - README.rdoc
138
+ - Rakefile
139
+ - cycle_analyst_logger.gemspec
140
+ - cycle_analyst_logger.rdoc
141
+ - exe/cycle_analyst_logger
142
+ - lib/cycle_analyst_logger.rb
143
+ - lib/cycle_analyst_logger/cycle_analyst.rb
144
+ - lib/cycle_analyst_logger/gli_patch.rb
145
+ - lib/cycle_analyst_logger/main.rb
146
+ - lib/cycle_analyst_logger/version.rb
147
+ - todo.txt
148
+ homepage: https://github.com/rberger/cycle_analyst_logger
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options:
154
+ - "--title"
155
+ - cycle_analyst_logger
156
+ - "--main"
157
+ - README.rdoc
158
+ - "-ri"
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.6.14
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Read and store log output from the Grin Cycle Analyst
177
+ test_files: []