Example #1
0
    def setup_device(self, address, 
                     max_apdu_len=1024, 
                     seg_supported='segmentedBoth', 
                     obj_id=599, 
                     obj_name='sMap BACnet driver', 
                     ven_id=15): 
                    
        _log.info('seg_supported '+str(seg_supported))
        _log.info('max_apdu_len '+str(max_apdu_len))
        _log.info('obj_id '+str(obj_id))
        _log.info('obj_name '+str(obj_name))
        _log.info('ven_id '+str(ven_id))

        this_device = LocalDeviceObject(
            objectName=obj_name,
            objectIdentifier=obj_id,
            maxApduLengthAccepted=max_apdu_len,
            segmentationSupported=seg_supported,
            vendorIdentifier=ven_id,
            )
        
        # build a bit string that knows about the bit names and leave it empty. We respond to NOTHING.
        pss = ServicesSupported()
    
        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value
        
        self.this_application = BACnet_application(this_device, address)
      
        server_thread = threading.Thread(target=bacpypes.core.run)
    
        # exit the BACnet App thread when the main thread terminates
        server_thread.daemon = True
        server_thread.start()
def main():
    # parse the command line arguments and initialize loggers
    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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        vendorName="B612",
    )

    # make a sample application
    this_application = SampleApplication(this_device, args.ini.address)
    if _debug: _log.debug("    - this_application: %r", this_application)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    _log.debug("running")

    run()

    _log.debug("fini")
Example #3
0
    def _init_bacnet(self):
        # local bacnet device 
        ldo = LocalDeviceObject(
            objectName=self._config.bacnet.get('objectName'),
            objectIdentifier=int(self._config.bacnet.get('objectIdentifier')),
            maxApduLengthAccepted=int(self._config.bacnet.get('maxApduLengthAccepted')),
            segmentationSupported=self._config.bacnet.get('segmentationSupported'),
            vendorIdentifier=int(self._config.bacnet.get('vendorIdentifier')),)

        # Send an empty support string
        pss = ServicesSupported()
        ldo.protocolServicesSupported = pss.value

        # TODO: look to use domain name resolution on address
        info = self._config.bacnet.get('address')
        hostname = ""
        for i, c in enumerate(info):
            if c is '/' or c is ':':
                break
            hostname += c
        suffix = info[i:]

        # MRH: The way BACpypes binds to the interface for broadcast is tricky with containers
        #      overload this for now
        if docker_test():
            import fcntl
            hostname = socket.gethostname()
            netmask = socket.inet_ntoa(fcntl.ioctl(socket.socket(socket.AF_INET, socket.SOCK_DGRAM), 0x891b, struct.pack(b'256s', b'eth0'))[20:24])
            suffix = "/" + str(sum([bin(int(x)).count('1') for x in netmask.split('.')])) + ":47808"

        print("host %s" % hostname)
        addr = socket.gethostbyname(hostname)
        print("bacnet stack using %s" % (addr + suffix))
        self.bacnet_app = BACnet(ldo, addr + suffix)
def Init(pAddress):
    global this_application, this_ServerAdress

    this_ServerAdress = pAddress
    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a simple application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value
def main():
    # parse the command line arguments and initialize loggers
    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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        vendorName="B612",
        )

    # make a sample application
    this_application = SampleApplication(this_device, args.ini.address)
    if _debug: _log.debug("    - this_application: %r", this_application)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    _log.debug("running")

    run()

    _log.debug("fini")
Example #6
0
    def get_server_application(self):
        if _debug: DeviceAbstraction._debug("    - creating application")
        # make a device object
        this_device = LocalDeviceObject(objectName="Betelgeuse",
                                        objectIdentifier=args.device_id,
                                        maxApduLengthAccepted=1024,
                                        segmentationSupported="segmentedBoth",
                                        vendorIdentifier=15)

        # build a bit string that knows about the bit names
        pss = ServicesSupported()
        pss['whoIs'] = 1
        pss['iAm'] = 1
        pss['readProperty'] = 1
        pss['readPropertyMultiple'] = 1
        pss['writeProperty'] = 1

        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value

        # make a sample application
        this_application = ReadPropertyMultipleApplication(
            this_device, args.interface)

        registers = self.registers[('byte', True)]

        #Currently we don't actually enforce read only properties.
        for register in registers:
            if _debug:
                DeviceAbstraction._debug(
                    "    - creating object of type: %s, %i",
                    register.object_type, register.instance_number)
            klass = get_object_class(register.object_type)
            ravo = klass(objectIdentifier=(register.object_type,
                                           register.instance_number),
                         objectName=register.point_name)

            ravo.WriteProperty("presentValue", 0, direct=True)

            this_application.add_object(ravo)

        registers = self.registers[('byte', False)]

        for register in registers:
            if _debug:
                DeviceAbstraction._debug(
                    "    - creating object of type: %s, %i",
                    register.object_type, register.instance_number)
            klass = get_object_class(register.object_type)
            ravo = klass(objectIdentifier=(register.object_type,
                                           register.instance_number),
                         objectName=register.point_name)

            ravo.WriteProperty("presentValue", 0, direct=True)

            this_application.add_object(ravo)

        return this_application
def main():
    global this_application, context

    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)
    parser.add_argument(
        "address",
        help="address of server",
    )
    parser.add_argument(
        "objtype",
        help="object type",
    )
    parser.add_argument(
        "objinst",
        type=int,
        help="object instance",
    )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # set the context, the collection of the above parameters
    context = args.address, args.objtype, args.objinst
    if _debug: _log.debug("    - context: %r", context)

    # make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a simple application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a console
    this_console = ReadWritePropertyConsoleCmd()
    if _debug: _log.debug("    - this_console: %r", this_console)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Example #8
0
def main():
    global this_device, this_application

    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )
    if _debug: _log.debug("    - this_device: %r", this_device)

    # build a bit string that knows about the bit names
    pss = ServicesSupported()
    pss['whoIs'] = 1
    pss['iAm'] = 1
    pss['readProperty'] = 1
    pss['writeProperty'] = 1

    # set the property value to be just the bits
    this_device.protocolServicesSupported = pss.value

    # make a simple application
    this_application = WhoIsIAmApplication(
        this_device,
        args.ini.address,
        Address(args.ini.foreignbbmd),
        int(args.ini.foreignttl),
    )
    if _debug: _log.debug("    - this_application: %r", this_application)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a console
    this_console = WhoIsIAmConsoleCmd()
    if _debug: _log.debug("    - this_console: %r", this_console)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Example #9
0
def main():
    global this_device, this_application

    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )
    if _debug: _log.debug("    - this_device: %r", this_device)

    # build a bit string that knows about the bit names
    pss = ServicesSupported()
    pss['whoIs'] = 1
    pss['iAm'] = 1
    pss['readProperty'] = 1
    pss['writeProperty'] = 1

    # set the property value to be just the bits
    this_device.protocolServicesSupported = pss.value

    # make a simple application
    this_application = WhoIsIAmApplication(
        this_device, args.ini.address,
        Address(args.ini.foreignbbmd),
        int(args.ini.foreignttl),
        )
    if _debug: _log.debug("    - this_application: %r", this_application)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a console
    this_console = WhoIsIAmConsoleCmd()
    if _debug: _log.debug("    - this_console: %r", this_console)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
def main():
    global args

    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)

    # add an option to override the sleep time
    parser.add_argument(
        '--sleep',
        type=float,
        help="sleep before returning the value",
        default=SLEEP_TIME,
    )

    # parse the command line arguments
    args = parser.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,
        objectIdentifier=('device', int(args.ini.objectidentifier)),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make some random input objects
    for i in range(1, RANDOM_OBJECT_COUNT + 1):
        ravo = RandomAnalogValueObject(
            objectIdentifier=('analogValue', i),
            objectName='Random-%d' % (i, ),
        )
        _log.debug("    - ravo: %r", ravo)
        this_application.add_object(ravo)

    # make sure they are all there
    _log.debug("    - object list: %r", this_device.objectList)

    _log.debug("running")

    run()

    _log.debug("fini")
Example #11
0
def main():
    global this_application
    global Dispositivos
    args = ConfigArgumentParser(description=__doc__).parse_args()
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )
    this_application = SubscribeCOVApplication(this_device, args.ini.address)
    try:
        ficheiro = open(this_file_path + "/" + "Config.csv", "r")
        configs = ficheiro.read()
        ficheiro.close()
        numLinhas = 0
        for linha in configs.split("\n"):
            valores = {}
            argumento = {}
            objectos = {}
            try:
                if numLinhas == 0:
                    numLinhas += 1
                    pass
                else:
                    DeviceID, IPort, ProcID, Object, ObjectID, Argument, VarName, DefaultVarValue, writeble = linha.split(
                        ";")
                    valores["valorActual"] = int(DefaultVarValue)
                    valores["NomeVAR"] = VarName
                    valores["ProcID"] = int(ProcID)
                    valores["escrita"] = bool(int(writeble))
                    argumento[Argument] = valores
                    objectos[Object + "_" + ObjectID] = argumento
                    objectos["IPort"] = IPort
                    if not DeviceID in Dispositivos:
                        Dispositivos[DeviceID] = objectos
                    else:
                        Dispositivos[DeviceID].update(objectos)
                    numLinhas += 1
            except:
                pass  #serve para ignorar a ultima linha que nao contem qualquer tipo de informacao util
    except Exception as e:
        with open("ErrorLog.txt", "a") as myfile:
            myfile.write(
                str(time.strftime("%d-%m-%Y %H:%M:%S")) +
                " Failed to open configuration file.\n")
            myfile.write("Error -> " + str(e) + "\n")
    services_supported = this_application.get_services_supported()
    this_device.protocolServicesSupported = services_supported.value
    enable_sleeping()
    subscribe_thread = SubscricaoDados()
    SMmonitor_thread = ComunicacaoSM()
    deferred(SMmonitor_thread.start)
    deferred(subscribe_thread.start)
    run()
Example #12
0
    def setup_device(self,
                     async_call,
                     address,
                     max_apdu_len=1024,
                     seg_supported='segmentedBoth',
                     obj_id=599,
                     obj_name='sMap BACnet driver',
                     ven_id=15):

        _log.info('seg_supported ' + str(seg_supported))
        _log.info('max_apdu_len ' + str(max_apdu_len))
        _log.info('obj_id ' + str(obj_id))
        _log.info('obj_name ' + str(obj_name))
        _log.info('ven_id ' + str(ven_id))

        # Check to see if they gave a valid apdu length.
        if encode_max_apdu_length_accepted(max_apdu_len) is None:
            raise ValueError(
                "Invalid max_apdu_len: {} Valid options are 50, "
                "128, 206, 480, 1024, and 1476".format(max_apdu_len))

        this_device = LocalDeviceObject(
            objectName=obj_name,
            objectIdentifier=obj_id,
            maxApduLengthAccepted=max_apdu_len,
            segmentationSupported=seg_supported,
            vendorIdentifier=ven_id,
        )

        # build a bit string that knows about the bit names.
        pss = ServicesSupported()
        pss['whoIs'] = 1
        pss['iAm'] = 1

        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value

        def i_am_callback(address, device_id, max_apdu_len, seg_supported,
                          vendor_id):
            async_call.send(None, self.i_am, address, device_id, max_apdu_len,
                            seg_supported, vendor_id)

        #i_am_callback('foo', 'bar', 'baz', 'foobar', 'foobaz')

        self.this_application = BACnet_application(i_am_callback, this_device,
                                                   address)

        kwargs = {"spin": 0.1, "sigterm": None, "sigusr1": None}

        server_thread = threading.Thread(target=bacpypes.core.run,
                                         kwargs=kwargs)

        # exit the BACnet App thread when the main thread terminates
        server_thread.daemon = True
        server_thread.start()
Example #13
0
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,
        objectIdentifier=('device', int(args.ini.objectidentifier)),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # add the additional service
    this_application.add_capability(ReadWritePropertyMultipleServices)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a random input object
    accumulator = AccumulatorObject(
        objectIdentifier=('accumulator', 1),
        objectName='Something1',
        presentValue=100,
        statusFlags = [0, 0, 0, 0],
        eventState='normal',
        scale=Scale(floatScale=2.3),
        units='btusPerPoundDryAir',
        )
    if _debug: _log.debug("    - accumulator: %r", accumulator)

    # add it to the device
    this_application.add_object(accumulator)
    if _debug: _log.debug("    - object list: %r", this_device.objectList)

    # create a task that bumps the value by one every 10 seconds
    pulse_task = PulseTask(accumulator, 1, 10 * 1000)
    if _debug: _log.debug("    - pulse_task: %r", pulse_task)

    _log.debug("running")

    run()

    _log.debug("fini")
Example #14
0
def main():
    global this_application

    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a simple application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    thread_list = []

    # loop through the address and point lists
    for addr, points in point_list:
        # create a thread
        read_thread = ReadPointListThread(addr, points)
        if _debug: _log.debug("    - read_thread: %r", read_thread)
        thread_list.append(read_thread)

    # create a thread supervisor
    thread_supervisor = ThreadSupervisor(thread_list)

    # start it running when the core is running
    deferred(thread_supervisor.start)

    _log.debug("running")

    run()

    # dump out the results
    for read_thread in thread_list:
        for request, response in zip(read_thread.point_list,
                                     read_thread.response_values):
            print(request, response)

    _log.debug("fini")
Example #15
0
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,
        objectIdentifier=('device', int(args.ini.objectidentifier)),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # add the additional service
    this_application.add_capability(ReadWritePropertyMultipleServices)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a random input object
    accumulator = AccumulatorObject(
        objectIdentifier=('accumulator', 1),
        objectName='Something1',
        presentValue=100,
        statusFlags=[0, 0, 0, 0],
        eventState='normal',
        scale=Scale(floatScale=2.3),
        units='btusPerPoundDryAir',
    )
    if _debug: _log.debug("    - accumulator: %r", accumulator)

    # add it to the device
    this_application.add_object(accumulator)
    if _debug: _log.debug("    - object list: %r", this_device.objectList)

    # create a task that bumps the value by one every 10 seconds
    pulse_task = PulseTask(accumulator, 1, 10 * 1000)
    if _debug: _log.debug("    - pulse_task: %r", pulse_task)

    _log.debug("running")

    run()

    _log.debug("fini")
Example #16
0
    def setup_device(self, async_call, address,
                     max_apdu_len=1024,
                     seg_supported='segmentedBoth',
                     obj_id=599,
                     obj_name='sMap BACnet driver',
                     ven_id=15):

        _log.info('seg_supported '+str(seg_supported))
        _log.info('max_apdu_len '+str(max_apdu_len))
        _log.info('obj_id '+str(obj_id))
        _log.info('obj_name '+str(obj_name))
        _log.info('ven_id '+str(ven_id))

        # Check to see if they gave a valid apdu length.
        if encode_max_apdu_length_accepted(max_apdu_len) is None:
            raise ValueError("Invalid max_apdu_len: {} Valid options are 50, "
                             "128, 206, 480, 1024, and 1476".format(
                                 max_apdu_len))

        this_device = LocalDeviceObject(
            objectName=obj_name,
            objectIdentifier=obj_id,
            maxApduLengthAccepted=max_apdu_len,
            segmentationSupported=seg_supported,
            vendorIdentifier=ven_id,
            )

        # build a bit string that knows about the bit names.
        pss = ServicesSupported()
        pss['whoIs'] = 1
        pss['iAm'] = 1

        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value

        def i_am_callback(address, device_id, max_apdu_len,
                          seg_supported, vendor_id):
            async_call.send(None, self.i_am, address, device_id, max_apdu_len,
                            seg_supported, vendor_id)

        #i_am_callback('foo', 'bar', 'baz', 'foobar', 'foobaz')

        self.this_application = BACnet_application(i_am_callback, this_device,
                                                   address)

        kwargs = {"spin":0.1,
                  "sigterm": None,
                  "sigusr1": None}

        server_thread = threading.Thread(target=bacpypes.core.run, kwargs=kwargs)

        # exit the BACnet App thread when the main thread terminates
        server_thread.daemon = True
        server_thread.start()
Example #17
0
    def get_server_application(self):
        if _debug: DeviceAbstraction._debug("    - creating application")
        # make a device object
        this_device = LocalDeviceObject(
            objectName="Betelgeuse",
            objectIdentifier=args.device_id,
            maxApduLengthAccepted=1024,
            segmentationSupported="segmentedBoth",
            vendorIdentifier=15
            )
    
        # build a bit string that knows about the bit names
        pss = ServicesSupported()
        pss['whoIs'] = 1
        pss['iAm'] = 1
        pss['readProperty'] = 1
        pss['readPropertyMultiple'] = 1
        pss['writeProperty'] = 1
    
        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value        

        # make a sample application
        this_application = ReadPropertyMultipleApplication(this_device, args.interface)
    
       
        registers= self.registers[('byte',True)]
        
        #Currently we don't actually enforce read only properties.        
        for register in registers:
            if _debug: DeviceAbstraction._debug("    - creating object of type: %s, %i", register.object_type, register.instance_number)
            klass = get_object_class(register.object_type)
            ravo = klass(objectIdentifier=(register.object_type, register.instance_number), 
                         objectName=register.point_name)
            
            ravo.WriteProperty("presentValue", 0, direct=True)
            
            this_application.add_object(ravo)
            
            
        registers= self.registers[('byte',False)]
        
        for register in registers:
            if _debug: DeviceAbstraction._debug("    - creating object of type: %s, %i", register.object_type, register.instance_number)
            klass = get_object_class(register.object_type)
            ravo = klass(objectIdentifier=(register.object_type, register.instance_number), 
                         objectName=register.point_name)
            
            ravo.WriteProperty("presentValue", 0, direct=True)
            
            this_application.add_object(ravo)
            
        return this_application
Example #18
0
def main():
    # 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()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a sample application
    this_application = ReadPropertyMultipleApplication(this_device, args.ini.address)

    # make a random input object
    ravo1 = RandomAnalogValueObject(
        objectIdentifier=('analogValue', 1), objectName='Random1'
        )
    _log.debug("    - ravo1: %r", ravo1)

    ravo2 = RandomAnalogValueObject(
        objectIdentifier=('analogValue', 2), objectName='Random2'
        )
    _log.debug("    - ravo2: %r", ravo2)

    # add it to the device
    this_application.add_object(ravo1)
    this_application.add_object(ravo2)
    _log.debug("    - object list: %r", this_device.objectList)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    _log.debug("running")

    run()

    _log.debug("fini")
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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        _dcc_password="******",
    )

    # make a sample application
    this_application = ReadPropertyMultipleApplication(this_device,
                                                       args.ini.address)

    # make a random input object
    ravo1 = RandomAnalogValueObject(
        objectIdentifier=('analogValue', 1),
        objectName='Random1',
        eventMessageTexts=ArrayOf(CharacterString)(["hello"]),
    )
    _log.debug("    - ravo1: %r", ravo1)

    ravo2 = RandomAnalogValueObject(objectIdentifier=('analogValue', 2),
                                    objectName='Random2')
    _log.debug("    - ravo2: %r", ravo2)

    # add it to the device
    this_application.add_object(ravo1)
    this_application.add_object(ravo2)
    _log.debug("    - object list: %r", this_device.objectList)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    _log.debug("running")

    run()

    _log.debug("fini")
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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # add the capability to server file content
    this_application.add_capability(FileServices)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a record access file, add to the device
    f1 = TestRecordFile(
        objectIdentifier=('file', 1),
        objectName='RecordAccessFile1'
        )
    _log.debug("    - f1: %r", f1)
    this_application.add_object(f1)

    # make a stream access file, add to the device
    f2 = TestStreamFile(
        objectIdentifier=('file', 2),
        objectName='StreamAccessFile2'
        )
    _log.debug("    - f2: %r", f2)
    this_application.add_object(f2)

    _log.debug("running")

    run()

    _log.debug("fini")
Example #21
0
def main():
    global vendor_id

    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=vendor_id,
        )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make some objects
    ravo1 = VendorAVObject(
        objectIdentifier=(513, 1), objectName='Random1'
        )
    if _debug: _log.debug("    - ravo1: %r", ravo1)

    ravo2 = VendorAVObject(
        objectIdentifier=(513, 2), objectName='Random2'
        )
    if _debug: _log.debug("    - ravo2: %r", ravo2)

    # add it to the device
    this_application.add_object(ravo1)
    this_application.add_object(ravo2)
    if _debug: _log.debug("    - object list: %r", this_device.objectList)

    if _debug: _log.debug("running")

    run()

    if _debug: _log.debug("fini")
Example #22
0
    def __init__(self, template, template_directory, args):
        self.dom = etree.parse(template)
        databus = conpot_core.get_databus()
        device_info_root = self.dom.xpath('//bacnet/device_info')[0]

        name_key = databus.get_value(
            device_info_root.xpath('./device_name/text()')[0])
        id_key = device_info_root.xpath('./device_identifier/text()')[0]
        vendor_name_key = device_info_root.xpath('./vendor_name/text()')[0]
        vendor_identifier_key = device_info_root.xpath(
            './vendor_identifier/text()')[0]
        apdu_length_key = device_info_root.xpath(
            './max_apdu_length_accepted/text()')[0]
        segmentation_key = device_info_root.xpath(
            './segmentation_supported/text()')[0]

        # self.local_device_address = dom.xpath('./@*[name()="host" or name()="port"]')

        self.thisDevice = LocalDeviceObject(
            objectName=name_key,
            objectIdentifier=int(id_key),
            maxApduLengthAccepted=int(apdu_length_key),
            segmentationSupported=segmentation_key,
            vendorName=vendor_name_key,
            vendorIdentifier=int(vendor_identifier_key))
        self.bacnet_app = None

        logger.info('Conpot Bacnet initialized using the %s template.',
                    template)
def main():
    global this_application

    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a simple application
    #this_application = BIPSimpleApplication(this_device, args.ini.address)
    this_application = BIPForeignApplication(
        this_device,
        args.ini.address,
        Address(args.ini.foreignbbmd),
        int(args.ini.foreignttl),
    )
    if _debug: _log.debug("    - this_application: %r", this_application)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a console
    this_console = WriteSomethingConsoleCmd()
    if _debug: _log.debug("    - this_console: %r", this_console)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Example #24
0
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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # add the capability to server file content
    this_application.add_capability(FileServices)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a record access file, add to the device
    f1 = TestRecordFile(objectIdentifier=('file', 1),
                        objectName='RecordAccessFile1')
    _log.debug("    - f1: %r", f1)
    this_application.add_object(f1)

    # make a stream access file, add to the device
    f2 = TestStreamFile(objectIdentifier=('file', 2),
                        objectName='StreamAccessFile2')
    _log.debug("    - f2: %r", f2)
    this_application.add_object(f2)

    _log.debug("running")

    run()

    _log.debug("fini")
Example #25
0
def main():
    global vendor_id

    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=vendor_id,
    )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make some objects
    ravo1 = VendorAVObject(objectIdentifier=(513, 1), objectName='Random1')
    if _debug: _log.debug("    - ravo1: %r", ravo1)

    ravo2 = VendorAVObject(objectIdentifier=(513, 2), objectName='Random2')
    if _debug: _log.debug("    - ravo2: %r", ravo2)

    # add it to the device
    this_application.add_object(ravo1)
    this_application.add_object(ravo2)
    if _debug: _log.debug("    - object list: %r", this_device.objectList)

    if _debug: _log.debug("running")

    run()

    if _debug: _log.debug("fini")
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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a multistate value object
    msvo = MultiStateValueObject(
        objectIdentifier=('multiStateValue', 1),
        objectName='My Special Object',
        presentValue=1,
        numberOfStates=3,
        stateText=ArrayOf(CharacterString)(['red', 'green', 'blue']),
        )
    _log.debug("    - msvo: %r", msvo)

    # add it to the device
    this_application.add_object(msvo)
    _log.debug("    - object list: %r", this_device.objectList)

    _log.debug("running")

    run()

    _log.debug("fini")
Example #27
0
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()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a simple application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a console
    this_console = ReadPropertyConsoleCmd()
    if _debug: _log.debug("    - this_console: %r", this_console)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Example #28
0
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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a multistate value object
    msvo = MultiStateValueObject(
        objectIdentifier=('multiStateValue', 1),
        objectName='My Special Object',
        presentValue=1,
        numberOfStates=3,
        stateText=ArrayOf(CharacterString)(['red', 'green', 'blue']),
    )
    _log.debug("    - msvo: %r", msvo)

    # add it to the device
    this_application.add_object(msvo)
    _log.debug("    - object list: %r", this_device.objectList)

    _log.debug("running")

    run()

    _log.debug("fini")
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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a sample application
    this_application = WhoIsIAmApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug:
        _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    _log.debug("running")

    run()

    _log.debug("fini")

    print("----- Who Is -----")
    for (src, lowlim, hilim), count in sorted(who_is_counter.items()):
        print("%-20s %8s %8s %4d" % (src, lowlim, hilim, count))
    print("")

    print("----- I Am -----")
    for (src, devid), count in sorted(i_am_counter.items()):
        print("%-20s %8d %4d" % (src, devid, count))
    print("")
def main():
    global this_application

    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a simple application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # create a thread and
    read_thread = ReadPointListThread(point_list)
    if _debug: _log.debug("    - read_thread: %r", read_thread)

    # start it running when the core is running
    deferred(read_thread.start)

    _log.debug("running")

    run()

    # dump out the results
    for request, response in zip(point_list, read_thread.response_values):
        print(request, response)

    _log.debug("fini")
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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # make a commandable analog value object, add to the device
    avo1 = LocalAnalogValueObjectCmd(
        objectIdentifier=('analogValue', 1),
        objectName='avo1',
        )
    if _debug: _log.debug("    - avo1: %r", avo1)
    this_application.add_object(avo1)

    # make a commandable binary output object, add to the device
    boo1 = LocalBinaryOutputObjectCmd(
        objectIdentifier=('binaryOutput', 1),
        objectName='boo1',
        presentValue='inactive',
        relinquishDefault='inactive',
        minimumOnTime=5,        # let it warm up
        minimumOffTime=10,      # let it cool off
        )
    if _debug: _log.debug("    - boo1: %r", boo1)
    this_application.add_object(boo1)

    # get the current date
    today = Date().now()

    # make a commandable date value object, add to the device
    dvo1 = LocalDateValueObjectCmd(
        objectIdentifier=('dateValue', 1),
        objectName='dvo1',
        presentValue=today.value,
        )
    if _debug: _log.debug("    - dvo1: %r", dvo1)
    this_application.add_object(dvo1)

    if _debug: _log.debug("running")

    run()

    _log.debug("fini")
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,
        objectIdentifier=('device', int(args.ini.objectidentifier)),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make some random input objects
    for i in range(1, RANDOM_OBJECT_COUNT+1):
        ravo = RandomAnalogValueObject(
            objectIdentifier=('analogValue', i),
            objectName='Random-%d' % (i,),
            )
        _log.debug("    - ravo: %r", ravo)
        this_application.add_object(ravo)

    # make sure they are all there
    _log.debug("    - object list: %r", this_device.objectList)

    _log.debug("running")

    run()

    _log.debug("fini")
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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a sample application
    this_application = WhoHasIHaveApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    _log.debug("running")

    # run until stopped, ^C works
    run()

    _log.debug("fini")

    print("----- Who Has -----")
    for (src, objname), count in sorted(who_has_counter.items()):
        print("%-20s %-30s %4d" % (src, objname, count))
    print("")

    print("----- I Have -----")
    for (src, devid, objid, objname), count in sorted(i_have_counter.items()):
        print("%-20s %-20s %-20s %-20s %4d" %
              (src, devid, objid, objname, count))
    print("")
Example #34
0
def main():
    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)

    # add an argument for interval
    parser.add_argument(
        'interval',
        type=int,
        help='repeat rate in seconds',
    )

    # now parse the arguments
    args = parser.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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a dog
    this_application = PrairieDog(args.interval, this_device, args.ini.address)
    if _debug: _log.debug("    - this_application: %r", this_application)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    _log.debug("running")

    run()

    _log.debug("fini")
Example #35
0
def main():
    global this_application

    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a simple application
    this_application = ReadPointListApplication(point_list, this_device,
                                                args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # fire off a request when the core has a chance
    deferred(this_application.next_request)

    _log.debug("running")

    run()

    # dump out the results
    for request, response in zip(point_list, this_application.response_values):
        print(request, response)

    _log.debug("fini")
Example #36
0
def main():
    global this_application

    # 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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a simple application
    this_application = SubscribeCOVApplication(this_device, args.ini.address)

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # make a console
    this_console = SubscribeCOVConsoleCmd()
    if _debug: _log.debug("    - this_console: %r", this_console)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Example #37
0
    def startApp(self):
        """
        Define the local device, including services supported.
        Once defined, start the BACnet stack in its own thread.
        """
        self._log.debug("Create Local Device")
        try:
            # make a device object
            self.this_device = LocalDeviceObject(
                objectName= self.localObjName,
                objectIdentifier= self.Boid,
                maxApduLengthAccepted=int(self.maxAPDULengthAccepted),
                segmentationSupported=self.segmentationSupported,
                vendorIdentifier= self.vendorId,
                vendorName= self.vendorName,
                modelName= self.modelName,
                systemStatus= self.systemStatus,
                description='http://christiantremblay.github.io/BAC0/',
                firmwareRevision=''.join(sys.version.split('|')[:2]),
                applicationSoftwareVersion=infos.__version__,
                protocolVersion=1,
                protocolRevision=0,
            )

            # build a bit string that knows about the bit names
            pss = ServicesSupported()
            pss['whoIs'] = 1
            pss['iAm'] = 1
            pss['readProperty'] = 1
            pss['writeProperty'] = 1
            pss['readPropertyMultiple'] = 1

            # set the property value to be just the bits
            self.this_device.protocolServicesSupported = pss.value

            # make a simple application
            self.this_application = ScriptApplication(self.this_device, self.localIPAddr)

            self._log.debug("Starting")
            self._initialized = True
            try:
                self._startAppThread()
            except:
                self._log.warning("Error opening socket")
                raise
            self._log.debug("Running")

        except Exception as error:
            self._log.error("an error has occurred: %s", error)
        finally:
            self._log.debug("finally")
Example #38
0
def main():
    global this_application

    # make a device object
    this_device = LocalDeviceObject(
        objectName='Energy Box',
        objectIdentifier=599,
        maxApduLengthAccepted=1024,
        segmentationSupported='segmentedBoth',
        vendorIdentifier=15,
    )

    points = []
    for i in range(10):
        points.append(
            ('analogInput', i, ['presentValue', 'objectName', 'units']))
    this_application = ReadPointListApplication(points, this_device,
                                                '10.81.0.14')

    # get the services supported
    services_supported = this_application.get_services_supported()
    if _debug:
        _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    this_device.protocolServicesSupported = services_supported.value

    # fire off a request when the core has a chance
    deferred(this_application.do_request)
    _log.debug("running")
    # enable_sleeping()
    run()

    # dump out the results
    pprint.pprint(this_application.response_values)

    _log.debug("fini")
Example #39
0
    def __init__(self):
        if _debug: ApplicationNetwork._debug("__init__")
        StateMachineGroup.__init__(self)

        # reset the time machine
        reset_time_machine()
        if _debug: ApplicationNetwork._debug("    - time machine reset")

        # make a little LAN
        self.vlan = Network(broadcast_address=LocalBroadcast())

        # test device object
        self.td_device_object = LocalDeviceObject(
            objectName="td",
            objectIdentifier=("device", 10),
            maxApduLengthAccepted=1024,
            segmentationSupported='noSegmentation',
            vendorIdentifier=999,
        )

        # test device
        self.td = ApplicationNode(self.td_device_object, self.vlan)
        self.append(self.td)

        # implementation under test device object
        self.iut_device_object = LocalDeviceObject(
            objectName="iut",
            objectIdentifier=("device", 20),
            maxApduLengthAccepted=1024,
            segmentationSupported='noSegmentation',
            vendorIdentifier=999,
        )

        # implementation under test
        self.iut = ApplicationNode(self.iut_device_object, self.vlan)
        self.append(self.iut)
Example #40
0
    def __init__(self, objectName, deviceInstance, address, aseID=None):
        if _debug: VLANApplication._debug("__init__ %r %r %r aseID=%r", objectName, deviceInstance, address, aseID)

        # make an address
        vlan_address = Address(address)
        _log.debug("    - vlan_address: %r", vlan_address)

        # make a device object
        vlan_device = LocalDeviceObject(
            objectName=objectName,
            objectIdentifier=('device', deviceInstance),
            maxApduLengthAccepted=1024,
            segmentationSupported='noSegmentation',
            vendorIdentifier=15,
            )
        _log.debug("    - vlan_device: %r", vlan_device)

        # continue with the initialization
        Application.__init__(self, vlan_device, vlan_address, aseID)

        # include a application decoder
        self.asap = ApplicationServiceAccessPoint()

        # pass the device object to the state machine access point so it
        # can know if it should support segmentation
        self.smap = StateMachineAccessPoint(vlan_device)

        # the segmentation state machines need access to the same device
        # information cache as the application
        self.smap.deviceInfoCache = self.deviceInfoCache

        # a network service access point will be needed
        self.nsap = NetworkServiceAccessPoint()

        # give the NSAP a generic network layer service element
        self.nse = NetworkServiceElement()
        bind(self.nse, self.nsap)

        # bind the top layers
        bind(self, self.asap, self.smap, self.nsap)

        # create a vlan node at the assigned address
        self.vlan_node = Node(vlan_address)
        if _debug: VLANApplication._debug("    - vlan_node: %r", self.vlan_node)

        # bind the stack to the node, no network number
        self.nsap.bind(self.vlan_node)
        if _debug: VLANApplication._debug("    - node bound")
Example #41
0
    def __init__(self, address, device_id):
        #
        # 親コンストラクタの呼び出し
        #
        Thread.__init__(self)

        #
        # デーモンの設定
        #
        self.daemon = True

        #
        # デバイスの設定情報の定義
        #
        self.device_name = 'EYED DEVICE'
        self.device_id = device_id
        self.vendor_name = 'EYED.ORG'
        self.vendor_id = 65535
        self.maxApduLengthAccepted = 1024
        self.segmentationSupported = 'segmentedBoth'
        self.systemStatus = 0

        #
        # デバイスの定義
        #
        self.device = LocalDeviceObject(
            objectName=self.device_name,
            objectIdentifier=('device', self.device_id),
            maxApduLengthAccepted=self.maxApduLengthAccepted,
            segmentationSupported=self.segmentationSupported,
            vendorName=self.vendor_name,
            vendorIdentifier=self.vendor_id,
            systemStatus=self.systemStatus)

        #
        # アプリケーションの定義
        #
        #self.application = BIPSimpleApplication(self.device, Address(address))
        self.application = App(self.device, Address(address))

        #
        # サポートしているプロトコルの定義
        #
        services_supported = self.application.get_services_supported()
        self.device.protocolServicesSupported = services_supported
Example #42
0
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,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # make a commandable analog value object, add to the device
    cavo1 = CommandableAnalogValueObject(
        objectIdentifier=('analogValue', 1), objectName='Commandable1',
        )
    if _debug: _log.debug("    - cavo1: %r", cavo1)
    this_application.add_object(cavo1)

    # get the current date
    today = Date().now()

    # make a commandable date value object, add to the device
    cdvo2 = CommandableDateValueObject(
        objectIdentifier=('dateValue', 1), objectName='Commandable2',
        presentValue=today.value,
        )
    if _debug: _log.debug("    - cdvo2: %r", cdvo2)
    this_application.add_object(cdvo2)

    if _debug: _log.debug("running")

    run()

    _log.debug("fini")
Example #43
0
def main():
    global test_application

    # make a parser
    parser = ConfigArgumentParser(description=__doc__)
    parser.add_argument("--console",
        action="store_true",
        default=False,
        help="create a console",
        )

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a device object
    test_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )

    # make a sample application
    test_application = SubscribeCOVApplication(test_device, args.ini.address)

    # make a binary value object
    test_bv = BinaryValueObject(
        objectIdentifier=('binaryValue', 1),
        objectName='bv',
        presentValue='inactive',
        statusFlags=[0, 0, 0, 0],
        )
    _log.debug("    - test_bv: %r", test_bv)

    # add it to the device
    test_application.add_object(test_bv)

    # make an analog value object
    test_av = AnalogValueObject(
        objectIdentifier=('analogValue', 1),
        objectName='av',
        presentValue=0.0,
        statusFlags=[0, 0, 0, 0],
        covIncrement=1.0,
        )
    _log.debug("    - test_av: %r", test_av)

    # add it to the device
    test_application.add_object(test_av)
    _log.debug("    - object list: %r", test_device.objectList)

    # get the services supported
    services_supported = test_application.get_services_supported()
    if _debug: _log.debug("    - services_supported: %r", services_supported)

    # let the device object know
    test_device.protocolServicesSupported = services_supported.value

    # make a console
    if args.console:
        test_console = COVConsoleCmd()
        _log.debug("    - test_console: %r", test_console)

        # enable sleeping will help with threads
        enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Example #44
0
    field_names = ["address",
                   "device_id",
                   "max_apdu_length",
                   "segmentation_supported",
                   "vendor_id"]
    this_csv_file = csv.DictWriter(f, field_names)
    this_csv_file.writeheader()

if _debug: _log.debug("initialization")
if _debug: _log.debug("    - args: %r", args)

# make a device object
this_device = LocalDeviceObject(
    objectName=args.ini.objectname,
    objectIdentifier=int(args.ini.objectidentifier),
    maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
    segmentationSupported=args.ini.segmentationsupported,
    vendorIdentifier=int(args.ini.vendoridentifier),
    )

# build a bit string that knows about the bit names
pss = ServicesSupported()
pss['whoIs'] = 1
pss['iAm'] = 1

# set the property value to be just the bits
this_device.protocolServicesSupported = pss.value

# make a simple application
this_application = WhoIsIAmApplication(this_device, args.ini.address)
_log.debug("running")
Example #45
0
    def setup_device(self, async_call, address,
                     max_apdu_len=1024,
                     seg_supported='segmentedBoth',
                     obj_id=599,
                     obj_name='sMap BACnet driver',
                     ven_id=15,
                     request_check_interval=100):

        _log.info('seg_supported '+str(seg_supported))
        _log.info('max_apdu_len '+str(max_apdu_len))
        _log.info('obj_id '+str(obj_id))
        _log.info('obj_name '+str(obj_name))
        _log.info('ven_id '+str(ven_id))

        # Check to see if they gave a valid apdu length.
        if encode_max_apdu_length_accepted(max_apdu_len) is None:
            raise ValueError("Invalid max_apdu_len: {} Valid options are 50, "
                             "128, 206, 480, 1024, and 1476".format(
                                 max_apdu_len))

        this_device = LocalDeviceObject(
            objectName=obj_name,
            objectIdentifier=obj_id,
            maxApduLengthAccepted=max_apdu_len,
            segmentationSupported=seg_supported,
            vendorIdentifier=ven_id,
            )

        # build a bit string that knows about the bit names.
        pss = ServicesSupported()
        pss['whoIs'] = 1
        pss['iAm'] = 1

        # set the property value to be just the bits
        this_device.protocolServicesSupported = pss.value

        def i_am_callback(address, device_id, max_apdu_len,
                          seg_supported, vendor_id):
            async_call.send(None, self.i_am, address, device_id, max_apdu_len,
                            seg_supported, vendor_id)

        def send_cov_subscription_callback(device_address,
                                           subscriberProcessIdentifier,
                                           monitoredObjectIdentifier, lifetime,
                                           point_name):
            """Asynchronus cov subscription callback for gevent"""
            async_call.send(None, self.send_cov_subscription, device_address,
                            subscriberProcessIdentifier,
                            monitoredObjectIdentifier, lifetime, point_name)

        def forward_cov_callback(point_name, apdu, result_dict):
            """Asynchronus callback to forward cov values to the master driver
            for gevent"""
            async_call.send(None, self.forward_cov, point_name, apdu, result_dict)


        #i_am_callback('foo', 'bar', 'baz', 'foobar', 'foobaz')

        self.this_application = BACnet_application(i_am_callback,
                                                   send_cov_subscription_callback,
                                                   forward_cov_callback,
                                                   request_check_interval,
                                                   this_device,
                                                   address)

        # Having a recurring task makes the spin value kind of irrelevant.
        kwargs = {"spin": 0.1,
                  "sigterm": None,
                  "sigusr1": None}

        server_thread = threading.Thread(target=bacpypes.core.run, kwargs=kwargs)

        # exit the BACnet App thread when the main thread terminates
        server_thread.daemon = True
        server_thread.start()