lxp-packet 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a06975e75dcaa0908d9f1e795d6a9106cf4cabe951b5907ce9b73802d1322999
4
- data.tar.gz: 32919a40bd5f34819be74a7b5eeb51d5c6cdd322882d75b2f533f2cbc73c68a6
3
+ metadata.gz: b7aaa9f0df8afa2c5c3c3c5652f8dc437c86fd400b499b400b61220c60795c88
4
+ data.tar.gz: 73ec58f5d96b333555e6d6fd3e45c56c50e389bab58ab6e25b992276e9c6a4d3
5
5
  SHA512:
6
- metadata.gz: 52d0753334fb109f1caddbf00ced45d9e2d372b8de76cc8358154d95a79931357d71cfad525a0f8ee578e89f15a95648d599948501f17f8ca3a7c137bca926b0
7
- data.tar.gz: 75e3b687650069eb24fd0d875b27a0a831ef20157d885b5c12450cee60e7c6e1f038606109e2dd0338f9cd9d710ce1a6a6dd240a228364c0fee65dd81975d7e4
6
+ metadata.gz: 1874992682079715b761e8a68c8abc4c643c39b9398541934360e982eb91fb25e5f8e4cffbe504711edc38bd9b29cb42b89037ac7b5ea5c05dd792d790e235b0
7
+ data.tar.gz: ae61d070c93e133eac2a3240c649c13184b1da69fe5f0faaa45fa15d7180d4022d690c8e72587f496aa692983f726524e60b1601db0fc10a6bfafbd7167da7ad
data/CHANGELOG.md CHANGED
@@ -1,12 +1,23 @@
1
1
  # Changelog
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
7
 
7
- ## [Unreleased]
8
+ ## [0.1.2] - 2020-01-15
9
+
10
+ ### Fixed
11
+
12
+ - broken require 'utils' in 0.1.1
13
+
14
+ ## [0.1.1] - 2020-01-15
15
+
16
+ ### Changed
8
17
 
9
- - Nothing yet
18
+ - move Utils module into LXP namespace
19
+ - add Packet#tcp_function
20
+ - add Heartbeat packet support
10
21
 
11
22
  ## [0.1.0] - 2020-01-05
12
23
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'tcp_functions'
3
4
  require_relative 'device_functions'
4
5
 
5
6
  class LXP
@@ -28,9 +29,7 @@ class LXP
28
29
  # length after first 6 bytes maybe?
29
30
  self.packet_length = 32
30
31
 
31
- @header[6] = 1 # unsure
32
-
33
- @header[7] = 194 # translated data, TBD
32
+ @header[6] = 1 # unsure, always seems to be 1
34
33
  end
35
34
 
36
35
  def bytes
@@ -82,6 +81,14 @@ class LXP
82
81
  @header[5] = (packet_length >> 8) & 0xff
83
82
  end
84
83
 
84
+ def tcp_function
85
+ @header[7]
86
+ end
87
+
88
+ def tcp_function=(tcp_function)
89
+ @header[7] = tcp_function & 0xff
90
+ end
91
+
85
92
  # Passed as a string
86
93
  def datalog_serial=(datalog_serial)
87
94
  @header[8, 10] = datalog_serial.bytes
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+ require_relative 'device_functions'
5
+
6
+ class LXP
7
+ class Packet
8
+ # This isn't really used for anything; we don't send heartbeats to
9
+ # the inverter, but we do receive them. So this is just instantiated
10
+ # if we receive one, so that Parser.parse has something to return.
11
+ #
12
+ # They are a very minimal packet of 19 bytes total:
13
+ # 6 of which is frame (161, 26, p1, p2, l1, l2)
14
+ # 13 bytes of header (1, 193, serial * 10, 0)
15
+ #
16
+ # They have no data and no checksum, so there's really not a lot here.
17
+ #
18
+ # Ideally these could be instantiated via .parse, but they only seem to
19
+ # have one byte for the length, and .parse expects two. There's nothing
20
+ # to parse anyway so never mind.
21
+ #
22
+ class Heartbeat < Base
23
+ def initialize
24
+ super
25
+
26
+ self.tcp_function = TcpFunctions::HEARTBEAT
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'utils'
4
-
5
3
  require_relative 'device_functions'
6
4
  require_relative 'tcp_functions'
7
5
 
@@ -23,7 +21,7 @@ class LXP
23
21
 
24
22
  def parse
25
23
  case bdata[7] # tcp_function
26
- when TcpFunctions::HEARTBEAT then nil # ignored
24
+ when TcpFunctions::HEARTBEAT then Heartbeat.new
27
25
  when TcpFunctions::TRANSLATED_DATA then parse_translated_data
28
26
  else
29
27
  raise "unhandled tcp_function #{bdata[7]}"
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
- require_relative 'device_functions'
5
4
 
6
5
  class LXP
7
6
  class Packet
@@ -9,6 +8,7 @@ class LXP
9
8
  def initialize
10
9
  super
11
10
 
11
+ self.tcp_function = TcpFunctions::TRANSLATED_DATA
12
12
  self.device_function = DeviceFunctions::READ_HOLD
13
13
 
14
14
  self.data_length = 18
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'utils'
4
3
  require_relative 'read_input'
5
4
 
6
5
  class LXP
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'utils'
4
3
  require_relative 'read_input'
5
4
 
6
5
  class LXP
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'utils'
4
3
  require_relative 'read_input'
5
4
 
6
5
  class LXP
@@ -8,6 +8,7 @@ class LXP
8
8
  def initialize
9
9
  super
10
10
 
11
+ self.tcp_function = TcpFunctions::TRANSLATED_DATA
11
12
  self.device_function = DeviceFunctions::WRITE_SINGLE
12
13
  self.data_length = 18
13
14
  end
data/lib/lxp/packet.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'utils'
4
+
3
5
  require_relative 'packet/registers'
4
6
  require_relative 'packet/register_bits'
5
7
 
6
8
  require_relative 'packet/parser'
7
9
 
10
+ require_relative 'packet/heartbeat'
8
11
  require_relative 'packet/read_input1'
9
12
  require_relative 'packet/read_input2'
10
13
  require_relative 'packet/read_input3'
data/lib/lxp/utils.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class LXP
4
+ module Utils
5
+ module_function
6
+
7
+ def int(bytes, order = :lsb)
8
+ bytes = bytes.reverse if order == :msb
9
+
10
+ bytes.each_with_index.map do |b, idx|
11
+ b << (idx * 8)
12
+ end.inject(:|)
13
+ end
14
+
15
+ def int_complement(bytes, order = :lsb)
16
+ r = int(bytes, order)
17
+ r -= 0x10000 if r & 0x8000 == 0x8000
18
+ r
19
+ end
20
+ end
21
+ end
data/lib/lxp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module LXP
4
- VERSION = '0.1.0'
3
+ class LXP
4
+ VERSION = '0.1.2'
5
5
  end
data/lxp-packet.gemspec CHANGED
@@ -17,11 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.metadata['homepage_uri'] = s.homepage
18
18
  s.metadata['source_code_uri'] = 'https://github.com/celsworth/lxp-packet'
19
19
 
20
- s.files = Dir.chdir(File.expand_path(__dir__)) do
21
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|s|features)/}) }
22
- end
23
- s.bindir = 'exe'
24
- s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ s.files = `git ls-files -z`.split("\x0")
25
21
  s.require_paths = ['lib']
26
22
 
27
23
  s.add_development_dependency 'bundler', '~> 2.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lxp-packet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Elsworth
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-05 00:00:00.000000000 Z
11
+ date: 2020-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -41,6 +41,7 @@ files:
41
41
  - lib/lxp/packet.rb
42
42
  - lib/lxp/packet/base.rb
43
43
  - lib/lxp/packet/device_functions.rb
44
+ - lib/lxp/packet/heartbeat.rb
44
45
  - lib/lxp/packet/parser.rb
45
46
  - lib/lxp/packet/read_hold.rb
46
47
  - lib/lxp/packet/read_input.rb
@@ -51,8 +52,8 @@ files:
51
52
  - lib/lxp/packet/registers.rb
52
53
  - lib/lxp/packet/tcp_functions.rb
53
54
  - lib/lxp/packet/write_single.rb
55
+ - lib/lxp/utils.rb
54
56
  - lib/lxp/version.rb
55
- - lib/utils.rb
56
57
  - lxp-packet.gemspec
57
58
  homepage: https://github.com/celsworth/lxp-packet
58
59
  licenses:
data/lib/utils.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Utils
4
- module_function
5
-
6
- def int(bytes, order = :lsb)
7
- bytes = bytes.reverse if order == :msb
8
-
9
- bytes.each_with_index.map do |b, idx|
10
- b << (idx * 8)
11
- end.inject(:|)
12
- end
13
-
14
- def int_complement(bytes, order = :lsb)
15
- r = int(bytes, order)
16
- r -= 0x10000 if r & 0x8000 == 0x8000
17
- r
18
- end
19
- end