nxt 0.3.0 → 0.5.0

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 (109) hide show
  1. checksums.yaml +15 -0
  2. data/README.md +45 -0
  3. data/lib/communication/bluetooth_communication.rb +85 -0
  4. data/lib/communication/serial_port_profile.rb +71 -0
  5. data/lib/nxt.rb +111 -20
  6. data/lib/ruby-nxt.sublime-project +8 -0
  7. data/lib/ruby-nxt.sublime-workspace +288 -0
  8. data/lib/telegrams/commands/direct/get_battery_level.rb +8 -0
  9. data/lib/telegrams/commands/direct/get_current_program_name.rb +8 -0
  10. data/lib/{nxt/commands/sound.rb → telegrams/commands/direct/get_input_values.rb} +0 -0
  11. data/lib/{nxt/commands/tone.rb → telegrams/commands/direct/keep_alive.rb} +0 -0
  12. data/lib/telegrams/commands/direct/ls_get_status.rb +0 -0
  13. data/lib/telegrams/commands/direct/ls_read.rb +0 -0
  14. data/lib/telegrams/commands/direct/ls_write.rb +0 -0
  15. data/lib/telegrams/commands/direct/message_read.rb +0 -0
  16. data/lib/telegrams/commands/direct/message_write.rb +0 -0
  17. data/lib/telegrams/commands/direct/output_state.rb +229 -0
  18. data/lib/telegrams/commands/direct/play_sound_file.rb +38 -0
  19. data/lib/telegrams/commands/direct/play_tone.rb +34 -0
  20. data/lib/telegrams/commands/direct/replies/get_battery_level_reply.rb +28 -0
  21. data/lib/telegrams/commands/direct/replies/get_current_program_name_reply.rb +30 -0
  22. data/lib/telegrams/commands/direct/replies/play_sound_file_reply.rb +13 -0
  23. data/lib/telegrams/commands/direct/replies/play_tone_reply.rb +14 -0
  24. data/lib/telegrams/commands/direct/replies/reset_motor_position_reply.rb +13 -0
  25. data/lib/telegrams/commands/direct/replies/set_input_mode_reply.rb +11 -0
  26. data/lib/telegrams/commands/direct/replies/set_output_state_reply.rb +11 -0
  27. data/lib/telegrams/commands/direct/replies/start_program_reply.rb +13 -0
  28. data/lib/telegrams/commands/direct/replies/stop_program_reply.rb +13 -0
  29. data/lib/telegrams/commands/direct/replies/stop_sound_playback_reply.rb +13 -0
  30. data/lib/telegrams/commands/direct/reset_input_scaled_value.rb +0 -0
  31. data/lib/telegrams/commands/direct/reset_motor_position.rb +8 -0
  32. data/lib/telegrams/commands/direct/set_input_mode.rb +101 -0
  33. data/lib/telegrams/commands/direct/set_output_state.rb +29 -0
  34. data/lib/telegrams/commands/direct/start_program.rb +30 -0
  35. data/lib/telegrams/commands/direct/stop_program.rb +9 -0
  36. data/lib/telegrams/commands/direct/stop_sound_playback.rb +8 -0
  37. data/lib/telegrams/commands/direct_command.rb +8 -0
  38. data/lib/telegrams/commands/direct_command_reply.rb +10 -0
  39. data/lib/telegrams/commands/message_translator.rb +46 -0
  40. data/lib/telegrams/commands/system/get_device_info.rb +8 -0
  41. data/lib/telegrams/commands/system/replies/get_device_info_reply.rb +41 -0
  42. data/lib/telegrams/commands/system_command.rb +8 -0
  43. data/lib/telegrams/messages/error.rb +0 -0
  44. data/lib/telegrams/messages/message.rb +0 -0
  45. data/lib/telegrams/messages/success.rb +0 -0
  46. data/lib/telegrams/no_message_reply.rb +10 -0
  47. data/lib/telegrams/reply.rb +82 -0
  48. data/lib/telegrams/respondable_telegram.rb +29 -0
  49. data/lib/telegrams/telegram.rb +14 -0
  50. data/spec/communication/bluetooth_communication_spec.rb +170 -0
  51. data/spec/communication/serial_port_profile_spec.rb +139 -0
  52. data/spec/helper.rb +1 -0
  53. data/spec/nxt_spec.rb +438 -0
  54. data/spec/telegrams/commands/direct/get_battery_level_spec.rb +26 -0
  55. data/spec/telegrams/commands/direct/get_current_program_name_spec.rb +26 -0
  56. data/spec/telegrams/commands/direct/output_state_spec.rb +198 -0
  57. data/spec/telegrams/commands/direct/play_sound_file_spec.rb +75 -0
  58. data/spec/telegrams/commands/direct/play_tone_spec.rb +63 -0
  59. data/spec/telegrams/commands/direct/replies/get_battery_level_reply_spec.rb +40 -0
  60. data/spec/telegrams/commands/direct/replies/get_current_program_name_reply_spec.rb +33 -0
  61. data/spec/telegrams/commands/direct/replies/play_sound_file_reply_spec.rb +13 -0
  62. data/spec/telegrams/commands/direct/replies/play_tone_reply_spec.rb +14 -0
  63. data/spec/telegrams/commands/direct/replies/reset_motor_position_reply_spec.rb +13 -0
  64. data/spec/telegrams/commands/direct/replies/set_input_mode_reply_spec.rb +12 -0
  65. data/spec/telegrams/commands/direct/replies/set_output_state_reply_spec.rb +12 -0
  66. data/spec/telegrams/commands/direct/replies/start_program_reply_spec.rb +12 -0
  67. data/spec/telegrams/commands/direct/replies/stop_program_reply_spec.rb +13 -0
  68. data/spec/telegrams/commands/direct/replies/stop_sound_playback_reply_spec.rb +13 -0
  69. data/spec/telegrams/commands/direct/reset_motor_position_spec.rb +31 -0
  70. data/spec/telegrams/commands/direct/set_input_mode_spec.rb +122 -0
  71. data/spec/telegrams/commands/direct/set_output_state_spec.rb +72 -0
  72. data/spec/telegrams/commands/direct/start_program_spec.rb +58 -0
  73. data/spec/telegrams/commands/direct/stop_program_spec.rb +34 -0
  74. data/spec/telegrams/commands/direct/stop_sound_playback_spec.rb +34 -0
  75. data/spec/telegrams/commands/direct_command_reply_spec.rb +7 -0
  76. data/spec/telegrams/commands/direct_command_spec.rb +34 -0
  77. data/spec/telegrams/commands/system/get_device_info_spec.rb +16 -0
  78. data/spec/telegrams/commands/system/replies/get_device_info_reply_spec.rb +63 -0
  79. data/spec/telegrams/commands/system_command_spec.rb +26 -0
  80. data/spec/telegrams/no_message_reply_spec.rb +12 -0
  81. data/spec/telegrams/reply_spec.rb +63 -0
  82. data/spec/telegrams/respondable_telegram_spec.rb +66 -0
  83. data/spec/telegrams/telegram_spec.rb +38 -0
  84. metadata +97 -116
  85. data/README.markdown +0 -52
  86. data/Rakefile +0 -35
  87. data/lib/nxt/commands/base.rb +0 -51
  88. data/lib/nxt/commands/input.rb +0 -60
  89. data/lib/nxt/commands/output.rb +0 -105
  90. data/lib/nxt/commands/program.rb +0 -70
  91. data/lib/nxt/connectors/base.rb +0 -35
  92. data/lib/nxt/connectors/input/color.rb +0 -30
  93. data/lib/nxt/connectors/input/touch.rb +0 -11
  94. data/lib/nxt/connectors/input/ultrasonic.rb +0 -11
  95. data/lib/nxt/connectors/output/motor.rb +0 -114
  96. data/lib/nxt/errors.rb +0 -25
  97. data/lib/nxt/exceptions.rb +0 -26
  98. data/lib/nxt/interfaces/base.rb +0 -36
  99. data/lib/nxt/interfaces/serial_port.rb +0 -88
  100. data/lib/nxt/interfaces/usb.rb +0 -8
  101. data/lib/nxt/nxt_brick.rb +0 -167
  102. data/lib/nxt/patches/module.rb +0 -22
  103. data/lib/nxt/patches/string.rb +0 -29
  104. data/lib/nxt/utils/accessors.rb +0 -24
  105. data/spec/matchers.rb +0 -7
  106. data/spec/nxt/connectors/output/motor_spec.rb +0 -55
  107. data/spec/nxt/interfaces/serial_port_spec.rb +0 -73
  108. data/spec/nxt/nxt_brick_spec.rb +0 -199
  109. data/spec/spec_helper.rb +0 -4
@@ -0,0 +1,13 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/replies/play_sound_file_reply'
3
+
4
+ describe PlaySoundFileReply do
5
+ it "must have a reply type" do
6
+ PlaySoundFileReply.new([0x02, 0x02, 0x00]).type.must_equal 0x02
7
+ end
8
+
9
+ it "must raise an ArgumentError when the reply is not for a play_sound_file message" do
10
+ -> { PlaySoundFileReply.new([0x02, 0x9A, 0x00]) }.must_raise ArgumentError
11
+ end
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/replies/play_tone_reply.rb'
3
+
4
+ describe PlayToneReply do
5
+ it "must support a reply for the PlayTone command" do
6
+ PlayToneReply.new([0x02, 0x03, 0x00]).success?.must_equal true
7
+ PlayToneReply.new([0x02, 0x03, 0x01]).success?.must_equal false
8
+ end
9
+
10
+ it "must raise an ArgumentError when the reply is not for the PlayTone command" do
11
+ -> { PlayToneReply.new([0x02, 0x00, 0x00]) }.must_raise ArgumentError
12
+ end
13
+
14
+ end
@@ -0,0 +1,13 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/replies/reset_motor_position_reply'
3
+
4
+ describe ResetMotorPositionReply do
5
+ it "must have a reply type" do
6
+ ResetMotorPositionReply.new([0x02, 0x0A, 0x00]).type.must_equal 0x02
7
+ end
8
+
9
+ it "must raise an ArgumentError when the reply is not for a reset_motor_position message" do
10
+ -> { ResetMotorPositionReply.new([0x02, 0x9A, 0x00]) }.must_raise ArgumentError
11
+ end
12
+
13
+ end
@@ -0,0 +1,12 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/replies/set_input_mode_reply'
3
+
4
+ describe SetInputModeReply do
5
+ it "must 5ave a reply type" do
6
+ SetInputModeReply.new([0x02, 0x05, 0x00]).type.must_equal 0x02
7
+ end
8
+
9
+ it "must raise an ArgumentError when the reply is not for a set_input_mode message" do
10
+ -> { SetInputModeReply.new([0x02, 0xFF, 0x00]) }.must_raise ArgumentError
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/replies/set_output_state_reply'
3
+
4
+ describe SetOutputStateReply do
5
+ it "must 5ave a reply type" do
6
+ SetOutputStateReply.new([0x02, 0x04, 0x00]).type.must_equal 0x02
7
+ end
8
+
9
+ it "must raise an ArgumentError when the reply is not for a set_input_mode message" do
10
+ -> { SetOutputStateReply.new([0x02, 0xFF, 0x00]) }.must_raise ArgumentError
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/replies/start_program_reply'
3
+
4
+ describe StartProgramReply do
5
+ it "must have a reply type" do
6
+ StartProgramReply.new([0x02, 0x00, 0x00]).type.must_equal 0x02
7
+ end
8
+
9
+ it "must raise an ArgumentError when the reply is not for a start_program message" do
10
+ -> { StartProgramReply.new([0x02, 0x9A, 0x00]) }.must_raise ArgumentError
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/replies/stop_program_reply'
3
+
4
+ describe StopProgramReply do
5
+ it "must have a reply type" do
6
+ StopProgramReply.new([0x02, 0x01, 0x00]).type.must_equal 0x02
7
+ end
8
+
9
+ it "must raise an ArgumentError when the reply is not for a stop_program message" do
10
+ -> { StopProgramReply.new([0x02, 0x9A, 0x00]) }.must_raise ArgumentError
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/replies/stop_sound_playback_reply'
3
+
4
+ describe StopSoundPlaybackReply do
5
+ it "must have a reply type" do
6
+ StopSoundPlaybackReply.new([0x02, 0x0C, 0x00]).type.must_equal 0x02
7
+ end
8
+
9
+ it "must raise an ArgumentError when the reply is not for a stop_sound_playback message" do
10
+ -> { StopSoundPlaybackReply.new([0x02, 0x9A, 0x00]) }.must_raise ArgumentError
11
+ end
12
+
13
+ end
@@ -0,0 +1,31 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/reset_motor_position'
3
+
4
+ describe ResetMotorPosition do
5
+ before do
6
+ @command = ResetMotorPosition.new
7
+ end
8
+
9
+ it "must be a direct command type" do
10
+ @command.type.must_equal DirectCommand.new.type
11
+ end
12
+
13
+ it "must have a command of 0x0A" do
14
+ @command.command.must_equal 0x0A
15
+ end
16
+
17
+ it "must start out with its type at the first byte" do
18
+ @command.as_bytes[0].must_equal @command.type
19
+ end
20
+
21
+ it "must start out with its command at the second byte" do
22
+ @command.as_bytes[1].must_equal @command.command
23
+ end
24
+
25
+ describe "when NOT wanting to wait for a reply" do
26
+ it "must have a first byte of 0x80" do
27
+ no_wait_command = ResetMotorPosition.new false
28
+ no_wait_command.as_bytes[0].must_equal 0x80
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,122 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/set_input_mode'
3
+
4
+ describe SetInputMode do
5
+ describe "when constructing the command" do
6
+ before do
7
+ @command = SetInputMode.new(:three, :colornone, :booleanmode)
8
+ end
9
+
10
+ it "must be a direct command" do
11
+ @command.type.must_equal DirectCommand.new.type
12
+ end
13
+
14
+ it "must have a command of 0x05" do
15
+ @command.command.must_equal 0x05
16
+ end
17
+
18
+ it "must require a response by default" do
19
+ @command.require_response?.must_equal true
20
+ end
21
+
22
+ it "must throw an ArgumentException if the input_port is not passed in" do
23
+ -> { SetInputMode.new }.must_raise ArgumentError
24
+ end
25
+
26
+ it "must throw an ArgumentException if the sensor_type is not passed in" do
27
+ -> { SetInputMode.new(:one) }.must_raise ArgumentError
28
+ end
29
+
30
+ it "must throw an ArgumentException if the sensor_mode is not passed in" do
31
+ -> { SetInputMode.new(:one, :colorred) }.must_raise ArgumentError
32
+ end
33
+
34
+ it "must set the input_port to what is passed in" do
35
+ SetInputMode.new(:one, :colorblue, :booleanmode).input_port.must_equal :one
36
+ end
37
+
38
+ it "must set the sensor_type to what is passed in" do
39
+ SetInputMode.new(:three, :colorgreen, :booleanmode).sensor_type.must_equal :colorgreen
40
+ end
41
+
42
+ it "must set the sensor_mode to what is passed in" do
43
+ SetInputMode.new(:three, :colorgreen, :booleanmode).sensor_mode.must_equal :booleanmode
44
+ end
45
+
46
+ it "must validate that the input_port is valid (:one, :two, or :three)" do
47
+ -> { SetInputMode.new(:five, :colorgreen, :booleanmode) }.must_raise ArgumentError
48
+ -> { SetInputMode.new(:zero, :colorgreen, :booleanmode) }.must_raise ArgumentError
49
+ SetInputMode.new(:one, :colorgreen, :booleanmode)
50
+ SetInputMode.new(:two, :colorgreen, :booleanmode)
51
+ SetInputMode.new(:three, :colorgreen, :booleanmode)
52
+ end
53
+
54
+ it "must validate the passed in sensor_type is valid" do
55
+ -> { SetInputMode.new(:one, :foobar, :booleanmode) }.must_raise ArgumentError
56
+ SetInputMode.new(:one, :colorfull, :booleanmode)
57
+ end
58
+
59
+ it "must validate the passed in sensor_mode is valid" do
60
+ -> { SetInputMode.new(:one, :colorgreen, :foobarmode) }.must_raise ArgumentError
61
+ SetInputMode.new(:one, :colorgreen, :booleanmode)
62
+ end
63
+ end
64
+
65
+ describe "when getting the valid list of input ports" do
66
+ describe "when accessing the class methods" do
67
+ it "must return an array of symbols for input_ports" do
68
+ SetInputMode.input_ports.must_equal [:one, :two, :three, :four]
69
+ end
70
+
71
+ it "must return an array of symbols for sensor_types" do
72
+ SetInputMode.sensor_types.must_include :sound_db
73
+ end
74
+
75
+ it "must return an array of symbols for sensor_modes" do
76
+ SetInputMode.sensor_modes.must_include :rawmode
77
+ end
78
+
79
+ end
80
+
81
+ describe "when accessing the instance methods" do
82
+ before do
83
+ @command = SetInputMode.new(:one, :colornone, :booleanmode)
84
+ end
85
+
86
+ it "must return an array of symbols for input_ports" do
87
+ @command.input_ports.must_equal [:one, :two, :three, :four]
88
+ end
89
+
90
+ it "must return an array of symbols for sensor_types" do
91
+ @command.sensor_types.must_include :sound_db
92
+ end
93
+
94
+ it "must return an array of symbols for sensor_modes" do
95
+ @command.sensor_modes.must_include :rawmode
96
+ end
97
+
98
+ end
99
+ end
100
+ describe "when rendering the command as bytes" do
101
+ before do
102
+ @command = SetInputMode.new(:three, :colorgreen, :booleanmode)
103
+ end
104
+
105
+ it "must set byte 1 to 0x05 as the SetInputMode command" do
106
+ @command.as_bytes[1].must_equal 0x05
107
+ end
108
+
109
+ it "must set byte 2 to the input port value" do
110
+ @command.as_bytes[2].must_equal 0x02
111
+ end
112
+
113
+ it "must set byte 3 to the sensor type value" do
114
+ @command.as_bytes[3].must_equal 0x0F
115
+ end
116
+
117
+ it "must set byte 4 to the sensor mode value" do
118
+ @command.as_bytes[4].must_equal 0x20
119
+ end
120
+ end
121
+
122
+ end
@@ -0,0 +1,72 @@
1
+ require './spec/helper'
2
+ require './lib/telegrams/commands/direct/set_output_state'
3
+
4
+ describe SetOutputState do
5
+ describe 'when constructing the object' do
6
+ it "must set the command to 0x04 for set_output_state" do
7
+ SetOutputState.new(OutputState.new).command.must_equal 0x04
8
+ end
9
+
10
+ it "must raise an ArgumentError when the output_state is nil" do
11
+ -> { SetOutputState.new(nil) }.must_raise ArgumentError
12
+ end
13
+
14
+ it "must set the output_state member to what is passed in" do
15
+ state = OutputState.new
16
+ SetOutputState.new(state).instance_eval('output_state').must_equal state
17
+ end
18
+ end
19
+
20
+ describe "when calling as_bytes" do
21
+ before do
22
+ @state = OutputState.new({
23
+ :port => :b,
24
+ :power => 50,
25
+ :mode_flags => OutputModeFlags.MOTORON | OutputModeFlags.REGULATED,
26
+ :regulation_mode => :motor_sync,
27
+ :turn_ratio => -25,
28
+ :run_state => :running,
29
+ :tacho_limit => 39123
30
+ })
31
+
32
+ @command = SetOutputState.new @state
33
+ @bytes = @command.as_bytes
34
+ end
35
+
36
+ it "must have the command type as the byte 0" do
37
+ @bytes[0].must_equal 0x00
38
+ end
39
+
40
+ it "must have the proper command as the byte 1" do
41
+ @bytes[1].must_equal 0x04
42
+ end
43
+
44
+ it "must have the output port as byte 2" do
45
+ @bytes[2].must_equal 0x01
46
+ end
47
+
48
+ it "must have the power set point as byte 3" do
49
+ @bytes[3].must_equal 50
50
+ end
51
+
52
+ it "must have the mode set as byte 4" do
53
+ @bytes[4].must_equal 0x05 # (motoron and regulated)
54
+ end
55
+
56
+ it "must have the regulation mode set at byte 5" do
57
+ @bytes[5].must_equal 0x02 # (motor_sync)
58
+ end
59
+
60
+ it "must have the turn ratio set at byte 6" do
61
+ @bytes[6].must_equal -25
62
+ end
63
+
64
+ it "must have the run state set at byte 7" do
65
+ @bytes[7].must_equal 0x20
66
+ end
67
+
68
+ it "must have the tacho limit set to bytes 8-12 in little endian" do
69
+ @bytes[8..12].must_equal [211, 152, 0, 0]
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,58 @@
1
+ require './spec/helper'
2
+
3
+ require './lib/telegrams/commands/direct/start_program'
4
+
5
+
6
+ describe StartProgram do
7
+ describe "when creating the start program command" do
8
+ it "must default to requiring a response" do
9
+ StartProgram.new('name').require_response?.must_equal true
10
+ end
11
+
12
+ it "must set the require_response member to the value passed in" do
13
+ StartProgram.new('name', false).require_response?.must_equal false
14
+ end
15
+
16
+ it "must raise an ArgumentError when the program name is nil" do
17
+ -> { StartProgram.new(nil) }.must_raise ArgumentError
18
+ end
19
+
20
+ it "must set the command value to 0x00 (startprogram)" do
21
+ StartProgram.new('name').command.must_equal 0x00
22
+ end
23
+
24
+ it "must set the program name to the value passed in" do
25
+ StartProgram.new('name.rxe').name.must_equal 'name.rxe'
26
+ end
27
+
28
+ it "must try adding '.rxe' to the end of the filename if there is no file extension" do
29
+ name = 'program'
30
+ StartProgram.new(name).name.must_equal "#{name}.rxe"
31
+ end
32
+
33
+ it "must leave the filename alone if there is a 3 letter extension of any kind" do
34
+ name = 'program.foo'
35
+ StartProgram.new(name).name.must_equal name
36
+ end
37
+ end
38
+
39
+ describe "when rendering the command using as_bytes" do
40
+ it "must have the command value as the second byte" do
41
+ command = StartProgram.new('name')
42
+ command.as_bytes[1].must_equal command.command
43
+ end
44
+
45
+ it "must have the program name in ASCIIZ (null terminated ascii) for bytes 3-22" do
46
+ name = 'myrobot.rxe'
47
+ name_as_asciiz = [109, 121, 114, 111, 98, 111, 116, 46, 114, 120, 101, 0,
48
+ 0, 0, 0, 0, 0, 0, 0, 0]
49
+
50
+ command = StartProgram.new(name)
51
+ bytes = command.as_bytes
52
+ name_bytes = bytes.slice(2, 20)
53
+
54
+ name_bytes.must_equal name_as_asciiz
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,34 @@
1
+ require './spec/helper'
2
+
3
+ require './lib/telegrams/commands/direct/stop_sound_playback'
4
+
5
+
6
+ describe StopSoundPlayback do
7
+ before do
8
+ @command = StopSoundPlayback.new
9
+ end
10
+
11
+ it "must be a direct command type" do
12
+ @command.type.must_equal DirectCommand.new.type
13
+ end
14
+
15
+ it "must have a command of 0x0C" do
16
+ @command.command.must_equal 0x0C
17
+ end
18
+
19
+ it "must start out with its type at the first byte" do
20
+ @command.as_bytes[0].must_equal @command.type
21
+ end
22
+
23
+ it "must start out with its command at the second byte" do
24
+ @command.as_bytes[1].must_equal @command.command
25
+ end
26
+
27
+ describe "when NOT wanting to wait for a reply" do
28
+ it "must have a first byte of 0x80" do
29
+ no_wait_command = StopSoundPlayback.new false
30
+ no_wait_command.as_bytes[0].must_equal 0x80
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,34 @@
1
+ require './spec/helper'
2
+
3
+ require './lib/telegrams/commands/direct/stop_program'
4
+
5
+
6
+ describe StopProgram do
7
+ before do
8
+ @command = StopProgram.new
9
+ end
10
+
11
+ it "must be a direct command type" do
12
+ @command.type.must_equal StopProgram.new.type
13
+ end
14
+
15
+ it "must have a command of 0x01" do
16
+ @command.command.must_equal 0x01
17
+ end
18
+
19
+ it "must start out with its type at the first byte" do
20
+ @command.as_bytes[0].must_equal @command.type
21
+ end
22
+
23
+ it "must start out with its command at the second byte" do
24
+ @command.as_bytes[1].must_equal @command.command
25
+ end
26
+
27
+ describe "when NOT wanting to wait for a reply" do
28
+ it "must have a first byte of 0x80" do
29
+ no_wait_command = StopProgram.new false
30
+ no_wait_command.as_bytes[0].must_equal 0x80
31
+ end
32
+ end
33
+ end
34
+