utils.py
Go to the documentation of this file.
00001 """--------------------------------------------------------------------
00002 COPYRIGHT 2013 SEGWAY Inc.
00003 
00004 Software License Agreement:
00005 
00006 The software supplied herewith by Segway Inc. (the "Company") for its 
00007 RMP Robotic Platforms is intended and supplied to you, the Company's 
00008 customer, for use solely and exclusively with Segway products. The 
00009 software is owned by the Company and/or its supplier, and is protected 
00010 under applicable copyright laws.  All rights are reserved. Any use in 
00011 violation of the foregoing restrictions may subject the user to criminal 
00012 sanctions under applicable laws, as well as to civil liability for the 
00013 breach of the terms and conditions of this license. The Company may 
00014 immediately terminate this Agreement upon your use of the software with 
00015 any products that are not Segway products.
00016 
00017 The software was written using Python programming language.  Your use 
00018 of the software is therefore subject to the terms and conditions of the 
00019 OSI- approved open source license viewable at http://www.python.org/.  
00020 You are solely responsible for ensuring your compliance with the Python 
00021 open source license.
00022 
00023 You shall indemnify, defend and hold the Company harmless from any claims, 
00024 demands, liabilities or expenses, including reasonable attorneys fees, incurred 
00025 by the Company as a result of any claim or proceeding against the Company 
00026 arising out of or based upon: 
00027 
00028 (i) The combination, operation or use of the software by you with any hardware, 
00029     products, programs or data not supplied or approved in writing by the Company, 
00030     if such claim or proceeding would have been avoided but for such combination, 
00031     operation or use.
00032  
00033 (ii) The modification of the software by or on behalf of you 
00034 
00035 (iii) Your use of the software.
00036 
00037  THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
00038  WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
00039  TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00040  PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
00041  IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
00042  CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
00043  
00044  \file   utils.py
00045 
00046  \brief  This module contains general utility functions
00047 
00048  \Platform: Cross Platform
00049 --------------------------------------------------------------------"""
00050 import struct
00051 import socket
00052 
00053 """
00054 For IEEE754 processors this function converts a 32-bit floating point number to
00055 a 32-bit integer representation
00056 """
00057 def convert_float_to_u32(value):
00058     return struct.unpack('I', struct.pack('f', value))[0]
00059 
00060 """
00061 For IEEE754 processors this function converts a 32-bit integer representation
00062 of a floating point value to float representation
00063 """
00064 def convert_u32_to_float(bits):
00065     return struct.unpack('f', struct.pack('I', bits))[0]
00066 
00067 """
00068 Used to convert a byte array (string) into an array of 32-bit values
00069 """
00070 def convert_byte_data_to_U32(data):
00071 
00072     rx_dat = [];
00073     k = 0;
00074     
00075     #
00076     # Convert the string into a byte array
00077     #
00078     
00079     for x in range(0,len(data)):
00080         rx_dat.append(ord(data[x]));
00081         
00082     number_of_u32s = (len(rx_dat)/4)
00083 
00084     #
00085     # Convert the byte array into an array of 32bit values
00086     #
00087     converted = [0]*number_of_u32s;
00088     for x in range(0,number_of_u32s):
00089         converted[x] = int((((rx_dat[k]   << 24) & 0xFF000000)) |
00090                         (((rx_dat[k+1] << 16) & 0x00FF0000)) |
00091                         (((rx_dat[k+2] << 8)  & 0x0000FF00)) |
00092                           (rx_dat[k+3] & 0x000000FF));
00093 
00094         k+=4;
00095         
00096     return converted;
00097 
00098 """
00099 Used to convert an IP address string in dotted quad format to an integer
00100 """  
00101 def dottedQuadToNum(ip):
00102     "convert decimal dotted quad string to long integer"
00103     return struct.unpack('I',socket.inet_aton(ip))[0]
00104 
00105 """
00106 Used to convert an IP address in integer format to a dotted quad string
00107 """ 
00108 def numToDottedQuad(n):
00109     "convert long int to dotted quad string"
00110     return socket.inet_ntoa(struct.pack('I',n))


python_ethernet_rmp
Author(s): SEGWAY Inc.
autogenerated on Tue Mar 8 2016 00:53:38