ruby-xbee 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/apicontrol.rb ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.dirname(__FILE__)
3
+
4
+ require 'date'
5
+ require 'ruby-xbee'
6
+ require 'pp'
7
+
8
+ @xbee = XBee::BaseAPIModeInterface.new(@xbee_usbdev_str)
9
+
10
+ puts "Testing API now ..."
11
+ puts "====================================================="
12
+ puts "Association Indication: 0x%02x" % @xbee.association_indication
13
+ puts "-----------------------------------------------------"
14
+ puts "Firmware Rev: 0x%04x" % @xbee.fw_rev
15
+ puts "-----------------------------------------------------"
16
+ puts "Hardware Rev: 0x%04x" % @xbee.hw_rev
17
+ puts "-----------------------------------------------------"
18
+ puts "Serial Number High: 0x%08x" % @xbee.serial_num_high
19
+ puts "Serial Number Low: 0x%08x" % @xbee.serial_num_low
20
+ puts "Serial Number: 0x%016x" % @xbee.serial_num
21
+ puts "-----------------------------------------------------"
22
+ puts "Detecting neighbors ..."
23
+ response = @xbee.neighbors
24
+ response.each do |r|
25
+ puts "----------------------"
26
+ r.each do |key, val|
27
+ puts case key
28
+ when :NI
29
+ "#{key} = '#{val}'"
30
+ when :STATUS, :DEVICE_TYPE
31
+ "#{key} = 0x%02x" % val
32
+ when :SH, :SL
33
+ "#{key} = 0x%08x" % val
34
+ else "#{key} = 0x%04x" % val
35
+ end
36
+ end
37
+ end
data/bin/apilisten.rb ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.dirname(__FILE__)
3
+
4
+ require 'date'
5
+ require 'ruby-xbee'
6
+ require 'pp'
7
+
8
+ @uart_config = XBee::Config::XBeeUARTConfig.new()
9
+ @xbee = XBee::BaseAPIModeInterface.new(@xbee_usbdev_str, @uart_config, 'API')
10
+
11
+ # read XBee output forever
12
+ while 1
13
+ @xbee.getresponse true
14
+ end
data/bin/ruby-xbee.rb ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'rubygems'
4
+ gem 'ruby-xbee'
5
+ rescue LoadError => e
6
+ load_path_addition = File.dirname(File.dirname(__FILE__)) + "/lib"
7
+ puts "Falling back to extended load path #{load_path_addition}"
8
+ $: << load_path_addition
9
+ require 'ruby_xbee'
10
+ end
11
+
12
+ @xbee_usbdev_str = case ARGV[0]
13
+ when "cable"
14
+ "/dev/tty.usbserial-A101KYF6"
15
+ else
16
+ "/dev/tty.usbserial-A101KYF6"
17
+ end
18
+
19
+ # default baud - this can be overridden on the command line
20
+ @xbee_baud = 9600
21
+
22
+ # serial framing
23
+ @data_bits = 8
24
+ @stop_bits = 1
25
+ @parity = 0
26
+
27
+ puts File.dirname(File.dirname(__FILE__)) + "/lib"
@@ -0,0 +1,263 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # == Synopsis
4
+ # xbeeconfigure.rb - A utility for configuring an XBee using Ruby and the Ruby::XBee class
5
+ #
6
+ # :title: xbeeconfigure.rb A utility for configuring an XBee using Ruby and the Ruby::XBee class
7
+ #
8
+ # == Usage
9
+ # === Syntax
10
+ # ./xbeeconfigure.rb [options]
11
+ #
12
+ # Command line help
13
+ #
14
+ # ./xbeeconfigure.rb --help
15
+ # xbeeconfigure.rb [options]
16
+ # Options:
17
+ # [--panid new_pan_id] [-p new_pan_id] sets the XBee PAN ID
18
+ # [--channel new_channel] [-c new_channel] sets the new channel number for XBee RF
19
+ # [--mysrc new_address] [-M new_address] sets MY 16-bit source address (0-0xffff)
20
+ # [--nodeid new_node_id] [-n new_node_id] sets the text for the XBee node ID
21
+ # [--desthigh highaaddress] [-H highaddress] sets the high portion of the destination address
22
+ # [--destlow low_address] [-L low_address] sets the low portion of the destination address
23
+ # [--parity [NEOMS]] [-P [NEOMS]] sets new parity, N = 8bit no-parity, E = 8bit even, O = 8bit odd, M = 8bit mark, S = 8bit space
24
+ # [--newbaud baud_rate] [-B baud_rate] sets a new baud rate in XBee to take effect after configuration is complete
25
+ # [--dev device] [-d device] use this device to talk to XBee (ie: /dev/tty.usb-791jdas)
26
+ # [--baud baud_rate] [-b baud_rate] use this baud rate for configuring the device
27
+ # [--save] [-s] write new configuration to XBee flash when finished; default is: configuration is not flashed
28
+ # [--help] print this command help message
29
+ #
30
+ #
31
+ # Example usage
32
+ # ./xbeeconfigure.rb --nodeid BaseStation --panid 01 --mysrc 01 -H0 -L 2 -s
33
+ #
34
+ # The command above configures an XBee with a human readable node ID of "BaseStation", a PAN ID of 1, sets the device's MY 16-bit source
35
+ # address to 1, sets the destination to point to an XBee in a 16-bit addressing mode with a low address of 2 (-L 2) and a high of 0
36
+ # which determines this is a 16-bit address.) Finally, the -s causes the new configuration to be saved in XBee flash when
37
+ # the configuration is completed. The "BaseStation" node id is reported as one of the attributes from neighboring nodes.
38
+ #
39
+ # Since there are both long and short versions of the same options, an equivalent, shorter command line is:
40
+ # ./xbeeconfigure.rb -n BaseStation -M 01 -M 01 -H0 -L 2 -s
41
+ #
42
+ # See conf/xbeeconfig.rb for configuration defaults
43
+ #
44
+ # this code is designed for the following XBee modules:
45
+ # IEEE® 802.15.4 OEM RF Modules by Digi International
46
+ # Series 1 XBee and XBee Pro modules
47
+ #
48
+ # == Copyright
49
+ # Copyright (C) 2008-2009 360VL, Inc. and Landon Cox
50
+ #
51
+ # == License
52
+ # This program is free software: you can redistribute it and/or modify
53
+ # it under the terms of the GNU Affero General Public License version 3 as
54
+ # published by the Free Software Foundation.
55
+ #
56
+ # This program is distributed in the hope that it will be useful,
57
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
58
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59
+ # GNU Affero General Public License version 3 for more details.
60
+ #
61
+ # You should have received a copy of the GNU Affero General Public License along with this program.
62
+ # If not, see http://www.gnu.org/licenses/
63
+ #
64
+ # == See Also
65
+ # xbeeinfo.rb, xbeeconfigure.rb, xbeedio.rb, xbeelisten.rb, xbeesend.rb
66
+ #
67
+ # == Learn More
68
+ #
69
+ # You can learn more about Ruby::XBee and other projects at http://sawdust.see-do.org
70
+ #
71
+ # see Digi product manual: "Product Manual v1.xCx - 802.15.4 Protocol"
72
+ # for details on the operation of XBee series 1 modules.
73
+
74
+ $: << File.dirname(__FILE__)
75
+
76
+ require 'date'
77
+ require 'getoptlong'
78
+
79
+ require 'ruby-xbee'
80
+
81
+ @xbee_config_version = "xbeeconfig 1.0"
82
+
83
+ =begin rdoc
84
+ dump usage info to the console
85
+ =end
86
+ def dump_help
87
+
88
+ puts "xbeeconfigure.rb [options]"
89
+ puts "Options:"
90
+ puts " [--panid new_pan_id] [-p new_pan_id] sets the XBee PAN ID" # set panid
91
+ puts " [--channel new_channel] [-c new_channel] sets the new channel number for XBee RF" # set channel
92
+ puts " [--mysrc new_address] [-M new_address] sets MY 16-bit source address (0-0xffff)"
93
+ puts " [--nodeid new_node_id] [-n new_node_id] sets the text for the XBee node ID" # set nodeid
94
+ puts " [--desthigh highaddress] [-H highaddress] sets the high portion of the destination address" # set destination high address
95
+ puts " [--destlow low_address] [-L low_address] sets the low portion of the destination address" # set destination low address
96
+ puts " [--parity [NEOMS]] [-P [NEOMS]] sets new parity, N = 8bit no-parity, E = 8bit even, O = 8bit odd, M = 8bit mark, S = 8bit space"
97
+ puts " [--newbaud baud_rate] [-B baud_rate] sets a new baud rate in XBee to take effect after configuration is complete"
98
+
99
+ puts " [--dev device] [-d device] use this device to talk to XBee (ie: /dev/tty.usb-791jdas)"
100
+ puts " [--baud baud_rate] [-b baud_rate] use this baud rate for configuring the device" # override baud
101
+ puts " [--save] [-s] write new configuration to XBee flash when finished; default is: configuration is not flashed"
102
+ puts " [--help] print this command help message"
103
+
104
+ puts "\nSee conf/xbeeconfig.rb for defaults and edit conf/xbeeconfig.rb to change the defaults used to communicate with the device"
105
+ puts "\nCopyright (C) 2008-2009 360VL, Inc and Landon Cox"
106
+ puts "\nThis program comes with ABSOLUTELY NO WARRANTY;"
107
+ puts "This is free software, and you are welcome to redistribute it"
108
+ puts "under certain conditions detailed in: GNU Affero General Public License version 3"
109
+
110
+ end
111
+
112
+ =begin rdoc
113
+ configure the command line parameters to accept
114
+ =end
115
+ def setup_cli_options
116
+
117
+ @options = GetoptLong.new()
118
+ @options.quiet = true
119
+
120
+ @options_array = Array.new
121
+
122
+ @options_array << [ "--panid", "-p", GetoptLong::REQUIRED_ARGUMENT ] # set panid
123
+ @options_array << [ "--nodeid", "-n", GetoptLong::REQUIRED_ARGUMENT ] # set nodeid
124
+ @options_array << [ "--desthigh", "-H", GetoptLong::REQUIRED_ARGUMENT ] # set destination high address
125
+ @options_array << [ "--destlow", "-L", GetoptLong::REQUIRED_ARGUMENT ] # set destination low address
126
+ @options_array << [ "--channel", "-c", GetoptLong::REQUIRED_ARGUMENT ] # set channel
127
+ @options_array << [ "--parity", "-P", GetoptLong::REQUIRED_ARGUMENT ] # set parity
128
+ @options_array << [ "--newbaud", "-B", GetoptLong::REQUIRED_ARGUMENT ] # set new baud rate in XBee, will not take effect until exiting command mode or AT command mode timeout
129
+ @options_array << [ "--mysrc", "-M", GetoptLong::REQUIRED_ARGUMENT ] # set nodeid
130
+
131
+ @options_array << [ "--dev", "-d", GetoptLong::REQUIRED_ARGUMENT ] # override serial /dev string
132
+ @options_array << [ "--baud", "-b", GetoptLong::REQUIRED_ARGUMENT ] # use this baud to configure device
133
+ @options_array << [ "--save", "-s", GetoptLong::NO_ARGUMENT ] # write new configuration to XBee flash when finished
134
+ @options_array << [ "--help", "-h", GetoptLong::NO_ARGUMENT ] # help message
135
+ @options_array << [ "--version", "-v", GetoptLong::NO_ARGUMENT ] # get version of xbeeconfig.rb
136
+
137
+ @options.set_options( *@options_array )
138
+ end
139
+
140
+ =begin rdoc
141
+ process the command line interface options and set the appropriate variables with the cli data
142
+ =end
143
+ def process_cli_options
144
+
145
+ @options.each do | opt, arg |
146
+
147
+ case opt
148
+
149
+ when "--panid"
150
+ @panid = arg
151
+
152
+ when "--nodeid"
153
+ @nodeid = arg
154
+
155
+ when "--mysrc"
156
+ @mysrc = arg
157
+
158
+ when "--dev"
159
+ @xbee_usbdev_str = arg
160
+
161
+ when "--baud"
162
+ @xbee_baud = arg
163
+
164
+ when "--newbaud"
165
+ @new_baud_rate = arg
166
+
167
+ when "--desthigh"
168
+ @dest_high = arg
169
+
170
+ when "--destlow"
171
+ @dest_low = arg
172
+
173
+ when "--channel"
174
+ @channel = arg
175
+
176
+ when "--parity"
177
+ @newparity = arg
178
+
179
+ when "--help"
180
+ dump_help
181
+ exit 0
182
+
183
+ when "--version"
184
+ puts @xbeeconfig_version
185
+ exit 0
186
+
187
+ when "--save"
188
+ @save = true
189
+
190
+ end # case
191
+ end # options
192
+ end
193
+
194
+ =begin rdoc
195
+ after the cli options have been processed, the configuration is executed
196
+ =end
197
+ def execute_configuration
198
+ # start the configuration
199
+
200
+ @xbee = XBee.new( @xbee_usbdev_str, @xbee_baud, @data_bits, @stop_bits, @parity )
201
+
202
+ # before doing anything else, put XBee into AT command mode
203
+
204
+ puts "Attention..."
205
+ if !@xbee.attention.match("OK")
206
+ puts "Can't talk to XBee. Please check your connection or configuration: #{res}"
207
+ exit 1
208
+ end
209
+
210
+ # execute configuration
211
+
212
+ if @panid
213
+ puts "Setting PAN ID"
214
+ @xbee.pan_id!(@panid)
215
+ puts "PAN id: #{@xbee.pan_id}"
216
+ end
217
+
218
+ if @mysrc
219
+ puts "Setting MY 16-bit source address"
220
+ @xbee.my_src_address!( @mysrc.upcase )
221
+ end
222
+
223
+ if @nodeid
224
+ puts "Setting Node ID"
225
+ @xbee.node_id!(@nodeid)
226
+ end
227
+
228
+ if @dest_high && @dest_low
229
+ puts "Setting destination address"
230
+ @xbee.destination_high!(@dest_high)
231
+ @xbee.destination_low!(@dest_low)
232
+ end
233
+
234
+ if @channel
235
+ puts "Setting channel"
236
+ @xbee.channel!(@channel)
237
+ puts "Channel: #{@xbee.channel}"
238
+ end
239
+
240
+ if @new_baud_rate
241
+ puts "Setting new baud rate"
242
+ @xbee.baud!(new_baud_rate)
243
+ end
244
+
245
+ if @newparity
246
+ puts "Setting new parity"
247
+ @xbee.parity!( @newparity.upcase.to_sym )
248
+ end
249
+
250
+ if @save
251
+ puts "Saving configuration to XBee flash"
252
+ @xbee.save!
253
+ end
254
+
255
+ puts "Exiting AT command mode"
256
+ @xbee.exit_command_mode
257
+
258
+ end
259
+
260
+ setup_cli_options
261
+ process_cli_options
262
+ execute_configuration
263
+
data/bin/xbeedio.rb ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synopsis
3
+ # xbeedio.rb - A Ruby utility for reading DIO port configuration and sample data
4
+ #
5
+ # :title: A Ruby utility for configuring and manipulating XBee DIO ports
6
+ # == Usage
7
+ # xbeedio.rb
8
+ #
9
+ # See conf/xbeeconfig.rb for configuration defaults
10
+ #
11
+ # Example output from xbeedio.rb
12
+ # $ ./xbeedio.rb
13
+ # Attention: OK
14
+ # Port 0: Disabled
15
+ # Port 1: DI
16
+ # Port 2: Disabled
17
+ # Port 3: Disabled
18
+ # Port 4: Disabled
19
+ # Port 5: Associated_Indicator
20
+ # Port 6: Disabled
21
+ # Port 7: CTS
22
+ # Port 8: Disabled
23
+ # DIO inputs:
24
+ # Number of Samples: 1
25
+ # Channel mask: 002
26
+ # DIO data: 002
27
+ #
28
+ # this code is designed for the following XBee modules:
29
+ # IEEE® 802.15.4 OEM RF Modules by Digi International
30
+ # Series 1 XBee and XBee Pro modules
31
+ #
32
+ # == Copyright
33
+ #
34
+ # Copyright (C) 2008-2009 360VL, Inc. and Landon Cox
35
+ #
36
+ # == License
37
+ # This program is free software: you can redistribute it and/or modify
38
+ # it under the terms of the GNU Affero General Public License version 3 as
39
+ # published by the Free Software Foundation.
40
+ #
41
+ # This program is distributed in the hope that it will be useful,
42
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
43
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44
+ # GNU Affero General Public License version 3 for more details.
45
+ #
46
+ # You should have received a copy of the GNU Affero General Public License along with this program.
47
+ # If not, see http://www.gnu.org/licenses/
48
+ #
49
+ # == See Also
50
+ # xbeeinfo.rb, xbeeconfigure.rb, xbeedio.rb, xbeelisten.rb, xbeesend.rb
51
+
52
+ # == Learn More
53
+ # You can learn more about Ruby::XBee and other projects at http://sawdust.see-do.org
54
+ #
55
+ # see Digi product manual: "Product Manual v1.xCx - 802.15.4 Protocol"
56
+ # for details on the operation of XBee series 1 modules.
57
+
58
+ $: << File.dirname(__FILE__)
59
+
60
+ require 'date'
61
+ require 'ruby-xbee'
62
+ require 'pp'
63
+
64
+ @xbee = XBee.new( @xbee_usbdev_str, @xbee_baud, @data_bits, @stop_bits, @parity )
65
+
66
+ puts "Attention: #{@xbee.attention}"
67
+
68
+ 0.upto(8) do | num |
69
+ portsym = "D#{num}".to_sym
70
+ puts "Port #{num}: #{@xbee.dio( portsym )}"
71
+ end
72
+
73
+ puts "DIO inputs:"
74
+ results = @xbee.io_input
75
+ if ( !results.nil? && results[:ERROR].nil? )
76
+ puts "Number of Samples: #{results[:NUM]}"
77
+ puts "Channel mask: #{results[:CM]}"
78
+ puts "DIO data: #{results[:DIO]}"
79
+
80
+ # up to 6 lines (ADC0-ADC5) of ADC could be present if all enabled
81
+ 0.upto(5) do | adc_channel |
82
+ adcsym = "ADC#{adc_channel}".to_sym
83
+ if ( !results[adcsym].nil? )
84
+ puts "ADC#{adc_channel} data: #{results[adcsym]}"
85
+ end
86
+ end
87
+ else
88
+ puts "No DIO input data to report"
89
+ end
data/bin/xbeeinfo.rb ADDED
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+ # == Synopsis
3
+ # xbeeinfo.rb - A Ruby utility for extracting XBee setup information using xbee ruby class (Ruby::XBee)
4
+ #
5
+ # :title: A Ruby utility for extracting XBee setup information using xbee ruby class (Ruby::XBee)
6
+ # == Usage
7
+ # ./xbeeinfo.rb
8
+ #
9
+ # example output from xbeeinfo:
10
+ # Attention: OK
11
+ # Firmware: 10CD
12
+ # Hardware: 180B
13
+ # Baud: 9600
14
+ # Parity: None
15
+ # Neighbors:
16
+ # [{:SL=>"4008A642", :DB=>"-56", :NI=>" ", :MY=>"0", :SH=>"13A200"},
17
+ # {:SL=>"4008A697", :DB=>"-75", :NI=>" ", :MY=>"0", :SH=>"13A200"},
18
+ # {:SL=>"40085AD5", :DB=>"-64", :NI=>" ", :MY=>"0", :SH=>"13A200"}]
19
+ # Node ID: BaseStation
20
+ # Channel: C
21
+ # PAN ID: 1
22
+ # MY: 1
23
+ # SH: 13A200
24
+ # SL: 4008A64E
25
+ # DH: 0
26
+ # DL: 2
27
+ # Last received signal strength (dBm): -36
28
+ # Port 0: Disabled
29
+ # Port 1: DI
30
+ # Port 2: Disabled
31
+ # Port 3: Disabled
32
+ # Port 4: Disabled
33
+ # Port 5: Associated_Indicator
34
+ # Port 6: Disabled
35
+ # Port 7: CTS
36
+ # Port 8: Disabled
37
+ #
38
+ # See conf/xbeeconfig.rb for configuration defaults
39
+ #
40
+ # this code is designed for the following XBee modules:
41
+ # IEEE® 802.15.4 OEM RF Modules by Digi International
42
+ # Series 1 XBee and XBee Pro modules
43
+ #
44
+ # == Copyright
45
+ # Copyright (C) 2008-2009 360VL, Inc. and Landon Cox
46
+ #
47
+ # == License
48
+ #
49
+ # This program is free software: you can redistribute it and/or modify
50
+ # it under the terms of the GNU Affero General Public License version 3 as
51
+ # published by the Free Software Foundation.
52
+ #
53
+ # This program is distributed in the hope that it will be useful,
54
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
55
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56
+ # GNU Affero General Public License version 3 for more details.
57
+ #
58
+ # You should have received a copy of the GNU Affero General Public License along with this program.
59
+ # If not, see http://www.gnu.org/licenses/
60
+ #
61
+ # == See Also
62
+ # xbeeinfo.rb, xbeeconfigure.rb, xbeedio.rb, xbeelisten.rb, xbeesend.rb
63
+ #
64
+ # == Learn more
65
+ # You can learn more about Ruby::XBee and other projects at http://sawdust.see-do.org
66
+ #
67
+ # see Digi product manual: "Product Manual v1.xCx - 802.15.4 Protocol"
68
+ # for details on the operation of XBee series 1 modules.
69
+
70
+
71
+ $: << File.dirname(__FILE__)
72
+
73
+ require 'date'
74
+ require 'ruby-xbee'
75
+
76
+ STDIN.sync = 1
77
+ STDOUT.sync = 1
78
+ $stdin.sync = true
79
+ $stdout.sync = true
80
+
81
+ require 'pp'
82
+
83
+ @xbee = XBee.new( @xbee_usbdev_str, @xbee_baud, @data_bits, @stop_bits, @parity )
84
+
85
+ puts "Attention: #{@xbee.attention}"
86
+ puts "Firmware: #{@xbee.fw_rev}"
87
+ puts "Hardware: #{@xbee.hw_rev}"
88
+
89
+ puts "Baud: #{@xbee.baud}"
90
+ puts "Parity: #{@xbee.parity}"
91
+
92
+ puts "Neighbors:"
93
+ pp @xbee.neighbors
94
+
95
+ puts "Node ID: #{@xbee.node_id}"
96
+ puts "Channel: #{@xbee.channel}"
97
+ puts "PAN ID: #{@xbee.pan_id}"
98
+ puts "MY: #{@xbee.my_src_address}"
99
+ puts "SH: #{@xbee.serial_num_high}"
100
+ puts "SL: #{@xbee.serial_num_low}"
101
+ puts "DH: #{@xbee.destination_high}"
102
+ puts "DL: #{@xbee.destination_low}"
103
+ puts "Last received signal strength (dBm): #{@xbee.received_signal_strength}"
104
+
105
+ 0.upto(8) do | num |
106
+ portsym = "D#{num}".to_sym
107
+ puts "Port #{num}: #{@xbee.dio( portsym )}"
108
+ end
109
+
110
+
data/bin/xbeelisten.rb ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ # == Synposis
3
+ # xbeelisten.rb - A ruby utility for listening to data output from an XBee
4
+ #
5
+ # :title: xbeelisten.rb - A ruby utility for listening to data output from an XBee
6
+ #
7
+ # == Copyright
8
+ # Copyright (C) 2008-2009 360VL, Inc. and Landon Cox
9
+ #
10
+ # == License
11
+ # This program is free software: you can redistribute it and/or modify
12
+ # it under the terms of the GNU Affero General Public License version 3 as
13
+ # published by the Free Software Foundation.
14
+ #
15
+ # This program is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU Affero General Public License version 3 for more details.
19
+ #
20
+ # You should have received a copy of the GNU Affero General Public License along with this program.
21
+ # If not, see http://www.gnu.org/licenses/
22
+ #
23
+ # You can learn more about ruby for XBee and other projects at http://sawdust.see-do.org
24
+ #
25
+ # == Usage
26
+ # ./xbeelisten.rb
27
+ #
28
+ # Example output from xbeelisten...this example is an XBee listening to
29
+ # a Sparkfun USB Weather board which is transmitting data through a 2nd
30
+ # XBee:
31
+ # cooper:ruby-xbee lcox$ ./xbeelisten.rb
32
+ # #10.75,069.47,020.9,069.62,079038,612,050580$
33
+ # #10.22,070.46,021.5,070.70,078998,613,052232$
34
+ # #10.22,070.44,021.6,070.88,078993,613,052233$
35
+ #
36
+ # See conf/xbeeconfig.rb for configuration defaults
37
+ #
38
+ # == See Also
39
+ # xbeeinfo.rb, xbeeconfigure.rb, xbeedio.rb, xbeelisten.rb, xbeesend.rb
40
+ #
41
+ # == Learn more
42
+ # You can learn more about Ruby::XBee and other projects at http://sawdust.see-do.org
43
+ #
44
+ # see Digi product manual: "Product Manual v1.xCx - 802.15.4 Protocol"
45
+ # for details on the operation of XBee series 1 modules.
46
+ #
47
+ # this code is for the following XBee modules:
48
+ # IEEE® 802.15.4 OEM RF Modules by Digi International
49
+ #
50
+
51
+ $: << File.dirname(__FILE__)
52
+
53
+ require 'date'
54
+ require 'getoptlong'
55
+
56
+ require 'ruby-xbee'
57
+
58
+ def dump_help
59
+
60
+ puts "xbeelisten.rb [options]"
61
+ puts "Options:"
62
+
63
+ puts " [--dev device] [-d device] use this device to talk to XBee (ie: /dev/tty.usb-791jdas)"
64
+ puts " [--baud new_baud_rate] [-b new_baud_rate] sets the baud rate with which to talk to the device" # override baud
65
+ puts " [--help] print this command help message"
66
+
67
+ puts "\nSee conf/config.rb for defaults and edit conf/config.rb to change the defaults used to communicate with the device"
68
+ puts "License: GNU Affero General Public License version 3"
69
+ puts "Copyright (C) 2008-2009 360VL, Inc"
70
+ puts "Copyright (C) 2008-2009 Landon Cox"
71
+
72
+ end
73
+
74
+ options = GetoptLong.new()
75
+ options.quiet = true
76
+
77
+ options_array = Array.new
78
+
79
+ options_array << [ "--dev", "-d", GetoptLong::REQUIRED_ARGUMENT ] # override serial /dev string
80
+ options_array << [ "--baud", "-b", GetoptLong::REQUIRED_ARGUMENT ] # override baud
81
+ options_array << [ "--help", "-h", GetoptLong::NO_ARGUMENT ] # write new configuration to XBee flash
82
+
83
+ options.set_options( *options_array )
84
+
85
+ options.each do | opt, arg |
86
+
87
+ case opt
88
+
89
+ when "--dev"
90
+ @xbee_usbdev_str = arg
91
+
92
+ when "--baud"
93
+ @xbee_baud = arg
94
+
95
+ when "--help"
96
+ dump_help
97
+ exit 0
98
+
99
+ when "--save"
100
+ @save = true
101
+
102
+ end
103
+
104
+ end
105
+
106
+ # start a connection to the XBee
107
+ @xbee = XBee.new( @xbee_usbdev_str, @xbee_baud, @data_bits, @stop_bits, @parity )
108
+
109
+ # read XBee output forever
110
+ while( 1 )
111
+ @xbee.getresponse true
112
+ end
113
+
114
+