movingsign_api 0.0.1

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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +8 -0
  5. data/.yardopts +1 -0
  6. data/CHANGELOG.md +11 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +60 -0
  10. data/Rakefile +1 -0
  11. data/lib/movingsign_api/commands/command.rb +76 -0
  12. data/lib/movingsign_api/commands/hard_reset_command.rb +16 -0
  13. data/lib/movingsign_api/commands/internal/align_mode.rb +50 -0
  14. data/lib/movingsign_api/commands/internal/display_mode.rb +61 -0
  15. data/lib/movingsign_api/commands/internal/display_pause.rb +33 -0
  16. data/lib/movingsign_api/commands/internal/display_speed.rb +45 -0
  17. data/lib/movingsign_api/commands/internal/file_handle.rb +54 -0
  18. data/lib/movingsign_api/commands/internal/pretty_keyable.rb +50 -0
  19. data/lib/movingsign_api/commands/internal/sender_receiver_address.rb +82 -0
  20. data/lib/movingsign_api/commands/internal/utilities.rb +8 -0
  21. data/lib/movingsign_api/commands/set_clock_command.rb +32 -0
  22. data/lib/movingsign_api/commands/set_sound_command.rb +21 -0
  23. data/lib/movingsign_api/commands/software_reset_command.rb +16 -0
  24. data/lib/movingsign_api/commands/write_control_command.rb +35 -0
  25. data/lib/movingsign_api/commands/write_text_command.rb +116 -0
  26. data/lib/movingsign_api/errors.rb +22 -0
  27. data/lib/movingsign_api/sign.rb +144 -0
  28. data/lib/movingsign_api/version.rb +3 -0
  29. data/lib/movingsign_api.rb +13 -0
  30. data/movingsign_api.gemspec +30 -0
  31. data/spec/align_mode_spec.rb +28 -0
  32. data/spec/commands/set_sound_command_spec.rb +19 -0
  33. data/spec/display_mode_spec.rb +57 -0
  34. data/spec/display_speed_spec.rb +23 -0
  35. data/spec/examples/example_A_spec.rb +24 -0
  36. data/spec/examples/example_C_spec.rb +16 -0
  37. data/spec/examples/example_D_spec.rb +14 -0
  38. data/spec/examples/example_K_spec.rb +14 -0
  39. data/spec/examples/expected.rb +130 -0
  40. data/spec/file_handle_spec.rb +17 -0
  41. data/spec/sender_receiver_address_spec.rb +60 -0
  42. data/spec/spec_helper.rb +19 -0
  43. data/spec/tutorials/readme_1.rb +5 -0
  44. data/spec/tutorials/readme_2.rb +5 -0
  45. data/spec/tutorials/tutorials_spec.rb +14 -0
  46. metadata +188 -0
@@ -0,0 +1,130 @@
1
+ # Contains the expected binary output for the examples given in the "MovingSign Communication Protocol V2.1" specification
2
+
3
+ EXAMPLE_A_EXPECTED = [
4
+ 0x00, # <NUL> x 5
5
+ 0x00, # <NUL> x 5
6
+ 0x00, # <NUL> x 5
7
+ 0x00, # <NUL> x 5
8
+ 0x00, # <NUL> x 5
9
+ 0x01, # <SOH>
10
+ 0x46, # Sender Address, 'FF'
11
+ 0x46, # Sender Address, 'FF'
12
+ 0x30, # Receiver Address, '03'
13
+ 0x33, # Receiver Address, '03'
14
+ 0x02, # <SOT> Start of Text
15
+ 0x41, # Command 'A' - Write Text File
16
+ 0x41, # Text File Name 'A'
17
+ 0x41, # Text Display Mode 'A'
18
+ 0x32, # Text Display Speed '2'
19
+ 0x32, # Pause Seconds '2'
20
+ 0x37, # Display Every Day '7F'
21
+ 0x46, # Display Every Day '7F'
22
+ 0x30, # Display Time Start '0100'
23
+ 0x31, # Display Time Start '0100'
24
+ 0x30, # Display Time Start '0100'
25
+ 0x30, # Display Time Start '0100'
26
+ 0x31, # Display Time End '1200'
27
+ 0x32, # Display Time End '1200'
28
+ 0x30, # Display Time End '1200'
29
+ 0x30, # Display Time End '1200'
30
+ 0x30, # No Use '000'
31
+ 0x30, # No Use '000'
32
+ 0x30, # No Use '000'
33
+ 0x31, # Alight Left '1'
34
+ 0x48, # Text Body: 'HELLO'
35
+ 0x45, # Text Body: 'HELLO'
36
+ 0x4C, # Text Body: 'HELLO'
37
+ 0x4C, # Text Body: 'HELLO'
38
+ 0x4F, # Text Body: 'HELLO'
39
+ 0x03, # <ETX>
40
+ 0x30, # Checksum '0562' - spec says '0564' but it is wrong
41
+ 0x35, # Checksum '0562'
42
+ 0x36, # Checksum '0562'
43
+ 0x32, # Checksum '0562'
44
+ 0x04, # <EOT>
45
+ ]
46
+
47
+ EXAMPLE_C_EXPECTED = [
48
+ 0x00, # <NUL> x 5
49
+ 0x00, # <NUL> x 5
50
+ 0x00, # <NUL> x 5
51
+ 0x00, # <NUL> x 5
52
+ 0x00, # <NUL> x 5
53
+ 0x01, # <SOH>
54
+ 0x46, # Sender Address, 'FF'
55
+ 0x46, # Sender Address, 'FF'
56
+ 0x32, # Receiver Address, 34 dec, 22 hex
57
+ 0x32, # Receiver Address, 34 dec, 22 hex
58
+ 0x02, # <SOT> Start of Text
59
+ 0x57, # Command 'W' - Control Command
60
+ 0x41, # Sub Command 'A' - Write Clock Command
61
+ 0x32, # Clock Data 200404021236235 - 2
62
+ 0x30, # Clock Data 200404021236235 - 0
63
+ 0x30, # Clock Data 200404021236235 - 0
64
+ 0x34, # Clock Data 200404021236235 - 4
65
+ 0x30, # Clock Data 200404021236235 - 0
66
+ 0x34, # Clock Data 200404021236235 - 4
67
+ 0x30, # Clock Data 200404021236235 - 0
68
+ 0x32, # Clock Data 200404021236235 - 2
69
+ 0x31, # Clock Data 200404021236235 - 1
70
+ 0x32, # Clock Data 200404021236235 - 2
71
+ 0x33, # Clock Data 200404021236235 - 3
72
+ 0x36, # Clock Data 200404021236235 - 6
73
+ 0x32, # Clock Data 200404021236235 - 2
74
+ 0x33, # Clock Data 200404021236235 - 3
75
+ 0x35, # Clock Data 200404021236235 - 5
76
+ 0x03, # <EOT>
77
+ 0x30, # Checksum '038F'
78
+ 0x33, # Checksum '038F'
79
+ 0x38, # Checksum '038F'
80
+ 0x46, # Checksum '038F'
81
+ 0x04, # <EOT>
82
+ ]
83
+
84
+ EXAMPLE_D_EXPECTED = [
85
+ 0x00, # <NUL> x 5
86
+ 0x00, # <NUL> x 5
87
+ 0x00, # <NUL> x 5
88
+ 0x00, # <NUL> x 5
89
+ 0x00, # <NUL> x 5
90
+ 0x01, # <SOH>
91
+ 0x46, # Sender Address, 'FF'
92
+ 0x46, # Sender Address, 'FF'
93
+ 0x32, # Receiver Address, 34 dec, 22 hex
94
+ 0x32, # Receiver Address, 34 dec, 22 hex
95
+ 0x02, # <SOT> Start of Text
96
+ 0x57, # Command 'W' - Control Command
97
+ 0x42, # Sub Command 'B' - Software Reset
98
+ 0x03, # <EOT>
99
+ 0x30, # Checksum '009E'
100
+ 0x30, # Checksum '009E'
101
+ 0x39, # Checksum '009E'
102
+ 0x45, # Checksum '009E'
103
+ 0x04, # <EOT>
104
+ ]
105
+
106
+ EXAMPLE_K_EXPECTED = [
107
+ 0x00, # <NUL> x 5
108
+ 0x00, # <NUL> x 5
109
+ 0x00, # <NUL> x 5
110
+ 0x00, # <NUL> x 5
111
+ 0x00, # <NUL> x 5
112
+ 0x01, # <SOH>
113
+ 0x46, # Sender Address, 'FF'
114
+ 0x46, # Sender Address, 'FF'
115
+ 0x31, # Receiver Address, 16 dec, 10 hex
116
+ 0x30, # Receiver Address, 16 dec, 10 hex
117
+ 0x02, # <SOT> Start of Text
118
+ 0x57, # Command 'W' - Control Command
119
+ 0x4C, # Sub Command 'L' - Software Reset
120
+ 0x03, # <EOT>
121
+ 0x30, # Checksum '00A8'
122
+ 0x30, # Checksum '00A8'
123
+ 0x41, # Checksum '00A8'
124
+ 0x38, # Checksum '00A8'
125
+ 0x04, # <EOT>
126
+ ]
127
+
128
+ # Calc checksum
129
+ sum = EXAMPLE_K_EXPECTED[10..-6].reduce(:+)
130
+ puts ('%04x' % sum).upcase
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe MovingsignApi::FileHandle do
4
+ it '::handle_to_code' do
5
+ expect(described_class.handle_to_code(0)).to eq '0'
6
+ expect(described_class.handle_to_code(9)).to eq '9'
7
+ expect(described_class.handle_to_code(10)).to eq 'A'
8
+ expect(described_class.handle_to_code(35)).to eq 'Z'
9
+ end
10
+
11
+ it '::code_to_handle' do
12
+ expect(described_class.code_to_handle('0')).to eq 0
13
+ expect(described_class.code_to_handle('9')).to eq 9
14
+ expect(described_class.code_to_handle('A')).to eq 10
15
+ expect(described_class.code_to_handle('Z')).to eq 35
16
+ end
17
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe MovingsignApi::SenderReceiverAddress do
4
+ describe '::parse' do
5
+ it "Integer" do
6
+ # valid broadcast address
7
+ expect(described_class.parse(0).to_s).to eq '00'
8
+ expect(described_class.parse(0)).to be_broadcast
9
+
10
+ expect(described_class.parse(3).to_s).to eq '03'
11
+
12
+ # valid pc address
13
+ expect(described_class.parse(255).to_s).to eq 'FF'
14
+ expect(described_class.parse(255)).to be_pc
15
+
16
+ # out of range
17
+ expect { described_class.parse(-1) }.to raise_error(MovingsignApi::InvalidInputError)
18
+ expect { described_class.parse(256) }.to raise_error(MovingsignApi::InvalidInputError)
19
+ end
20
+
21
+ it "Symbols :pc and :broadcast" do
22
+ expect(described_class.parse(:broadcast).to_s).to eq '00'
23
+ expect(described_class.parse(:broadcast)).to be_broadcast
24
+
25
+ expect(described_class.parse(:pc).to_s).to eq 'FF'
26
+ expect(described_class.parse(:pc)).to be_pc
27
+
28
+ expect { described_class.parse(:invalid) }.to raise_error(MovingsignApi::InvalidInputError)
29
+ end
30
+
31
+ it 'String' do
32
+ # valid broadcast address
33
+ expect(described_class.parse('00').to_s).to eq '00'
34
+ expect(described_class.parse('00')).to be_broadcast
35
+
36
+ expect(described_class.parse('0a').to_s).to eq '0A'
37
+
38
+ # valid pc address
39
+ expect(described_class.parse('ff').to_s).to eq 'FF'
40
+ expect(described_class.parse('FF').to_s).to eq 'FF'
41
+ expect(described_class.parse('FF')).to be_pc
42
+
43
+ # valid with wildcard
44
+ expect(described_class.parse('1?').to_s).to eq '1?'
45
+ expect(described_class.parse('?5').to_s).to eq '?5'
46
+
47
+ # invalid (only one character)
48
+ expect { described_class.parse('?') }.to raise_error(MovingsignApi::InvalidInputError)
49
+ expect { described_class.parse('0') }.to raise_error(MovingsignApi::InvalidInputError)
50
+
51
+ # invalid (out of hex range)
52
+ expect { described_class.parse('?Z') }.to raise_error(MovingsignApi::InvalidInputError)
53
+ end
54
+ end
55
+
56
+ it "#to_bytes" do
57
+ expect(described_class.parse(:pc).to_bytes).to eq [0x46, 0x46]
58
+ expect(described_class.parse(3).to_bytes).to eq [0x30, 0x33]
59
+ end
60
+ end
@@ -0,0 +1,19 @@
1
+ require 'movingsign_api'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
@@ -0,0 +1,5 @@
1
+ require 'movingsign_api'
2
+
3
+ sign = MovingsignApi::Sign.new '/dev/ttyUSB0'
4
+
5
+ sign.show_text "Hello World"
@@ -0,0 +1,5 @@
1
+ require 'movingsign_api'
2
+
3
+ sign = MovingsignApi::Sign.new '/dev/ttyUSB0'
4
+
5
+ sign.show_text "Hello World"
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Tutorial Examples" do
4
+ describe "README Example 1" do
5
+ it "Works" do
6
+ pending "Todo"
7
+
8
+ path = File.join(File.dirname(__FILE__), 'readme_1.rb')
9
+ script = File.read(path)
10
+
11
+ eval(File.read(path), nil, path)
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: movingsign_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Webb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-19 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.7.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.7.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: wwtd
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: serialport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ description: MovingSign Communication Protocol V2.1 Implementation in Ruby
98
+ email:
99
+ - opensource@collectivegenius.net
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .travis.yml
107
+ - .yardopts
108
+ - CHANGELOG.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/movingsign_api.rb
114
+ - lib/movingsign_api/commands/command.rb
115
+ - lib/movingsign_api/commands/hard_reset_command.rb
116
+ - lib/movingsign_api/commands/internal/align_mode.rb
117
+ - lib/movingsign_api/commands/internal/display_mode.rb
118
+ - lib/movingsign_api/commands/internal/display_pause.rb
119
+ - lib/movingsign_api/commands/internal/display_speed.rb
120
+ - lib/movingsign_api/commands/internal/file_handle.rb
121
+ - lib/movingsign_api/commands/internal/pretty_keyable.rb
122
+ - lib/movingsign_api/commands/internal/sender_receiver_address.rb
123
+ - lib/movingsign_api/commands/internal/utilities.rb
124
+ - lib/movingsign_api/commands/set_clock_command.rb
125
+ - lib/movingsign_api/commands/set_sound_command.rb
126
+ - lib/movingsign_api/commands/software_reset_command.rb
127
+ - lib/movingsign_api/commands/write_control_command.rb
128
+ - lib/movingsign_api/commands/write_text_command.rb
129
+ - lib/movingsign_api/errors.rb
130
+ - lib/movingsign_api/sign.rb
131
+ - lib/movingsign_api/version.rb
132
+ - movingsign_api.gemspec
133
+ - spec/align_mode_spec.rb
134
+ - spec/commands/set_sound_command_spec.rb
135
+ - spec/display_mode_spec.rb
136
+ - spec/display_speed_spec.rb
137
+ - spec/examples/example_A_spec.rb
138
+ - spec/examples/example_C_spec.rb
139
+ - spec/examples/example_D_spec.rb
140
+ - spec/examples/example_K_spec.rb
141
+ - spec/examples/expected.rb
142
+ - spec/file_handle_spec.rb
143
+ - spec/sender_receiver_address_spec.rb
144
+ - spec/spec_helper.rb
145
+ - spec/tutorials/readme_1.rb
146
+ - spec/tutorials/readme_2.rb
147
+ - spec/tutorials/tutorials_spec.rb
148
+ homepage: ''
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.0.14
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: MovingSign Communication Protocol V2.1 Implementation in Ruby
172
+ test_files:
173
+ - spec/align_mode_spec.rb
174
+ - spec/commands/set_sound_command_spec.rb
175
+ - spec/display_mode_spec.rb
176
+ - spec/display_speed_spec.rb
177
+ - spec/examples/example_A_spec.rb
178
+ - spec/examples/example_C_spec.rb
179
+ - spec/examples/example_D_spec.rb
180
+ - spec/examples/example_K_spec.rb
181
+ - spec/examples/expected.rb
182
+ - spec/file_handle_spec.rb
183
+ - spec/sender_receiver_address_spec.rb
184
+ - spec/spec_helper.rb
185
+ - spec/tutorials/readme_1.rb
186
+ - spec/tutorials/readme_2.rb
187
+ - spec/tutorials/tutorials_spec.rb
188
+ has_rdoc: