Home | History | Annotate | Download | only in anritsu_lib
      1 #/usr/bin/env python3.4
      2 #
      3 #   Copyright 2016 - The Android Open Source Project
      4 #
      5 #   Licensed under the Apache License, Version 2.0 (the "License");
      6 #   you may not use this file except in compliance with the License.
      7 #   You may obtain a copy of the License at
      8 #
      9 #       http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 #   Unless required by applicable law or agreed to in writing, software
     12 #   distributed under the License is distributed on an "AS IS" BASIS,
     13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 #   See the License for the specific language governing permissions and
     15 #   limitations under the License.
     16 
     17 """
     18 Utility functions for for Anritsu Signalling Tester.
     19 """
     20 
     21 OPERATION_COMPLETE = 1
     22 NO_ERROR = 0
     23 
     24 ANRITSU_ERROR_CODES = {
     25     0: 'No errors occurred',
     26     2: 'The specified file does not exist',
     27     14: 'The buffer size is insufficient',
     28     29: 'The save destination is a write-protected file.',
     29     80: 'A file with the same name already exists.'
     30         ' (If Overwrite is specified to 0.)',
     31     87: 'The specified value is wrong.',
     32     112: 'The disk space is insufficient.',
     33     183: 'SmartStudio is already running.',
     34     1060: 'The control software has not been started or has already terminated',
     35     1067: 'SmartStudio, control software or SMS Centre could not start due to'
     36           'a problem or problems resulting from OS or the MD8475A system.',
     37     1229: 'Connecting to the server failed.',
     38     1235: 'A request is suspended.',
     39     1460: 'The operation is terminated due to the expiration of the'
     40           ' timeout period.',
     41     9999: 'A GPIB command error occurred.',
     42     536870912: 'The license could not be confirmed.',
     43     536870913: 'The specified file cannot be loaded by the SmartStudio.',
     44     536870914: 'The specified process ID does not exist.',
     45     536870915: 'The received data does not exist.',
     46     536870916: 'Simulation is not running.',
     47     536870917: 'Simulation is running.',
     48     536870918: 'Test Case has never been executed.',
     49     536870919: 'The resource cannot be obtained.',
     50     536870920: 'A resource protocol error, such as download error or'
     51                ' license error, occurred.',
     52     536870921: 'The function call has been in invalid status.',
     53     536870922: 'The current Simulation Model does not allow the operation.',
     54     536870923: 'The Cell name to be set does not exist.',
     55     536870924: 'The test is being executed.',
     56     536870925: 'The current UE status does not correspond to the'
     57                ' test parameters.',
     58     536870926: 'There is no LOG information because the simulation'
     59                ' has not been executed.',
     60     536870927: 'Measure Export has already been executed.',
     61     536870928: 'SmartStudio is not connected to the SMS Centre.',
     62     536870929: 'SmartStudio failed to send an SMS message to the SMS Centre.',
     63     536870930: 'SmartStudio has successfully sent an SMS message'
     64                ' to the SMS Centre,but the SMS Centre judges it as an error.',
     65     536870931: 'The processing that is unavailable with the current system'
     66                ' status has been executed.',
     67     536870932: 'The option could not be confirmed.',
     68     536870933: 'Measure Export has been stopped.',
     69     536870934: 'SmartStudio cannot load the specified file because the'
     70                ' version is old.',
     71     536870935: 'The data with the specified PDN number does not exist.',
     72     536870936: 'The data with the specified Dedicated number does not exist.',
     73     536870937: 'The PDN data cannot be added because the upper limit of the'
     74                ' number of PDN data has been reached.',
     75     536870938: 'The number of antennas, which cannot be set to the current'
     76                ' Simulation Model,has been specified.',
     77     536870939: 'Calibration of path loss failed.',
     78     536870940: 'There is a parameter conflict.',
     79     536870941: 'The DL Ref Power setting is out of the setting range'
     80                ' at W-CDMA (Evolution).',
     81     536870942: 'DC-HSDPA is not available for the current channel setting.',
     82     536870943: 'The specified Packet Rate cannot be used by the current'
     83                ' Simulation Model.',
     84     536870944: 'The W-CDMA Cell parameter F-DPCH is set to Enable.',
     85     536870945: 'Target is invalid.',
     86     536870946: 'The PWS Centre detects an error.',
     87     536870947: 'The Ec/Ior setting is invalid.',
     88     536870948: 'The combination of Attach Type and TA Update Type is invalid.',
     89     536870949: 'The license of the option has expired.',
     90     536870950: 'The Ping command is being executed.',
     91     536870951: 'The Ping command is not being executed.',
     92     536870952: 'The current Test Case parameter setting is wrong.',
     93     536870953: 'The specified IP address is the same as that of Default Gateway'
     94                'specified by Simulation parameter.',
     95     536870954: 'TFT IE conversion failed.',
     96     536875008: 'An error exists in the parameter configuration.'
     97                '(This error applies only to the current version.)',
     98     536936448: 'License verification failed.',
     99     536936449: 'The IMS Services cannot load the specified file.',
    100     536936462: 'Simulation is not performed and no log information exists.',
    101     536936467: 'The executed process is inoperable in the current status'
    102                ' of Visual User Agent.',
    103     536936707: 'The specified Virtual Network is not running.',
    104     536936709: 'The specified Virtual Network is running. '
    105                'Any one of the Virtual Networks is running.',
    106     536936727: 'The specified Virtual Network does not exist.',
    107     536936729: 'When the Virtual Network already exists.',
    108     554762241: 'The RF Measurement launcher cannot be accessed.',
    109     554762242: 'License check of the RF Measurement failed.',
    110     554762243: 'Function is called when RF Measurement cannot be set.',
    111     554762244: 'RF Measurement has been already started.',
    112     554762245: 'RF Measurement failed to start due to a problem resulting'
    113                ' from OS or the MD8475A system.',
    114     554762246: 'RF Measurement is not started or is already terminated.',
    115     554762247: 'There is a version mismatch between RF Measurement and CAL.',
    116     554827777: 'The specified value for RF Measurement is abnormal.',
    117     554827778: 'GPIB command error has occurred in RF Measurement.',
    118     554827779: 'Invalid file path was specified to RF Measurement.',
    119     554827780: 'RF Measurement argument is NULL pointer.',
    120     555810817: 'RF Measurement is now performing the measurement.',
    121     555810818: 'RF Measurement is now not performing the measurement.',
    122     555810819: 'RF Measurement is not measured yet. (There is no result '
    123                'information since measurement is not performed.)',
    124     555810820: 'An error has occurred when RF Measurement'
    125                ' starts the measurement.',
    126     555810821: 'Simulation has stopped when RF Measurement is '
    127                'performing the measurement.',
    128     555810822: 'An error has been retrieved from the Platform when '
    129                'RF Measurement is performing the measurement.',
    130     555810823: 'Measurement has been started in the system state where RF '
    131                'Measurement is invalid.',
    132     556859393: 'RF Measurement is now saving a file.',
    133     556859394: 'There is insufficient disk space when saving'
    134                'a Measure Result file of RF Measurement.',
    135     556859395: 'An internal error has occurred or USB cable has been'
    136                ' disconnected when saving a Measure Result'
    137                ' file of RF Measurement.',
    138     556859396: 'A write-protected file was specified as the save destination'
    139                ' when saving a Measure Result file of RF Measurement.',
    140     568328193: 'An internal error has occurred in RF Measurement.',
    141     687865857: 'Calibration Measure DSP is now being measured.',
    142     687865858: 'Calibration measurement failed.',
    143     687865859: 'Calibration slot is empty or its system does not apply.',
    144     687865860: 'Unexpected command is received from Calibration HWC.',
    145     687865861: 'Failed to receive the Calibration measurement result.',
    146     687865862: 'Failed to open the correction value file on the'
    147                ' Calibration HDD.',
    148     687865863: 'Failed to move the pointer on the Calibration correction'
    149                ' value table.',
    150     687865864: 'Failed to write the correction value to the Calibration'
    151                ' correction value file on the Calibration HDD.',
    152     687865865: 'Failed to load the correction value from the Calibration HDD.',
    153     687865866: 'Failed to create a directory to which the correction value '
    154                'file on the Calibration HDD is saved.',
    155     687865867: 'Correction data has not been written in the'
    156                ' Calibration-specified correction table.',
    157     687865868: 'Data received from Calibration HWC does not exist.',
    158     687865869: 'Data has not been written to the Flash ROM'
    159                ' of Calibration BASE UNIT.',
    160     687865870: 'Correction data has not been written to the'
    161                ' Calibration-specified sector.',
    162     687866111: 'An calibration error other than described above occurred.',
    163 }
    164 
    165 
    166 def _error_code_tostring(error_code):
    167     ''' returns the description of the error from the error code
    168     returned by anritsu MD8475A '''
    169     try:
    170         error_string = ANRITSU_ERROR_CODES[error_code]
    171     except KeyError:
    172         error_string = "Error : {} ".format(error_code)
    173 
    174     return error_string
    175 
    176 
    177 class AnritsuUtils(object):
    178     def gsm_encode(text):
    179         '''To encode text string with GSM 7-bit alphabet for common symbols'''
    180         table = {' ': '%20', '!': '%21', '\"': '%22', '#': '%23', '$': '%24',
    181                  '/': '%2F', '%': '%25', '&': '%26', '\'': '%27', '(': '%28',
    182                  ')': '%29', '*': '%2A', '+': '%2B', ',': '%2C', ':': '%3A',
    183                  ';': '%3B', '<': '%3C', '=': '%3D', '>': '%3E', '?': '%3F',
    184                  '@': '%40', '[': '%5B', ']': '%5D', '_': '%5F', '': '%C3%A9'}
    185         coded_str = ""
    186         for char in text:
    187             if char in table:
    188                 coded_str += table[char]
    189             else:
    190                 coded_str += char
    191         return coded_str
    192 
    193     def gsm_decode(text):
    194         '''To decode text string with GSM 7-bit alphabet for common symbols'''
    195         table = {'%20': ' ', '%21': '!', '%22': '\"', '%23': '#', '%24': '$',
    196                  '%2F': '/', '%25': '%', '%26': '&', '%27': '\'', '%28': '(',
    197                  '%29': ')', '%2A': '*', '%2B': '+', '%2C': ',', '%3A': ':',
    198                  '%3B': ';', '%3C': '<', '%3D': '=', '%3E': '>', '%3F': '?',
    199                  '%40': '@', '%5B': '[', '%5D': ']', '%5F': '_', '%C3%A9': ''}
    200         coded_str = text
    201         for char in table:
    202             if char in text:
    203                 coded_str = coded_str.replace(char, table[char])
    204         return coded_str
    205 
    206     def cdma_encode(text):
    207         '''To encode text string with GSM 7-bit alphabet for common symbols'''
    208         table = {' ': '%20', '!': '%21', '\"': '%22', '#': '%23', '$': '%24',
    209                  '/': '%2F', '%': '%25', '&': '%26', '\'': '%27', '(': '%28',
    210                  ')': '%29', '*': '%2A', '+': '%2B', ',': '%2C', ':': '%3A',
    211                  ';': '%3B', '<': '%3C', '=': '%3D', '>': '%3E', '?': '%3F',
    212                  '@': '%40', '[': '%5B', ']': '%5D', '_': '%5F'}
    213         coded_str = ""
    214         for char in text:
    215             if char in table:
    216                 coded_str += table[char]
    217             else:
    218                 coded_str += char
    219         return coded_str
    220 
    221 class AnritsuError(Exception):
    222     '''Exception for errors related to Anritsu.'''
    223     def __init__(self, error, command=None):
    224         self._error_code = error
    225         self._error_message = _error_code_tostring(self._error_code)
    226         if command is not None:
    227             self._error_message = "Command {} returned the error: '{}'".format(
    228                                   command, self._error_message)
    229 
    230     def __str__(self):
    231         return self._error_message
    232