ruby-xbee 1.1.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.
- checksums.yaml +15 -0
- data/LICENSE +11 -0
- data/README.rdoc +232 -0
- data/Rakefile +38 -0
- data/agpl.txt +661 -0
- data/bin/apicontrol.rb +37 -0
- data/bin/apilisten.rb +14 -0
- data/bin/ruby-xbee.rb +27 -0
- data/bin/xbeeconfigure.rb +263 -0
- data/bin/xbeedio.rb +89 -0
- data/bin/xbeeinfo.rb +110 -0
- data/bin/xbeelisten.rb +114 -0
- data/bin/xbeesend.rb +81 -0
- data/lib/apimode/at_commands.rb +28 -0
- data/lib/apimode/frame/at_command.rb +34 -0
- data/lib/apimode/frame/at_command_response.rb +33 -0
- data/lib/apimode/frame/explicit_addressing_command.rb +7 -0
- data/lib/apimode/frame/explicit_rx_indicator.rb +6 -0
- data/lib/apimode/frame/frame.rb +123 -0
- data/lib/apimode/frame/modem_status.rb +32 -0
- data/lib/apimode/frame/receive_packet.rb +6 -0
- data/lib/apimode/frame/remote_command_request.rb +34 -0
- data/lib/apimode/frame/remote_command_response.rb +22 -0
- data/lib/apimode/frame/transmit_request.rb +7 -0
- data/lib/apimode/frame/transmit_status.rb +6 -0
- data/lib/apimode/xbee_api.rb +608 -0
- data/lib/legacy/command_mode.rb +553 -0
- data/lib/module_config.rb +77 -0
- data/lib/ruby_xbee.rb +134 -0
- data/test/ruby_xbee_test.rb +20 -0
- data/test/test_helper.rb +22 -0
- metadata +110 -0
data/lib/ruby_xbee.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# == Synopsis
|
2
|
+
# xbee.rb - A Ruby class for manipulating an XBee via the serial communication port of the host
|
3
|
+
#
|
4
|
+
# this code is designed for the following XBee modules:
|
5
|
+
# IEEE® 802.15.4 OEM RF Modules by Digi International
|
6
|
+
# Series 1 XBee and XBee Pro modules
|
7
|
+
#
|
8
|
+
# :title: xbee.rb - A Ruby class for manipulating an XBee via the serial communication port of the host
|
9
|
+
#
|
10
|
+
# == Copyright
|
11
|
+
#
|
12
|
+
# Copyright (C) 2008-2009 360VL, Inc. and Landon Cox
|
13
|
+
#
|
14
|
+
# This program is free software: you can redistribute it and/or modify
|
15
|
+
# it under the terms of the GNU Affero General Public License version 3 as
|
16
|
+
# published by the Free Software Foundation.
|
17
|
+
#
|
18
|
+
# This program is distributed in the hope that it will be useful,
|
19
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21
|
+
# GNU Affero General Public License version 3 for more details.
|
22
|
+
#
|
23
|
+
# You should have received a copy of the GNU Affero General Public License along with this program.
|
24
|
+
# If not, see http://www.gnu.org/licenses/
|
25
|
+
#
|
26
|
+
# You can learn more about Ruby::XBee and other projects at http://sawdust.see-do.org
|
27
|
+
#
|
28
|
+
# see Digi product manual: "Product Manual v1.xCx - 802.15.4 Protocol"
|
29
|
+
# for details on the operation of XBee series 1 modules.
|
30
|
+
|
31
|
+
require 'date'
|
32
|
+
require 'pp'
|
33
|
+
|
34
|
+
require 'rubygems'
|
35
|
+
gem 'serialport'
|
36
|
+
require 'serialport'
|
37
|
+
|
38
|
+
require 'module_config'
|
39
|
+
|
40
|
+
module XBee
|
41
|
+
|
42
|
+
##
|
43
|
+
# supports legacy API, command-mode interface
|
44
|
+
def XBee.new( xbee_usbdev_str, baud, data_bits, stop_bits, parity )
|
45
|
+
require 'legacy/command_mode'
|
46
|
+
BaseCommandModeInterface.new(xbee_usbdev_str, baud, data_bits, stop_bits, parity)
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# a method for getting results from any Ruby SerialPort object. Not ideal, but seems effective enough.
|
51
|
+
def getresults( sp, echo = true )
|
52
|
+
results = ""
|
53
|
+
while (c = sp.getc) do
|
54
|
+
if ( !echo.nil? && echo )
|
55
|
+
putc c
|
56
|
+
end
|
57
|
+
results += "#{c.chr}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# deal with multiple lines
|
61
|
+
results.gsub!( "\r", "\n")
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
##
|
66
|
+
# This is it, the base class where it all starts. Command mode or API mode, version 1 or version 2, all XBees descend
|
67
|
+
# from this class.
|
68
|
+
class RFModule
|
69
|
+
|
70
|
+
VERSION = "2.1"
|
71
|
+
|
72
|
+
include XBee
|
73
|
+
include Config
|
74
|
+
attr_accessor :xbee_serialport, :xbee_uart_config, :guard_time, :command_mode_timeout, :command_character, :node_discover_timeout, :node_identifier, :operation_mode, :transmission_mode
|
75
|
+
attr_reader :serial_number, :hardware_rev, :firmware_rev
|
76
|
+
|
77
|
+
def version
|
78
|
+
VERSION
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# This is the way we instantiate XBee modules now, via this factory method. It will ultimately autodetect what
|
83
|
+
# flavor of XBee module we're using and return the most appropriate subclass to control that module.
|
84
|
+
def initialize(xbee_usbdev_str = "/dev/tty.usbserial-A7004nmf", uart_config = XBeeUARTConfig.new, operation_mode = :AT, transmission_mode = :SYNC)
|
85
|
+
unless uart_config.kind_of?(XBeeUARTConfig)
|
86
|
+
raise "uart_config must be an instance of XBeeUARTConfig for this to work"
|
87
|
+
end
|
88
|
+
unless operation_mode == :AT || operation_mode == :API
|
89
|
+
raise "XBee operation_mode must be either AT or API"
|
90
|
+
end
|
91
|
+
unless transmission_mode == :SYNC || transmission_mode == :ASYNC
|
92
|
+
raise "XBee transmission_mode must be either SYNC (Synchronous) or ASYNC (Asynchronous)"
|
93
|
+
end
|
94
|
+
self.xbee_uart_config = uart_config
|
95
|
+
@xbee_serialport = SerialPort.new( xbee_usbdev_str, uart_config.baud, uart_config.data_bits, uart_config.stop_bits, uart_config.parity )
|
96
|
+
@xbee_serialport.read_timeout = self.read_timeout(:short)
|
97
|
+
@guard_time = GuardTime.new
|
98
|
+
@command_mode_timeout= CommandModeTimeout.new
|
99
|
+
@command_character = CommandCharacter.new
|
100
|
+
@node_discover_timeout = NodeDiscoverTimeout.new
|
101
|
+
@node_identifier = NodeIdentifier.new
|
102
|
+
@operation_mode = operation_mode
|
103
|
+
@transmission_mode = transmission_mode
|
104
|
+
end
|
105
|
+
|
106
|
+
def in_command_mode
|
107
|
+
sleep self.guard_time.in_seconds
|
108
|
+
@xbee_serialport.write(self.command_character.value * 3)
|
109
|
+
sleep self.guard_time.in_seconds
|
110
|
+
@xbee_serialport.read(3)
|
111
|
+
# actually do some work now ...
|
112
|
+
yield if block_given?
|
113
|
+
# Exit command mode
|
114
|
+
@xbee_serialport.write("ATCN\r")
|
115
|
+
@xbee_serialport.read(3)
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# XBee response times vary based on both hardware and firmware versions. These
|
120
|
+
# constants may need to be adjusted for your devices, but these will
|
121
|
+
# work fine for most cases. The unit of time for a timeout constant is ms
|
122
|
+
def read_timeout(type = :short)
|
123
|
+
case type
|
124
|
+
when :short
|
125
|
+
1200
|
126
|
+
when :long
|
127
|
+
3000
|
128
|
+
else 3000
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end # module XBee
|
133
|
+
|
134
|
+
require 'apimode/xbee_api'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$: << File.dirname(__FILE__)
|
2
|
+
require 'test_helper'
|
3
|
+
require 'version'
|
4
|
+
|
5
|
+
# The most simple test there can possibly BE, let's check constant for constant
|
6
|
+
class RubyXbeeTest < MiniTest::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@xbee_version_major = ::XBee::Version::MAJOR
|
9
|
+
@xbee_version_minor = ::XBee::Version::MINOR
|
10
|
+
@xbee_version_patch = ::XBee::Version::PATCH
|
11
|
+
@xbee_version_string = ::XBee::Version::STRING
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_version_matches_testsuite
|
15
|
+
assert_equal 1, @xbee_version_major
|
16
|
+
assert_equal 1, @xbee_version_minor
|
17
|
+
assert_equal 0, @xbee_version_patch
|
18
|
+
assert_equal '1.1.0', @xbee_version_string
|
19
|
+
end
|
20
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'versioncheck'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/reporters'
|
5
|
+
|
6
|
+
rb_vc = VersionCheck.rubyversion
|
7
|
+
if !rb_vc.have_version?(2,0)
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.command_name 'MiniTest'
|
10
|
+
SimpleCov.start
|
11
|
+
end
|
12
|
+
|
13
|
+
MiniTest::Reporters.use!
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'bin'))
|
17
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
18
|
+
|
19
|
+
require 'ruby_xbee'
|
20
|
+
require 'coveralls'
|
21
|
+
|
22
|
+
Coveralls.wear!
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-xbee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Landon Cox
|
8
|
+
- Mike Ashmore
|
9
|
+
- Sten Feldman
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-03-09 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: serialport
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.1'
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.1.0
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '1.1'
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.1.0
|
35
|
+
description: A Ruby XBee gem
|
36
|
+
email: exile@chamber.ee
|
37
|
+
executables:
|
38
|
+
- apicontrol.rb
|
39
|
+
- apilisten.rb
|
40
|
+
- ruby-xbee.rb
|
41
|
+
- xbeeconfigure.rb
|
42
|
+
- xbeedio.rb
|
43
|
+
- xbeeinfo.rb
|
44
|
+
- xbeelisten.rb
|
45
|
+
- xbeesend.rb
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files:
|
48
|
+
- LICENSE
|
49
|
+
- agpl.txt
|
50
|
+
- README.rdoc
|
51
|
+
files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
- Rakefile
|
55
|
+
- agpl.txt
|
56
|
+
- bin/apicontrol.rb
|
57
|
+
- bin/apilisten.rb
|
58
|
+
- bin/ruby-xbee.rb
|
59
|
+
- bin/xbeeconfigure.rb
|
60
|
+
- bin/xbeedio.rb
|
61
|
+
- bin/xbeeinfo.rb
|
62
|
+
- bin/xbeelisten.rb
|
63
|
+
- bin/xbeesend.rb
|
64
|
+
- lib/apimode/at_commands.rb
|
65
|
+
- lib/apimode/frame/at_command.rb
|
66
|
+
- lib/apimode/frame/at_command_response.rb
|
67
|
+
- lib/apimode/frame/explicit_addressing_command.rb
|
68
|
+
- lib/apimode/frame/explicit_rx_indicator.rb
|
69
|
+
- lib/apimode/frame/frame.rb
|
70
|
+
- lib/apimode/frame/modem_status.rb
|
71
|
+
- lib/apimode/frame/receive_packet.rb
|
72
|
+
- lib/apimode/frame/remote_command_request.rb
|
73
|
+
- lib/apimode/frame/remote_command_response.rb
|
74
|
+
- lib/apimode/frame/transmit_request.rb
|
75
|
+
- lib/apimode/frame/transmit_status.rb
|
76
|
+
- lib/apimode/xbee_api.rb
|
77
|
+
- lib/legacy/command_mode.rb
|
78
|
+
- lib/module_config.rb
|
79
|
+
- lib/ruby_xbee.rb
|
80
|
+
- test/ruby_xbee_test.rb
|
81
|
+
- test/test_helper.rb
|
82
|
+
homepage: http://github.com/exsilium/ruby-xbee
|
83
|
+
licenses:
|
84
|
+
- AGPL
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options:
|
88
|
+
- --charset=UTF-8
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.2.2
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Controlling an XBee module from Ruby either in AT (Transparent) or API mode.
|
107
|
+
Both Series 1 and Series 2 radio modules are supported.
|
108
|
+
test_files:
|
109
|
+
- test/ruby_xbee_test.rb
|
110
|
+
- test/test_helper.rb
|