def make_modbus_request_handler(app_dict, mb_timeout=1000, tcp_timeout=5000, mb_translation=True): # @bacpypes_debugging class KlassModbusRequestHandler(socketserver.BaseRequestHandler): # , object): def __init__(self, *args, **kwargs): self.th_id = threading.get_ident() % 10000 if _debug: KlassModbusRequestHandler._debug('%s __init__ mb timeout: %r, tcp timeout: %r', self.th_id, mb_timeout, tcp_timeout) self.app_dict = app_dict # don't think this works the way I want since this is a class constructor self.mb_timeout = mb_timeout self.tcp_timeout = tcp_timeout / 1000.0 self.mb_translation = mb_translation super(KlassModbusRequestHandler, self).__init__(*args, **kwargs) def handle(self): # available class variables # self.request - # self.client_address - # self.server - while True: if self.tcp_timeout == 0: # if tcp_timeout is 0, then run until client closes select_inputs = select.select([self.request], [], [])[0] else: select_inputs = select.select([self.request], [], [], self.tcp_timeout)[0] if select_inputs: # data = None try: data = self.request.recv(1024) except socket.timeout: if _debug: KlassModbusRequestHandler._debug('%s - modbus socket timeout', self.th_id) break except socket.error: if _debug: KlassModbusRequestHandler._debug('%s - modbus socket error', self.th_id) break # if _debug: KlassModbusRequestHandler._debug('incoming modbus request in process %s: %s', # cur_process, data) if not data: # if socket closes, recv() returns '' if _debug: KlassModbusRequestHandler._debug('%s - modbus socket closed by other', self.th_id) break mb_error, transaction_id, virt_id, mb_func, mb_register, mb_num_regs = parse_modbus_request(data) dev_inst, mb_ip, slave_id = self.find_slave_id(virt_id) if _debug: KlassModbusRequestHandler._debug('%s - modbus request: virt_id: %s, register: %s at ' '%s', self.th_id, virt_id, mb_register, _get_ftime()) if mb_error != 0: # if error found in request if _debug: KlassModbusRequestHandler._debug('%s - modbus request error: %r', self.th_id, mb_error) response = bytes([transaction_id[0], transaction_id[1], 0, 0, 0, 3, virt_id, mb_func + 128, mb_error[1]]) elif dev_inst != 0 and self.mb_translation and 19999 < mb_register < 40000: # TBD # search for device info, then use that to make direct query of modbus device, modifying for # datatype response = self._convert_req_float(mb_ip, transaction_id, virt_id, slave_id, mb_func, mb_register, mb_num_regs) elif dev_inst != 0 and self.mb_translation and 39999 < mb_register < 60000: # search for device info and grab values direct from bacnet objects (limit to one?) response = self._bacnet_request(dev_inst, transaction_id, virt_id, mb_func, mb_register, mb_num_regs) else: # straight through request to meter response = self._straight_through_request(mb_ip, transaction_id, virt_id, slave_id, mb_func, mb_register, mb_num_regs) # if _debug: KlassModbusRequestHandler._debug('response to modbus request in process %s: %s', # cur_process, response) self.request.sendall(response) else: break def find_slave_id(self, virt_id): for dev_inst in self.app_dict: if dev_inst % 100 == virt_id: if self.app_dict[dev_inst].localDevice.deviceIp == '0.0.0.0': mb_ip = '/dev/serial0' else: mb_ip = self.app_dict[dev_inst].localDevice.deviceIp return dev_inst, mb_ip, self.app_dict[dev_inst].localDevice.modbusId # if no matching device is found, assume a serial connection is desired return 0, '/dev/serial0', virt_id def _convert_req_float(self, mb_ip, transaction_id, virt_id, slave_id, mb_func, mb_register, mb_num_regs): # TBD mb_error = mb_poll.MB_ERR_DICT[2] response = bytes([transaction_id[0], transaction_id[1], 0, 0, 0, 3, virt_id, mb_func + 128, mb_error[1]]) return response def _bacnet_request(self, dev_inst, transaction_id, virt_id, mb_func, mb_register, mb_num_regs): if _debug: KlassModbusRequestHandler._debug('%s - bacnet store request: %r, virt_id: %r, func: %r, ' 'register: %r, num_regs: %r', self.th_id, transaction_id, virt_id, mb_func, mb_register, mb_num_regs) if mb_num_regs == 2: for obj_inst in self.app_dict[dev_inst].objectIdentifier: bcnt_pt = self.app_dict[dev_inst].objectIdentifier[obj_inst] if bcnt_pt.objectIdentifier[0] == 'device': continue if bcnt_pt.registerStart == (mb_register - 39999): if _debug: KlassModbusRequestHandler._debug('%s - request for %s, %s', self.th_id, dev_inst, obj_inst) if bcnt_pt.reliability == 'noFaultDetected': val = bytearray(struct.pack('>f', bcnt_pt.presentValue)) # > forces big endian if self.app_dict[dev_inst].localDevice.meterRespWordOrder == 'msw': pass # nothing to do here else: val.extend(val[0:2]) val = val[2:] response = bytearray([transaction_id[0], transaction_id[1], 0, 0, 0, 7, virt_id, mb_func, 4]) response.extend(val) if _debug: KlassModbusRequestHandler._debug('%s - modbus return success: %r at %s', self.th_id, list(response), _get_ftime()) else: # bad reliability mb_error = mb_poll.MB_ERR_DICT[4] response = bytes([transaction_id[0], transaction_id[1], 0, 0, 0, 3, virt_id, mb_func + 128, mb_error[1]]) if _debug: KlassModbusRequestHandler._debug('%s - modbus return comm FAILURE: %r at %s', self.th_id, list(response), _get_ftime()) break else: if _debug: KlassModbusRequestHandler._debug('%s - bad register request: %s not in library', self.th_id, mb_register) # no such register found: mb_register - 49999 mb_error = mb_poll.MB_ERR_DICT[2] response = bytes([transaction_id[0], transaction_id[1], 0, 0, 0, 3, virt_id, mb_func + 128, mb_error[1]]) else: # wrong number of regs requested if _debug: KlassModbusRequestHandler._debug('%s - bad number of regs requested (%s), should be 2', self.th_id, mb_num_regs) mb_error = mb_poll.MB_ERR_DICT[2] response = bytes([transaction_id[0], transaction_id[1], 0, 0, 0, 3, virt_id, mb_func + 128, mb_error[1]]) return response def _straight_through_request(self, mb_ip, transaction_id, virt_id, slave_id, mb_func, mb_register, mb_num_regs): if _debug: KlassModbusRequestHandler._debug('%s - straighthrough request: %r, slave: %r, func: %r, ' 'register: %r, num_regs: %r', self.th_id, transaction_id, slave_id, mb_func, mb_register, mb_num_regs) raw_byte_return = mb_poll.modbus_poller(mb_ip, slave_id, mb_register, mb_num_regs, data_type='uint16', zero_based=True, mb_func=mb_func, b_raw_bytes=True, mb_timeout=self.mb_timeout) if raw_byte_return[0] == 'Err': mb_error = raw_byte_return response = bytes([transaction_id[0], transaction_id[1], 0, 0, 0, 3, virt_id, mb_func + 128, mb_error[1]]) if _debug: KlassModbusRequestHandler._debug('%s - modbus return error trans id %r: %r', self.th_id, transaction_id, mb_error) else: len_return = len(raw_byte_return) + 3 len_rtn_hi = (len_return >> 8) & 0xff len_rtn_lo = len_return & 0xff response_list = transaction_id + [0, 0, len_rtn_hi, len_rtn_lo, virt_id, mb_func, len_return - 3] response_list.extend(raw_byte_return) response = bytes(response_list) if _debug: KlassModbusRequestHandler._debug('%s - modbus return success %r', self.th_id, response_list[0:9]) return response bacpypes_debugging(KlassModbusRequestHandler) return KlassModbusRequestHandler
SERVER_HOST = os.getenv('SERVER_HOST', 'any') SERVER_PORT = int(os.getenv('SERVER_PORT', 9000)) # # EchoMaster # class EchoMaster(Client): def confirmation(self, pdu): if _debug: EchoMaster._debug('confirmation %r', pdu) # send it back down the stack self.request(PDU(pdu.pduData, destination=pdu.pduSource)) bacpypes_debugging(EchoMaster) # # MiddleManASE # class MiddleManASE(ApplicationServiceElement): """ An instance of this class is bound to the director, which is a ServiceAccessPoint. It receives notifications of new actors connected from a client, actors that are going away when the connections are closed, and socket errors. """ def indication(self, add_actor=None, del_actor=None, actor_error=None, error=None): if add_actor: if _debug: MiddleManASE._debug("indication add_actor=%r", add_actor)
BIPSimpleApplication.request(self, apdu) def indication(self, apdu): if _debug: SampleApplication._debug("indication %r", apdu) BIPSimpleApplication.indication(self, apdu) def response(self, apdu): if _debug: SampleApplication._debug("response %r", apdu) BIPSimpleApplication.response(self, apdu) def confirmation(self, apdu): if _debug: SampleApplication._debug("confirmation %r", apdu) BIPSimpleApplication.confirmation(self, apdu) bacpypes_debugging(SampleApplication) # # __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname,
""" import unittest from bacpypes.debugging import bacpypes_debugging, ModuleLogger from bacpypes.comm import PCI # some debugging _debug = 0 _log = ModuleLogger(globals()) def setUpModule(): if _debug: setUpModule._debug("setUpModule") bacpypes_debugging(setUpModule) def tearDownModule(): if _debug: tearDownModule._debug("tearDownModule") bacpypes_debugging(tearDownModule) class TestPCI(unittest.TestCase): @classmethod def setUpClass(cls): if _debug: TestPCI._debug("setUpClass") @classmethod
# special case for array parts, others are managed by cast_out if issubclass(datatype, Array) and (apdu.propertyArrayIndex is not None): if apdu.propertyArrayIndex == 0: value = apdu.propertyValue.cast_out(Unsigned) else: value = apdu.propertyValue.cast_out(datatype.subtype) else: value = apdu.propertyValue.cast_out(datatype) if _debug: ReadPropertyApplication._debug(" - value: %r", value) sys.stdout.write(str(value) + '\n') if hasattr(value, 'debug_contents'): value.debug_contents(file=sys.stdout) sys.stdout.flush() bacpypes_debugging(ReadPropertyApplication) # # ReadPropertyConsoleCmd # class ReadPropertyConsoleCmd(ConsoleCmd): def do_read(self, args): """read <addr> <type> <inst> <prop> [ <indx> ]""" args = args.split() if _debug: ReadPropertyConsoleCmd._debug("do_read %r", args) try: addr, obj_type, obj_inst, prop_id = args[:4]
def setUpPackage(): global test_options # create an argument parser parser = ArgumentParser(description=__doc__) # add an option parser.add_argument('--option', help="this is an option", default=os.getenv("BACPYPES_TEST_OPTION") or BACPYPES_TEST_OPTION, ) # get the debugging args and parse them arg_str = os.getenv("BACPYPES_TEST") or BACPYPES_TEST test_options = parser.parse_args(arg_str.split()) if _debug: setUpPackage._debug("setUpPackage") if _debug: setUpPackage._debug(" - test_options: %r", test_options) bacpypes_debugging(setUpPackage) # # tearDownPackage # def tearDownPackage(): if _debug: tearDownPackage._debug("tearDownPackage") bacpypes_debugging(tearDownPackage)
if _debug: ReadPropertyMultipleConsoleCmd._debug( " - value: %r", value) sys.stdout.write(" = " + str(value) + '\n') sys.stdout.flush() # do something for error/reject/abort if iocb.ioError: sys.stdout.write(str(iocb.ioError) + '\n') except Exception, error: ReadPropertyMultipleConsoleCmd._exception("exception: %r", error) bacpypes_debugging(ReadPropertyMultipleConsoleCmd) # # __main__ # def main(): global this_application # check the version if (sys.version_info[:2] != (2, 5)): sys.stderr.write("Python 2.5 only\n") sys.exit(1) # parse the command line arguments
# no data means EOF, stop if not pdu.pduData: stop() return # pass it along self.request(PDU(pdu.pduData, destination=server_address)) def confirmation(self, pdu): if _debug: MiddleMan._debug("confirmation %r", pdu) # pass it along self.response(pdu) bacpypes_debugging(MiddleMan) # # MiddleManASE # class MiddleManASE(ApplicationServiceElement): def indication(self, add_actor=None, del_actor=None, actor_error=None, error=None): if add_actor: if _debug: MiddleManASE._debug("indication add_actor=%r", add_actor) if del_actor: if _debug: MiddleManASE._debug("indication del_actor=%r", del_actor) if actor_error:
elif (self._request.deviceInstanceRangeHighLimit is not None) and \ (device_instance > self._request.deviceInstanceRangeHighLimit): pass else: # print out the contents sys.stdout.write('pduSource = ' + repr(apdu.pduSource) + '\n') sys.stdout.write('iAmDeviceIdentifier = ' + str(apdu.iAmDeviceIdentifier) + '\n') sys.stdout.write('maxAPDULengthAccepted = ' + str(apdu.maxAPDULengthAccepted) + '\n') sys.stdout.write('segmentationSupported = ' + str(apdu.segmentationSupported) + '\n') sys.stdout.write('vendorID = ' + str(apdu.vendorID) + '\n') sys.stdout.flush() # forward it along BIPSimpleApplication.indication(self, apdu) bacpypes_debugging(WhoIsIAmApplication) # # WhoIsIAmConsoleCmd # class WhoIsIAmConsoleCmd(ConsoleCmd): def do_whois(self, args): """whois [ <addr>] [ <lolimit> <hilimit> ]""" args = args.split() if _debug: WhoIsIAmConsoleCmd._debug("do_whois %r", args) try: # build a request request = WhoIsRequest()
if _debug: SampleApplication._debug("request %r", apdu) BIPSimpleApplication.request(self, apdu) def indication(self, apdu): if _debug: SampleApplication._debug("indication %r", apdu) BIPSimpleApplication.indication(self, apdu) def response(self, apdu): if _debug: SampleApplication._debug("response %r", apdu) BIPSimpleApplication.response(self, apdu) def confirmation(self, apdu): if _debug: SampleApplication._debug("confirmation %r", apdu) BIPSimpleApplication.confirmation(self, apdu) bacpypes_debugging(SampleApplication) # # SampleConsoleCmd # class SampleConsoleCmd(ConsoleCmd): def do_nothing(self, args): """nothing can be done""" args = args.split() if _debug: SampleConsoleCmd._debug("do_nothing %r", args) bacpypes_debugging(SampleConsoleCmd) #
# set the transition self.timeout_transition = TimeoutTransition(delay, next_state) # return the next state return next_state def __repr__(self): return "<%s(%s) at %s>" % ( self.__class__.__name__, self.doc_string, hex(id(self)), ) bacpypes_debugging(State) # # StateMachine # class StateMachine: """ StateMachine ~~~~~~~~~~~~ A state machine consisting of states. Every state machine has a start state where the state machine begins when it is started. It also has an *unexpected receive* fail state where the state machine goes if there is an unexpected (unmatched) PDU received.
if _debug: SampleEventDetection._debug("execute") # if _triggered is true this function was called because of some # parameter change, but could have been called for some other reason if self._triggered: if _debug: SampleEventDetection._debug(" - was triggered") else: if _debug: SampleEventDetection._debug(" - was not triggered") # check for things if self.pParameter == self.pSetPoint: if _debug: SampleEventDetection._debug(" - parameter match") else: if _debug: SampleEventDetection._debug(" - parameter mismatch") bacpypes_debugging(SampleEventDetection) # # # # parse the command line arguments parser = ArgumentParser(usage=__doc__) args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # analog value 1 av1 = AnalogValueObject( objectIdentifier=('analogValue', 1),
#!/usr/bin/python # -*- coding: utf-8 -*- """ test_something -------------- """ import unittest from bacpypes.debugging import bacpypes_debugging, ModuleLogger # some debugging _debug = 0 _log = ModuleLogger(globals()) class TestSomething(unittest.TestCase): def setUp(self): if _debug: TestSomething._debug("setUp") def test_something(self): if _debug: TestSomething._debug("test_something") def tearDown(self): if _debug: TestSomething._debug("tearDown") bacpypes_debugging(TestSomething)
BIPSimpleApplication.request(self, apdu) def indication(self, apdu): if _debug: SampleApplication._debug("indication %r", apdu) BIPSimpleApplication.indication(self, apdu) def response(self, apdu): if _debug: SampleApplication._debug("response %r", apdu) BIPSimpleApplication.response(self, apdu) def confirmation(self, apdu): if _debug: SampleApplication._debug("confirmation %r", apdu) BIPSimpleApplication.confirmation(self, apdu) bacpypes_debugging(SampleApplication) # # SampleConsoleCmd # class SampleConsoleCmd(ConsoleCmd): def do_nothing(self, args): """nothing can be done""" args = args.split() if _debug: SampleConsoleCmd._debug("do_nothing %r", args) bacpypes_debugging(SampleConsoleCmd)
raise ValueError("off the rails") # set the transition self.timeout_transition = TimeoutTransition(delay, next_state) # return the next state return next_state def __repr__(self): return "<%s(%s) at %s>" % ( self.__class__.__name__, self.doc_string, hex(id(self)), ) bacpypes_debugging(State) # # StateMachine # class StateMachine: """ StateMachine ~~~~~~~~~~~~ A state machine consisting of states. Every state machine has a start state where the state machine begins when it is started. It also has
""" import unittest from bacpypes.debugging import bacpypes_debugging, ModuleLogger from . import utilities # some debugging _debug = 0 _log = ModuleLogger(globals()) def setUpModule(): if _debug: setUpModule._debug("setUpModule") bacpypes_debugging(setUpModule) def tearDownModule(): if _debug: tearDownModule._debug("tearDownModule") bacpypes_debugging(tearDownModule) class TestCaseTemplate(unittest.TestCase): @classmethod def setUpClass(cls): if _debug: TestCaseTemplate._debug("setUpClass") @classmethod
RandomValueProperty._debug( "WriteProperty %r %r arrayIndex=%r priority=%r direct=%r", obj, value, arrayIndex, priority, direct) raise ExecutionError(errorClass='property', errorCode='writeAccessDenied') class RandomInputProperty(RandomValueProperty): pass class RandomOutputProperty(RandomValueProperty): pass bacpypes_debugging(RandomValueProperty) class RandomAnalogValueObject(AnalogValueObject): properties = [ RandomValueProperty('presentValue'), ] def __init__(self, **kwargs): if _debug: RandomAnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs) class RandomBinaryValueObject(BinaryValueObject):
import unittest from bacpypes.debugging import bacpypes_debugging, ModuleLogger from . import utilities # some debugging _debug = 0 _log = ModuleLogger(globals()) def setUpModule(): if _debug: setUpModule._debug("setUpModule") bacpypes_debugging(setUpModule) def tearDownModule(): if _debug: tearDownModule._debug("tearDownModule") bacpypes_debugging(tearDownModule) class TestCaseTemplate(unittest.TestCase): @classmethod def setUpClass(cls): if _debug: TestCaseTemplate._debug("setUpClass") @classmethod
args = None # # EchoMaster # class EchoMaster(Client): def confirmation(self, pdu): if _debug: EchoMaster._debug('confirmation %r', pdu) # send it back down the stack self.request(PDU(pdu.pduData, destination=pdu.pduSource)) bacpypes_debugging(EchoMaster) # # MiddleManASE # class MiddleManASE(ApplicationServiceElement): """ An instance of this class is bound to the director, which is a ServiceAccessPoint. It receives notifications of new actors connected from a client, actors that are going away when the connections are closed, and socket errors. """ def indication(self, add_actor=None,
"""rtn <addr> <net> ... """ args = args.split() if _debug: ReadPropertyConsoleCmd._debug("do_rtn %r", args) # safe to assume only one adapter adapter = this_application.nsap.adapters[0] if _debug: ReadPropertyConsoleCmd._debug(" - adapter: %r", adapter) # provide the address and a list of network numbers router_address = Address(args[0]) network_list = [int(arg) for arg in args[1:]] # pass along to the service access point this_application.nsap.add_router_references(adapter, router_address, network_list) bacpypes_debugging(ReadPropertyConsoleCmd) # # __main__ # def main(): global this_application # check the version if (sys.version_info[:2] != (2, 5)): sys.stderr.write("Python 2.5 only\n") sys.exit(1) # parse the command line arguments
trigger = self.filter(old_value, new_value) else: trigger = (old_value != new_value) if _debug: DetectionMonitor._debug(" - trigger: %r", trigger) # trigger it if trigger: deferred(self.algorithm._execute) if _debug: DetectionMonitor._debug(" - deferred: %r", self.algorithm._execute) self.algorithm._triggered = True bacpypes_debugging(DetectionMonitor) # # monitor_filter # def monitor_filter(parameter): def transfer_filter_decorator(fn): fn._monitor_filter = parameter return fn return transfer_filter_decorator #
def process_task(self): if _debug: PulseTask._debug("process_task") # increment the present value self.accumulator.presentValue += self.increment # update the value change time current_date = Date().now().value current_time = Time().now().value value_change_time = DateTime(date=current_date, time=current_time) if _debug: PulseTask._debug(" - value_change_time: %r", value_change_time) self.accumulator.valueChangeTime = value_change_time bacpypes_debugging(PulseTask) # # __main__ # def main(): # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname,
if indx is not None: request.propertyArrayIndex = indx # optional priority if priority is not None: request.priority = priority if _debug: TestConsoleCmd._debug(" - request: %r", request) # give it to the application vlan_app_1.request(request) except Exception, e: TestConsoleCmd._exception("exception: %r", e) bacpypes_debugging(TestConsoleCmd) # # __main__ # try: # parse the command line arguments args = ArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # create a VLAN vlan = Network()
# increment the present value self.accumulator.presentValue += self.increment # update the value change time current_date = Date().now().value current_time = Time().now().value value_change_time = DateTime(date=current_date, time=current_time) if _debug: PulseTask._debug(" - value_change_time: %r", value_change_time) self.accumulator.valueChangeTime = value_change_time bacpypes_debugging(PulseTask) # # __main__ # def main(): # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject(
# if there is a special filter, use it, otherwise use != if self.filter: trigger = self.filter(old_value, new_value) else: trigger = (old_value != new_value) if _debug: DetectionMonitor._debug(" - trigger: %r", trigger) # trigger it if trigger: deferred(self.algorithm._execute) if _debug: DetectionMonitor._debug(" - deferred: %r", self.algorithm._execute) self.algorithm._triggered = True bacpypes_debugging(DetectionMonitor) # # monitor_filter # def monitor_filter(parameter): def transfer_filter_decorator(fn): fn._monitor_filter = parameter return fn return transfer_filter_decorator # # DetectionAlgorithm #
# if _triggered is true this function was called because of some # parameter change, but could have been called for some other reason if self._triggered: if _debug: SampleEventDetection._debug(" - was triggered") else: if _debug: SampleEventDetection._debug(" - was not triggered") # check for things if self.pParameter == self.pSetPoint: if _debug: SampleEventDetection._debug(" - parameter match") else: if _debug: SampleEventDetection._debug(" - parameter mismatch") bacpypes_debugging(SampleEventDetection) # # # # parse the command line arguments parser = ArgumentParser(usage=__doc__) args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # analog value 1 av1 = AnalogValueObject( objectIdentifier=('analogValue', 1),
if _debug: TrappedClient._debug("request %r", pdu) # a reference for checking self.request_sent = pdu # continue with regular processing Client.request(self, pdu) def confirmation(self, pdu): if _debug: TrappedClient._debug("confirmation %r", pdu) # a reference for checking self.confirmation_received = pdu bacpypes_debugging(TrappedClient) # # TrappedServer # class TrappedServer(Server): """ TrappedServer ~~~~~~~~~~~~~ An instance of this class sits at the bottom of a stack. """ def __init__(self): if _debug: TrappedServer._debug("__init__")
if _debug: SampleApplication._debug("request %r", apdu) BIPSimpleApplication.request(self, apdu) def indication(self, apdu): if _debug: SampleApplication._debug("indication %r", apdu) BIPSimpleApplication.indication(self, apdu) def response(self, apdu): if _debug: SampleApplication._debug("response %r", apdu) BIPSimpleApplication.response(self, apdu) def confirmation(self, apdu): if _debug: SampleApplication._debug("confirmation %r", apdu) BIPSimpleApplication.confirmation(self, apdu) bacpypes_debugging(SampleApplication) # # __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname,
if indx is not None: request.propertyArrayIndex = indx # optional priority if priority is not None: request.priority = priority if _debug: TestConsoleCmd._debug(" - request: %r", request) # give it to the application vlan_app_1.request(request) except Exception, e: TestConsoleCmd._exception("exception: %r", e) bacpypes_debugging(TestConsoleCmd) # # __main__ # try: # parse the command line arguments args = ArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # create a VLAN vlan = Network(broadcast_address=LocalBroadcast())
# pass it along self.request(PDU(pdu.pduData, destination=server_address)) def confirmation(self, pdu): if _debug: MiddleMan._debug("confirmation %r", pdu) # check for errors if isinstance(pdu, Exception): if _debug: MiddleMan._debug(" - exception: %s", pdu) return # pass it along self.response(pdu) bacpypes_debugging(MiddleMan) # # MiddleManASE # class MiddleManASE(ApplicationServiceElement): """ An instance of this class is bound to the director, which is a ServiceAccessPoint. It receives notifications of new actors connected to a server, actors that are going away when the connections are closed, and socket errors. """ def indication(self, add_actor=None,
def request(self, pdu): if _debug: TrappedClient._debug("request %r", pdu) # a reference for checking self.request_sent = pdu # continue with regular processing Client.request(self, pdu) def confirmation(self, pdu): if _debug: TrappedClient._debug("confirmation %r", pdu) # a reference for checking self.confirmation_received = pdu bacpypes_debugging(TrappedClient) # # TrappedServer # class TrappedServer(Server): """ TrappedServer ~~~~~~~~~~~~~ An instance of this class sits at the bottom of a stack. """
# 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 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') bacpypes_debugging(RandomValueProperty) # # Random Value Object Type # class RandomAnalogValueObject(AnalogValueObject): properties = [ RandomValueProperty('presentValue'), ] def __init__(self, **kwargs): if _debug: RandomAnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs)
value = propertyValue.cast_out(datatype.subtype) else: value = propertyValue.cast_out(datatype) if _debug: ReadPropertyMultipleConsoleCmd._debug(" - value: %r", value) sys.stdout.write(" = " + str(value) + '\n') sys.stdout.flush() # do something for error/reject/abort if iocb.ioError: sys.stdout.write(str(iocb.ioError) + '\n') except Exception, error: ReadPropertyMultipleConsoleCmd._exception("exception: %r", error) bacpypes_debugging(ReadPropertyMultipleConsoleCmd) # # __main__ # def main(): global this_application # check the version if (sys.version_info[:2] != (2, 5)): sys.stderr.write("Python 2.5 only\n") sys.exit(1) # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args()