Skip to content
envbox_database.py 11.4 KiB
Newer Older
lucasgrelaud's avatar
lucasgrelaud committed
#!/usr/bin/env python

"""*****************************************************"""
"""                                                     """
"""           Distec Protocol Implementation		"""
"""                                                     """
"""*****************************************************"""
""" Database containing all supported function 
IDs and associated hex code """


class envbox_types:
   uint8	= 0
   uint16	= 1
   uint32	= 2
   uint64	= 3
   int8		= 4
   int16	= 5
   int32	= 6
   int64	= 7
   float	= 8
   double	= 9
   string	= 10


class envbox_db:
   F_NAME = 0
   F_CMD  = 1
   F_SUBCMD  = 2
   F_FIELD= -1
   F_VALUES= 3
   F_RANGE = 4
   """ """
   db = [
      [ 'HardwareRevision',	0x00, 0x00, None, None, True ],
      [ 'SoftwareRevision',	0x00, 0x01, None, None, True ],
      [ 'SoftwareType',		0x00, 0x02, None, None, True ],
      [ 'DeviceID',		0x00, 0x03, None, None, True ],
      [ 'PlatformID',		0x00, 0x04, None, None, True ],
      [ 'Uptime',		0x00, 0x05, None, None, True ],
      [ 'Reflash',		0x00, 0x06, None, None, True ],
      [ 'Reboot',		0x00, 0x07, None, None, True ],
      [ 'Operatingtime',	0x00, 0x08, None, None, True ],
      [ 'Test',			0x00, 0x09, [ 'None', 'InfiniteLoop', 'MallocFailure', 'TaskSuspend', 'DeadLock', 'CrazyPointer' ], None, True ],
      [ 'Sensors_T',		0x00, 0x0A, None, None, True ],
      [ 'Sensors_L',		0x00, 0x0B, None, None, True ],
      [ 'Sensors_P',		0x00, 0x0C, None, None, True ],
      [ 'Sensors_B',		0x00, 0x0D, None, None, True ],
      [ 'Sensors_F',		0x00, 0x0E, None, None, True ],
      [ 'Sensors_S',		0x00, 0x0F, None, None, True ],
      [ 'DownTime',		0x00, 0x11, None, None, True ],
      [ 'SafeMode',		0x00, 0x12, None, None, True ],
      [ 'DownTimePC',		0x00, 0x13, None, None, True ],
      
      [ 'Backlight1Name',	0x01, 0x00, None, None, True ],
      [ 'Backlight1ID',	0x01, 0x01, None, None, True ],
      [ 'Backlight1LVL',	0x01, 0x02, None, None, True ],
      [ 'Backlight1Mode',	0x01, 0x03, [ 'Auto', 'Manual' ], None, True ],
      [ 'Backlight1Status',	0x01, 0x04, [ 'Ok', 'Error' ], None, True ],
      [ 'Backlight1Enable',	0x01, 0x05, [ 'Off', 'On' ], None, True ],
      [ 'Backlight1Enabled',	0x01, 0x06, [ 'Off', 'On' ], None, True ],
      [ 'Backlight1Protection',	0x01, 0x07, [ 'Off', 'On' ], None, True ],

     [ 'Backlight2Name',	0x01, 0x00, None, None, True ],
      [ 'Backlight2LVL',	0x01, 0x12, None, None, True ],
      [ 'Backlight2Mode',	0x01, 0x13, [ 'Auto', 'Manual' ], None, True ],
      [ 'Backlight2Status',	0x01, 0x14, [ 'Ok', 'Error' ], None, True ],
      [ 'Backlight2Enable',	0x01, 0x15, [ 'Off', 'On' ], None, True ],
      [ 'Backlight2Enabled',	0x01, 0x16, [ 'Off', 'On' ], None, True ],
      [ 'Backlight2Protection',	0x01, 0x17, [ 'Off', 'On' ], None, True ],
 
      [ 'RouterName',		0x01, 0x20, None, None, True ],
      [ 'RouterStatus',		0x01, 0x24, [ 'Ok', 'Error' ], None, True ],
      [ 'RouterEnable',		0x01, 0x25, [ 'Off', 'On' ], None, True ],
      [ 'RouterEnabled',	0x01, 0x26, [ 'Off', 'On' ], None, True ],



     
      [ 'Fan1Name',		0x02, 0x00, None, None, True ],
      [ 'Fan1Status',		0x02, 0x01, None, None, True ],
      [ 'Fan1PWM',		0x02, 0x02, None, None, True ],
      [ 'Fan1RPM',		0x02, 0x03, None, None, True ],
      [ 'Fan1Mode',		0x02, 0x04, [ 'Auto', 'Manual' ], None, True ],
      [ 'Fan1Ttarget',		0x02, 0x05, None, None, True ],
      [ 'Fan1Tmax',		0x02, 0x06, None, None, True ],

      [ 'Fan2Name',		0x02, 0x20, None, None, True ],
      [ 'Fan2Status',		0x02, 0x21, None, None, True ],
      [ 'Fan2PWM',		0x02, 0x22, None, None, True ],
      [ 'Fan2RPM',		0x02, 0x23, None, None, True ],
      [ 'Fan2Mode',		0x02, 0x24, [ 'Auto', 'Manual' ], None, True ],
      [ 'Fan2Ttarget',		0x02, 0x25, None, None, True ],
      [ 'Fan2Tmax',		0x02, 0x26, None, None, True ],

      [ 'Fan3Name',		0x02, 0x40, None, None, True ],
      [ 'Fan3Status',		0x02, 0x41, None, None, True ],
      [ 'Fan3PWM',		0x02, 0x42, None, None, True ],
      [ 'Fan3RPM',		0x02, 0x43, None, None, True ],
      [ 'Fan3Mode',		0x02, 0x44, [ 'Auto', 'Manual' ], None, True ],
      [ 'Fan3Ttarget',		0x02, 0x45, None, None, True ],
      [ 'Fan3Tmax',		0x02, 0x46, None, None, True ],

      [ 'Fan4Name',		0x02, 0x60, None, None, True ],
      [ 'Fan4Status',		0x02, 0x61, None, None, True ],
      [ 'Fan4PWM',		0x02, 0x62, None, None, True ],
      [ 'Fan4RPM',		0x02, 0x63, None, None, True ],
      [ 'Fan4Mode',		0x02, 0x64, [ 'Auto', 'Manual' ], None, True ],
      [ 'Fan4Ttarget',		0x02, 0x65, None, None, True ],
      [ 'Fan4Tmax',		0x02, 0x66, None, None, True ],

      [ 'Fan5Name',		0x02, 0x80, None, None, True ],
      [ 'Fan5Status',		0x02, 0x81, None, None, True ],
      [ 'Fan5PWM',		0x02, 0x82, None, None, True ],
      [ 'Fan5RPM',		0x02, 0x83, None, None, True ],
      [ 'Fan5Mode',		0x02, 0x84, [ 'Auto', 'Manual' ], None, True ],
      [ 'Fan5Ttarget',		0x02, 0x85, None, None, True ],
      [ 'Fan5Tmax',		0x02, 0x86, None, None, True ],

      [ 'Fan6Name',		0x02, 0xA0, None, None, True ],
      [ 'Fan6Status',		0x02, 0xA1, None, None, True ],
      [ 'Fan6PWM',		0x02, 0xA2, None, None, True ],
      [ 'Fan6RPM',		0x02, 0xA3, None, None, True ],
      [ 'Fan6Mode',		0x02, 0xA4, [ 'Auto', 'Manual' ], None, True ],
      [ 'Fan6Ttarget',		0x02, 0xA5, None, None, True ],
      [ 'Fan6Tmax',		0x02, 0xA6, None, None, True ],

      
      [ 'Temperature1Name',	0x03, 0x00, None, None, True ],
      [ 'Temperature1Status',	0x03, 0x01, None, None, True ],
      [ 'Temperature1Temp',	0x03, 0x02, None, None, True ],
      [ 'Temperature2Name',	0x03, 0x10, None, None, True ],
      [ 'Temperature2Status',	0x03, 0x11, None, None, True ],
      [ 'Temperature2Temp',	0x03, 0x12, None, None, True ],
      [ 'Temperature3Name',	0x03, 0x20, None, None, True ],
      [ 'Temperature3Status',	0x03, 0x21, None, None, True ],
      [ 'Temperature3Temp',	0x03, 0x22, None, None, True ],
      [ 'Temperature4Name',	0x03, 0x30, None, None, True ],
      [ 'Temperature4Status',	0x03, 0x31, None, None, True ],
      [ 'Temperature4Temp',	0x03, 0x32, None, None, True ],
      [ 'Temperature5Name',	0x03, 0x40, None, None, True ],
      [ 'Temperature5Status',	0x03, 0x41, None, None, True ],
      [ 'Temperature5Temp',	0x03, 0x42, None, None, True ],
      [ 'Temperature6Name',	0x03, 0x50, None, None, True ],
      [ 'Temperature6Status',	0x03, 0x51, None, None, True ],
      [ 'Temperature6Temp',	0x03, 0x52, None, None, True ],
      [ 'Temperature7Name',	0x03, 0x60, None, None, True ],
      [ 'Temperature7Status',	0x03, 0x61, None, None, True ],
      [ 'Temperature7Temp',	0x03, 0x62, None, None, True ],
      [ 'Temperature8Name',	0x03, 0x70, None, None, True ],
      [ 'Temperature8Status',	0x03, 0x71, None, None, True ],
      [ 'Temperature8Temp',	0x03, 0x72, None, None, True ],
      [ 'Temperature9Name',	0x03, 0x80, None, None, True ],
      [ 'Temperature9Status',	0x03, 0x81, None, None, True ],
      [ 'Temperature9Temp',	0x03, 0x82, None, None, True ],

      [ 'Light1Name',		0x04, 0x00, None, None, True ],
      [ 'Light1Status',		0x04, 0x01, None, None, True ],
      [ 'Light1Intensity',	0x04, 0x02, None, None, True ],
      [ 'Light1Gain',		0x04, 0x03, None, None, True ],
      [ 'Light1Time',		0x04, 0x04, None, None, True ],

      [ 'Light2Name',		0x04, 0x10, None, None, True ],
      [ 'Light2Status',		0x04, 0x11, None, None, True ],
      [ 'Light2Intensity',	0x04, 0x12, None, None, True ],
      [ 'Light2Gain',		0x04, 0x13, None, None, True ],
      [ 'Light2Time',		0x04, 0x14, None, None, True ],

      [ 'Light3Name',		0x04, 0x20, None, None, True ],
      [ 'Light3Status',		0x04, 0x21, None, None, True ],
      [ 'Light3Intensity',	0x04, 0x22, None, None, True ],
      [ 'Light3Gain',		0x04, 0x23, None, None, True ],
      [ 'Light3Time',		0x04, 0x24, None, None, True ],

      [ 'Hygrometry1Name',	0x06, 0x00, None, None, True ],
      [ 'Hygrometry1Status',	0x06, 0x01, None, None, True ],
      [ 'Hygrometry1',		0x06, 0x02, None, None, True ],

      [ 'Hygrometry2Name',	0x06, 0x10, None, None, True ],
      [ 'Hygrometry2Status',	0x06, 0x11, None, None, True ],
      [ 'Hygrometry2',		0x06, 0x12, None, None, True ],

      [ 'LineName',		0x05, 0x00, None, None, True ],
      [ 'LineStatus',		0x05, 0x01, None, None, True ],
      [ 'LineVoltage',		0x05, 0x02, None, None, True ],
      [ 'LineCurrent',		0x05, 0x03, None, None, True ],
      [ 'LinePower',		0x05, 0x04, None, None, True ],
      [ 'LineEnergy',		0x05, 0x05, None, None, True ],
      [ 'LinePF',		0x05, 0x0A, None, None, True ],
      [ 'LineFrequency',	0x05, 0x0B, None, None, True ],
      [ 'LineAngle',		0x05, 0x0C, None, None, True ],

      
      [ 'Switch1Name',		0x08, 0x00, None, None, True ],
      [ 'Switch1Status',	0x08, 0x01, [ 'Closed', 'Opened' ], None, True ],
      [ 'Switch2Name',		0x08, 0x10, None, None, True ],
      [ 'Switch2Status',	0x08, 0x11, [ 'Closed', 'Opened' ], None, True ],
      [ 'Switch2Set',		0x01, 0x13, [ 'Off', 'On' ], None, True ],
      [ 'Switch3Name',		0x08, 0x20, None, None, True ],
      [ 'Switch3Status',	0x08, 0x21, [ 'Closed', 'Opened' ], None, True ],
      [ 'Switch4Name',		0x08, 0x30, None, None, True ],
      [ 'Switch4Status',	0x08, 0x31, [ 'Closed', 'Opened' ], None, True ],


      [ 'Accelerometer1Name',	0x0A, 0x00, None, None, True ],
      [ 'Accelerometer1Status',	0x0A, 0x01, None, None, True ],
      [ 'Accelerometer1Acceleration',	0x0A, 0x02, None, None, True ],

      [ 'Accelerometer2Name',	0x0A, 0x10, None, None, True ],
      [ 'Accelerometer2Status',	0x0A, 0x11, None, None, True ],
      [ 'Accelerometer2Acceleration',	0x0A, 0x12, None, None, True ],




   ]


   """
	Return Command Code from name
   """
   @staticmethod
   def getCommandByName( name ):
     for n in envbox_db.db:
       if n[ envbox_db.F_NAME ] == name:
         return (n[ envbox_db.F_CMD ], n[ envbox_db.F_SUBCMD ])
     return None

   """
	
   """
   @staticmethod
   def getValueByName( name, value ):
      for n in envbox_db.db:
         if n[ envbox_db.F_NAME ] == name:
            if not n[ envbox_db.F_VALUES ] is None:
               i=0
               for v in n[ envbox_db.F_VALUES ]:
                  if v == value:
                     return i
                  i = i + 1

      try:
	 f = float( value )
	 try:
   	    i = int( value )
	    return i
	 except:
	    return f
      except:
         return int( value )


   """
	Verify that a command is valid
   """
   @staticmethod
   def isCommand( name ):
     for n in envbox_db.db:
       if n[ envbox_db.F_NAME ] == name:
	  return True
     return False 


   """
	Return a user friendly name for a value when possible
   """
   @staticmethod
   def getValueName( name, value ):
     for n in envbox_db.db:
       if n[ envbox_db.F_NAME ] == name:
         if not n[ envbox_db.F_VALUES ] is None:
           return n[ envbox_db . F_VALUES ][ value ]
     return value 

   """
	Print database
   """
   @staticmethod
   def printCommandList():
      for n in envbox_db.db:
	 txt = n[ envbox_db.F_NAME ]
         if not n[ envbox_db.F_VALUES ] is None:
            i=0
            txt = txt + ' : '
            for v in n[ envbox_db.F_VALUES ]:
               if not v is None:
                  txt = txt + v + '(' + str(i) + ') '
               i = i + 1
         
         if not n[ envbox_db.F_RANGE ] is None:
            txt = txt + ' : Range ' + str(n[ envbox_db.F_RANGE ][0]) + ' to ' + str(n[ envbox_db.F_RANGE ][1])
         
         print txt