cycle_analyst_logger 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +15 -12
- data/cycle_analyst_logger.gemspec +4 -3
- data/cycle_analyst_logger.rdoc +35 -15
- data/lib/cycle_analyst_logger/cycle_analyst.rb +48 -18
- data/lib/cycle_analyst_logger/main.rb +47 -16
- data/lib/cycle_analyst_logger/version.rb +1 -1
- metadata +32 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c14b7775ea0c3bb48e42d175c8848aa3098630e0
|
4
|
+
data.tar.gz: 48aee7dce5942646f3e9e6d10591ac4da3116d7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a132b986dc5239b4a9b396bcd745b60710f8112fdd420ff66ffff5cf169e96e14ab3675951124ac581aafd89bf9a05c35c2fe53df8fe5b9e5f8c669887b78bd1
|
7
|
+
data.tar.gz: 035e128d2bd96f8df6a765e09bbd7a8595135ff11f904d8d3183af72aba7fbf968371289582002d523a344139fe4153f17ad145312d37302e2a73ace241c1a40
|
data/README.rdoc
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
= cycle_analyst_logger
|
2
2
|
|
3
3
|
== NAME
|
4
|
-
cycle_analyst_logger - Store the streaming data log output of a Grin Cycle Analyst V3
|
4
|
+
cycle_analyst_logger - Store the streaming data log output of a Grin Cycle Analyst V3 and optionally a Phaserunner
|
5
5
|
|
6
6
|
== SYNOPSIS
|
7
7
|
cycle_analyst_logger [global options] command [command options] [arguments...]
|
8
|
+
cycle_analyst_logger [global options] log [tty] [baudrate] [enable_phaserunner] [tty] [baudrate]
|
9
|
+
|
10
|
+
== VERSION
|
11
|
+
0.2.0
|
8
12
|
|
9
13
|
== GLOBAL OPTIONS
|
10
|
-
-t, --
|
11
|
-
-b, --
|
12
|
-
--
|
13
|
-
|
14
|
-
--
|
14
|
+
-t, --tty_ca=arg - Cycle Analyst Serial (USB) device (default: /dev/ttyUSB1)
|
15
|
+
-b, --baud_ca=arg - Cycle Analyst Serial port baudrate (default: 9600)
|
16
|
+
--enable_phaserunner=arg - Get PhaseRunner Logs also (default: true)
|
17
|
+
--tty_pr=arg - Phaserunner Serial (USB) device (default: /dev/ttyUSB0)
|
18
|
+
--baud_pr=arg - Phaserunner Serial port baudrate (default: 115200)
|
19
|
+
-l, --loop_count=arg - How many lines to read (default: forever)
|
20
|
+
--version - Display the program version
|
21
|
+
-q, --[no-]quiet - Do not output to stdout
|
22
|
+
--help - Show this message
|
15
23
|
|
16
24
|
== COMMANDS
|
17
25
|
help - Shows a list of commands or help for one command
|
18
|
-
log - Capture the logging output of the
|
19
|
-
|
20
|
-
=== log - Capture the logging output of the CA to a file
|
21
|
-
cycle_analyst_logger [global options] log [command options] [tty] [baudrate]
|
26
|
+
log - Capture the logging output of the Cycle Analyst and optionally Phaserunner to a file
|
22
27
|
|
23
|
-
=== COMMAND OPTIONS
|
24
|
-
-l, --line_count=arg - How many lines to read (default: forever)
|
25
28
|
|
26
29
|
:include:cycle_analyst_logger.rdoc
|
27
30
|
|
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Robert J. Berger"]
|
10
10
|
spec.email = ["rberger@ibd.com"]
|
11
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}
|
12
|
+
spec.summary = %q{Read and store log output from the Grin Cycle Analyst and Phaserunner}
|
13
|
+
spec.description = %q{Read and store log output from the Grin Cycle Analyst and optionally Phaserunner}
|
14
14
|
spec.homepage = "https://github.com/rberger/cycle_analyst_logger"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -27,11 +27,12 @@ Gem::Specification.new do |spec|
|
|
27
27
|
|
28
28
|
spec.add_runtime_dependency 'gli', '~> 2.17'
|
29
29
|
spec.add_runtime_dependency 'serialport', '~> 1.3'
|
30
|
+
spec.add_runtime_dependency 'phaserunner', '~> 0.1', '>= 0.1.3'
|
30
31
|
|
31
32
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
32
33
|
spec.add_development_dependency 'rake', '~> 10.0'
|
33
34
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
-
spec.add_development_dependency 'rdoc'
|
35
|
+
spec.add_development_dependency 'rdoc', '~> 0', '>= 5.0.0'
|
35
36
|
spec.add_development_dependency 'aruba', '~> 0.14'
|
36
37
|
spec.add_development_dependency 'yard', '~> 0.9'
|
37
38
|
end
|
data/cycle_analyst_logger.rdoc
CHANGED
@@ -1,22 +1,50 @@
|
|
1
|
-
== cycle_analyst_logger -
|
1
|
+
== cycle_analyst_logger - Store the streaming data log output of a Grin Cycle Analyst V3 and optionally a Phaserunner
|
2
2
|
|
3
|
-
v0.0
|
3
|
+
v0.2.0
|
4
4
|
|
5
5
|
=== Global Options
|
6
|
-
=== -b|--
|
6
|
+
=== -b|--baud_ca arg
|
7
7
|
|
8
|
-
Serial port baudrate
|
8
|
+
Cycle Analyst Serial port baudrate
|
9
9
|
|
10
10
|
[Default Value] 9600
|
11
11
|
|
12
12
|
|
13
|
-
===
|
13
|
+
=== --baud_pr arg
|
14
14
|
|
15
|
-
Serial
|
15
|
+
Phaserunner Serial port baudrate
|
16
|
+
|
17
|
+
[Default Value] 115200
|
18
|
+
|
19
|
+
|
20
|
+
=== --enable_phaserunner arg
|
21
|
+
|
22
|
+
Get PhaseRunner Logs also
|
23
|
+
|
24
|
+
[Default Value] true
|
25
|
+
|
26
|
+
|
27
|
+
=== -l|--loop_count arg
|
28
|
+
|
29
|
+
How many lines to read
|
30
|
+
|
31
|
+
[Default Value] forever
|
32
|
+
|
33
|
+
|
34
|
+
=== -t|--tty_ca arg
|
35
|
+
|
36
|
+
Cycle Analyst Serial (USB) device
|
16
37
|
|
17
38
|
[Default Value] /dev/ttyUSB1
|
18
39
|
|
19
40
|
|
41
|
+
=== --tty_pr arg
|
42
|
+
|
43
|
+
Phaserunner Serial (USB) device
|
44
|
+
|
45
|
+
[Default Value] /dev/ttyUSB0
|
46
|
+
|
47
|
+
|
20
48
|
=== --help
|
21
49
|
Show this message
|
22
50
|
|
@@ -44,14 +72,6 @@ List commands one per line, to assist with shell completion
|
|
44
72
|
|
45
73
|
|
46
74
|
==== Command: <tt>log </tt>
|
47
|
-
Capture the logging output of the
|
48
|
-
|
49
|
-
|
50
|
-
===== Options
|
51
|
-
===== -l|--line_count arg
|
52
|
-
|
53
|
-
How many lines to read
|
54
|
-
|
55
|
-
[Default Value] forever
|
75
|
+
Capture the logging output of the Cycle Analyst and optionally Phaserunner to a file
|
56
76
|
|
57
77
|
|
@@ -1,13 +1,28 @@
|
|
1
1
|
require 'time'
|
2
2
|
require 'serialport'
|
3
|
+
require 'phaserunner'
|
3
4
|
|
4
5
|
module CycleAnalystLogger
|
5
6
|
class CycleAnalyst
|
7
|
+
# Cycle Analyst serial port Baudrate
|
6
8
|
attr_reader :baudrate
|
9
|
+
|
10
|
+
# Cycle Analyst serial port name
|
7
11
|
attr_reader :tty
|
12
|
+
|
13
|
+
# Hash that describes the names, values and units of the Cycle Analyst log data
|
8
14
|
attr_reader :dict
|
15
|
+
|
16
|
+
# Handle from the SerialPort object
|
9
17
|
attr_reader :serial_io
|
10
|
-
|
18
|
+
|
19
|
+
# If the phaeserunner should be read
|
20
|
+
attr_reader :enable_phaserunner
|
21
|
+
|
22
|
+
# Handle of the Phaserunner::Modbus object
|
23
|
+
attr_reader :phaserunner
|
24
|
+
|
25
|
+
# Hash definition that describes the names, values and units of the Cycle Analyst log data
|
11
26
|
CA_DICT = {
|
12
27
|
0 => {address: 0, name: "Amp Hours", units: "Ah", scale: 1},
|
13
28
|
1 => { address: 1, name: "Volts", units: "V", scale: 1 },
|
@@ -25,45 +40,60 @@ module CycleAnalystLogger
|
|
25
40
|
13 => { address: 12, name: "Limit Flags", units: "bit flags", scale: 1}
|
26
41
|
}
|
27
42
|
|
43
|
+
# CycleAnalyst New
|
28
44
|
def initialize(opts)
|
29
|
-
@baudrate = opts[:
|
30
|
-
@tty = opts[:
|
45
|
+
@baudrate = opts[:baud_ca]
|
46
|
+
@tty = opts[:tty_ca]
|
31
47
|
@dict = CA_DICT
|
32
48
|
@serial_io = SerialPort.new @tty, @baudrate, 8, 1
|
49
|
+
@enable_phaserunner = opts[:enable_phaserunner]
|
50
|
+
if @enable_phaserunner
|
51
|
+
@phaserunner = Phaserunner::Modbus.new(
|
52
|
+
tty: opts[:tty_pr], baudrate: opts[:baud_pr]
|
53
|
+
)
|
54
|
+
end
|
33
55
|
end
|
34
56
|
|
57
|
+
# Forms the proper header line
|
58
|
+
# @return [String] of a printable CSV header line
|
35
59
|
def logs_header
|
36
|
-
dict.map do |(address, node)|
|
60
|
+
hdr = dict.map do |(address, node)|
|
37
61
|
"#{node[:name]} (#{node[:units]})"
|
38
|
-
end
|
62
|
+
end
|
63
|
+
if enable_phaserunner
|
64
|
+
hdr += phaserunner.bulk_log_header.map { |name| "PR #{name}" }
|
65
|
+
end
|
66
|
+
hdr.join(',')
|
39
67
|
end
|
40
68
|
|
69
|
+
# Converts a TSV string into an array
|
41
70
|
def tsv2array(line)
|
42
|
-
line.split("\t")
|
71
|
+
line.strip.split("\t")
|
43
72
|
end
|
44
73
|
|
45
|
-
# Get line from serial port and send to file
|
74
|
+
# Get line from Cycle Analyst serial port, optionally also the Phaserunner and send to stdout and file
|
46
75
|
# @param output_fd [File] File Descriptor of the output file to write to. Don't write to file if nil
|
47
|
-
# @param
|
76
|
+
# @param loop_count [Integer, Symbol] Number of lines to output, or forever if :forever
|
48
77
|
# @param quite [Boolean] Don't output to stdout if true
|
49
|
-
def get_logs(output_fd,
|
78
|
+
def get_logs(output_fd, loop_count, quiet)
|
50
79
|
line_number = 0
|
51
80
|
hdr = %Q(Timestamp,#{logs_header})
|
52
81
|
|
53
82
|
puts hdr if not quiet
|
54
83
|
output_fd.puts hdr if output_fd
|
55
84
|
|
56
|
-
serial_io.each_line do |line|
|
57
|
-
|
58
|
-
|
85
|
+
serial_io.each_line.with_index do |line, idx|
|
86
|
+
output = (
|
87
|
+
[Time.now.utc.round(10).iso8601(6)] +
|
88
|
+
tsv2array(line)
|
89
|
+
)
|
90
|
+
output += phaserunner.bulk_log_data if enable_phaserunner
|
91
|
+
output_line = output.flatten.join(',')
|
92
|
+
|
93
|
+
puts output_line unless quiet
|
59
94
|
output_fd.puts output_line if output_fd
|
60
95
|
|
61
|
-
|
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
|
96
|
+
break if idx >= loop_count
|
67
97
|
end
|
68
98
|
end
|
69
99
|
end
|
@@ -1,14 +1,23 @@
|
|
1
1
|
require 'gli'
|
2
2
|
|
3
3
|
module CycleAnalystLogger
|
4
|
+
# Handle Ctl-C exit
|
5
|
+
trap "SIGINT" do
|
6
|
+
puts "Exiting"
|
7
|
+
exit 130
|
8
|
+
end
|
4
9
|
|
5
10
|
class Cli
|
6
|
-
attr_reader :
|
11
|
+
attr_reader :cycle_analyst
|
12
|
+
attr_reader :enable_phaserunner
|
13
|
+
attr_reader :pr
|
14
|
+
attr_reader :quiet
|
15
|
+
attr_reader :loop_count
|
7
16
|
|
8
17
|
include GLI::App
|
9
18
|
|
10
19
|
def main
|
11
|
-
program_desc 'Store the streaming data log output of a Grin Cycle Analyst V3'
|
20
|
+
program_desc 'Store the streaming data log output of a Grin Cycle Analyst V3 and optionally a Phaserunner'
|
12
21
|
|
13
22
|
version CycleAnalystLogger::VERSION
|
14
23
|
|
@@ -16,30 +25,44 @@ module CycleAnalystLogger
|
|
16
25
|
arguments :strict
|
17
26
|
sort_help :manually
|
18
27
|
|
19
|
-
desc 'Serial (USB) device'
|
28
|
+
desc 'Cycle Analyst Serial (USB) device'
|
20
29
|
default_value '/dev/ttyUSB1'
|
21
30
|
arg 'tty', :optional
|
22
|
-
flag [:t, :
|
31
|
+
flag [:t, :tty_ca]
|
23
32
|
|
24
|
-
desc 'Serial port baudrate'
|
33
|
+
desc 'Cycle Analyst Serial port baudrate'
|
25
34
|
default_value 9600
|
26
35
|
arg 'baudrate', :optional
|
27
|
-
flag [:b, :
|
36
|
+
flag [:b, :baud_ca]
|
37
|
+
|
38
|
+
desc 'Get PhaseRunner Logs also'
|
39
|
+
default_value true
|
40
|
+
arg 'enable_phaserunner', :optional
|
41
|
+
flag [:enable_phaserunner]
|
42
|
+
|
43
|
+
desc 'Phaserunner Serial (USB) device'
|
44
|
+
default_value '/dev/ttyUSB0'
|
45
|
+
arg 'tty', :optional
|
46
|
+
flag [:tty_pr]
|
47
|
+
|
48
|
+
desc 'Phaserunner Serial port baudrate'
|
49
|
+
default_value 115200
|
50
|
+
arg 'baudrate', :optional
|
51
|
+
flag [:baud_pr]
|
52
|
+
|
53
|
+
desc "How many lines to read"
|
54
|
+
default_value :forever
|
55
|
+
flag [:l, :loop_count]
|
28
56
|
|
29
57
|
desc 'Do not output to stdout'
|
30
58
|
switch [:q, :quiet]
|
31
59
|
|
32
|
-
desc 'Capture the logging output of the
|
60
|
+
desc 'Capture the logging output of the Cycle Analyst and optionally Phaserunner to a file'
|
33
61
|
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
62
|
log.action do |global_options, options, args|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
ca.get_logs(output_fd, line_count, quiet)
|
63
|
+
filename = "cycle_analyst.#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}.csv"
|
64
|
+
output_fd = File.open(filename, 'w')
|
65
|
+
cycle_analyst.get_logs(output_fd, loop_count, quiet)
|
43
66
|
end
|
44
67
|
end
|
45
68
|
|
@@ -49,7 +72,15 @@ module CycleAnalystLogger
|
|
49
72
|
# chosen command
|
50
73
|
# Use skips_pre before a command to skip this block
|
51
74
|
# on that command only
|
52
|
-
@
|
75
|
+
@quiet = global[:quiet]
|
76
|
+
# Handle that loop_count can be :forever or an Integer
|
77
|
+
@loop_count = if global[:loop_count] == :forever
|
78
|
+
Float::INFINITY
|
79
|
+
else
|
80
|
+
global[:loop_count].to_i
|
81
|
+
end
|
82
|
+
@enable_phaserunner = global[:enable_phaserunner]
|
83
|
+
@cycle_analyst = CycleAnalyst.new(global)
|
53
84
|
end
|
54
85
|
|
55
86
|
post do |global,command,options,args|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cycle_analyst_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert J. Berger
|
@@ -38,6 +38,26 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: phaserunner
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.1.3
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.1'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.1.3
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: bundler
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,16 +104,22 @@ dependencies:
|
|
84
104
|
name: rdoc
|
85
105
|
requirement: !ruby/object:Gem::Requirement
|
86
106
|
requirements:
|
87
|
-
- - "
|
107
|
+
- - "~>"
|
88
108
|
- !ruby/object:Gem::Version
|
89
109
|
version: '0'
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 5.0.0
|
90
113
|
type: :development
|
91
114
|
prerelease: false
|
92
115
|
version_requirements: !ruby/object:Gem::Requirement
|
93
116
|
requirements:
|
94
|
-
- - "
|
117
|
+
- - "~>"
|
95
118
|
- !ruby/object:Gem::Version
|
96
119
|
version: '0'
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 5.0.0
|
97
123
|
- !ruby/object:Gem::Dependency
|
98
124
|
name: aruba
|
99
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +148,8 @@ dependencies:
|
|
122
148
|
- - "~>"
|
123
149
|
- !ruby/object:Gem::Version
|
124
150
|
version: '0.9'
|
125
|
-
description: Read and store log output from the Grin Cycle Analyst
|
151
|
+
description: Read and store log output from the Grin Cycle Analyst and optionally
|
152
|
+
Phaserunner
|
126
153
|
email:
|
127
154
|
- rberger@ibd.com
|
128
155
|
executables:
|
@@ -173,5 +200,5 @@ rubyforge_project:
|
|
173
200
|
rubygems_version: 2.6.14
|
174
201
|
signing_key:
|
175
202
|
specification_version: 4
|
176
|
-
summary: Read and store log output from the Grin Cycle Analyst
|
203
|
+
summary: Read and store log output from the Grin Cycle Analyst and Phaserunner
|
177
204
|
test_files: []
|