Skip to content

Commit

Permalink
Merge a128295 into cae83a4
Browse files Browse the repository at this point in the history
  • Loading branch information
kjlockhart committed Apr 7, 2017
2 parents cae83a4 + a128295 commit 95bcc20
Show file tree
Hide file tree
Showing 44 changed files with 1,438 additions and 1,225 deletions.
60 changes: 26 additions & 34 deletions BAC0/core/app/ScriptApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,46 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 by Christian Tremblay, P.Eng <christian.tremblay@servisys.com>
#
# Licensed under LGPLv3, see file LICENSE in this source tree.
"""
ScriptApplication
#
'''
ScriptApplication
=================
Built around a simple BIPSimpleApplication this module deals with requests
created by a child app. It will prepare the requests and give them back to the
stack.
This module will also listen for responses to requests (indication or confirmation).
Response will be added to a Queue, we'll wait for the response to be processed
by the caller, then resume.
A basic BACnet application (bacpypes BIPSimpleApplication) for interacting with
the bacpypes BACnet stack. It enables the base-level BACnet functionality
(a.k.a. device discovery) - meaning it can send & receive WhoIs & IAm messages.
This object will be added to script objects and will be runned as thread
Additional functionality is enabled by inheriting this application, and then
extending it with more functions. [See BAC0.scripts for more examples of this.]
See BAC0.scripts for more details.
"""
'''
#--- standard Python modules ---
from collections import defaultdict
import logging

#--- 3rd party modules ---
from bacpypes.debugging import bacpypes_debugging

from bacpypes.app import BIPSimpleApplication
from bacpypes.pdu import Address

from collections import defaultdict
import logging

#--- this application's modules ---
from ..functions.debug import log_debug


#------------------------------------------------------------------------------

@bacpypes_debugging
class ScriptApplication(BIPSimpleApplication):
"""
This class defines the bacnet application that process requests
"""

def __init__(self, *args):
"""
Creation of the application. Adding properties to basic B/IP App.
Defines a basic BACnet/IP application to process BACnet requests.
:param *args: local object device, local IP address
:param *args: local object device, local IP address
See BAC0.scripts.BasicScript for more details.
"""
"""
def __init__(self, *args):
logging.getLogger("comtypes").setLevel(logging.INFO)

self.localAddress = None
Expand All @@ -62,35 +59,30 @@ def __init__(self, *args):
else:
self.local_unicast_tuple = ('', 47808)
self.local_broadcast_tuple = ('255.255.255.255', 47808)

#log_debug(ScriptApplication, "__init__ %r" % args)


def do_WhoIsRequest(self, apdu):
"""Respond to a Who-Is request."""
if self._debug: ScriptApplication._debug("do_WhoIsRequest %r", apdu)

# build a key from the source and parameters
key = (str(apdu.pduSource),
apdu.deviceInstanceRangeLowLimit,
apdu.deviceInstanceRangeHighLimit,
)
apdu.deviceInstanceRangeHighLimit )

# count the times this has been received
self.who_is_counter[key] += 1

# continue with the default implementation
BIPSimpleApplication.do_WhoIsRequest(self, apdu)


def do_IAmRequest(self, apdu):
"""Given an I-Am request, cache it."""
if self._debug: ScriptApplication._debug("do_IAmRequest %r", apdu)

# build a key from the source, just use the instance number
key = (str(apdu.pduSource),
apdu.iAmDeviceIdentifier[1],
)

# count the times this has been received
key = (str(apdu.pduSource), apdu.iAmDeviceIdentifier[1] )
self.i_am_counter[key] += 1

# continue with the default implementation
Expand Down

0 comments on commit 95bcc20

Please sign in to comment.