Ejemplo n.º 1
0
def create_AI(oid=1, pv=0, name="AI", units=None):
    aio = AnalogInputObject(
        objectIdentifier=("analogInput", oid),
        objectName=name,
        presentValue=pv,
        units=units,
    )
    return aio
Ejemplo n.º 2
0
def create_AI(oid=1, pv=0, name="AI", units=None):
    aio = AnalogInputObject(
        objectIdentifier=("analogInput", oid),
        objectName=name,
        presentValue=pv,
        units=units,
        outOfService=Boolean(False),
    )
    aio = _make_mutable(aio, identifier="outOfService", mutable=True)
    return aio
Ejemplo n.º 3
0
 def __init__(self, **kwargs):
     if _debug: ModbusAnalogInputObject._debug("__init__ %r", kwargs)
     AnalogInputObject.__init__(self, **kwargs)
Ejemplo n.º 4
0
def run_application() -> str:
    '''
    Simulate and query the device.
    :return: Object query result.
    '''
    from bacpypes.object import AnalogInputObject, AnalogValueObject, BinaryValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject
    from bacnet.local_device_applications import SimulateAndQueryDeviceApplication
    import bacpypes.basetypes

    analog_input_objects =\
        [
        AnalogInputObject(
        objectIdentifier=('analogInput', 1),
        objectName='CO2_Level',
        objectType='analogInput',
        presentValue=21,
        description='CO2 Level',
        deviceType='0-2000 ppm CO2 Sensor',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='partsPerMillion'
    ), AnalogInputObject(
        objectIdentifier=('analogInput', 2),
        objectName='Relative_Humidity',
        objectType='analogInput',
        presentValue=60,
        description='Relative Humidity',
        deviceType='0-100 %RH Sensor',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='percentRelativeHumidity'
    ), AnalogInputObject(
        objectIdentifier=('analogInput', 3),
        objectName='Temperature',
        objectType='analogInput',
        presentValue=19,
        description='Temperature',
        deviceType='0-35 C Temperature Sensor or 32-95 F Temperature Sensor',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='degreesCelsius'
    ), AnalogInputObject(
        objectIdentifier=('analogInput', 4),
        objectName='Setpoint_Control',
        objectType='analogInput',
        presentValue=67,
        description='Setpoint Value',
        deviceType='0-100 % Setpoint',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='percent'
    )]

    analog_value_objects = [
        AnalogValueObject(
            objectIdentifier=('analogValue', 1),
            objectName='Relay_Setpoint',
            objectType='analogValue',
            presentValue=1000,
            description='Relay Setpoint',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='partsPerMillion'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 2),
            objectName='Relay_Hysteresis',
            objectType='analogValue',
            presentValue=50,
            description='Relay Hysteresis',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='partsPerMillion'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 3),
            objectName='Temperature_Offset',
            objectType='analogValue',
            presentValue=50,
            description='Temperature Offset Calibration',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='deltaDegreesFahrenheit'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 4),
            objectName='Relative_Humidity_Offset',
            objectType='analogValue',
            presentValue=0,
            description='RH Offset Calibration',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='percentRelativeHumidity'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 5),
            objectName='Sensor_Altitude',
            objectType='analogValue',
            presentValue=50,
            description='CO2 Sensor Altitude',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='feet'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 6),
            objectName='Display_Modes',
            objectType='analogValue',
            presentValue=50,
            description='CO2 LCD Display Modes',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='noUnits')
    ]

    binary_value_objects = [
        BinaryValueObject(
            objectIdentifier=('binaryValue', 1),
            objectName='Override_Switch',
            objectType='binaryValue',
            presentValue=0,
            description='Override Switch',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False),
        BinaryValueObject(
            objectIdentifier=('binaryValue', 2),
            objectName='Auto_Cal_Enable',
            objectType='binaryValue',
            presentValue=1,
            description='Auto Calibration Enable',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False),
        BinaryValueObject(
            objectIdentifier=('binaryValue', 3),
            objectName='Fahrenheit',
            objectType='binaryValue',
            presentValue=1,
            description='Fahrenheit (1) or Celsius (0)',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False)
    ]

    binary_input_objects = [
        BinaryInputObject(
            objectIdentifier=('binaryInput', 1),
            objectName='Relay_On',
            objectType='binaryInput',
            presentValue=0,
            description='Relay Status',
            deviceType='Indicates On/Off Status of Relay',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False,
            polarity='normal',
        )
    ]

    objects = analog_input_objects + analog_value_objects + binary_value_objects + binary_input_objects

    return SimulateAndQueryDeviceApplication.run_application(
        objectIdentifier=381003,
        objectName="CDD_CO2_Detector_003",
        objectType=8,
        systemStatus='operational',
        vendorName='Greystone Energy Systems',
        vendorIdentifier=381,
        modelName='CDD2A',
        firmwareRevision='1.4',
        applicationSoftwareVersion='1.0',
        description='Greystone CO2 Detector',
        protocolVersion=1,
        protocolRevision=7,
        protocolObjectTypesSupported=[
            'analogInput', 'analogValue', 'binaryInput', 'binaryValue',
            'device'
        ],
        maxapdulength=128,
        segmentationSupported="noSegmentation",
        apduTimeout=10000,
        numberOfApduRetries=3,
        maxMaster=127,
        maxInfoFrames=1,
        objects=objects)
Ejemplo n.º 5
0
def run_application() -> str:
    '''
    Simulate and query the device.
    :return: Object query result.
    '''
    from bacpypes.object import AnalogInputObject, AnalogValueObject, BinaryValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject
    from bacnet.local_device_applications import SimulateAndQueryDeviceApplication
    import bacpypes.basetypes

    analog_input_objects =\
        [
        AnalogInputObject(
        objectIdentifier=('analogInput', 1),
        objectName='Pressure_Sensor_Value',
        objectType='analogInput',
        presentValue=101325,
        description='Pressure Value in Pa or wc',
        deviceType='Room Pressure Sensor',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='pascals'
    )]

    analog_value_objects = [
        AnalogValueObject(
            objectIdentifier=('analogValue', 1),
            objectName='Pressure_Averaging_Time',
            objectType='analogValue',
            presentValue=5,
            description='Pressure Averaging Time',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='seconds'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 2),
            objectName='Alarm_High_Limit',
            objectType='analogValue',
            presentValue=0.5,
            description='Alarm High Limit in Pa or wc',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='pascals'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 3),
            objectName='Alarm_Low_Limit',
            objectType='analogValue',
            presentValue=-0.5,
            description='Alarm Low Limit in Pa or wc',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='pascals'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 4),
            objectName='Alarm_On_Delay',
            objectType='analogValue',
            presentValue=5,
            description='Alarm On Delay',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='minutes'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 5),
            objectName='Alarm_Off_Delay',
            objectType='analogValue',
            presentValue=5,
            description='Alarm Off Delay',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='minutes'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 6),
            objectName='Alarm_Silence_Time',
            objectType='analogValue',
            presentValue=30,
            description='Alarm Silence Time',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='minutes'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 7),
            objectName='Buzzer_Volume',
            objectType='analogValue',
            presentValue=2,
            description='CO2 LCD Display Modes',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='noUnits')
    ]

    binary_value_objects = [
        BinaryValueObject(
            objectIdentifier=('binaryValue', 1),
            objectName='Alarm_Enable',
            objectType='binaryValue',
            presentValue=1,
            description='0 = Alarm Disable, 1 = Alarm Enable',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False),
        BinaryValueObject(
            objectIdentifier=('binaryValue', 2),
            objectName='Alarm_Test',
            objectType='binaryValue',
            presentValue=0,
            description='0 = Normal Operation, 1 = Alarm Test',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False),
        BinaryValueObject(
            objectIdentifier=('binaryValue', 3),
            objectName='Backlight_Enable',
            objectType='binaryValue',
            presentValue=1,
            description='0 = Backlight Disable, 1 = Backlight Enable',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False),
        BinaryValueObject(
            objectIdentifier=('binaryValue', 4),
            objectName='Pressure_Units',
            objectType='binaryValue',
            presentValue=0,
            description='0 = wc, 1 = Pa ',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False),
        BinaryValueObject(
            objectIdentifier=('binaryValue', 5),
            objectName='Pressure_Range',
            objectType='binaryValue',
            presentValue=1,
            description='0 = Low Pressure Range, 1 = High Pressure Range',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False)
    ]

    binary_input_objects = [
        BinaryInputObject(
            objectIdentifier=('binaryInput', 1),
            objectName='Alarm_Status',
            objectType='binaryInput',
            presentValue=0,
            description='Alarm Status',
            deviceType='0 = No Alarm, 1 = Pressure Alarm',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False,
            polarity='normal',
        ),
        BinaryInputObject(
            objectIdentifier=('binaryInput', 2),
            objectName='Low_Alarm_Status',
            objectType='binaryInput',
            presentValue=0,
            description='Low Alarm Status',
            deviceType='0 = No Low Alarm, 1 = Low Pressure Alarm',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False,
            polarity='normal',
        ),
        BinaryInputObject(
            objectIdentifier=('binaryInput', 3),
            objectName='High_Alarm_Status',
            objectType='binaryInput',
            presentValue=0,
            description='High Alarm Status',
            deviceType='0 = No High Alarm, 1 = High Pressure Alarm',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False,
            polarity='normal',
        )
    ]

    objects = analog_input_objects + analog_value_objects + binary_value_objects + binary_input_objects

    return SimulateAndQueryDeviceApplication.run_application(
        objectIdentifier=381003,
        objectName="Room Pressure Monitor 003",
        objectType=8,
        systemStatus='operational',
        vendorName='Greystone Energy Systems',
        vendorIdentifier=381,
        modelName='RPC',
        firmwareRevision='1.4',
        applicationSoftwareVersion='1.0',
        description='Greystone RP Monitor',
        protocolVersion=1,
        protocolRevision=7,
        protocolObjectTypesSupported=[
            'analogInput', 'analogValue', 'binaryInput', 'binaryValue',
            'device'
        ],
        maxapdulength=128,
        segmentationSupported="noSegmentation",
        apduTimeout=10000,
        numberOfApduRetries=3,
        maxMaster=127,
        maxInfoFrames=1,
        objects=objects)
Ejemplo n.º 6
0
def create_AI(oid=1, pv=0, name='AI', units=None):
    aio = AnalogInputObject(objectIdentifier=('analogInput', oid),
                            objectName=name,
                            presentValue=pv,
                            units=units)
    return aio
Ejemplo n.º 7
0
def run_application() -> str:
    '''
    Simulate and query the device.
    :return: Object query result.
    '''
    from bacpypes.object import AnalogInputObject, AnalogOutputObject, AnalogValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject
    from bacnet.local_device_applications import SimulateAndQueryDeviceApplication
    import bacpypes.basetypes

    analog_input_objects =\
        [
        AnalogInputObject(
        objectName='Temperature Sensor',
        objectIdentifier=('analogInput', 0),
        objectType='analogInput',
        presentValue=21,
        #statusFlags='inAlarm',
        eventState='normal',
        outOfService=False,
        units='degreesCelsius'
    ), AnalogInputObject(
        objectName='Setpoint Adjust',
        objectIdentifier=('analogInput', 1),
        objectType='analogInput',
        presentValue=259,
        #statusFlags='inAlarm',
        eventState='normal',
        outOfService=False,
        units='degreesCelsius'
    ), AnalogInputObject(
        objectName='Humidity Sensor',
        objectIdentifier=('analogInput', 2),
        objectType='analogInput',
        presentValue=27,
        #statusFlags='inAlarm',
        eventState='normal',
        outOfService=False,
        units='percent'
    ), AnalogInputObject(
        objectName='RI1',
        objectIdentifier=('analogInput', 3),
        objectType='analogInput',
        presentValue=20981,
        #statusFlags='inAlarm',
        eventState='normal',
        outOfService=False,
        units='ohms'
    ), AnalogInputObject(
        objectName='RI2',
        objectIdentifier=('analogInput', 4),
        objectType='analogInput',
        presentValue=12841,
        #statusFlags='inAlarm',
        eventState='normal',
        outOfService=False,
        units='ohms'
    ), AnalogInputObject(
        objectName='CO2 Sensor',
        objectIdentifier=('analogInput', 5),
        objectType='analogInput',
        presentValue=738,
        #statusFlags='inAlarm',
        eventState='normal',
        outOfService=False,
        units='partsPerMillion'
    ), AnalogInputObject(
        objectName='LUX Sensor',
        objectIdentifier=('analogInput', 6),
        objectType='analogInput',
        presentValue=1974,
        #statusFlags='inAlarm',
        eventState='normal',
        outOfService=False,
        units='luxes'
    )]

    analog_output_objets = [
        AnalogOutputObject(objectIdentifier=('analogOutput', 0),
                           objectName='Y1',
                           objectType='analogOutput',
                           presentValue=72,
                           eventState='normal',
                           outOfService=False,
                           units='percent'),
        AnalogOutputObject(objectIdentifier=('analogOutput', 1),
                           objectName='Y2',
                           objectType='analogOutput',
                           presentValue=21,
                           eventState='normal',
                           outOfService=False,
                           units='percent'),
        AnalogOutputObject(objectIdentifier=('analogOutput', 2),
                           objectName='Y3',
                           objectType='analogOutput',
                           presentValue=82,
                           eventState='normal',
                           outOfService=False,
                           units='percent')
    ]

    analog_value_objects = [
        AnalogValueObject(objectIdentifier=('analogValue', 0),
                          objectName='Temperature Setpoint',
                          objectType='analogValue',
                          presentValue=27,
                          eventState='normal',
                          outOfService=False,
                          units='degreesCelsius',
                          relinquishDefault=20),
        AnalogValueObject(objectIdentifier=('analogValue', 1),
                          objectName='Humidity Setpoint',
                          objectType='analogValue',
                          presentValue=12,
                          eventState='normal',
                          outOfService=False,
                          units='percent',
                          relinquishDefault=50),
        AnalogValueObject(objectIdentifier=('analogValue', 2),
                          objectName='CO2 Setpoint',
                          objectType='analogValue',
                          presentValue=502,
                          eventState='normal',
                          outOfService=False,
                          units='partsPerMillion',
                          relinquishDefault=500),
        AnalogValueObject(objectIdentifier=('analogValue', 3),
                          objectName='LUX Setpoint',
                          objectType='analogValue',
                          presentValue=1129,
                          eventState='normal',
                          outOfService=False,
                          units='luxes',
                          relinquishDefault=1500),
        AnalogValueObject(objectIdentifier=('analogValue', 4),
                          objectName='DI1 Pulse Count',
                          objectType='analogValue',
                          presentValue=8276491,
                          eventState='normal',
                          outOfService=False,
                          units='noUnits',
                          relinquishDefault=0),
        AnalogValueObject(objectIdentifier=('analogValue', 5),
                          objectName='DI2 Pulse Count',
                          objectType='analogValue',
                          presentValue=292384,
                          eventState='normal',
                          outOfService=False,
                          units='noUnits',
                          relinquishDefault=0),
        AnalogValueObject(objectIdentifier=('analogValue', 6),
                          objectName='LCD Backlight Brightness',
                          objectType='analogValue',
                          presentValue=7,
                          eventState='normal',
                          outOfService=False,
                          units='noUnits',
                          relinquishDefault=0),
    ]

    binary_input_objects = [
        BinaryInputObject(objectIdentifier=('binaryInput', 0),
                          objectName='DI1',
                          objectType='binaryInput',
                          presentValue=0,
                          eventState='normal',
                          outOfService=False,
                          polarity='normal',
                          activeText='on',
                          inactiveText='off'),
        BinaryInputObject(objectIdentifier=('binaryInput', 1),
                          objectName='DI2',
                          objectType='binaryInput',
                          presentValue=1,
                          eventState='normal',
                          outOfService=False,
                          polarity='normal',
                          activeText='on',
                          inactiveText='off'),
        BinaryInputObject(objectIdentifier=('binaryInput', 2),
                          objectName='Occupancy',
                          objectType='binaryInput',
                          presentValue=1,
                          eventState='normal',
                          outOfService=False,
                          polarity='normal',
                          activeText='on',
                          inactiveText='off'),
        BinaryInputObject(objectIdentifier=('binaryInput', 3),
                          objectName='Push Button 1',
                          objectType='binaryInput',
                          presentValue=0,
                          eventState='normal',
                          outOfService=False,
                          polarity='normal',
                          activeText='on',
                          inactiveText='off'),
        BinaryInputObject(objectIdentifier=('binaryInput', 4),
                          objectName='Push Button 2',
                          objectType='binaryInput',
                          presentValue=0,
                          eventState='normal',
                          outOfService=False,
                          polarity='normal',
                          activeText='on',
                          inactiveText='off')
    ]

    binary_output_objects = [
        BinaryOutputObject(objectIdentifier=('binaryOutput', 0),
                           objectName='DO1',
                           objectType='binaryOutput',
                           presentValue=0,
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 1),
                           objectName='DO2',
                           objectType='binaryOutput',
                           presentValue=0,
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 2),
                           objectName='SPA Reset',
                           objectType='binaryOutput',
                           presentValue=0,
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off')
    ]

    multistate_input_objects = [
        MultiStateInputObject(objectIdentifier=('multiStateInput', 0),
                              objectName='Alarm Level',
                              objectType='multiStateInput',
                              presentValue=1,
                              eventState='normal',
                              outOfService=False,
                              numberOfStates=3)
    ]

    objects = analog_output_objets + analog_input_objects + analog_value_objects + binary_input_objects + binary_output_objects + multistate_input_objects

    return SimulateAndQueryDeviceApplication.run_application(
        objectIdentifier=651000,
        objectName="CDR_001",
        objectType=8,
        systemStatus='operational',
        vendorName='SyxthSense',
        vendorIdentifier=651,
        modelName='CDR',
        protocolVersion=1,
        protocolRevision=10,
        maxapdulength=480,
        segmentationSupported="noSegmentation",
        apduTimeout=3000,
        numberOfApduRetries=3,
        maxMaster=127,
        maxInfoFrames=1,
        databaseRevision=0,
        objects=objects)
Ejemplo n.º 8
0
def main():
    device_info = {
        'ip': '10.169.204.200',
        'netmask': 23,
        'port': 47809,
        'objectName': 'FHL-DAF-DUSTMETER',
        'objectIdentifier': 522020,
        'vendorIdentifier': 15,
        'location': 'FHL-DAF-CLEAN-ROOM',
        'vendorName': 'DESY-ATLAS',
        'modelName': 'DUST-METERS',
        'softwareVersion': 'bacpypes_v0.16.2_py27',
        'description': 'FHL-DAF clean room dustmeter server'
    }

    print device_info

    this_device = LocalDeviceObject(
        objectName=device_info['objectName'],
        objectIdentifier=device_info['objectIdentifier'],
        vendorIdentifier=device_info['vendorIdentifier'])

    this_device._values['location'] = CharacterString(device_info['location'])
    this_device._values['vendorName'] = CharacterString(
        device_info['vendorName'])
    this_device._values['modelName'] = CharacterString(
        device_info['modelName'])
    this_device._values['applicationSoftwareVersion'] = CharacterString(
        device_info['softwareVersion'])
    this_device._values['description'] = CharacterString(
        device_info['description'])

    this_addr = str(device_info['ip'] + '/' + str(device_info['netmask']) +
                    ':' + str(device_info['port']))
    print 'bacnet server will listen at', this_addr
    this_application = BIPSimpleApplication(this_device, this_addr)
    this_application.add_capability(ReadWritePropertyMultipleServices)
    this_device.protocolServicesSupported = this_application.get_services_supported(
    ).value

    meter_info = [
        {
            'name': 'dustmeter_a19',
            'index': 1,
            'host': 'fhlrs232_a19.desy.de',
            'description': 'dustmeter on RS232-Ethernet bridge at somewhere',
        },
        {
            'name': 'dustmeter_a27',
            'index': 2,
            'host': 'fhlrs232_a27.desy.de',
            'description': 'dustmeter on RS232-Ethernet bridge at somewhere',
        },
        {
            'name': 'dustmeter_a40',
            'index': 3,
            'host': 'fhlrs232_a40.desy.de',
            'description': 'dustmeter on RS232-Ethernet bridge at somewhere',
        },
        {
            'name': 'dustmeter_a43',
            'index': 4,
            'host': 'fhlrs232_a43.desy.de',
            'description': 'dustmeter on RS232-Ethernet bridge at somewhere',
        },
        {
            'name': 'dustmeter_a49',
            'index': 5,
            'host': 'fhlrs232_a49.desy.de',
            'description': 'dustmeter on RS232-Ethernet bridge at somewhere',
        },
        {
            'name': 'dustmeter_a56',
            'index': 6,
            'host': 'fhlrs232_a56.desy.de',
            'description': 'dustmeter on RS232-Ethernet bridge at somewhere',
        },
    ]

    meters = []
    for info in meter_info:
        m = dustmeter.DustMeter(name=info['name'], host=info['host'])
        m.start()
        meters.append(m)

    objs = []
    for info in meter_info:
        ai_obj = AnalogInputObject(objectIdentifier=('analogInput', info['index']), \
                                   objectName=info['name'])
        ai_obj._values['description'] = CharacterString(info['description'])
        ai_obj._values['deviceType'] = CharacterString(
            'Particles(>0.5um) PerCubicFoot')
        ai_obj._values['units'] = EngineeringUnits('noUnits')
        ai_obj._values['updateInterval'] = Unsigned(60)
        ai_obj._values['resolution'] = Real(100)
        this_application.add_object(ai_obj)
        objs.append(ai_obj)

    mythread = dataThread(meters, objs)
    mythread.start()

    run()

    mythread.stop()
    mythread.join()
    for m in meters:
        m.stop()
        m.join()
    print "end of join"
Ejemplo n.º 9
0
def run_application() -> str:
    '''
    Simulate and query the device.
    :return: Object query result.
    '''
    from bacpypes.object import AnalogInputObject, AnalogOutputObject, AnalogValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject
    from bacnet.local_device_applications import SimulateAndQueryDeviceApplication
    import bacpypes.basetypes

    analog_input_objects = [
        AnalogInputObject(objectName='Built-In Temperature Sensor',
                          objectIdentifier=('analogInput', 1),
                          objectType='analogInput',
                          presentValue=21,
                          eventState='normal',
                          outOfService=False,
                          units='degreesCelsius'),
        AnalogInputObject(objectName='External Temperature Sensor',
                          objectIdentifier=('analogInput', 2),
                          objectType='analogInput',
                          presentValue=87,
                          eventState='normal',
                          outOfService=False,
                          units='degreesCelsius'),
        AnalogInputObject(objectName='Calculated Setpoint',
                          objectIdentifier=('analogInput', 3),
                          objectType='analogInput',
                          presentValue=87,
                          eventState='normal',
                          outOfService=False,
                          units='degreesCelsius')
    ]

    analog_output_objets = [
        AnalogOutputObject(objectIdentifier=('analogOutput', 1),
                           objectName='Y1',
                           objectType='analogOutput',
                           presentValue=12,
                           eventState='normal',
                           outOfService=False,
                           units='percent'),
        AnalogOutputObject(objectIdentifier=('analogOutput', 2),
                           objectName='Y2',
                           objectType='analogOutput',
                           presentValue=88,
                           eventState='normal',
                           outOfService=False,
                           units='percent'),
        AnalogOutputObject(objectIdentifier=('analogOutput', 3),
                           objectName='Y3',
                           objectType='analogOutput',
                           presentValue=62,
                           eventState='normal',
                           outOfService=False,
                           units='percent'),
        AnalogOutputObject(objectIdentifier=('analogOutput', 4),
                           objectName='Thermic1_Position',
                           objectType='analogOutput',
                           presentValue=10,
                           eventState='normal',
                           outOfService=False,
                           units='percent'),
        AnalogOutputObject(objectIdentifier=('analogOutput', 5),
                           objectName='Thermic2_Position',
                           objectType='analogOutput',
                           presentValue=97,
                           eventState='normal',
                           outOfService=False,
                           units='percent'),
        AnalogOutputObject(objectIdentifier=('analogOutput', 6),
                           objectName='ThreePoint_Position',
                           objectType='analogOutput',
                           presentValue=62,
                           eventState='normal',
                           outOfService=False,
                           units='percent')
    ]

    analog_value_objects = [
        AnalogValueObject(objectIdentifier=('analogValue', 0),
                          objectName='Temperature Setpoint',
                          objectType='analogValue',
                          presentValue=18,
                          eventState='normal',
                          outOfService=False,
                          units='degreesCelsius',
                          relinquishDefault=20),
        AnalogValueObject(objectIdentifier=('analogValue', 1),
                          objectName='LCD Brightness',
                          objectType='analogValue',
                          presentValue=3.5,
                          eventState='normal',
                          outOfService=False,
                          units='percent',
                          relinquishDefault=50)
    ]

    binary_input_objects = [
        BinaryInputObject(objectIdentifier=('binaryInput', 0),
                          objectName='DI1',
                          objectType='binaryInput',
                          presentValue=0,
                          eventState='normal',
                          outOfService=False,
                          polarity='normal',
                          activeText='on',
                          inactiveText='off')
    ]

    binary_output_objects = [
        BinaryOutputObject(objectIdentifier=('binaryOutput', 0),
                           objectName='DO1',
                           objectType='binaryOutput',
                           presentValue=0,
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 1),
                           objectName='DO2',
                           objectType='binaryOutput',
                           presentValue=0,
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 2),
                           objectName='Night_Mode_Override',
                           objectType='binaryOutput',
                           presentValue=0,
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 3),
                           objectName='Summer_Winter_Changeover',
                           objectType='binaryOutput',
                           presentValue=0,
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 4),
                           objectName='Cooling_Disable',
                           objectType='binaryOutput',
                           presentValue=0,
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off')
    ]

    objects = analog_output_objets + analog_input_objects + analog_value_objects + binary_input_objects + binary_output_objects

    return SimulateAndQueryDeviceApplication.run_application(
        objectIdentifier=651000,
        objectName="SRC100_001",
        objectType='device',
        systemStatus='operational',
        vendorName='SyxthSense',
        vendorIdentifier=651,
        modelName='URD',
        protocolVersion=1,
        protocolRevision=10,
        maxapdulength=480,
        segmentationSupported="noSegmentation",
        apduTimeout=3000,
        numberOfApduRetries=3,
        maxMaster=127,
        maxInfoFrames=1,
        databaseRevision=0,
        objects=objects)
Ejemplo n.º 10
0
def run_application() -> str:
    '''
    Simulate and query the device.
    :return: Object query result.
    '''
    from bacpypes.object import AnalogInputObject, AnalogValueObject, BinaryValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject
    from bacnet.local_device_applications import SimulateAndQueryDeviceApplication
    import bacpypes.basetypes

    analog_input_objects =\
        [
        AnalogInputObject(
        objectIdentifier=('analogInput', 1),
        objectName='Temperature',
        objectType='analogInput',
        presentValue=19,
        description='Temperature',
        deviceType='Temperature Sensor',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='degreesCelsius'
    ), AnalogInputObject(
        objectIdentifier=('analogInput', 2),
        objectName='Relative Humidity',
        objectType='analogInput',
        presentValue=60,
        description='Relative Humidity',
        deviceType='RH Sensor',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='percentRelativeHumidity'
    ), AnalogInputObject(
        objectIdentifier=('analogInput', 3),
        objectName='Dewpoint Temperature',
        objectType='analogInput',
        presentValue=8,
        description='Dewpoint Temperature',
        deviceType='Dewpoint Temperature Sensor',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='degreesCelsius'
    ), AnalogInputObject(
        objectIdentifier=('analogInput', 4),
        objectName='Wet Bulb Temperature',
        objectType='analogInput',
        presentValue=19,
        description='Wet Bulb Temperature',
        deviceType='Wet Bulb Temperature Sensor',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='degreesCelsius'
    ), AnalogInputObject(
        objectIdentifier=('analogInput', 5),
        objectName='Enthalpy',
        objectType='analogInput',
        presentValue=19,
        description='Enthalpy',
        deviceType='Enthalpy Sensor',
        statusFlags=['inAlarm','inAlarm','inAlarm','inAlarm'],
        eventState='normal',
        reliability='noFaultDetected',
        outOfService=False,
        units='kilojoulesPerKilogramDryAir'
    )]

    analog_value_objects = [
        AnalogValueObject(
            objectIdentifier=('analogValue', 1),
            objectName='Temperature Offset',
            objectType='analogValue',
            presentValue=0,
            description='Temperature Offset',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='deltaDegreesFahrenheit'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 2),
            objectName='RH Offset',
            objectType='analogValue',
            presentValue=0,
            description='RH Offset',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='percentRelativeHumidity'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 3),
            objectName='Atmospheric Pressure',
            objectType='analogValue',
            presentValue=1013,
            description='Atmospheric Pressure',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='hectopascals'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 4),
            objectName='Altitude',
            objectType='analogValue',
            presentValue=0,
            description='Altitude',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='feet'),
        AnalogValueObject(
            objectIdentifier=('analogValue', 5),
            objectName='Display Mode',
            objectType='analogValue',
            presentValue=0,
            description='Display Mode',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            outOfService=False,
            units='noUnits')
    ]

    binary_value_objects = [
        BinaryValueObject(
            objectIdentifier=('binaryValue', 1),
            objectName='Temperature Units',
            objectType='binaryValue',
            presentValue=0,
            description='Celsius (0) or Fahrenheit (1)',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False),
        BinaryValueObject(
            objectIdentifier=('binaryValue', 2),
            objectName='Enthalpy Units',
            objectType='binaryValue',
            presentValue=0,
            description='kJ/kg (0) or BTU/lb (1)',
            statusFlags=['inAlarm', 'inAlarm', 'inAlarm', 'inAlarm'],
            eventState='normal',
            reliability='noFaultDetected',
            outOfService=False)
    ]

    objects = analog_input_objects + analog_value_objects + binary_value_objects

    return SimulateAndQueryDeviceApplication.run_application(
        objectIdentifier=381001,
        objectName="DP_001",
        objectType=8,
        systemStatus='operational',
        vendorName='Greystone Energy Systems',
        vendorIdentifier=381,
        modelName='DP',
        firmwareRevision='1.2',
        applicationSoftwareVersion='1.0',
        description='Greystone Dewpoint Systems',
        protocolVersion=1,
        protocolRevision=14,
        protocolObjectTypesSupported=[
            'analogInput', 'analogValue', 'binaryValue', 'device'
        ],
        maxapdulength=128,
        segmentationSupported="noSegmentation",
        apduTimeout=6000,
        numberOfApduRetries=3,
        maxMaster=127,
        maxInfoFrames=1,
        objects=objects)
Ejemplo n.º 11
0
def run_application() -> str:
    '''
    Simulate and query the device.
    :return: Object query result.
    '''
    from bacpypes.object import AnalogInputObject, AnalogOutputObject, AnalogValueObject, BinaryValueObject, BinaryInputObject, BinaryOutputObject, MultiStateInputObject
    from bacnet.local_device_applications import SimulateAndQueryDeviceApplication
    from random import randint

    analog_input_objects = [
        AnalogInputObject(objectIdentifier=('analogInput', 0),
                          objectName='Sensor_Temperature',
                          objectType='analogInput',
                          presentValue=randint(0, 150),
                          eventState='normal',
                          outOfService=False,
                          units='degreesCelsius'),
        AnalogInputObject(objectIdentifier=('analogInput', 1),
                          objectName='Setpoint_Adjust',
                          objectType='analogInput',
                          presentValue=randint(0, 150),
                          eventState='normal',
                          outOfService=False,
                          units='degreesCelsius'),
        AnalogInputObject(objectIdentifier=('analogInput', 2),
                          objectName='Sensor_Humidity',
                          objectType='analogInput',
                          presentValue=randint(0, 100),
                          eventState='normal',
                          outOfService=False,
                          units='percent'),
        AnalogInputObject(objectIdentifier=('analogInput', 3),
                          objectName='RI1',
                          objectType='analogInput',
                          presentValue=randint(0, 50000),
                          eventState='normal',
                          outOfService=False,
                          units='ohms'),
        AnalogInputObject(objectIdentifier=('analogInput', 4),
                          objectName='User_Fan_Speed',
                          objectType='analogInput',
                          presentValue=randint(0, 100),
                          eventState='normal',
                          outOfService=False,
                          units='noUnits')
    ]

    analog_output_objects = [
        AnalogOutputObject(objectIdentifier=('analogOutput', 0),
                           objectName='Y1',
                           objectType='analogOutput',
                           presentValue=randint(0, 100),
                           eventState='normal',
                           outOfService=False,
                           units='percent')
    ]

    analog_value_objects = [
        AnalogValueObject(
            objectIdentifier=('analogValue', 0),
            objectName='Setpoint_Temperature',
            objectType='analogValue',
            presentValue=randint(0, 100),
            eventState='normal',
            outOfService=False,
            units='degreesCelsius',
        ),
        AnalogValueObject(
            objectIdentifier=('analogValue', 1),
            objectName='Fan_Speed',
            objectType='analogValue',
            presentValue=randint(0, 10),
            eventState='normal',
            outOfService=False,
            units='noUnits',
        ),
        AnalogValueObject(
            objectIdentifier=('analogValue', 2),
            objectName='Alarm_Code',
            objectType='analogValue',
            presentValue=randint(0, 100),
            eventState='normal',
            outOfService=False,
            units='noUnits',
        )
    ]

    binary_input_objects = [
        BinaryInputObject(objectIdentifier=('binaryInput', 0),
                          objectName='DI1',
                          objectType='binaryInput',
                          presentValue=randint(0, 1),
                          eventState='normal',
                          outOfService=False,
                          polarity='normal',
                          activeText='on',
                          inactiveText='off'),
        BinaryInputObject(objectIdentifier=('binaryInput', 1),
                          objectName='Operating_Mode',
                          objectType='binaryInput',
                          presentValue=randint(0, 1),
                          eventState='normal',
                          outOfService=False,
                          polarity='normal',
                          activeText='on',
                          inactiveText='off')
    ]

    binary_output_ojects = [
        BinaryOutputObject(objectIdentifier=('binaryOutput', 0),
                           objectName='DO1',
                           objectType='binaryOutput',
                           presentValue=randint(0, 1),
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 1),
                           objectName='DO2',
                           objectType='binaryOutput',
                           presentValue=randint(0, 1),
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 2),
                           objectName='Heating Symbol',
                           objectType='binaryOutput',
                           presentValue=randint(0, 1),
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 3),
                           objectName='Cooling Symbol',
                           objectType='binaryOutput',
                           presentValue=randint(0, 1),
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 4),
                           objectName='Open Arrow Symbol',
                           objectType='binaryOutput',
                           presentValue=randint(0, 1),
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 5),
                           objectName='Close Arrow Symbol',
                           objectType='binaryOutput',
                           presentValue=randint(0, 1),
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 6),
                           objectName='Day/Night Model',
                           objectType='binaryOutput',
                           presentValue=randint(0, 1),
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off'),
        BinaryOutputObject(objectIdentifier=('binaryOutput', 7),
                           objectName='SPA Reset',
                           objectType='binaryOutput',
                           presentValue=randint(0, 1),
                           eventState='normal',
                           outOfService=False,
                           polarity='normal',
                           relinquishDefault=0,
                           activeText='on',
                           inactiveText='off')
    ]

    objects = analog_input_objects + analog_output_objects + analog_value_objects + binary_input_objects + binary_output_ojects

    return SimulateAndQueryDeviceApplication.run_application(
        objectIdentifier=651000,
        objectName="RIU_001",
        objectType=8,
        systemStatus='operational',
        vendorName='SyxthSense',
        vendorIdentifier=651,
        modelName='RI',
        protocolVersion=1,
        protocolRevision=10,
        maxapdulength=480,
        segmentationSupported="noSegmentation",
        apduTimeout=3000,
        numberOfApduRetries=3,
        maxMaster=127,
        maxInfoFrames=1,
        objects=objects)
Ejemplo n.º 12
0
def main():
    global test_ai, test_application

    # make a parser
    parser = ConfigArgumentParser(description=__doc__)
    parser.add_argument(
        "--console",
        action="store_true",
        default=False,
        help="create a console",
    )

    # analog value task and thread
    parser.add_argument(
        "--aitask",
        type=float,
        help="analog input recurring task",
    )
    parser.add_argument(
        "--aithread",
        type=float,
        help="analog input thread",
    )

    # analog value task and thread
    parser.add_argument(
        "--bvtask",
        type=float,
        help="binary value recurring task",
    )
    parser.add_argument(
        "--bvthread",
        type=float,
        help="binary value thread",
    )

    # provide a different spin value
    parser.add_argument(
        "--spin",
        type=float,
        help="spin time",
        default=1.0,
    )

    # parse the command line arguments
    args = parser.parse_args()

    if _debug:
        _log.debug("initialization")
    if _debug:
        _log.debug("    - args: %r", args)

    # make a device object
    this_device = LocalDeviceObject(ini=args.ini)
    if _debug:
        _log.debug("    - this_device: %r", this_device)

    # make a sample application
    test_application = SubscribeCOVApplication(this_device, args.ini.address)

    # make an analog value object
    test_ai = AnalogInputObject(
        objectIdentifier=("analogInput", 1),
        objectName="ai",
        presentValue=0.0,
        covIncrement=0.5,
        eventDetectionEnable=True,
        eventEnable=[1, 1, 1],
        ackedTransitions=[1, 1, 1],
        notifyType=1,
        reliability=1,
        outOfService=False,
        eventState=0,
        statusFlags=[0, 0, 0, 0],
        units=19,
    )
    _log.debug("    - test_ai: %r", test_ai)

    # add it to the device
    test_application.add_object(test_ai)
    _log.debug("    - object list: %r", this_device.objectList)

    # make a console
    if args.console:
        test_console = COVConsoleCmd()
        _log.debug("    - test_console: %r", test_console)

        # enable sleeping will help with threads
        enable_sleeping()

    # analog input task
    if args.aitask:
        test_ai_task = TestAnalogInputTask(args.aitask)
        test_ai_task.install_task()

    # analog input thread
    if args.aithread:
        test_ai_thread = TestAnalogInputThread(args.aithread)
        deferred(test_ai_thread.start)

    _log.debug("running")

    run(args.spin)

    _log.debug("fini")
Ejemplo n.º 13
0
        if len(missing_metersections) != 0:
            print("Missing config sections for meters: " +
                  "".join(missing_metersections))
            exit(1)

        for metersection in metersections:
            info = cparser[metersection]

            ms = metermodule.getMeters(info)
            print("Got {} meter(s) from {}".format(len(ms), metersection))
            meters_active.extend(ms)

            for m in ms:
                m.name = "{}_{}".format(metersection, m.name)
                ai_obj = AnalogInputObject(objectIdentifier=("analogInput",
                                                             idx),
                                           objectName=m.name)
                if "description" in info:
                    ai_obj._values["description"] = CharacterString(
                        info["description"])
                if "deviceType" in info:
                    ai_obj._values["deviceType"] = CharacterString(
                        info["deviceType"])
                ai_obj._values["units"] = EngineeringUnits("noUnits")
                if "updateInterval" in info:
                    try:
                        updateInterval = int(info["updateInterval"])
                        if updateInterval < 0:
                            raise ValueError("Invalid negative value :" +
                                             info["updateInterval"])
                    except ValueError as e:
Ejemplo n.º 14
0
def main():

    if not path.exists("server.cfg"):
        logger.error("Error: File server.cfg not found.")
        exit(1)

    cparser = configparser.ConfigParser()
    cparser.read("server.cfg")

    if not "server" in cparser:
        logger.error("Invalid config: No server section")
        exit(1)

    required_keys = {
        "ip", "port", "objectname", "vendoridentifier", "location",
        "vendorname", "modelname", "description"
    }
    missing_keys = required_keys - set(cparser["server"].keys())
    if len(missing_keys) != 0:
        logger.error("Missing config keys in server section: " +
                     (" ".join(missing_keys)))
        exit(1)

    device_info = {
        'ip':
        cparser["server"]["ip"],
        'netmask':
        23,
        'port':
        cparser["server"]["port"],
        'objectName':
        cparser["server"]["objectName"],
        'objectIdentifier':
        522020,
        'vendorIdentifier':
        int(cparser["server"]["vendorIdentifier"]),
        'location':
        cparser["server"]["location"],
        'vendorName':
        cparser["server"]["vendorName"],
        'modelName':
        cparser["server"]["modelName"],
        'softwareVersion':
        "bacpypes_{}_python{}.{}.{}".format(bacpypes_version, version_info[0],
                                            version_info[1], version_info[2]),
        'description':
        cparser["server"]["description"]
    }

    logger.info("=== INIT ===")
    logger.info(device_info)

    this_device = LocalDeviceObject(
        objectName=device_info["objectName"],
        objectIdentifier=device_info["objectIdentifier"],
        vendorIdentifier=device_info["vendorIdentifier"])

    this_device._values['location'] = CharacterString(device_info['location'])
    this_device._values['vendorName'] = CharacterString(
        device_info['vendorName'])
    this_device._values['modelName'] = CharacterString(
        device_info['modelName'])
    this_device._values['applicationSoftwareVersion'] = CharacterString(
        device_info['softwareVersion'])
    this_device._values['description'] = CharacterString(
        device_info['description'])

    this_addr = str(device_info['ip'] + '/' + str(device_info['netmask']) +
                    ':' + str(device_info['port']))
    logger.info("bacnet server will listen at {}".format(this_addr))
    this_application = BIPSimpleApplication(this_device, this_addr)
    this_application.add_capability(ReadWritePropertyMultipleServices)
    this_device.protocolServicesSupported = this_application.get_services_supported(
    ).value

    meters_active = []
    ai_objs = []
    idx = 1

    logger.info("Initializing meters...")
    for key, metermodule in METERS.items():
        if not key in cparser["server"]:
            logger.warning(
                "No key '{}' in config server section. Skipping".format(key))
            continue
        metersections = cparser["server"][key].split()
        missing_metersections = set(metersections) - set(cparser.keys())
        if len(missing_metersections) != 0:
            logger.error("Missing config sections for meters: " +
                         "".join(missing_metersections))
            exit(1)

        for metersection in metersections:
            info = cparser[metersection]

            ms = metermodule.getMeters(info)
            logger.info("Got {} meter(s) from {}".format(
                len(ms), metersection))
            meters_active.extend(ms)

            for m in ms:
                m.name = "{}_{}".format(metersection, m.name)
                ai_obj = AnalogInputObject(objectIdentifier=("analogInput",
                                                             idx),
                                           objectName=m.name)
                if "description" in info:
                    ai_obj._values["description"] = CharacterString(
                        info["description"])
                if "deviceType" in info:
                    ai_obj._values["deviceType"] = CharacterString(
                        info["deviceType"])
                ai_obj._values["units"] = EngineeringUnits("noUnits")
                if "updateInterval" in info:
                    try:
                        updateInterval = int(info["updateInterval"])
                        if updateInterval < 0:
                            raise ValueError("Invalid negative value :" +
                                             info["updateInterval"])
                    except ValueError as e:
                        logger.error(
                            "Value of updateInterval in section {}: {}".format(
                                metersection, e))
                        exit(1)
                    ai_obj._values["updateInterval"] = Unsigned(updateInterval)
                if "resolution" in info:
                    try:
                        resolution = float(info["resolution"])
                    except ValueError as e:
                        logger.error(
                            "Value of updateInterval in section {}: {}".format(
                                metersection, e))
                        exit(1)
                    ai_obj._values["resolution"] = Real(resolution)
                this_application.add_object(ai_obj)
                ai_objs.append(ai_obj)

                idx += 1

                fname = m.name
                output_csv = os.path.join(str('/var/www/html'),
                                          fname + u".csv")
                mode = 'a'
                if sys.version_info.major < 3:
                    mode += 'b'
                with open(output_csv, mode) as f:
                    header = OrderedDict([('# time', None), (m.name, None)])
                    writer = csv.DictWriter(f,
                                            fieldnames=header,
                                            extrasaction=u"ignore")
                    writer.writeheader()

                    f.close()

    for m in meters_active:
        m.start()

    datathread = DataThread(meters_active, ai_objs)
    datathread.start()

    bacpypesrun()

    datathread.stop()
    datathread.join()

    for m in meters_active:
        m.stop()
        m.join()