build_watcher 0.1.0 → 0.1.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.
- data/History.txt +5 -1
- data/Manifest.txt +3 -0
- data/lib/build_watcher/fake_serial_port.rb +40 -0
- data/lib/build_watcher/message.rb +61 -0
- data/lib/build_watcher/zigbee_device.rb +79 -0
- data/lib/build_watcher.rb +1 -1
- metadata +5 -2
data/History.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
-
=== 0.
|
1
|
+
=== 0.1.1 / 21-APR-2010 / 9ef8534bc8e6719bd5e9fb01dc13b7d699288990
|
2
|
+
|
3
|
+
* Added files forgotten in manifest
|
4
|
+
|
5
|
+
=== 0.1.0 / 21-APR-2010 / 9ef8534bc8e6719bd5e9fb01dc13b7d699288990
|
2
6
|
|
3
7
|
* Initial release
|
data/Manifest.txt
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module BuildWatcher
|
2
|
+
class FakeSerialPort
|
3
|
+
attr_reader :projects, :messages_sent, :messages_received
|
4
|
+
attr_accessor :read_timeout
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@projects = []
|
8
|
+
@messages_sent = []
|
9
|
+
@messages_received = []
|
10
|
+
@serial_buffer = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def register_project(public_key, private_key)
|
14
|
+
@projects << [public_key, private_key]
|
15
|
+
end
|
16
|
+
|
17
|
+
# If an array is passed in, the first element is "sent"
|
18
|
+
# and the second element is added to the list of messages
|
19
|
+
# recieved
|
20
|
+
def puts(content)
|
21
|
+
message, response = content
|
22
|
+
@messages_sent << message
|
23
|
+
|
24
|
+
unless response.nil?
|
25
|
+
@messages_received << response
|
26
|
+
@serial_buffer << response
|
27
|
+
end
|
28
|
+
|
29
|
+
message
|
30
|
+
end
|
31
|
+
|
32
|
+
def read
|
33
|
+
buffers_contents = @serial_buffer.join
|
34
|
+
@serial_buffer = []
|
35
|
+
buffers_contents
|
36
|
+
end
|
37
|
+
|
38
|
+
def close; end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module BuildWatcher
|
2
|
+
class Message
|
3
|
+
MSG_START = "\002"
|
4
|
+
MSG_END = "\003"
|
5
|
+
MSG_SEP = "\037"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def project_qty_request
|
9
|
+
quantity_request
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns an array of the request which would be generated, as well
|
13
|
+
# as the associated response for this request.
|
14
|
+
#
|
15
|
+
# Only intended for testing purposes!
|
16
|
+
def project_qty_request!(number_of_projects_to_return)
|
17
|
+
[quantity_request, project_qty_response(number_of_projects_to_return)]
|
18
|
+
end
|
19
|
+
|
20
|
+
def project_qty_response(number_of_projects)
|
21
|
+
wrap separate("N", number_of_projects)
|
22
|
+
end
|
23
|
+
|
24
|
+
def project_info_request(project_index)
|
25
|
+
wrap separate("G", project_index)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns an array of the request which would be generated, as well
|
29
|
+
# as the associated response for this request.
|
30
|
+
#
|
31
|
+
# Only intended for testing purposes!
|
32
|
+
def project_info_request!(project_index, public_key_returned, private_key_returned)
|
33
|
+
[project_info_request(project_index), project_info_response(public_key_returned, private_key_returned)]
|
34
|
+
end
|
35
|
+
|
36
|
+
def project_info_response(public_key, private_key)
|
37
|
+
wrap separate("I", public_key, private_key)
|
38
|
+
end
|
39
|
+
|
40
|
+
def project_status(public_key, status)
|
41
|
+
unless status && [:nobuilds,:running, :failed, :successful].include?(status.to_sym)
|
42
|
+
raise ArgumentError, "Invalid status supplied (provided: '#{status}')"
|
43
|
+
end
|
44
|
+
wrap separate("S", public_key, status.split(//).first.upcase)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def wrap(string)
|
49
|
+
"#{MSG_START}#{string}#{MSG_END}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def separate(*list)
|
53
|
+
list.join(MSG_SEP)
|
54
|
+
end
|
55
|
+
|
56
|
+
def quantity_request
|
57
|
+
wrap "Q"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module BuildWatcher
|
2
|
+
class ZigbeeDevice
|
3
|
+
def initialize(device)
|
4
|
+
@device = device
|
5
|
+
@connection = "USE #serial_device INSTEAD OF CONNECTION DIRECTLY"
|
6
|
+
Struct.new("ProjectInfo", :public_key, :private_key) unless defined?(Struct::ProjectInfo)
|
7
|
+
end
|
8
|
+
|
9
|
+
def project_quantity
|
10
|
+
serial_device do
|
11
|
+
request_project_count
|
12
|
+
sleep(0.5)
|
13
|
+
read_project_count
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def project_info(project_index)
|
18
|
+
serial_device do
|
19
|
+
request_project_info(project_index)
|
20
|
+
sleep(0.5)
|
21
|
+
read_project_info
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def broadcast_status(public_key, status)
|
26
|
+
serial_device do |connection|
|
27
|
+
connection.puts(Message.project_status(public_key, status))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def request_project_count
|
33
|
+
@connection.puts Message.project_qty_request
|
34
|
+
end
|
35
|
+
|
36
|
+
def read_project_count
|
37
|
+
quantity_message = first_quantity_message_on_buffer
|
38
|
+
if quantity_message.nil?
|
39
|
+
raise AppropriateMessageTypeNotFound, "No 'quantity' message type found on serial buffer."
|
40
|
+
end
|
41
|
+
|
42
|
+
quantity_message.split(/#{Message::MSG_SEP}/).last.to_i
|
43
|
+
end
|
44
|
+
|
45
|
+
def first_quantity_message_on_buffer
|
46
|
+
individual_messages.find {|m| m[0].chr == "N"}
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_project_info(project_index)
|
50
|
+
@connection.puts Message.project_info_request(project_index)
|
51
|
+
end
|
52
|
+
|
53
|
+
def read_project_info
|
54
|
+
project_info = first_project_info_message_on_buffer
|
55
|
+
if project_info.nil?
|
56
|
+
raise AppropriateMessageTypeNotFound, "No 'project info' message type found on serial buffer."
|
57
|
+
end
|
58
|
+
|
59
|
+
#Struct.new("ProjectInfo", :public_key, :private_key)
|
60
|
+
Struct::ProjectInfo.new(*project_info.split(/#{Message::MSG_SEP}/).slice(1,3))
|
61
|
+
end
|
62
|
+
|
63
|
+
def first_project_info_message_on_buffer
|
64
|
+
individual_messages.find {|m| m[0].chr == "I"}
|
65
|
+
end
|
66
|
+
|
67
|
+
def individual_messages
|
68
|
+
@connection.read.scan(/#{Message::MSG_START}(.*?)#{Message::MSG_END}/).flatten
|
69
|
+
end
|
70
|
+
|
71
|
+
def serial_device(&block)
|
72
|
+
@connection = SerialPort.new(@device, 9600)
|
73
|
+
@connection.read_timeout = -1
|
74
|
+
yield @connection
|
75
|
+
ensure
|
76
|
+
@connection.close
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/build_watcher.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tom Kersten
|
@@ -80,6 +80,9 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- bin/update_listeners
|
82
82
|
- lib/build_watcher.rb
|
83
|
+
- lib/build_watcher/fake_serial_port.rb
|
84
|
+
- lib/build_watcher/message.rb
|
85
|
+
- lib/build_watcher/zigbee_device.rb
|
83
86
|
- lib/update_listeners/cli.rb
|
84
87
|
- script/console
|
85
88
|
- script/destroy
|