Esempio n. 1
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)

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

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 2
0
def run_application(**kwargs):
    '''
    Running the base application for spoofing bacnet test_devices on the local network.
    :param vendoridentifier:
    :param segmentationsupported:
    :param maxapdulength:
    :param objectidentifier:
    :param objectname:
    :param ini: Ini parameters
    :param objects: Objects to be attached to the device
    :return:
    '''

    import netifaces
    from ipaddress import IPv4Network

    #Get IP of 'en0' interface.
    wifi_ip = netifaces.ifaddresses('en0')[netifaces.AF_INET][0]

    #Construct address of device.
    address = wifi_ip['addr'] + "/" + str(
        IPv4Network("0.0.0.0/" + wifi_ip['netmask']).prefixlen) + ":47808"

    this_device = LocalDeviceObject(**kwargs)

    this_application = DebugApplication(this_device, address)

    if "objects" in kwargs.keys():
        for object in kwargs["objects"]:
            this_application.add_object(object)

    enable_sleeping()

    run()
Esempio n. 3
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
    mstp_args = {
        '_address': int(args.ini.address),
        '_interface': str(args.ini.interface),
        '_max_masters': int(args.ini.max_masters),
        '_baudrate': int(args.ini.baudrate),
        '_maxinfo': int(args.ini.maxinfo),
    }
    this_device = LocalDeviceObject(ini=args.ini, **mstp_args)
    if _debug: _log.debug("    - this_device: %r", this_device)

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

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

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 4
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(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

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

    # 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")
Esempio n. 5
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(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

    # 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)

    # 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")
Esempio n. 6
0
def main():
    global args

    # build a parser for the command line arguments
    parser = ArgumentParser(description=__doc__)

    # sample additional argument to change the prompt
    parser.add_argument(
        "--prompt", type=str,
        default="> ",
        help="change the prompt",
        )

    # accept everything else
    parser.add_argument('args', nargs=argparse.REMAINDER)

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

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

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

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 7
0
def main():
    # parse the command line arguments
    args = ArgumentParser(description=__doc__).parse_args()
    global this_switch, this_console

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

    # make some debugging terminals
    debug1 = DebugTerm("a")
    debug2 = DebugTerm("b")

    # make a switch with them
    this_switch = Switch(a=debug1, b=debug2)
    if _debug: _log.debug("    this_switch: %r", this_switch)

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

    # bind the console to the top and bottom of the switch
    bind(this_console, this_switch, this_console)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 8
0
def main():
    # build a parser for the command line arguments
    parser = ArgumentParser(description=__doc__)

    # sample additional argument to change the prompt
    parser.add_argument(
        "--prompt",
        type=str,
        default="> ",
        help="change the prompt",
    )

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

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

    # make a console
    this_console = ConsoleCmdTemplate(prompt=args.prompt)
    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 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(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

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

    # 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")
Esempio n. 10
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 simple application
    this_application = WhoIsRouterApplication(args.ini.address)
    if _debug: _log.debug("    - this_application: %r", this_application)

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

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 11
0
def main():
    global this_device, this_application, saved_recipent_list

    # 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(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

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

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

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 12
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 simple application
    this_application = WhoIsRouterApplication(args.ini.address,
                                              bbmdAddress=Address(
                                                  args.ini.foreignbbmd),
                                              bbmdTTL=int(args.ini.foreignttl))
    if _debug: _log.debug("    - this_application: %r", this_application)

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

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 13
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(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

    # provide max segments accepted if any kind of segmentation supported
    if args.ini.segmentationsupported != 'noSegmentation':
        this_device.maxSegmentsAccepted = int(args.ini.maxsegmentsaccepted)

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

    # make a console
    this_console = ReadPropertyAnyConsoleCmd()
    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():
    # 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 - Not required for this simple console cmd
    # this_device = LocalDeviceObject

    # Initialize application - Not required for this simple console cmd
    # this_application = SampleApplication(this_device, args.ini.address)

    # Make Console
    this_console = SampleConsoleCmd()
    if _debug: _log.debug("   - this_console: %r", this_console)

    # Sleeping with threads
    enable_sleeping()

    _log.debug("Running")
    run()
    _log.debug("Finish")

    return None
Esempio n. 15
0
def main():
    # build a parser for the command line arguments
    parser = ArgumentParser(description=__doc__)

    # sample additional argument to change the prompt
    parser.add_argument(
        "--prompt", type=str,
        default="> ",
        help="change the prompt",
        )

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

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

    # make a console
    this_console = ConsoleCmdTemplate(prompt=args.prompt)
    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 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")
Esempio n. 17
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")
Esempio n. 18
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")
Esempio n. 19
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()
Esempio n. 20
0
def main():
    global args, this_device, this_application

    # build a parser, add some options
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        '--lan',
        type=str,
        default=default_lan_name,
        help='lan name',
    )
    parser.add_argument(
        '--host',
        type=str,
        default=default_broker_host,
        help='broker host address',
    )
    parser.add_argument(
        '--port',
        type=int,
        default=default_broker_port,
        help='broker port',
    )
    parser.add_argument(
        '--keepalive',
        type=int,
        default=default_broker_keepalive,
        help=
        "maximum period in seconds allowed between communications with the broker",
    )

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

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

    # make a simple application
    this_application = MQTTSniffer(args.lan, args.host, args.port,
                                   args.keepalive)

    # enable sleeping will help with threads
    enable_sleeping()

    # start up the client
    this_application.startup()

    _log.debug("running")

    run()

    # shutdown the client
    this_application.shutdown()

    _log.debug("fini")
Esempio n. 21
0
 def _startAppThread(self):
     """
     Starts the application in its own thread so requests can be processed.
     Once started, socket will be reserved.
     """
     print('Starting app...')
     enable_sleeping(0.0005)
     self.t = Thread(target=startBacnetIPApp, daemon = True)
     self.t.start()
     self._started = True
     print('App started')
Esempio n. 22
0
 def _startAppThread(self):
     """
     Starts the BACnet stack in its own thread so requests can be processed.
     As signal cannot be called in another thread than the main thread
     when calling startBacnetIPApp, we must pass None to both parameters
     """
     self._log.info('Starting app...')
     enable_sleeping(0.0005)
     self.t = Thread(target=startBacnetIPApp, kwargs={'sigterm': None,'sigusr1': None}, daemon = True)
     self.t.start()
     self._started = True
     self._log.info('BAC0 started')
Esempio n. 23
0
    def connect(self):
        """

        :return:
        """
        try:
            self.this_device = LocalDeviceObject(
                objectName=self.local_object_name,
                objectIdentifier=self.boid,
                maxApduLengthAccepted=int(self.max_APDU_length_accepted),
                segmentationSupported=self.segmentation_supported,
                vendorIdentifier=self.vendor_id,
                vendorName=self.vendor_name,
                modelName=self.model_name,
                systemStatus=self.system_status,
                description=
                'PyScada BACnet DAQs Service (https://github.com/trombastic/pyscada)',
                firmwareRevision=''.join(sys.version.split('|')[:2]),
                applicationSoftwareVersion=pyscada.__version__,
                protocolVersion=1,
                protocolRevision=0,
            )
            self.this_application = BIPApplication(self.this_device,
                                                   self.local_ip)
            app_type = 'Simple BACnet/IP App'

            logger.debug("Starting")
            try:
                logger.info('Starting app...')
                enable_sleeping(0.0005)
                self.t = Thread(target=run,
                                kwargs={
                                    'sigterm': None,
                                    'sigusr1': None
                                },
                                daemon=True)
                self.t.start()
                logger.info('BAC0 started')
                print("Registered as {}".format(app_type))
            except:
                logger.warning("Error opening socket")
                raise
            logger.debug("Running")

        except Exception as error:
            logger.error("an error has occurred: {}".format(error))
        finally:
            logger.debug("finally")
Esempio n. 24
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)
    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")
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(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

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

    # 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")
Esempio n. 26
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")
Esempio n. 27
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
    mstp_args = {
        '_address': int(args.ini.address),
        '_interface': str(args.ini.interface),
        '_max_masters': int(args.ini.max_masters),
        '_baudrate': int(args.ini.baudrate),
        '_maxinfo': int(args.ini.maxinfo),
    }

    if hasattr(args.ini, 'mstpdbgfile'):
        mstp_args['_mstpdbgfile'] = str(args.ini.mstpdbgfile)

    this_device = LocalDeviceObject(ini=args.ini, **mstp_args)
    if _debug: _log.debug("    - this_device: %r", this_device)

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

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

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 28
0
def main():
    global this_application

    # create a console log handler to show how settings are gathered from
    # the JSON file.  The settings may include debugging, so this is to
    # debug the debugging and usually isn't necessary
    ConsoleLogHandler("bacpypes.consolelogging")

    # parse the command line arguments
    args = JSONArgumentParser(description=__doc__).parse_args()

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

    local_device = args.json["local-device"]
    if _debug:
        _log.debug("    - local_device: %r", local_device)

    # make a device object
    this_device = LocalDeviceObject(**local_device)
    if _debug:
        _log.debug("    - this_device: %r", this_device)

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

    # 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")
Esempio n. 29
0
 def _startAppThread(self):
     """
     Starts the BACnet stack in its own thread so requests can be processed.
     As signal cannot be called in another thread than the main thread
     when calling startBacnetIPApp, we must pass None to both parameters
     """
     self._log.info("Starting app...")
     enable_sleeping(0.0005)
     self.t = Thread(
         target=startBacnetIPApp,
         kwargs={"sigterm": None, "sigusr1": None},
         daemon=True,
     )
     try:
         self.t.start()
         self._started = True
         self._log.info("BAC0 started")
     except OSError:
         stopBacnetIPApp()
         self.t.join()
         raise
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 = SampleApplication(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 = SampleConsoleCmd()

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
    def __init__(self, 
                 logger: Logger, 
                 ini_file: str = None, 
                 config_file: str = None,
                 debug: bool = False
                 ) -> None:
        path = os.path.dirname(bnet_base.__file__)
        self.ini_file = path + '/' + ini_file
        self.config_file = path + '/' + config_file
        self.debug = debug
        self.logger = logger
        self.logger.debug(f"init: bacpypes with {self.ini_file}")

        cmd_line_args_simulated = []
        if self.debug:
            cmd_line_args_simulated.append("--debug")
            cmd_line_args_simulated.append(__name__)
        cmd_line_args_simulated.append("--ini")
        cmd_line_args_simulated.append(self.ini_file)
        self.args = ConfigArgumentParser().parse_args(cmd_line_args_simulated)

        # load our reliable config file that has ports, names, types, etc.
        self.bacnet_config = json.load(open(self.config_file, 'r'))
        self.logger.debug(f"loaded {self.bacnet_config.get('name')}")
        
        # make a device object
        self.device = LocalDeviceObject(ini=self.args.ini) 

        # Overwrite the IP address in the .ini file to match what this machine
        # is configured for (to work, it must be a static IP on the same
        # subnet as the reliable / bacnet devices: 192.168.1.XXX/24
        self.logger.debug(f"init: this host config IP {self.args.ini.address}")

        # make an application to get callbacks from bacpypes
        self.app = BIPSimpleApplication(self.device, self.args.ini.address)
        enable_sleeping() # backpypes core threads: must do since django is multi threaded
        self.taskman = TaskManager()
Esempio n. 32
0
 def _startAppThread(self):
     """
     Starts the BACnet stack in its own thread so requests can be processed.
     As signal cannot be called in another thread than the main thread
     when calling startBacnetIPApp, we must pass None to both parameters
     """
     self._log.info("Starting app...")
     enable_sleeping(0.0005)
     self.t = Thread(
         target=startBacnetIPApp,
         kwargs={
             "sigterm": None,
             "sigusr1": None
         },
         daemon=True,
     )
     try:
         self.t.start()
         self._started = True
         self._log.info("BAC0 started")
     except OSError:
         stopBacnetIPApp()
         self.t.join()
         raise
Esempio n. 33
0
        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 = ReadPropertyAnyApplication(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 = ReadPropertyAnyConsoleCmd()

    _log.debug("running")

    # enable sleeping will allow handling of threads
    enable_sleeping()
    run()

except Exception as error:
    _log.exception("an error has occurred: %s", error)
finally:
    _log.debug("finally")
Esempio n. 34
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")
Esempio n. 35
0
def main():
    global args, this_device, this_application

    # build a parser, add some options
    parser = ConfigArgumentParser(description=__doc__)
    parser.add_argument(
        '--lan',
        type=str,
        default=bacpypes_mqtt.default_lan_name,
        help='lan name',
    )
    parser.add_argument(
        '--host',
        type=str,
        default=bacpypes_mqtt.default_broker_host,
        help='broker host address',
    )
    parser.add_argument(
        '--port',
        type=int,
        default=bacpypes_mqtt.default_broker_port,
        help='broker port',
    )
    parser.add_argument(
        '--keepalive',
        type=int,
        default=bacpypes_mqtt.default_broker_keepalive,
        help=
        "maximum period in seconds allowed between communications with the broker",
    )

    # 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(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

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

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

    # enable sleeping will help with threads
    enable_sleeping()

    # start up the client
    this_application.mse.startup()

    _log.debug("running")

    run()

    # shutdown the client
    this_application.mse.shutdown()

    _log.debug("fini")
Esempio n. 36
0
def main():
    global args, this_application

    # parse the command line arguments
    parser = ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    # add an argument for interval
    parser.add_argument(
        "addr1",
        type=str,
        help="address of first network",
    )

    # add an argument for interval
    parser.add_argument(
        "net1",
        type=int,
        help="network number of first network",
    )

    # add an argument for interval
    parser.add_argument(
        "net2",
        type=int,
        help="network number of second network",
    )

    # add an argument for how many virtual devices
    parser.add_argument(
        "--count",
        type=int,
        help="number of virtual devices",
        default=1,
    )

    # add an argument for how many virtual devices
    parser.add_argument(
        "--rpm",
        help="enable read property multiple",
        action="store_true",
    )

    # add an argument for including the property list
    parser.add_argument(
        "--plist",
        help="enable property list property",
        action="store_true",
    )

    # now parse the arguments
    args = parser.parse_args()

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

    local_address = Address(args.addr1)
    local_network = args.net1
    vlan_network = args.net2

    # create the VLAN router, bind it to the local network
    router = VLANRouter(local_address, local_network)

    # create a VLAN
    vlan = Network(broadcast_address=LocalBroadcast())

    # create a node for the router, address 1 on the VLAN
    router_addr = Address(1)
    router_node = Node(router_addr)
    vlan.add_node(router_node)

    # bind the router stack to the vlan network through this node
    router.nsap.bind(router_node, vlan_network, router_addr)

    # send network topology
    deferred(router.nse.i_am_router_to_network)

    # add the dynamic property list
    if args.plist:
        RandomAnalogValueObject.properties.append(CurrentPropertyList())

    # register it now that all its properties are defined
    register_object_type(RandomAnalogValueObject, vendor_id=999)

    # console is the first device
    device_number = 2
    device_instance = vlan_network * 100 + device_number
    _log.debug("    - console device_instance: %r", device_instance)

    # make a vlan device object
    vlan_device = LocalDeviceObject(
        objectName="VLAN Console Node %d" % (device_instance, ),
        objectIdentifier=("device", device_instance),
        maxApduLengthAccepted=1024,
        segmentationSupported="noSegmentation",
        vendorIdentifier=15,
    )
    _log.debug("    - vlan_device: %r", vlan_device)

    vlan_address = Address(device_number)
    _log.debug("    - vlan_address: %r", vlan_address)

    # make the console application, add it to the network
    this_application = VLANConsoleApplication(vlan_device, vlan_address)
    vlan.add_node(this_application.vlan_node)
    _log.debug("    - this_application: %r", this_application)

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

    # make a random value object
    ravo = RandomAnalogValueObject(
        objectIdentifier=("analogValue", 1),
        objectName="Random-1-%d" % (device_instance, ),
    )
    _log.debug("    - ravo: %r", ravo)

    # add it to the device
    this_application.add_object(ravo)

    # make some more devices
    for device_number in range(3, 3 + args.count - 1):
        # device identifier is assigned from the address
        device_instance = vlan_network * 100 + device_number
        _log.debug("    - device_instance: %r", device_instance)

        # make a vlan device object
        vlan_device = LocalDeviceObject(
            objectName="VLAN Node %d" % (device_instance, ),
            objectIdentifier=("device", device_instance),
            maxApduLengthAccepted=1024,
            segmentationSupported="noSegmentation",
            vendorIdentifier=15,
        )
        _log.debug("    - vlan_device: %r", vlan_device)

        vlan_address = Address(device_number)
        _log.debug("    - vlan_address: %r", vlan_address)

        # make the application, add it to the network
        vlan_app = VLANApplication(vlan_device, vlan_address)
        vlan.add_node(vlan_app.vlan_node)
        _log.debug("    - vlan_app: %r", vlan_app)

        # make a random value object
        ravo = RandomAnalogValueObject(
            objectIdentifier=("analogValue", 1),
            objectName="Random-1-%d" % (device_instance, ),
        )
        _log.debug("    - ravo: %r", ravo)

        # add it to the device
        vlan_app.add_object(ravo)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")