itiscold 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +1 -1
  3. data/bin/itiscold +1 -0
  4. data/lib/itiscold.rb +43 -95
  5. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: baeb51b5de66b8e9235bcb239504a9e30bb9dc41
4
- data.tar.gz: 721c823a9712723ee5c50e6e40b45017ea3a16da
2
+ SHA256:
3
+ metadata.gz: cd0869cec41e9176d979090a0aef0bfea8794a85dc0509df7b178ba1e4d883b7
4
+ data.tar.gz: bacb9058aed2cd7513310e8107ea6980ad5f34b7dbf90127ce4ae28a5c58234b
5
5
  SHA512:
6
- metadata.gz: 5819af1c525e6e2d646c0d4b5385751a134f00cf242365ea597bb1b3eddd23dee3462dcc592745101e9067da0a9666799ce44653a272283318be794e5c7cfe8e
7
- data.tar.gz: 202c719103f2817e9044aa14f751293eb457c8b9c3092133be061ec01fec7c724efe1c901092b358676589029697e6e877c0491fbd4b0dd6139492e5847b1258
6
+ metadata.gz: 173188a5ad7a6323de6bf79c8535e42ee4add3e65e056d3b2f9a563d8f6d99718a63dddc0d94cf8c4b2eb86ba693e8bc5daae7b011f45bce8fbda94dfe3466ea
7
+ data.tar.gz: e92feba74df7e9aa2b456f3ca1eb77518dfade47d339e324728b07a84bd5a515117c253304c6bbffe4870cddefa3ceefcb6050db7a44a8b8b13c2509c6c9c639
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ Hoe.spec 'itiscold' do
13
13
  self.readme_file = 'README.md'
14
14
  self.history_file = 'CHANGELOG.md'
15
15
  self.extra_rdoc_files = FileList['*.md']
16
- self.extra_deps << ['ruby-termios', '~> 1']
16
+ self.extra_deps << ['uart', '~> 1']
17
17
  end
18
18
 
19
19
  # vim: syntax=ruby
@@ -48,6 +48,7 @@ when 'samples'
48
48
  end
49
49
  when 'info'
50
50
  require 'psych'
51
+ temp = Itiscold.open options[:tty]
51
52
  puts Psych.dump temp.device_info
52
53
  when 'server'
53
54
  Itiscold::WebServer.start options[:tty]
@@ -2,101 +2,18 @@ require 'termios'
2
2
  require 'fcntl'
3
3
  require 'webrick'
4
4
  require 'json'
5
+ require 'uart'
6
+ require 'io/wait'
5
7
 
6
8
  class Itiscold
7
- VERSION = '1.0.1'
8
-
9
- class TTY
10
- include Termios
11
-
12
- def self.open filename, speed, mode
13
- if mode =~ /^(\d)(\w)(\d)$/
14
- t.data_bits = $1.to_i
15
- t.stop_bits = $3.to_i
16
- t.parity = { 'N' => :none, 'E' => :even, 'O' => :odd }[$2]
17
- t.speed = speed
18
- t.read_timeout = 5
19
- t.reading = true
20
- t.update!
21
- end
22
- end
23
-
24
- def self.data_bits t, val
25
- t.cflag &= ~CSIZE # clear previous values
26
- t.cflag |= const_get("CS#{val}") # Set the data bits
27
- t
28
- end
29
-
30
- def self.stop_bits t, val
31
- case val
32
- when 1 then t.cflag &= ~CSTOPB
33
- when 2 then t.cflag |= CSTOPB
34
- else
35
- raise
36
- end
37
- t
38
- end
39
-
40
- def self.parity t, val
41
- case val
42
- when :none
43
- t.cflag &= ~PARENB
44
- when :even
45
- t.cflag |= PARENB # Enable parity
46
- t.cflag &= ~PARODD # Make it not odd
47
- when :odd
48
- t.cflag |= PARENB # Enable parity
49
- t.cflag |= PARODD # Make it odd
50
- else
51
- raise
52
- end
53
- t
54
- end
55
-
56
- def self.speed t, speed
57
- t.ispeed = const_get("B#{speed}")
58
- t.ospeed = const_get("B#{speed}")
59
- t
60
- end
61
-
62
- def self.read_timeout t, val
63
- t.cc[VTIME] = val
64
- t.cc[VMIN] = 0
65
- t
66
- end
67
-
68
- def self.reading t
69
- t.cflag |= CLOCAL | CREAD
70
- t
71
- end
72
- end
9
+ VERSION = '1.0.2'
73
10
 
74
11
  def self.open filename, speed = 115200
75
- f = File.open filename, File::RDWR|Fcntl::O_NOCTTY|Fcntl::O_NDELAY
76
- f.binmode
77
- f.sync = true
78
-
79
- # enable blocking reads, otherwise read timeout won't work
80
- f.fcntl Fcntl::F_SETFL, f.fcntl(Fcntl::F_GETFL, 0) & ~Fcntl::O_NONBLOCK
81
-
82
- t = Termios.tcgetattr f
83
- t.iflag = 0
84
- t.oflag = 0
85
- t.lflag = 0
86
- t = TTY.data_bits t, 8
87
- t = TTY.stop_bits t, 1
88
- t = TTY.parity t, :none
89
- t = TTY.speed t, speed
90
- t = TTY.read_timeout t, 5
91
- t = TTY.reading t
92
-
93
- Termios.tcsetattr f, Termios::TCSANOW, t
94
- Termios.tcflush f, Termios::TCIOFLUSH
12
+ f = UART.open filename, speed
95
13
 
96
14
  temp = new f
97
15
 
98
16
  # Try reading the version a few times before giving up
99
- temp.flush
100
17
  temp
101
18
  end
102
19
 
@@ -125,10 +42,21 @@ class Itiscold
125
42
  :new_station_number
126
43
 
127
44
  def device_info
128
- val = retry_comm(1) do
129
- @tty.write with_checksum([0xCC, 0x00, 0x06, 0x00]).pack('C5')
130
- @tty.read 160
45
+ val = nil
46
+
47
+ loop do
48
+ if @tty.wait_writable
49
+ @tty.write with_checksum([0xCC, 0x00, 0x06, 0x00]).pack('C5')
50
+ else
51
+ raise "Couldn't open tty for writing"
52
+ end
53
+
54
+ if @tty.wait_readable(2)
55
+ val = @tty.read 160
56
+ break
57
+ end
131
58
  end
59
+
132
60
  _, # C set number
133
61
  station_no, # C station number
134
62
  _, # C
@@ -166,6 +94,10 @@ class Itiscold
166
94
  temp_calib / 10.0
167
95
  end
168
96
 
97
+ def close
98
+ @tty.close
99
+ end
100
+
169
101
  def device_params= values
170
102
  data = [
171
103
  0x33, # C
@@ -173,8 +105,8 @@ class Itiscold
173
105
  0x05, 0x00, # CC
174
106
  ] + split_time(values.sample_interval) + # CCC
175
107
  [
176
- (values.upper_limit * 10).to_i, # n
177
- (values.lower_limit * 10).to_i, # s>
108
+ (values.upper_limit * 10).to_i & 0xFFFF, # n
109
+ (values.lower_limit * 10).to_i & 0xFFFF, # s>
178
110
  values.new_station_number || values.station_number, # C
179
111
  allowed_encode(values.stop_button), # C
180
112
  delay_time_encode(values.delay_time), # C
@@ -184,12 +116,25 @@ class Itiscold
184
116
  (values.temp_calibration * 10).to_i, # C
185
117
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00 # C6
186
118
  ]
187
- retry_comm(1) do
188
- @tty.write with_checksum(data).pack('CCCCCCCns>CCCCCCCC6C')
189
- @tty.read 3
119
+
120
+ loop do
121
+ if @tty.wait_writable
122
+ @tty.write with_checksum(data).pack('CCCCCCCns>CCCCCCCC6C')
123
+ else
124
+ raise "Couldn't open tty for writing"
125
+ end
126
+
127
+ if @tty.wait_readable(2)
128
+ @tty.read 3
129
+ break
130
+ end
190
131
  end
191
132
  end
192
133
 
134
+ def clear_data!
135
+ self.device_params = device_info
136
+ end
137
+
193
138
  def set_device_number station_number, dev_number
194
139
  str = dev_number.bytes.first(10)
195
140
  str.concat([0x00] * (10 - str.length))
@@ -358,7 +303,10 @@ class Itiscold
358
303
  raise "invalid checksum #{expected} == #{actual}" unless expected == actual
359
304
  end
360
305
 
306
+ NULL_DATE = [65535, 255, 255, 255, 255, 255].pack('nC5')
307
+
361
308
  def unpack_datetime bytes
309
+ return if bytes == NULL_DATE
362
310
  Time.new(*bytes.unpack('nC5'))
363
311
  end
364
312
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itiscold
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-06 00:00:00.000000000 Z
11
+ date: 2018-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ruby-termios
14
+ name: uart
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.9'
33
+ version: '5.10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.9'
40
+ version: '5.10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  requirements: []
117
117
  rubyforge_project:
118
- rubygems_version: 2.6.8
118
+ rubygems_version: 2.7.3
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: A thing that reads data from Elitech RC-5 temp sensor