Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-02: General clean-up of code comments and code readability. #36

Merged
merged 4 commits into from
Apr 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading