ieee.py
Go to the documentation of this file.
00001 """
00002 ieee.py
00003 
00004 By Paul Malmsten, 2010
00005 Inspired by code written by Amit Synderman and Marco Sangalli
00006 pmalmsten@gmail.com
00007 
00008 This module provides an XBee (IEEE 802.15.4) API library.
00009 """
00010 import struct
00011 from xbee.base import XBeeBase
00012 
00013 class XBee(XBeeBase):
00014     """
00015     Provides an implementation of the XBee API for IEEE 802.15.4 modules
00016     with recent firmware.
00017     
00018     Commands may be sent to a device by instansiating this class with
00019     a serial port object (see PySerial) and then calling the send
00020     method with the proper information specified by the API. Data may
00021     be read from a device syncronously by calling wait_read_frame. For
00022     asynchronous reads, see the definition of XBeeBase.
00023     """
00024     # Packets which can be sent to an XBee
00025     
00026     # Format: 
00027     #        {name of command:
00028     #           [{name:field name, len:field length, default: default value sent}
00029     #            ...
00030     #            ]
00031     #         ...
00032     #         }
00033     api_commands = {"at":
00034                         [{'name':'id',        'len':1,      'default':'\x08'},
00035                          {'name':'frame_id',  'len':1,      'default':'\x00'},
00036                          {'name':'command',   'len':2,      'default':None},
00037                          {'name':'parameter', 'len':None,   'default':None}],
00038                     "queued_at":
00039                         [{'name':'id',        'len':1,      'default':'\x09'},
00040                          {'name':'frame_id',  'len':1,      'default':'\x00'},
00041                          {'name':'command',   'len':2,      'default':None},
00042                          {'name':'parameter', 'len':None,   'default':None}],
00043                     "remote_at":
00044                         [{'name':'id',              'len':1,        'default':'\x17'},
00045                          {'name':'frame_id',        'len':1,        'default':'\x00'},
00046                          # dest_addr_long is 8 bytes (64 bits), so use an unsigned long long
00047                          {'name':'dest_addr_long',  'len':8,        'default':struct.pack('>Q', 0)},
00048                          {'name':'dest_addr',       'len':2,        'default':'\xFF\xFE'},
00049                          {'name':'options',         'len':1,        'default':'\x02'},
00050                          {'name':'command',         'len':2,        'default':None},
00051                          {'name':'parameter',       'len':None,     'default':None}],
00052                     "tx_long_addr":
00053                         [{'name':'id',              'len':1,        'default':'\x00'},
00054                          {'name':'frame_id',        'len':1,        'default':'\x00'},
00055                          {'name':'dest_addr',       'len':8,        'default':None},
00056                          {'name':'options',         'len':1,        'default':'\x00'},
00057                          {'name':'data',            'len':None,     'default':None}],
00058                     "tx":
00059                         [{'name':'id',              'len':1,        'default':'\x01'},
00060                          {'name':'frame_id',        'len':1,        'default':'\x00'},
00061                          {'name':'dest_addr',       'len':2,        'default':None},
00062                          {'name':'options',         'len':1,        'default':'\x00'},
00063                          {'name':'data',            'len':None,     'default':None}]
00064                     }
00065     
00066     # Packets which can be received from an XBee
00067     
00068     # Format: 
00069     #        {id byte received from XBee:
00070     #           {name: name of response
00071     #            structure:
00072     #                [ {'name': name of field, 'len':length of field}
00073     #                  ...
00074     #                  ]
00075     #            parse_as_io_samples:name of field to parse as io
00076     #           }
00077     #           ...
00078     #        }
00079     #
00080     api_responses = {"\x80":
00081                         {'name':'rx_long_addr',
00082                          'structure':
00083                             [{'name':'source_addr', 'len':8},
00084                              {'name':'rssi',        'len':1},
00085                              {'name':'options',     'len':1},
00086                              {'name':'rf_data',     'len':None}]},
00087                      "\x81":
00088                         {'name':'rx',
00089                          'structure':
00090                             [{'name':'source_addr', 'len':2},
00091                              {'name':'rssi',        'len':1},
00092                              {'name':'options',     'len':1},
00093                              {'name':'rf_data',     'len':None}]},
00094                      "\x82":
00095                         {'name':'rx_io_data_long_addr',
00096                          'structure':
00097                             [{'name':'source_addr_long','len':8},
00098                              {'name':'rssi',            'len':1},
00099                              {'name':'options',         'len':1},
00100                              {'name':'samples',         'len':None}],
00101                          'parse_as_io_samples':'samples'},
00102                      "\x83":
00103                         {'name':'rx_io_data',
00104                          'structure':
00105                             [{'name':'source_addr', 'len':2},
00106                              {'name':'rssi',        'len':1},
00107                              {'name':'options',     'len':1},
00108                              {'name':'samples',     'len':None}],
00109                          'parse_as_io_samples':'samples'},
00110                      "\x89":
00111                         {'name':'tx_status',
00112                          'structure':
00113                             [{'name':'frame_id',    'len':1},
00114                              {'name':'status',      'len':1}]},
00115                      "\x8a":
00116                         {'name':'status',
00117                          'structure':
00118                             [{'name':'status',      'len':1}]},
00119                      "\x88":
00120                         {'name':'at_response',
00121                          'structure':
00122                             [{'name':'frame_id',    'len':1},
00123                              {'name':'command',     'len':2},
00124                              {'name':'status',      'len':1},
00125                              {'name':'parameter',   'len':None}]},
00126                      "\x97":
00127                         {'name':'remote_at_response',
00128                          'structure':
00129                             [{'name':'frame_id',        'len':1},
00130                              {'name':'source_addr_long','len':8},
00131                              {'name':'source_addr',     'len':2},
00132                              {'name':'command',         'len':2},
00133                              {'name':'status',          'len':1},
00134                              {'name':'parameter',       'len':None}]},
00135                      }
00136     
00137     def __init__(self, *args, **kwargs):
00138         # Call the super class constructor to save the serial port
00139         super(XBee, self).__init__(*args, **kwargs)


rosserial_xbee
Author(s): Adam Stambler
autogenerated on Fri Dec 6 2013 20:35:48