def readCalendar(self, device, instance): ret = {} date_list = [] #---< Read the date list >------------------------------------------- # Read the date list property propData = _bacnet.read_property(device, (6, instance, 23)) # How many time events do we have here? iNumDates = len(propData.value[2].value) # Go through the date list for i in range(0, iNumDates): # Decode the date dtDate = decode_date(propData.value[2].value[i].data) # # Stuff date values into array date_list.append(dtDate.month) date_list.append(dtDate.day) date_list.append(dtDate.year) # Add the date list to the hash table ret['date_list'] = date_list # Return the result return ret
def read(self, device, instance): ret = {} effective_period = [] time_events = [] schedule_members = [] #----< Build the effective period array >------------------------ # Populate the effective start date/end date if they exist result = _bacnet.read_property(device, (131, instance, 32)) for i in range(2) : if result.value[2].value[i].value.month <> None : effective_period.append(result.value[2].value[i].value.month) effective_period.append(result.value[2].value[i].value.day) effective_period.append(result.value[2].value[i].value.year) # Set the effective period ret['effective_period'] = effective_period #----< Build the time events array >----------------------------- # Loop through days of the week for iDayOfWeek in range(1, 8) : # Read the event list property propData = _bacnet.read_property(device, (131, instance, 123, iDayOfWeek)) # Go through the property list iEventIdx = 0 while iEventIdx < len(propData.value[3].value) : # Get type and time iTime = decode_unsigned_integer(propData.value[3].value[iEventIdx].data) iType = decode_enumerated(propData.value[3].value[iEventIdx + 1].data) # Add basic info to the vector time_events.append(iDayOfWeek) time_events.append(iTime) time_events.append(iType) # What is the context tag? if propData.value[3].value[iEventIdx + 2].number == 2: # Context tag 2 - real number dblValue = decode_real(propData.value[3].value[iEventIdx + 2].data) time_events.append(dblValue) elif propData.value[3].value[iEventIdx + 2].number == 3: # Context tag 3 - integer iValue = decode_unsigned_integer(propData.value[3].value[iEventIdx + 2].data) time_events.append(iValue) elif propData.value[3].value[iEventIdx + 2].number == 4: # Context tag 4 - integer iValue = decode_unsigned_integer(propData.value[3].value[iEventIdx + 2].data) time_events.append(iValue) else: # Anything else, we don't care. Set to zero. iValue =0 time_events.append(iValue) # Increment the index iEventIdx += 3 # Save the time events out ret['time_events']=time_events #----< Build the special events hash table >--------------------- xcptList = [] # Read the property propData = _bacnet.read_property(device, (131, instance, 38)) # Go through all the records iXcptIdx = 0; while iXcptIdx < len(propData.value[2].value) : # Declare hash table for this exception record xcptInfo = {} # Is this a date range (exception) or a # ...calendar reference (holiday)? if propData.value[2].value[iXcptIdx].number == 1: # Date range dateRange = [] # Get and encode start date dtDate = decode_date(propData.value[2].value[iXcptIdx].value[0].data) dateRange.append(dtDate.month) dateRange.append(dtDate.day) dateRange.append(dtDate.year) # Get and encode end date dtDate = decode_date(propData.value[2].value[iXcptIdx].value[1].data) dateRange.append(dtDate.month) dateRange.append(dtDate.day) dateRange.append(dtDate.year) xcptInfo['date_range'] = dateRange elif propData.value[2].value[iXcptIdx].number == 3: # Calendar reference calRef = [] objId = decode_bacnet_object_identifier(propData.value[2].value[iXcptIdx].data) calRef.append(objId.id) calRef.append(objId.instance_number) xcptInfo['calendar_reference'] = calRef # Get priority xcptInfo['priority'] = decode_enumerated(propData.value[2].value[iXcptIdx + 2].data) # Loop through the events xcptEvents = [] iEventIdx = 0 while iEventIdx < len(propData.value[2].value[iXcptIdx + 1].value) : # Get type and time iTime = decode_unsigned_integer(propData.value[2].value[iXcptIdx + 1].value[iEventIdx].data) iType = decode_enumerated(propData.value[2].value[iXcptIdx + 1].value[iEventIdx + 1].data) # Add time, type to record xcptEvents.append(iTime) xcptEvents.append(iType) # Do we have a value? if len(propData.value[2].value[iXcptIdx + 1].value[iEventIdx + 2].data) > 0: # Yes, what is the context tag? if propData.value[2].value[iXcptIdx + 1].value[iEventIdx + 2].number == 2: # Context tag 2 - real number dblValue = decode_real(propData.value[2].value[iXcptIdx + 1].value[iEventIdx + 2].data) xcptEvents.append(dblValue) elif propData.value[2].value[iXcptIdx + 1].value[iEventIdx + 2].number == 3: # Context tag 3 - integer iValue = decode_unsigned_integer(propData.value[2].value[iXcptIdx + 1].value[iEventIdx + 2].data) xcptEvents.append(iValue) elif propData.value[2].value[iXcptIdx + 1].value[iEventIdx + 2].number == 4: # Context tag 4 - integer iValue = decode_unsigned_integer(propData.value[2].value[iXcptIdx + 1].value[iEventIdx + 2].data) xcptEvents.append(iValue) else: # Anything else, we don't care. Set to zero. iValue =0 xcptEvents.append(iValue) else: # Add a zero (there are always three parts to our exception "record" xcptEvents.append(0) # Increment the indices iEventIdx += 3 # Store the event list and then put the exception schedule into # ...the hash table xcptInfo['event_list'] = xcptEvents xcptList.append(xcptInfo) # Get next event iXcptIdx += 3 # Add special events to the return value ret['special_events']=xcptList if DEBUG: print "--[ Load Data ]-----------------------------------" print ret # Return the result to the caller return ret