freestyle_libre 0.1.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +18 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/freestyle_libre.gemspec +27 -0
- data/lib/freestyle_libre.rb +8 -0
- data/lib/freestyle_libre/export_file_parse_results.rb +66 -0
- data/lib/freestyle_libre/reader.rb +175 -0
- data/lib/freestyle_libre/record.rb +7 -0
- data/lib/freestyle_libre/version.rb +3 -0
- metadata +118 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 4fd9090a157f212434123eaf4a17440d39a2526c
|
|
4
|
+
data.tar.gz: b3de016be7a5cc7f85b04161db8311f3e039fc8f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e47787295efa0a27c8cc2ecf7ab49bba4ad295faf2e0cdac8d8f5c4d745d0196b7d34bf296bee1ec3734c9e598e91235f388ca5cc198496b7efe6ff7a5391182
|
|
7
|
+
data.tar.gz: 654aec7785ee02ab3c34705c95bf7a6d25d985f96749310df8dfe00736e5281e732851f3a1379ba057ba3e0a8466c885f705d53573a148ac4cb7079db97f4505
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at bert.bruynooghe@up-nxt.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
freestyle_libre (0.1.0)
|
|
5
|
+
hidapi (~> 0.1.8)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
byebug (9.0.6)
|
|
11
|
+
diff-lcs (1.2.5)
|
|
12
|
+
dotenv (2.1.1)
|
|
13
|
+
ffi (1.9.18)
|
|
14
|
+
hidapi (0.1.8)
|
|
15
|
+
i18n
|
|
16
|
+
libusb (~> 0.5.1)
|
|
17
|
+
i18n (0.8.1)
|
|
18
|
+
libusb (0.5.1)
|
|
19
|
+
ffi (>= 1.0)
|
|
20
|
+
rake (10.5.0)
|
|
21
|
+
rspec (3.5.0)
|
|
22
|
+
rspec-core (~> 3.5.0)
|
|
23
|
+
rspec-expectations (~> 3.5.0)
|
|
24
|
+
rspec-mocks (~> 3.5.0)
|
|
25
|
+
rspec-core (3.5.4)
|
|
26
|
+
rspec-support (~> 3.5.0)
|
|
27
|
+
rspec-expectations (3.5.0)
|
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
29
|
+
rspec-support (~> 3.5.0)
|
|
30
|
+
rspec-mocks (3.5.0)
|
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
32
|
+
rspec-support (~> 3.5.0)
|
|
33
|
+
rspec-support (3.5.0)
|
|
34
|
+
|
|
35
|
+
PLATFORMS
|
|
36
|
+
ruby
|
|
37
|
+
|
|
38
|
+
DEPENDENCIES
|
|
39
|
+
bundler (~> 1.13)
|
|
40
|
+
byebug
|
|
41
|
+
dotenv
|
|
42
|
+
freestyle_libre!
|
|
43
|
+
rake (~> 10.0)
|
|
44
|
+
rspec (~> 3.0)
|
|
45
|
+
|
|
46
|
+
BUNDLED WITH
|
|
47
|
+
1.13.6
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Bert Bruynooghe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
* FreestyleLibre
|
|
2
|
+
|
|
3
|
+
This is a gem the allows accessing Abbott's FreeStyle Libre data,
|
|
4
|
+
both over USB and from the export file from the official Abbott application.
|
|
5
|
+
|
|
6
|
+
It is based both on the splendid work of https://github.com/Flameeyes/glucometer-protocols, and https://github.com/barkerest/hidapi
|
|
7
|
+
|
|
8
|
+
Implementation is not fully complete, but it already supports all glucose measurements, both manual and automatic.
|
|
9
|
+
|
|
10
|
+
Documentation is following.
|
|
11
|
+
|
|
12
|
+
** Testing
|
|
13
|
+
|
|
14
|
+
* make sure you have a reader with at least some valid readings
|
|
15
|
+
* create a .env file with `SERIAL` and `SWVER` (if you don't, the tests will fail and you read the values form the test results)
|
|
16
|
+
* export data of your reader to `libre.export` and put the file in the root of the project
|
|
17
|
+
* connect your reader
|
|
18
|
+
* `bundle exec rspec`
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "freestyle_libre"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'freestyle_libre/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "freestyle_libre"
|
|
8
|
+
spec.version = FreestyleLibre::VERSION
|
|
9
|
+
spec.authors = ["Bert Bruynooghe"]
|
|
10
|
+
spec.email = ["bert@bruyooghe-polet.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Accessing the Abbot FreeStyle Libre reader through USB}
|
|
13
|
+
spec.homepage = "https://github.com/bertBruynooghe/freestyle_libre"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
|
18
|
+
end
|
|
19
|
+
spec.bindir = "exe"
|
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
26
|
+
spec.add_dependency "hidapi", "~>0.1.8"
|
|
27
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module FreestyleLibre
|
|
2
|
+
class ExportFileParseResult
|
|
3
|
+
attr_reader :patient_name, :patient_id, :auto_measurements, :manual_measurements
|
|
4
|
+
|
|
5
|
+
def initialize(export_file_path)
|
|
6
|
+
@auto_measurements = []
|
|
7
|
+
@manual_measurements = []
|
|
8
|
+
@time_changes = []
|
|
9
|
+
parse_file(export_file_path)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def parse_file(export_file_path)
|
|
16
|
+
File.open(export_file_path, "r") do |f|
|
|
17
|
+
@patient_name = f.readline.strip
|
|
18
|
+
@patient_id = f.readline.strip[2..-1]
|
|
19
|
+
@columns = f.readline.strip.split("\t")
|
|
20
|
+
while !f.eof?
|
|
21
|
+
parse_line(f.readline)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def parse_line(line)
|
|
27
|
+
tokens = line.split("\t")
|
|
28
|
+
case tokens[2]
|
|
29
|
+
when '0'
|
|
30
|
+
insert_auto_measurement(tokens)
|
|
31
|
+
when '1'
|
|
32
|
+
insert_manual_measurement(tokens)
|
|
33
|
+
when '4'
|
|
34
|
+
# fast acting insulin
|
|
35
|
+
when '5'
|
|
36
|
+
# food non-numerid
|
|
37
|
+
when '6'
|
|
38
|
+
insert_time_change(tokens)
|
|
39
|
+
else
|
|
40
|
+
puts Hash[@columns.zip(tokens)]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def insert_time_change(tokens)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def insert_auto_measurement(tokens)
|
|
48
|
+
@auto_measurements << Record.new(id: tokens[0].to_i,
|
|
49
|
+
date_time: DateTime.strptime("#{tokens[1]}", '%Y-%m-%d %H:%M'),
|
|
50
|
+
first_sensor_reading: nil,
|
|
51
|
+
sensor_runtime_minutes: nil,
|
|
52
|
+
value: tokens[3].to_i,
|
|
53
|
+
errored: false,
|
|
54
|
+
error_code: "0")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def insert_manual_measurement(tokens)
|
|
58
|
+
@manual_measurements << Record.new(id: tokens[0].to_i,
|
|
59
|
+
type: "2",
|
|
60
|
+
date_time: DateTime.strptime("#{tokens[1]}", '%Y-%m-%d %H:%M'),
|
|
61
|
+
value: tokens[4].to_i
|
|
62
|
+
#errored: false)
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
require 'ostruct'
|
|
2
|
+
module FreestyleLibre
|
|
3
|
+
class Reader
|
|
4
|
+
VENDOR_ID = 0x1a61
|
|
5
|
+
PRODUCT_ID = 0x3650
|
|
6
|
+
INIT_COMMAND_SEQUENCE = [0x04, 0x05, 0x15, 0x1]
|
|
7
|
+
|
|
8
|
+
# @param interface [Number] The interface number of the device; needed in case you have several readers connected
|
|
9
|
+
def initialize(interface = nil)
|
|
10
|
+
HIDAPI::SetupTaskHelper.new(VENDOR_ID, PRODUCT_ID, "abbott-freestyle-libre", interface).run
|
|
11
|
+
@device = HIDAPI::open(VENDOR_ID, PRODUCT_ID, interface)
|
|
12
|
+
raise 'device could not be opened' unless @device
|
|
13
|
+
|
|
14
|
+
INIT_COMMAND_SEQUENCE.each do |c|
|
|
15
|
+
write_report(c, '')
|
|
16
|
+
read_report
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def serial
|
|
21
|
+
write_report(0x60, '$sn?')
|
|
22
|
+
read_text_command.strip
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def software_version
|
|
26
|
+
write_report(0x60, '$swver?')
|
|
27
|
+
read_text_command.strip
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def date_time
|
|
31
|
+
write_report(0x60, '$date?')
|
|
32
|
+
date = read_text_command.strip
|
|
33
|
+
write_report(0x60, '$time?')
|
|
34
|
+
DateTime.strptime("#{date} #{read_text_command}", '%m,%d,%y %H,%M')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def date_time=(value)
|
|
38
|
+
write_report(0x60, "$date,#{value.strftime('%-m,%-d,%y')}")
|
|
39
|
+
read_text_command
|
|
40
|
+
write_report(0x60, "$time,#{value.strftime('%H,%M')}")
|
|
41
|
+
read_text_command
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def patient_name=(value)
|
|
45
|
+
write_report(0x60, "$ptname,#{value}")
|
|
46
|
+
read_text_command
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def patient_name
|
|
50
|
+
write_report(0x60, '$ptname?')
|
|
51
|
+
read_text_command.strip
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def patient_id=(value)
|
|
55
|
+
write_report(0x60, "$ptid,#{value}")
|
|
56
|
+
read_text_command
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def patient_id
|
|
60
|
+
write_report(0x60, '$ptid?')
|
|
61
|
+
read_text_command.strip
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# latest record ID ???
|
|
65
|
+
def database_record_number
|
|
66
|
+
# TODO: not sure this matches the description.
|
|
67
|
+
# We should check that by scanning the tag two times and seeing that the number of new history
|
|
68
|
+
# matches the increase of this number
|
|
69
|
+
write_report(0x60, '$dbrnum?')
|
|
70
|
+
read_text_command.gsub('DB Record Number =', '').strip.to_i
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Automatic glucose measurements
|
|
74
|
+
def history
|
|
75
|
+
write_report(0x60, '$history?')
|
|
76
|
+
read_multi.map { |record| auto_measurement(record) }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Manual measurements and date/time changes
|
|
80
|
+
# @return [Record]
|
|
81
|
+
def arresult
|
|
82
|
+
write_report(0x60, '$arresult?')
|
|
83
|
+
read_multi.map { |record| ar(record) }.compact
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def close
|
|
87
|
+
@device.close
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def ar(record)
|
|
93
|
+
fields = record.split(',').map(&:strip)
|
|
94
|
+
case fields[1]
|
|
95
|
+
when "2"
|
|
96
|
+
manual_measurement(fields)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def manual_measurement(fields)
|
|
101
|
+
Record.new(id: fields[0].to_i,
|
|
102
|
+
type: fields[1],
|
|
103
|
+
date_time: parse_date_time(fields[2...7]),
|
|
104
|
+
value: fields[12].to_i,
|
|
105
|
+
errored: fields[28].nil? || (fields[28].to_i & 0x8000) > 0,
|
|
106
|
+
error_code: fields[28])
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def auto_measurement(record)
|
|
110
|
+
fields = record.split(',').map(&:strip)
|
|
111
|
+
Record.new(id: fields[0].to_i,
|
|
112
|
+
date_time: parse_date_time(fields[2...7]),
|
|
113
|
+
first_sensor_reading: fields[12]== "1",
|
|
114
|
+
value: fields[13].to_i,
|
|
115
|
+
sensor_runtime_minutes: fields[14].to_i,
|
|
116
|
+
errored: fields[15].nil? || (fields[15].to_i & 0x8000) > 0,
|
|
117
|
+
error_code: fields[15])
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def parse_date_time(fields)
|
|
121
|
+
DateTime.new(fields[2].to_i + 2000, fields[0].to_i, fields[1].to_i,
|
|
122
|
+
fields[3].to_i, fields[4].to_i, fields[5].to_i)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def read_multi
|
|
126
|
+
msg = ""
|
|
127
|
+
while true
|
|
128
|
+
report = read_report
|
|
129
|
+
raise "unexpected message type 0x#{report[:msg_type].to_s(16)}" unless report[:msg_type] == 0x60
|
|
130
|
+
msg += report[:msg]
|
|
131
|
+
break if report[:msg].end_with?("CMD OK\r\n")
|
|
132
|
+
end
|
|
133
|
+
result = extract_text(msg).split("\r\n")
|
|
134
|
+
record_count, checksum = result.pop.split(',')
|
|
135
|
+
raise "wrong number of records: declared #{record_count}, got result.length" unless record_count.to_i == result.length
|
|
136
|
+
validate_checksum!(result.join("\r\n")+"\r\n", checksum.to_i(16))
|
|
137
|
+
result
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def read_text_command
|
|
141
|
+
report = read_report
|
|
142
|
+
raise "unexpected message type 0x#{report[:msg_type].to_s(16)}" unless report[:msg_type] == 0x60
|
|
143
|
+
extract_text(report[:msg])
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def extract_text(msg)
|
|
147
|
+
msg, status = msg.split('CMD ')
|
|
148
|
+
raise "*#{status}" unless status == "OK\r\n"
|
|
149
|
+
msg, checksum = msg.split('CKSM:')
|
|
150
|
+
validate_checksum!(msg, checksum.to_i(16))
|
|
151
|
+
msg
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def validate_checksum!(msg, checksum)
|
|
155
|
+
raise "checksum failed" unless checksum = msg.bytes.reduce(0){ |m, b| m + b }
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def read_report
|
|
159
|
+
reading = @device.read.bytes
|
|
160
|
+
msg_type = reading.shift
|
|
161
|
+
length = reading.shift
|
|
162
|
+
return read_report if msg_type == 0x22 && length == 0x1
|
|
163
|
+
msg = reading.pack('C*')[0...length]
|
|
164
|
+
while msg.length < length
|
|
165
|
+
msg += @device.read.pack('C*')[0...(length - msg.length)]
|
|
166
|
+
end
|
|
167
|
+
{msg_type: msg_type , msg: msg}
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def write_report(cmd, value)
|
|
171
|
+
value = value.bytes
|
|
172
|
+
@device.write([0x00, cmd, value.length, *value, *Array.new(61-value.length, 0x00) ])
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: freestyle_libre
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bert Bruynooghe
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-05-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.13'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.13'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: hidapi
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.1.8
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.1.8
|
|
69
|
+
description:
|
|
70
|
+
email:
|
|
71
|
+
- bert@bruyooghe-polet.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".ruby-version"
|
|
79
|
+
- ".travis.yml"
|
|
80
|
+
- CODE_OF_CONDUCT.md
|
|
81
|
+
- Gemfile
|
|
82
|
+
- Gemfile.lock
|
|
83
|
+
- LICENSE.txt
|
|
84
|
+
- README.md
|
|
85
|
+
- Rakefile
|
|
86
|
+
- bin/console
|
|
87
|
+
- bin/setup
|
|
88
|
+
- freestyle_libre.gemspec
|
|
89
|
+
- lib/freestyle_libre.rb
|
|
90
|
+
- lib/freestyle_libre/export_file_parse_results.rb
|
|
91
|
+
- lib/freestyle_libre/reader.rb
|
|
92
|
+
- lib/freestyle_libre/record.rb
|
|
93
|
+
- lib/freestyle_libre/version.rb
|
|
94
|
+
homepage: https://github.com/bertBruynooghe/freestyle_libre
|
|
95
|
+
licenses:
|
|
96
|
+
- MIT
|
|
97
|
+
metadata: {}
|
|
98
|
+
post_install_message:
|
|
99
|
+
rdoc_options: []
|
|
100
|
+
require_paths:
|
|
101
|
+
- lib
|
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
requirements: []
|
|
113
|
+
rubyforge_project:
|
|
114
|
+
rubygems_version: 2.5.1
|
|
115
|
+
signing_key:
|
|
116
|
+
specification_version: 4
|
|
117
|
+
summary: Accessing the Abbot FreeStyle Libre reader through USB
|
|
118
|
+
test_files: []
|