// By Morten Kvistgaard public virtual byte[] GetEncodedTrends(uint start, int count, out BacnetResultFlags status) { status = BacnetResultFlags.NONE; start--; //position is 1 based if (start >= m_PROP_RECORD_COUNT || (start + count) > m_PROP_RECORD_COUNT) { return(null); } if (start == 0) { status |= BacnetResultFlags.FIRST_ITEM; } if ((start + count) >= m_PROP_RECORD_COUNT) { status |= BacnetResultFlags.LAST_ITEM; } else { status |= BacnetResultFlags.MORE_ITEMS; } System.IO.BACnet.Serialize.EncodeBuffer buffer = new System.IO.BACnet.Serialize.EncodeBuffer(); int offset; if (m_PROP_RECORD_COUNT < m_PROP_BUFFER_SIZE) // the buffer is not full { offset = 0; } else { offset = LogPtr; // circular buffer } for (uint i = start; i < (start + count); i++) { System.IO.BACnet.Serialize.Services.EncodeLogRecord(buffer, TrendBuffer[(offset + i) % TrendBuffer.Length]); } return(buffer.ToArray()); }
// Ici les remplacement de la lecture de quelques élements private static void m_storage_ReadOverride(BacnetObjectId object_id, BacnetPropertyIds property_id, uint array_index, out IList <BacnetValue> value, out DeviceStorage.ErrorCodes status, out bool handled) { handled = true; value = new BacnetValue[0]; status = DeviceStorage.ErrorCodes.Good; if (object_id.type == BacnetObjectTypes.OBJECT_DEVICE && property_id == BacnetPropertyIds.PROP_OBJECT_LIST) { if (array_index == 0) { //object list count value = new BacnetValue[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, (uint)m_storage.Objects.Length) }; } else if (array_index != System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL) { //object list index value = new BacnetValue[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_OBJECT_ID, new BacnetObjectId(m_storage.Objects[array_index - 1].Type, m_storage.Objects[array_index - 1].Instance)) }; } else { //object list whole BacnetValue[] list = new BacnetValue[m_storage.Objects.Length]; for (int i = 0; i < list.Length; i++) { list[i].Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_OBJECT_ID; list[i].Value = new BacnetObjectId(m_storage.Objects[i].Type, m_storage.Objects[i].Instance); } value = list; } } else if (object_id.type == BacnetObjectTypes.OBJECT_DEVICE && object_id.instance == m_storage.DeviceId && property_id == BacnetPropertyIds.PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) { BacnetValue v = new BacnetValue(); v.Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_BIT_STRING; BacnetBitString b = new BacnetBitString(); b.SetBit((byte)BacnetObjectTypes.MAX_ASHRAE_OBJECT_TYPE, false); //set all false b.SetBit((byte)BacnetObjectTypes.OBJECT_ANALOG_INPUT, true); b.SetBit((byte)BacnetObjectTypes.OBJECT_DEVICE, true); b.SetBit((byte)BacnetObjectTypes.OBJECT_ANALOG_VALUE, true); b.SetBit((byte)BacnetObjectTypes.OBJECT_CHARACTERSTRING_VALUE, true); b.SetBit((byte)BacnetObjectTypes.OBJECT_MULTI_STATE_VALUE, true); b.SetBit((byte)BacnetObjectTypes.OBJECT_BINARY_VALUE, true); v.Value = b; value = new BacnetValue[] { v }; } else if (object_id.type == BacnetObjectTypes.OBJECT_DEVICE && object_id.instance == m_storage.DeviceId && property_id == BacnetPropertyIds.PROP_PROTOCOL_SERVICES_SUPPORTED) { BacnetValue v = new BacnetValue(); v.Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_BIT_STRING; BacnetBitString b = new BacnetBitString(); b.SetBit((byte)BacnetServicesSupported.MAX_BACNET_SERVICES_SUPPORTED, false); //set all false b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_SUBSCRIBE_COV, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_I_AM, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_WHO_IS, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_READ_PROP_MULTIPLE, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_READ_PROPERTY, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_WRITE_PROPERTY, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_CONFIRMED_COV_NOTIFICATION, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_UNCONFIRMED_COV_NOTIFICATION, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_SUBSCRIBE_COV_PROPERTY, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_REINITIALIZE_DEVICE, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_DEVICE_COMMUNICATION_CONTROL, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_TIME_SYNCHRONIZATION, true); b.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION, true); v.Value = b; value = new BacnetValue[] { v }; } else if (object_id.type == BacnetObjectTypes.OBJECT_DEVICE && object_id.instance == m_storage.DeviceId && property_id == BacnetPropertyIds.PROP_SEGMENTATION_SUPPORTED) { BacnetValue v = new BacnetValue(); v.Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_ENUMERATED; v.Value = (uint)BacnetSegmentations.SEGMENTATION_BOTH; value = new BacnetValue[] { v }; } else if (object_id.type == BacnetObjectTypes.OBJECT_DEVICE && object_id.instance == m_storage.DeviceId && property_id == BacnetPropertyIds.PROP_SYSTEM_STATUS) { BacnetValue v = new BacnetValue(); v.Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_ENUMERATED; v.Value = (uint)BacnetDeviceStatus.OPERATIONAL; //can we be in any other mode I wonder? value = new BacnetValue[] { v }; } else if (object_id.type == BacnetObjectTypes.OBJECT_DEVICE && object_id.instance == m_storage.DeviceId && property_id == BacnetPropertyIds.PROP_ACTIVE_COV_SUBSCRIPTIONS) { List <BacnetValue> list = new List <BacnetValue>(); foreach (KeyValuePair <BacnetObjectId, List <Subscription> > entry in m_subscriptions) { foreach (Subscription sub in entry.Value) { //encode System.IO.BACnet.Serialize.EncodeBuffer buffer = new System.IO.BACnet.Serialize.EncodeBuffer(); BacnetCOVSubscription cov = new BacnetCOVSubscription(); cov.Recipient = sub.reciever_address; cov.subscriptionProcessIdentifier = sub.subscriberProcessIdentifier; cov.monitoredObjectIdentifier = sub.monitoredObjectIdentifier; cov.monitoredProperty = sub.monitoredProperty; cov.IssueConfirmedNotifications = sub.issueConfirmedNotifications; cov.TimeRemaining = (uint)sub.lifetime - (uint)(DateTime.Now - sub.start).TotalMinutes; cov.COVIncrement = sub.covIncrement; System.IO.BACnet.Serialize.ASN1.encode_cov_subscription(buffer, cov); //add BacnetValue v = new BacnetValue(); v.Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_COV_SUBSCRIPTION; v.Value = buffer.ToArray(); list.Add(v); } } value = list; } else if (object_id.type == BacnetObjectTypes.OBJECT_OCTETSTRING_VALUE && object_id.instance == 0 && property_id == BacnetPropertyIds.PROP_PRESENT_VALUE) { //this is our huge blob BacnetValue v = new BacnetValue(); v.Tag = BacnetApplicationTags.BACNET_APPLICATION_TAG_OCTET_STRING; byte[] blob = new byte[2000]; for (int i = 0; i < blob.Length; i++) { blob[i] = (i % 2 == 0) ? (byte)'A' : (byte)'B'; } v.Value = blob; value = new BacnetValue[] { v }; } else if (object_id.type == BacnetObjectTypes.OBJECT_GROUP && property_id == BacnetPropertyIds.PROP_PRESENT_VALUE) { //get property list IList <BacnetValue> properties; if (m_storage.ReadProperty(object_id, BacnetPropertyIds.PROP_LIST_OF_GROUP_MEMBERS, System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL, out properties) != DeviceStorage.ErrorCodes.Good) { value = new BacnetValue[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR, new BacnetError(BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_INTERNAL_ERROR)) }; } else { List <BacnetValue> _value = new List <BacnetValue>(); foreach (BacnetValue p in properties) { if (p.Value is BacnetReadAccessSpecification) { BacnetReadAccessSpecification prop = (BacnetReadAccessSpecification)p.Value; BacnetReadAccessResult result = new BacnetReadAccessResult(); result.objectIdentifier = prop.objectIdentifier; List <BacnetPropertyValue> result_values = new List <BacnetPropertyValue>(); foreach (BacnetPropertyReference r in prop.propertyReferences) { BacnetPropertyValue prop_value = new BacnetPropertyValue(); prop_value.property = r; if (m_storage.ReadProperty(prop.objectIdentifier, (BacnetPropertyIds)r.propertyIdentifier, r.propertyArrayIndex, out prop_value.value) != DeviceStorage.ErrorCodes.Good) { prop_value.value = new BacnetValue[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR, new BacnetError(BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_INTERNAL_ERROR)) }; } result_values.Add(prop_value); } result.values = result_values; _value.Add(new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_READ_ACCESS_RESULT, result)); } } value = _value; } } else { handled = false; } }