[tuxdroid-svn] r399 - api/python/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-06-19 09:08:25
|
Author: jaguarondi Date: 2007-06-19 11:08:24 +0200 (Tue, 19 Jun 2007) New Revision: 399 Modified: api/python/trunk/tuxapi_class.py Log: * Udated the docstrings of the connection class. Modified: api/python/trunk/tuxapi_class.py =================================================================== --- api/python/trunk/tuxapi_class.py 2007-06-19 09:01:20 UTC (rev 398) +++ api/python/trunk/tuxapi_class.py 2007-06-19 09:08:24 UTC (rev 399) @@ -470,9 +470,21 @@ # TUXTCPCommunicator - connect - class #============================================================================== class TUXconnect(object): - """Class which manages connection functions """ + Class which manages connection functions + Functions list for the users: + tux.connect.disconnect_from_tux + tux.connect.connect_to_tux + tux.connect.random_connect_to_tux + tux.connect.id_request + tux.connect.id_lookup + tux.connect.change_id + tux.connect.sleep + tux.connect.wakeup + tux.connect.avoid_wifi + """ + #-------------------------------------------------------------------------- # Constructor of the class #-------------------------------------------------------------------------- @@ -487,6 +499,7 @@ #-------------------------------------------------------------------------- def tux_connection(self, connection_command, connection_args=[]): """ + Not a user function """ if not self.parent.daemon.connected: return 0 @@ -503,8 +516,15 @@ # Disconnect from tux #-------------------------------------------------------------------------- def disconnect_from_tux(self): - """Disconnect from tux """ + Disconnect from tux + + Parameters: + "seconds" as float : Time to wait in seconds + + Example: + >>> tux.sys.wait(2.4) + """ ack_frame = self.tux_connection(TUX_CONNECTION_DISCONNECT) if not ack_frame or ord(ack_frame[5]) != TUX_CONNECTION_ACK: return False @@ -515,8 +535,20 @@ # Connect to a tux by its ID #-------------------------------------------------------------------------- def connect_to_tux(self, id): - """Connect to a tux by its ID """ + Connect to a tux by its ID + + Parameters: + "id" as uint16 : ID of the tux you want to connect to + 0 and 0xFFFF (65536) are not valid ID's + + Returns: + "True" if the command has been sent successfully, + "False" otherwise. + + Example: + >>> tux.connect.connect_to_tux(300) + """ # 0 is an invalid id and 0xFFFF is reserved assert 0 < id < 0xFFFF id_msb = id >> 8 @@ -532,10 +564,15 @@ # Connect to the first tux discovered #-------------------------------------------------------------------------- def random_connect_to_tux(self): - """Connect to the first tux discovered + """ + Connect to the first tux discovered Catch any disconnected tux, request it's ID and connect to it. + Returns: + "True" if the command has been sent successfully, + "False" otherwise. + """ ack_frame = self.tux_connection(TUX_CONNECTION_RANDOM) if not ack_frame or ord(ack_frame[5]) != TUX_CONNECTION_ACK: @@ -547,8 +584,14 @@ # Get the ID of the first disconnected tux which is discoverred #-------------------------------------------------------------------------- def id_request(self): - """Get the ID of tux currently connected """ + Get the ID of tux currently connected + + Returns: + "id" as uint16 (0 < id < 65536) if the command has been sent + successfully, + "False" otherwise. + """ ack_frame = self.tux_connection(TUX_CONNECTION_ID_REQUEST) if ack_frame and ord(ack_frame[5]) == TUX_CONNECTION_ACK: return (ord(ack_frame[6])*256) + ord(ack_frame[7]) @@ -559,14 +602,20 @@ # Get the ID of the first disconnected tux which is discoverred #-------------------------------------------------------------------------- def id_lookup(self): - """Get the ID of the first disconnected tux which is discoverred + """ + Get the ID of the first disconnected tux which is discoverred - The first disconnected tux that will detect this command will reply - with it's ID and disconnect immediately. You can then connect to - that tux with the ID you just got. + The first disconnected tux that will detect this command will reply + with it's ID and disconnect immediately. You can then connect to + that tux with the ID you just got. - In order to get the ID's of more than one disconnected tux, you have - to issue this command multiple times until you don't get any new ID. + In order to get the ID's of more than one disconnected tux, you have + to issue this command multiple times until you don't get any new ID. + + Returns: + "id" as uint16 (0 < id < 65536) if the command has been sent + successfully, + "False" otherwise. """ ack_frame = self.tux_connection(TUX_CONNECTION_ID_LOOKUP) if ack_frame and ord(ack_frame[5]) == TUX_CONNECTION_ACK: @@ -578,11 +627,20 @@ # Changes the ID of a disconnected tux #-------------------------------------------------------------------------- def change_id(self, id): - """Changes the ID of a disconnected tux + """ + Changes the ID of a disconnected tux - You have to push on the head button of tux for XXX seconds while - sending this command in order to validate the ID change request, this - in order to avoid stealing a tux too easily. + You have to push on the head button of tux for XXX seconds while + sending this command in order to validate the ID change request, this + in order to avoid stealing a tux too easily. + + Parameters: + "id" as uint16 : new ID you want to set to your tux + 0 and 0xFFFF (65536) are not valid ID's + + Returns: + "True" if the command has been sent successfully, + "False" otherwise. """ assert 0 < id < 0xFFFF id_msb = id >> 8 @@ -598,8 +656,13 @@ # Set tux in sleep mode #-------------------------------------------------------------------------- def sleep(self): - """Set tux in sleep mode """ + Set tux in sleep mode + + Returns: + "True" if the command has been sent successfully, + "False" otherwise. + """ ack_frame = self.tux_connection(TUX_CONNECTION_SLEEP) if not ack_frame or ord(ack_frame[5]) != TUX_CONNECTION_ACK: return False @@ -610,8 +673,17 @@ # Wake-up a tux if it's in sleep mode. #-------------------------------------------------------------------------- def wakeup(self, id): - """Wake-up a tux if it's in sleep mode. """ + Wake-up a tux if it's in sleep mode. + + Parameters: + "id" as uint16 : ID of the tux you want to wake-up + 0 and 0xFFFF (65536) are not valid ID's + + Returns: + "True" if the command has been sent successfully, + "False" otherwise. + """ assert 0 < id < 0xFFFF id_msb = id >> 8 id_lsb = id % 256 @@ -626,11 +698,19 @@ # Configure the RF module to avoid a given wifi channel #-------------------------------------------------------------------------- def avoid_wifi(self, channel): - """Configure the RF module to avoid a given wifi channel + """ + Configure the RF module to avoid a given wifi channel - Channels from 1 to 14 are valid wifi channels. Set the wifi channel to - 0 to disable channel avoidance and use the complete range of - frequencies. + + Parameters: + "channel" : wifi channel number that tux should avoid using + Channels from 1 to 14 are valid wifi channels. Set the wifi + channel to 0 to disable channel avoidance and use the + complete range of frequencies. + + Returns: + "True" if the command has been sent successfully, + "False" otherwise. """ ack_frame = self.tux_connection(TUX_CONNECTION_WIRELESS_CHANNEL, [channel]) |