-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from synthead/add-sync-start-end-classes-for-…
…protocol-7 Add sync start end classes for protocol 7
- Loading branch information
Showing
8 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require "timex_datalink_client/helpers/crc_packets_wrapper" | ||
|
||
class TimexDatalinkClient | ||
class Protocol7 | ||
class End | ||
prepend Helpers::CrcPacketsWrapper | ||
|
||
SETUP_PACKET = [0x92, 0x05] | ||
CPACKET_SKIP = [0x21] | ||
|
||
# Compile packets for data end command. | ||
# | ||
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes. | ||
def packets | ||
[SETUP_PACKET, CPACKET_SKIP] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "timex_datalink_client/helpers/crc_packets_wrapper" | ||
|
||
class TimexDatalinkClient | ||
class Protocol7 | ||
class Start | ||
prepend Helpers::CrcPacketsWrapper | ||
|
||
CPACKET_START = [0x20, 0x00, 0x00, 0x07] | ||
|
||
SETUP_PACKETS = [ | ||
[ | ||
0x90, 0x05, 0x01, 0x44, 0x53, 0x49, 0x20, 0x54, 0x6f, 0x79, 0x73, 0x20, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, | ||
0x74, 0x73, 0x2e, 0x2e, 0x2e, 0x65, 0x42, 0x72, 0x61, 0x69, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
], | ||
[0x91, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04] | ||
] | ||
|
||
# Compile packets for data start command. | ||
# | ||
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes. | ||
def packets | ||
[CPACKET_START] + SETUP_PACKETS | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
class TimexDatalinkClient | ||
class Protocol7 | ||
class Sync | ||
PING_BYTE = [0x78] | ||
SYNC_1_BYTE = [0x55] | ||
SYNC_2_BYTE = [0xaa] | ||
|
||
SYNC_2_LENGTH = 5 | ||
|
||
attr_accessor :length | ||
|
||
# Create a Sync instance. | ||
# | ||
# @param length [Integer] Number of 0x55 sync bytes to use. | ||
# @return [Sync] Sync instance. | ||
def initialize(length: 300) | ||
@length = length | ||
end | ||
|
||
# Compile packets for syncronization data. | ||
# | ||
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes. | ||
def packets | ||
[PING_BYTE + render_sync_1 + render_sync_2] | ||
end | ||
|
||
private | ||
|
||
def render_sync_1 | ||
SYNC_1_BYTE * length | ||
end | ||
|
||
def render_sync_2 | ||
SYNC_2_BYTE * SYNC_2_LENGTH | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe TimexDatalinkClient::Protocol7::End do | ||
let(:end_instance) { described_class.new } | ||
|
||
describe "#packets", :crc do | ||
subject(:packets) { end_instance.packets } | ||
|
||
it_behaves_like "CRC-wrapped packets", [[0x92, 0x05], [0x21]] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe TimexDatalinkClient::Protocol7::Start do | ||
let(:start) { described_class.new } | ||
|
||
describe "#packets", :crc do | ||
subject(:packets) { start.packets } | ||
|
||
it_behaves_like "CRC-wrapped packets", [ | ||
[0x20, 0x00, 0x00, 0x07], | ||
[ | ||
0x90, 0x05, 0x01, 0x44, 0x53, 0x49, 0x20, 0x54, 0x6f, 0x79, 0x73, 0x20, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, | ||
0x74, 0x73, 0x2e, 0x2e, 0x2e, 0x65, 0x42, 0x72, 0x61, 0x69, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
], | ||
[0x91, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04] | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe TimexDatalinkClient::Protocol7::Sync do | ||
let(:length) { 200 } | ||
let(:sync) { described_class.new(length: length) } | ||
|
||
describe "#packets" do | ||
subject(:packets) { sync.packets } | ||
|
||
it { should eq([[0x78] + [0x55] * length + [0xaa] * 5]) } | ||
|
||
context "when length is 350" do | ||
let(:length) { 350 } | ||
|
||
it { should eq([[0x78] + [0x55] * length + [0xaa] * 5]) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters