def ReadProperty(self, obj, arrayIndex=None): # # Access an array # if arrayIndex is not None: raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') # # キャッシュに値があれば、キャシュの値を返す # datastore = SingleBACnetd().getDatastore() value = datastore.get(self.object_id, self.instance_id, self.property_id) # # DB への 接続 # with SessionFactory() as session: # # DBへの登録 # session.add( BACnetSimulationLog(self.object_id, self.instance_id, self.property_id, value)) session.commit() # # 値の返却 # if not value == None: return value raise ExecutionError(errorClass='property', errorCode='abortProprietary')
def WriteProperty(self, property, value, arrayIndex=None, priority=None, direct=False): if _debug: CommandableMixin._debug("WriteProperty %r %r arrayIndex=%r priority=%r direct=%r", property, value, arrayIndex, priority, direct) # when writing to the presentValue with a priority if (property == 'presentValue'): # default (lowest) priority if priority is None: priority = 16 if _debug: CommandableMixin._debug(" - translate to array index %d", priority) # translate to updating the priority array property = 'priorityArray' arrayIndex = priority priority = None # update the priority array entry if (property == 'priorityArray') and (arrayIndex is not None): # check the bounds if arrayIndex == 0: raise ExecutionError(errorClass='property', errorCode='writeAccessDenied') if (arrayIndex < 1) or (arrayIndex > 16): raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex') # update the specific priorty value element priority_value = self.priorityArray[arrayIndex] if _debug: CommandableMixin._debug(" - priority_value: %r", priority_value) # the null or the choice has to be set, the other clear if value is (): if _debug: CommandableMixin._debug(" - write a null") priority_value.null = value setattr(priority_value, self._pv_choice, None) else: if _debug: CommandableMixin._debug(" - write a value") priority_value.null = None setattr(priority_value, self._pv_choice, value) # look for the highest priority value for i in range(1, 17): priority_value = self.priorityArray[i] if priority_value.null is None: if (i < arrayIndex): if _debug: CommandableMixin._debug(" - existing higher priority value") return value = getattr(priority_value, self._pv_choice) break else: value = self.relinquishDefault if _debug: CommandableMixin._debug(" - new present value: %r", value) property = 'presentValue' arrayIndex = priority = None # allow the request to pass through if _debug: CommandableMixin._debug(" - super: %r %r arrayIndex=%r priority=%r", property, value, arrayIndex, priority) super(CommandableMixin, self).WriteProperty( property, value, arrayIndex=arrayIndex, priority=priority, direct=direct, )
def do_ReadRangeRequest(self, apdu): if _debug: ReadRangeApplication._debug("do_ReadRangeRequest %r", apdu) # extract the object identifier objId = apdu.objectIdentifier # get the object obj = self.get_object_id(objId) if _debug: ReadRangeApplication._debug(" - object: %r", obj) if not obj: raise ExecutionError(errorClass="object", errorCode="unknownObject") # get the datatype datatype = obj.get_datatype(apdu.propertyIdentifier) if _debug: ReadRangeApplication._debug(" - datatype: %r", datatype) # must be a list, or an array of lists if issubclass(datatype, List): pass elif ( (apdu.propertyArrayIndex is not None) and issubclass(datatype, Array) and issubclass(datatype.subtype, List) ): pass else: raise ExecutionError(errorClass="property", errorCode="propertyIsNotAList") # get the value value = obj.ReadProperty(apdu.propertyIdentifier, apdu.propertyArrayIndex) if _debug: ReadRangeApplication._debug(" - value: %r", value) if value is None: raise PropertyError(apdu.propertyIdentifier) # this is an ack resp = ReadRangeACK(context=apdu) resp.objectIdentifier = objId resp.propertyIdentifier = apdu.propertyIdentifier resp.propertyArrayIndex = apdu.propertyArrayIndex resp.resultFlags = [1, 1, 0] resp.itemCount = len(value) # save the result in the item data resp.itemData = SequenceOfAny() resp.itemData.cast_in(datatype(value)) if _debug: ReadRangeApplication._debug(" - resp: %r", resp) # return the result self.response(resp)
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False): if _debug: DOPresentValue._debug( "WriteProperty %r %r arrayIndex=%r priority=%r direct=%r", obj, value, arrayIndex, priority, direct, ) # access an array if arrayIndex is not None: raise ExecutionError( errorClass="property", errorCode="propertyIsNotAnArray" ) ###TODO: obj._button is the Button object if _debug: DOPresentValue._debug(" - write dev: %r", obj._dev) # raise ExecutionError(errorClass="property", errorCode="writeAccessDenied") if value == "active": obj._dev.write("active") elif value == "inactive": obj._dev.write("inactive") else: ### TODO: insert correct value error. Below is a placeholder. print("invalid value for led. Use 'active' to turn on or 'inactive' to turn off.")
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False): raise ExecutionError(errorClass='property', errorCode='writeAccessDenied')
def ReadPropertyToAny(obj, propertyIdentifier, propertyArrayIndex=None): """Read the specified property of the object, with the optional array index, and cast the result into an Any object.""" if _debug: ReadPropertyToAny._debug("ReadPropertyToAny %s %r %r", obj, propertyIdentifier, propertyArrayIndex) # get the datatype datatype = obj.get_datatype(propertyIdentifier) if _debug: ReadPropertyToAny._debug(" - datatype: %r", datatype) if datatype is None: raise ExecutionError(errorClass='property', errorCode='datatypeNotSupported') # get the value value = obj.ReadProperty(propertyIdentifier, propertyArrayIndex) if _debug: ReadPropertyToAny._debug(" - value: %r", value) if value is None: raise ExecutionError(errorClass='property', errorCode='unknownProperty') # change atomic values into something encodeable if issubclass(datatype, Atomic): value = datatype(value) elif issubclass(datatype, Array) and (propertyArrayIndex is not None): if propertyArrayIndex == 0: value = Unsigned(value) elif issubclass(datatype.subtype, Atomic): value = datatype.subtype(value) elif not isinstance(value, datatype.subtype): raise TypeError("invalid result datatype, expecting %s and got %s" \ % (datatype.subtype.__name__, type(value).__name__)) elif not isinstance(value, datatype): raise TypeError("invalid result datatype, expecting %s and got %s" \ % (datatype.__name__, type(value).__name__)) if _debug: ReadPropertyToAny._debug(" - encodeable value: %r", value) # encode the value result = Any() result.cast_in(value) if _debug: ReadPropertyToAny._debug(" - result: %r", result) # return the object return result
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False): if _debug: RandomValueProperty._debug( "WriteProperty %r %r arrayIndex=%r priority=%r direct=%r", obj, value, arrayIndex, priority, direct) if not direct: raise ExecutionError(errorClass='property', errorCode='writeAccessDenied') if arrayIndex is not None: raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') # continue along super(RandomValueProperty, self).WriteProperty(obj, value, direct=True)
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False): if _debug: RandomValueProperty._debug( "WriteProperty %r %r arrayIndex=%r priority=%r direct=%r", obj, value, arrayIndex, priority, direct, ) raise ExecutionError(errorClass="property", errorCode="writeAccessDenied")
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False): if _debug: ModbusValueProperty._debug( "WriteProperty %r %r arrayIndex=%r priority=%r direct=%r", obj, value, arrayIndex, priority, direct) raise ExecutionError(errorClass='property', errorCode='writeAccessDenied')
def ReadProperty(self, obj, arrayIndex=None): if _debug: RandomValueProperty._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex) # access an array if arrayIndex is not None: raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') # return a random value value = random.random() * 100.0 if _debug: RandomValueProperty._debug(" - value: %r", value) return value
def ReadProperty(self, obj, arrayIndex=None): if _debug: CurrentDateTimeProperty._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex) # access an array if arrayIndex is not None: raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') # get the value current_date = Date().now().value current_time = Time().now().value value = DateTime(date=current_date, time=current_time) if _debug: CurrentDateTimeProperty._debug(" - value: %r", value) return value
def ReadProperty(self, obj, arrayIndex=None): if _debug: BOPresentValue._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex) # access an array if arrayIndex is not None: raise ExecutionError(errorClass="property", errorCode="propertyIsNotAnArray") ###TODO: obj._led is the LED object if _debug: BOPresentValue._debug(" - read led: %r", obj._led) if obj._led.value == 1: return "active" else: return "inactive"
def ReadProperty(self, obj, arrayIndex=None): if _debug: DIPresentValue._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex) # access an array if arrayIndex is not None: raise ExecutionError( errorClass="property", errorCode="propertyIsNotAnArray" ) if _debug: DIPresentValue._debug(" - read button: %r", obj._dev.read()) if obj._dev.read() == 'active': return "active" else: return "inactive"
def ReadProperty(self, obj, arrayIndex=None): if _debug: ModbusValueProperty._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex) # access an array if arrayIndex is not None: raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') # check if register_reader was set, if not there will be no way to read the stored register values if self.register_reader is None: return float('NaN') # return a random value value = random.random() * 100.0 if _debug: ModbusValueProperty._debug(" - value: %r", value) return value
def ReadProperty(self, obj, arrayIndex=None): if _debug: RandomValueProperty._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex) # access an array if arrayIndex is not None: raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') # return a random value value = random.random() * 100.0 if _debug: RandomValueProperty._debug(" - value: %r", value) # save the value that was generated super(RandomValueProperty, self).WriteProperty(obj, value, direct=True) # now return it to the client return value
def ReadProperty(self, obj, arrayIndex=None): if _debug: RandomValueProperty._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex) # access an array if arrayIndex is not None: raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') # return a random value value = random.random() * 100.0 if _debug: RandomValueProperty._debug(" - value: %r", value) with open( "C:\Users\Preetham\Documents\PreethamMasters\Third_semester\Specialisation_Module_v2\CORE\BACnet_server\log_server.txt", 'a') as file: file.write('The value at: %s is %d\n' % (datetime.now(), value)) file.close() return value
def ReadProperty(self, obj, arrayIndex=None): if _debug: BIPresentValue._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex) # access an array if arrayIndex is not None: raise ExecutionError(errorClass="property", errorCode="propertyIsNotAnArray") ###TODO: obj._button is the Button object if _debug: BIPresentValue._debug(" - read button: %r", obj._button) if obj._button.is_pressed: return "active" else: return "inactive"
def do_ConfirmedCOVNotificationRequest(self, apdu): if _debug: SubscribeCOVApplication._debug("do_ConfirmedCOVNotificationRequest %r", apdu) # look up the process identifier context = subscription_contexts.get(apdu.subscriberProcessIdentifier, None) if not context or apdu.pduSource != context.address: if _debug: SubscribeCOVApplication._debug(" - no context") # this is turned into an ErrorPDU and sent back to the client raise ExecutionError('services', 'unknownSubscription') # now tell the context object context.cov_notification(apdu) # success response = SimpleAckPDU(context=apdu) if _debug: SubscribeCOVApplication._debug(" - simple_ack: %r", response) # return the result self.response(response)
def WriteProperty(self, property, value, arrayIndex=None, priority=None, direct=False): if _debug: Commandable._debug( "WriteProperty %r %r arrayIndex=%r priority=%r direct=%r", property, value, arrayIndex, priority, direct) # when writing to the presentValue with a priority if (property == presentValue): if _debug: Commandable._debug(" - writing to %s, priority %r", presentValue, priority) # default (lowest) priority if priority is None: priority = 16 if _debug: Commandable._debug( " - translate to priority array, index %d", priority) # translate to updating the priority array property = priorityArray arrayIndex = priority priority = None # update the priority array entry if (property == priorityArray): if (arrayIndex is None): if _debug: Commandable._debug(" - writing entire %s", priorityArray) # pass along the request super(_Commando, self).WriteProperty( property, value, arrayIndex=arrayIndex, priority=priority, direct=direct, ) else: if _debug: Commandable._debug( " - writing to %s, array index %d", priorityArray, arrayIndex) # check the bounds if arrayIndex == 0: raise ExecutionError(errorClass='property', errorCode='writeAccessDenied') if (arrayIndex < 1) or (arrayIndex > 16): raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex') # update the specific priorty value element priority_value = getattr(self, priorityArray)[arrayIndex] if _debug: Commandable._debug(" - priority_value: %r", priority_value) # the null or the choice has to be set, the other clear if value is (): if _debug: Commandable._debug(" - write a null") priority_value.null = value setattr(priority_value, _Commando._pv_choice, None) else: if _debug: Commandable._debug(" - write a value") if issubclass(datatype, Enumerated): value = datatype._xlate_table[value] if _debug: Commandable._debug( " - remapped enumeration: %r", value) priority_value.null = None setattr(priority_value, _Commando._pv_choice, value) # look for the highest priority value value, value_source = self._highest_priority_value() # compare with the current value current_value = getattr(self, presentValue) if value == current_value: if _debug: Commandable._debug(" - no present value change") return # turn this into a present value change property = presentValue arrayIndex = priority = None # allow the request to pass through if _debug: Commandable._debug( " - super: %r %r arrayIndex=%r priority=%r", property, value, arrayIndex, priority) super(_Commando, self).WriteProperty( property, value, arrayIndex=arrayIndex, priority=priority, direct=direct, )