class CpcAlarm: _status_values = EnumeratedDictionary({ 0: 'UNACKED', 1: 'ACKED', 2: 'RESET' }) _type_values = EnumeratedDictionary({0: 'NOTICE', 1: 'ALARM', 2: 'RESET'}) def __init__(self): self.id = None # unique instance ID (2 bytes of a Python int) self.orig_date = None # date alarm occurred (3-tuple) self.orig_time = None # time alarm occurred (3-tuple) self.ack_date = None # date alarm acknowledged (3-tuple) self.ack_time = None # time alarm acknowledged (3-tuple) self.status = None # 0, 1, or 2 (EnumeratedValue) self.type = None # 0 or 1 (EnumeratedValue) self.item = None # type of item that posted this alarm (Python int) self.item_num = None # instance of item that posted this alarm (Python int) self.obj = None # type of object that posted this alarm (Python int) self.obj_num = None # instance of object that posted this alarm (Python int) self.text = None # alarm text msg (Python string) def __eq__(self, o): return (self.id == o.id) def as_list(self): return [self.id,self.orig_date,self.orig_time,self.ack_date,self.ack_time, \ self.status, self.type,self.item,self.item_num,self.obj,self.obj_num, \ self.text]
def start(self): i = 0 enumeration = {} for word in self.scale_or_enum: enumeration[i] = word i += 1 self.enumeration = EnumeratedDictionary(enumeration) _Value.start(self) self.point = value.TCSValue(self.line_handler, self.parameter, self.position, self.unit_number)
class Enumerator(_Value): def __init__(self): _Value.__init__(self) self.__node_id__ = '120065' def configure(self, dict): _Value.configure(self, dict) set_attribute(self, 'scale_or_enum', REQUIRED, dict) if type(self.scale_or_enum) == str: #eonvert to list of words if self.scale_or_enum[0] == '[': #self discovered self.scale_or_enum = eval(self.scale_or_enum) else: #static self.scale_or_enum = string.split(self.scale_or_enum, ';') def configuration(self): config = _Value.configuration(self) get_attribute(self, 'scale_or_enum', config, str) get_attribute(self, '__node_id__', config, str) return config def start(self): i = 0 enumeration = {} for word in self.scale_or_enum: enumeration[i] = word i += 1 self.enumeration = EnumeratedDictionary(enumeration) _Value.start(self) self.point = value.TCSValue(self.line_handler, self.parameter, self.position, self.unit_number) def get(self, skipCache=0): answer = _Value.get(self, skipCache) if self.enumeration.has_key(answer): return self.enumeration[answer] return answer def _set(self, value): if self.enumeration.has_key(value): _Value._set(self, int(self.enumeration[value])) return raise EInvalidValue(str(self.enumeration), str(value), 'not found in enumeration list')
if mnt[self.version_status.model][1] == 0: #treadmill return 'n/a' resistance = self._feu_gear_node.get() if resistance: return str(resistance) except: pass return '-' def xcvr_status(self): return TransceiverState[int(self._xcvr_status)] TransceiverState = EnumeratedDictionary({ 0: 'stopped', 1: 'not responding', 2: 'responding', 3: 'exception in xmit' }) ## Map of model index number to model data. Model data array = [name,category,courses_table]: ## These tables will be downloaded as part of the configuration eventually #model number:[name,catagory,course_table_index] mnt = { 0: ["C964 (0)", 0, 0], 3: ["C764 (3)", 1, 0], 5: ["C964i (5)", 0, 1], 7: ["C966 (7)", 0, 2], 16: ["C846 (16)", 3, 9], 17: ["C846 (17)", 3, 9],
from mpx import properties from mpx.lib.configure import set_attribute, get_attribute from mpx.lib.configure import REQUIRED from mpx.lib.configure import as_boolean from mpx.lib.node import CompositeNode, as_node from mpx.lib.exceptions import EInvalidValue, ETimeout from mpx.lib import EnumeratedDictionary from mpx.lib import msglog from mpx.lib.msglog.types import INFO, WARN, ERR import mpx.lib.genericdriver.gdconnection as gdconn import mpx.lib.genericdriver.gdlinehandler as gdlh import mpx.ion.usap.usapmsg as usapm command = EnumeratedDictionary({0:'DACT', 1:'ACTI'}) class UsapDevice(CompositeNode): """ This class is used to define USAP device. Its primary role is to interact with USAP device over RS-232 medium.""" def __init__(self): CompositeNode.__init__(self) self.debug = 0 self.enabled = 1 self.legacy_operating_code = 1 self.lh = None self.conn = None self.request_obj = usapm.UsapRequest() self.response_obj = usapm.UsapResponse() self.req_startCode_obj = None self.req_vData_obj = None
from mpx.lib.exceptions import ETimeout, ENoData, EIOError, EInvalidValue, EConnectionError from mpx.lib.exceptions import * import array, struct import select from mpx.lib.event import EventProducerMixin, ChangeOfValueEvent from mpx.lib import EnumeratedDictionary, msglog from mpx.lib.aerocomm import aero from mpx.ion.aerocomm import feu import types bypass_who_is = 0 debug = 0 TransceiverState = EnumeratedDictionary({ 0:'stopped', 1:'transceiver_not_responding', 2:'transceiver_responding', 3:'exception_in_xmit' }) class AerocommServer(CompositeNode, AutoDiscoveredNode, EventProducerMixin): ## # @todo Fix this ugliness: All necy info is in nodedefs, but not really available to MFW code... _inherent_child_names = [ \ 'eeprom_params', 'server_status', ] def __init__(self): self._running = 0 self.driver = None self.mac_address = None self.discovery_mode = 'None'
LAN_ALARM_REPORT = 0x1A LAN_TOKEN_LIST = 0x1C LAN_EXTEND = 0x40 PacketTypeEnum = EnumeratedDictionary({ 'LAN_RESET': 0x03, 'LAN_TO_MEM': 0x05, 'LAN_TO_MEM_SEQ': 0x85, 'LAN_SEND_MEM': 0x06, 'LAN_GOTO ': 0x07, 'LAN_TO_HOST': 0x08, 'LAN_OBJ_VAL': 0x09, 'LAN_MTR_VAL': 0x0A, 'LAN_UPDATE': 0x0B, 'LAN_TIME ': 0x0C, 'LAN_OBJ_RQST': 0x0D, 'LAN_OBJ_OVRD': 0x0E, 'LAN_OBJ_CLOV': 0x0F, 'LAN_CML ': 0x10, 'LAN_AML ': 0x11, 'LAN_REPORT': 0x12, 'LAN_ALARMS': 0x14, 'LAN_ACK_ALARM': 0x15, 'LAN_ACK_TREND': 0x19, 'LAN_ALARM_REPORT': 0x1A, 'LAN_TOKEN_LIST': 0x1C, 'LAN_EXTEND': 0x40, }) # host_master pkt indices for packets from phwin to modem server RZHM_HDR_LEN = 10 RZHM_DST_1ST = 2
MINUTE = 60 EVENT_NAME_OFFSET = 120 EVENT_NAME_LEN = 40 ROOM_NAME_OFFSET = 171 ROOM_NAME_LEN = 40 START_TIME_OFFSET = 211 START_TIME_LEN = 4 END_TIME_OFFSET = 215 END_TIME_LEN = 4 AGREED_ATTD_OFFSET = 243 AGREED_ATTD_LEN = 7 MEETING_INFO_LEN = 252 MeetingSpaceStatus = EnumeratedDictionary({ 0: '0:Unknown', 1: '1:Available', 2: '2:Scheduled', 3: '3:In Progress' }) PropertyStatus = EnumeratedDictionary({ 0: '0:Init', 1: '1:OK', 2: '2:OK with event file same as yesterday', 3: '3:Incomplete meeting information', 4: '4:Communication Error, using backup event file', 5: '5:Communication Error', 6: '6:File IO Error' }) # String Marshalling using xmlrpc marshaller
from mpx.lib.magnitude import MagnitudeInterface from mpx.lib import EnumeratedDictionary from mpx.lib.exceptions import ETimeout from mpx.lib import debug as _debug debug = 0 def who_is_message(): return '\xf1\xf2' status_text = EnumeratedDictionary({ 0: 'Error', 1: 'Ready', 2: 'Idle', 3: 'HaveId', 5: 'InUse', 6: 'Paused', 7: 'Finished', 8: 'Manual', 9: 'OffLine', }) units_text = EnumeratedDictionary({ 1: 'mile', 2: 'tenth_mile', 3: 'hundredth_mile', 4: 'thousandth_mile', 5: 'ft', 6: 'inch', 7: 'lbs', 8: 'tenth_lbs', 10: 'ten_ft',
from stat import * from mpx.lib import EnumeratedDictionary from mpx.lib.node import CompositeNode from mpx.lib.configure import set_attribute, get_attribute, REQUIRED from mpx.lib.persistent import PersistentDataObject from mpx import properties from mpx.componentry.security.declarations import secured_by from mpx.componentry.security.declarations import SecurityInformation # General classifications for backup data with room # for additional granularity. backup_class = EnumeratedDictionary({ 0: 'Config', 10: 'Web Data', 20: 'PDO', 30: 'Other', 100: 'All' }) class _PersistentData(PersistentDataObject): def __init__(self, node): self.entries = None PersistentDataObject.__init__(self, node) PersistentDataObject.load(self) class BackupRegistry(CompositeNode): security = SecurityInformation.from_default() secured_by(security)
def test_1(self): try: ed = EnumeratedDictionary() except: raise 'Failed to create empty dictionary' try: one = EnumeratedValue(1, 'one') two = EnumeratedValue(2, 'two') ed[1] = one ed['two'] = two except: raise 'Basic assignment failed' try: ed[3] = one except: pass else: raise 'Failed to detect mismatch between int key and value' try: ed['three'] = one except: pass else: raise 'Failed to detect mismatch between str key and value' try: s = str(ed) except: raise 'Failed to produce str from self' #exp_str = "{1: EnumeratedValue(1,'one'), 2: EnumeratedValue(2,'two')}" exp_str = "{1: {'__base__': 'EnumeratedValue', 'num': 1, '__class__': 'mpx.lib.EnumeratedValue', 'str': 'one'}, 2: {'__base__': 'EnumeratedValue', 'num': 2, '__class__': 'mpx.lib.EnumeratedValue', 'str': 'two'}}" if s != exp_str: raise 'str conversion failed (%s vs %s)' % (s, exp_str) try: r = repr(ed) except: raise 'Failed to produce repr string' #exp_repr = "EnumeratedDictionary({1: EnumeratedValue(1,'one'), 2: EnumeratedValue(2,'two')})" exp_repr = "EnumeratedDictionary({1: {'__base__': 'EnumeratedValue', 'num': 1, '__class__': 'mpx.lib.EnumeratedValue', 'str': 'one'}, 2: {'__base__': 'EnumeratedValue', 'num': 2, '__class__': 'mpx.lib.EnumeratedValue', 'str': 'two'}})" if r != exp_repr: raise 'repr string comparison failed (%s vs %s)' % (r, exp_repr) if ed[1] != one: raise 'Failed to get correct item for int key' if ed['two'] != two: raise 'Failed to get correct item for str key' try: ed['three'] except: pass else: raise 'Failed to raise key exception on bad key' if ed.items() != [(1, EnumeratedValue(1,'one')), (2, EnumeratedValue(2,'two'))]: raise 'Failed to produce items' try: ed[3]='three' ed['four']=4 except: raise 'Failed set for simple int and str items' if ed[3] != EnumeratedValue(3,'three'): raise 'Implicit creation of EnumeratedValue failed' if ed['three'] != EnumeratedValue(3,'three'): raise 'str dict did not get implicit assignment' ed2 = EnumeratedDictionary(ed) try: if ed == ed2: pass else: raise 'Equality test failed' except: raise 'Equality test crashed' ed2 = EnumeratedDictionary(ed) try: ed3 = EnumeratedDictionary(ed2) except: raise 'Failed to instanciate from another EnumeratedDictionary' if ed != ed3: raise 'Non-equality test failed' try: del ed2[1] except: raise 'del failed' if ed2.get(1) != None: raise 'Failed to del an item' if ed2.get('one') != None: raise 'Failed to del an item from str_dict' try: del ed2['two'] except: raise 'del failed' if ed2.get(2) != None: raise 'Failed to del an item' if ed2.get('two') != None: raise 'Failed to del an item from str_dict' s = str(ed) #exp_str = "{1: EnumeratedValue(1,'one'), 2: EnumeratedValue(2,'two'), 3: EnumeratedValue(3,'three'), 4: EnumeratedValue(4,'four')}" exp_str = "{1: {'__base__': 'EnumeratedValue', 'num': 1, '__class__': 'mpx.lib.EnumeratedValue', 'str': 'one'}, 2: {'__base__': 'EnumeratedValue', 'num': 2, '__class__': 'mpx.lib.EnumeratedValue', 'str': 'two'}, 3: {'__base__': 'EnumeratedValue', 'num': 3, '__class__': 'mpx.lib.EnumeratedValue', 'str': 'three'}, 4: {'__base__': 'EnumeratedValue', 'num': 4, '__class__': 'mpx.lib.EnumeratedValue', 'str': 'four'}}" if s != exp_str: raise 'Failed to survive all the stuff I tried to do to it.... (%s vs %s)' % (s, exp_str)
""" ## # mpx/cpc/lib/tables.py: Lookup tables for CPC devices, items, objects, and properties. # @author [email protected] # @fixme Use regular expressions in Python to generate full EnumeratedDictionary tables from UHPDB "MDB" tables. # @fixme Try to eliminate "same data in two places" problem when instantiating ObjData/ItemData in EnumeratedDictionaries. # @fixme Had to guess at data_types for all PropTypes except Value and Status. Get correct data_types from CPC... import types from mpx.lib import EnumeratedValue, EnumeratedDictionary ## # _cmds: 2-way tables of allowed UHP Request Commands. _cmds = EnumeratedDictionary({ 'GetValue': 1, 'SetValue': 2, 'GetLog': 3, 'Backup': 7, 'Restore': 8 }) ## # _data_types: 2-way tables of supported UHP DataTypes. _data_types = EnumeratedDictionary({0:'NONE', 1:'UCHAR', 2:'CHAR', 3:'SCHAR', \ 4:'INT', 5:'UINT', 6:'INT_DIV10', \ 7:'UINT_DIV10', 8:'INT_DIV100', 9:'UINT_DIV100', \ 10:'LONG', 11:'ULONG', 12:'FUNK_FLOAT', \ 13:'FUNK_TIME', 15:'DATE', 16:'SZSTRING', \ 17:'LIST_ITEM', 19:'BIT_ARRAY', 20:'ALARM', \ 21:'INT_DIV1000', 22:'MONTH_DAY', \ 23:'SCHAR_DIV10', 24:'UCHAR_DIV10', 25:'TIME', \ 26:'LONG_DIV10', 27:'TIME_HHMM', 28:'TIME_HHMMSS', \ 29:'TIME_MMSS'})
from mpx import properties from mpx.lib.configure import set_attribute, get_attribute from mpx.lib.configure import REQUIRED from mpx.lib.configure import as_boolean from mpx.lib.node import CompositeNode, as_node from mpx.lib.exceptions import EInvalidValue, ETimeout from mpx.lib import EnumeratedDictionary from mpx.lib import msglog from mpx.lib.msglog.types import INFO, WARN, ERR import mpx.lib.genericdriver.gdconnection as gdconn import mpx.lib.genericdriver.gdlinehandler as gdlh import mpx.ion.usap.usapmsg as usapm command = EnumeratedDictionary({0: 'DACT', 1: 'ACTI'}) class UsapDevice(CompositeNode): """ This class is used to define USAP device. Its primary role is to interact with USAP device over RS-232 medium.""" def __init__(self): CompositeNode.__init__(self) self.debug = 0 self.enabled = 1 self.legacy_operating_code = 1 self.lh = None self.conn = None self.request_obj = usapm.UsapRequest() self.response_obj = usapm.UsapResponse() self.req_startCode_obj = None self.req_vData_obj = None