-
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 #48 from synthead/add-sync-start-stop-for-protocol-1
Add Sync, Start, and Stop models for protocol 1
- Loading branch information
Showing
8 changed files
with
94 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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require "timex_datalink_client/end" | ||
|
||
class TimexDatalinkClient | ||
class Protocol1 | ||
class End < 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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require "timex_datalink_client/helpers/crc_packets_wrapper" | ||
|
||
class TimexDatalinkClient | ||
class Protocol1 | ||
class Start | ||
prepend Helpers::CrcPacketsWrapper | ||
|
||
CPACKET_START = [0x20, 0x00, 0x00, 0x01] | ||
|
||
# Compile packets for data start command. | ||
# | ||
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes. | ||
def packets | ||
[CPACKET_START] | ||
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require "timex_datalink_client/sync" | ||
|
||
class TimexDatalinkClient | ||
class Protocol1 | ||
class Sync < Sync | ||
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::Protocol1::End do | ||
let(:end_instance) { described_class.new } | ||
|
||
describe "#packets", :crc do | ||
subject(:packets) { end_instance.packets } | ||
|
||
it_behaves_like "CRC-wrapped packets", [[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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe TimexDatalinkClient::Protocol1::Start do | ||
let(:start) { described_class.new } | ||
|
||
describe "#packets", :crc do | ||
subject(:packets) { start.packets } | ||
|
||
it_behaves_like "CRC-wrapped packets", [[0x20, 0x00, 0x00, 0x01]] | ||
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::Protocol1::Sync do | ||
let(:length) { 200 } | ||
let(:sync) { described_class.new(length: length) } | ||
|
||
describe "#packets" do | ||
subject(:packets) { sync.packets } | ||
|
||
it { should eq([[0x55] * length + [0xaa] * 40]) } | ||
|
||
context "when length is 350" do | ||
let(:length) { 350 } | ||
|
||
it { should eq([[0x55] * length + [0xaa] * 40]) } | ||
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