Esempio n. 1
0
 def add_point(self, point: BACnetPointModel, _update_point_store=True):
     [priority_array,
      present_value] = default_values(point.priority_array_write,
                                      point.relinquish_default)
     if point.use_next_available_address:
         point.address = BACnetPointModel.get_next_available_address(
             point.address)
     object_identifier = create_object_identifier(point.object_type.name,
                                                  point.address)
     if point.object_type.name == "analogOutput":
         register_object_type(AnalogOutputCmdObject)
         p = AnalogOutputFeedbackObject(
             profileName=point.uuid,
             objectIdentifier=(point.object_type.name, point.address),
             objectName=point.object_name,
             relinquishDefault=point.relinquish_default,
             presentValue=present_value,
             priorityArray=priority_array,
             eventState=point.event_state.name,
             statusFlags=StatusFlags(),
             units=EngineeringUnits(point.units.name),
             description=point.description,
             outOfService=False,
         )
         self.__bacnet.add_object(p)
         self.__registry[object_identifier] = p
     elif point.object_type.name == "analogValue":
         register_object_type(AnalogValueCmdObject)
         p = AnalogValueFeedbackObject(
             profileName=point.uuid,
             objectIdentifier=(point.object_type.name, point.address),
             objectName=point.object_name,
             relinquishDefault=point.relinquish_default,
             presentValue=present_value,
             priorityArray=priority_array,
             eventState=point.event_state.name,
             statusFlags=StatusFlags(),
             units=EngineeringUnits(point.units.name),
             description=point.description,
             outOfService=False,
         )
         self.__bacnet.add_object(p)
         self.__registry[object_identifier] = p
     if _update_point_store:  # make it so on start of app not to update the point store
         update_point_store(point.uuid, present_value)
     setting: AppSetting = current_app.config[AppSetting.FLASK_KEY]
     if setting.mqtt.enabled:
         priority = get_highest_priority_field(point.priority_array_write)
         mqtt_client = MqttClient()
         mqtt_client.publish_value(
             ('ao', object_identifier, point.object_name), present_value,
             priority)
Esempio n. 2
0
def create_BI(oid=1, pv=0, name="BI", activeText="On", inactiveText="Off"):
    deprecate_msg()
    return BinaryInputObject(
        objectIdentifier=("binaryInput", oid),
        objectName=name,
        presentValue=pv,
        activeText=activeText,
        inactiveText=inactiveText,
        statusFlags=StatusFlags(),
    )
Esempio n. 3
0
def create_CharStrValue(oid=1, pv="null", name="String", pv_writable=False):
    charval = CharacterStringValueObject(
        objectIdentifier=("characterstringValue", oid),
        objectName=name,
        priorityArray=PriorityArray(),
        statusFlags=StatusFlags(),
    )
    charval = _make_mutable(charval, mutable=pv_writable)
    charval.presentValue = CharacterString(pv)
    deprecate_msg()
    return charval
Esempio n. 4
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),
        statusFlags=StatusFlags(),
    )
    aio = _make_mutable(aio, identifier="outOfService", mutable=True)
    deprecate_msg()
    return aio
Esempio n. 5
0
def create_AO(oid=1, pv=0, name="AO", units=None, pv_writable=False):
    aoo = AnalogOutputObject(
        objectIdentifier=("analogOutput", oid),
        objectName=name,
        presentValue=pv,
        units=units,
        priorityArray=PriorityArray(),
        statusFlags=StatusFlags(),
    )
    aoo = _make_mutable(aoo, mutable=pv_writable)
    deprecate_msg()
    return aoo
Esempio n. 6
0
def create_DateTimeValue(oid=1,
                         date=None,
                         time=None,
                         name="DateTime",
                         pv_writable=False):
    datetime = DateTimeValueObject(
        objectIdentifier=("datetimeValue", oid),
        objectName=name,
        statusFlags=StatusFlags(),
    )
    datetime = _make_mutable(datetime, mutable=pv_writable)
    datetime.presentValue = DateTime(date=Date(date), time=Time(time))
    deprecate_msg()
    return datetime
Esempio n. 7
0
def create_object(object_class,
                  oid,
                  objectName,
                  description,
                  presentValue=None,
                  commandable=False):
    new_object = object_class(
        objectIdentifier=(object_class.objectType, oid),
        objectName="{}".format(objectName),
        presentValue=presentValue,
        description=CharacterString("{}".format(description)),
        statusFlags=StatusFlags(),
    )
    deprecate_msg()
    return _make_mutable(new_object, mutable=commandable)
Esempio n. 8
0
def create_AV(oid=1, pv=0, name="AV", units=None, pv_writable=False):
    avo = AnalogValueObject(
        objectIdentifier=("analogValue", oid),
        objectName=name,
        presentValue=pv,
        units=units,
        relinquishDefault=0,
        priorityArray=PriorityArray(),
        statusFlags=StatusFlags(),
    )
    avo = _make_mutable(avo, mutable=pv_writable)
    avo = _make_mutable(avo,
                        identifier="relinquishDefault",
                        mutable=pv_writable)
    deprecate_msg()
    return avo
Esempio n. 9
0
def create_MV(oid=1,
              pv=0,
              name="MV",
              states=["red", "green", "blue"],
              pv_writable=False):
    msvo = MultiStateValueObject(
        objectIdentifier=("multiStateValue", oid),
        objectName=name,
        presentValue=pv,
        numberOfStates=len(states),
        stateText=ArrayOf(CharacterString)(states),
        priorityArray=PriorityArray(),
        statusFlags=StatusFlags(),
    )
    msvo = _make_mutable(msvo, mutable=pv_writable)
    deprecate_msg()
    return msvo
Esempio n. 10
0
def create_BO(oid=1,
              pv=0,
              name="BO",
              activeText="On",
              inactiveText="Off",
              pv_writable=False):
    boo = LocalBinaryOutputObjectCmd(
        objectIdentifier=("binaryOutput", oid),
        objectName=name,
        presentValue=pv,
        activeText=activeText,
        inactiveText=inactiveText,
        statusFlags=StatusFlags(),
    )
    boo = _make_mutable(boo, mutable=pv_writable)
    deprecate_msg()
    return boo
Esempio n. 11
0
def create_BV(oid=1,
              pv=0,
              name="BV",
              activeText="On",
              inactiveText="Off",
              pv_writable=False):
    bvo = BinaryValueObject(
        objectIdentifier=("binaryValue", oid),
        objectName=name,
        presentValue=pv,
        activeText=activeText,
        inactiveText=inactiveText,
        priorityArray=PriorityArray(),
        statusFlags=StatusFlags(),
    )
    bvo = _make_mutable(bvo, mutable=pv_writable)
    deprecate_msg()
    return bvo
Esempio n. 12
0
def main():
    # global this_application

    # parse the command line arguments
    args = ConfigArgumentParser(description=__doc__).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
    this_application = BIPSimpleApplication(this_device, args.ini.address)
    # this_application

    # make a commandable binary output object, add to the device
    boo1 = BinaryOutputFeedbackObject(
        objectIdentifier=("binaryOutput", 1),
        objectName="boo1",
        presentValue="inactive",
        eventState="normal",
        statusFlags=StatusFlags(),
        feedbackValue="inactive",
        relinquishDefault="inactive",
        minimumOnTime=5,  # let it warm up
        minimumOffTime=10,  # let it cool off
        outOfService="inactive",
    )
    if _debug:
        _log.debug("    - boo1: %r", boo1)
    this_application.add_object(boo1)

    if _debug:
        _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 13
0
def main():
    global this_application

    # parse the command line arguments
    args = ConfigArgumentParser(description=__doc__).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 simple application
    this_application = ReadRangeApplication(this_device, args.ini.address)

    timestamp = DateTime(date=Date().now().value, time=Time().now().value)
    # log_status = LogStatus([0,0,0])
    log_record_datum = LogRecordLogDatum(booleanValue=False)
    status_flags = StatusFlags([0, 0, 0, 0])
    log_record = LogRecord(timestamp=timestamp,
                           logDatum=log_record_datum,
                           statusFlags=status_flags)

    trend_log_object = TrendLogObject(
        objectIdentifier=("trendLog", 1),
        objectName="Trend-Log-1",
        logBuffer=[log_record],
    )
    _log.debug("    - trend_log_object: %r", trend_log_object)
    this_application.add_object(trend_log_object)

    _log.debug("running")

    run()

    _log.debug("fini")