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

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

    # 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")
Пример #2
0
def main():
    global args

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

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

    # make a controller for to_do_item requests
    controller = SomethingController()
    if _debug: _log.debug("    - controller: %r", controller)

    for i in range(3):
        # make a list bound to the contoller
        to_do_list = ToDoList(controller, active_limit=2)
        if _debug: _log.debug("    - to_do_list: %r", to_do_list)

        for j in range(5):
            to_do_list.append(SomethingToDo(i, j))

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #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 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")
Пример #4
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")
Пример #5
0
def broadcast():

    try:
        device_list = list()
        localaddress = list()
        ips = getIPs()
        print "found local ip as ", ips
        for ip in ips:
            str(ip)
            localaddress = ip + "/24"

        # make a device object
        this_device = LocalDeviceObject(
            objectName="BEMOSS",
            objectIdentifier=
            599,  #change if there exists a bacnet device with same identifier
            maxApduLengthAccepted=1024,
            segmentationSupported="segmentedBoth",
            vendorIdentifier=99,
        )

        # Device application
        this_application = Application(this_device, localaddress)

        request = WhoIsRequest()
        request.pduDestination = GlobalBroadcast()

        def time_out():
            time.sleep(5)
            stop()

        thread = threading.Thread(target=time_out)
        thread.start()

        this_application.request(request)
        this_application.found_address = list()
        this_application.found_deviceidentifier = list()
        run()
        #time.sleep(10)
        this_application.release = True
        this_application.update = False
        address, deviceidentifier = this_application.updator()

        todelete = list()
        for i in range(0, len(deviceidentifier)):
            if deviceidentifier[i] == 0:
                todelete.append(i)
        for i in todelete:
            del address[i], deviceidentifier[
                i]  #Deleting identified bacnet router
        Remote_address = list(set(address))  #Removing repeatition
        Identifier = list(set(deviceidentifier))  #Removing repeatition

        print "destination address list is ", Remote_address
        print "object instance of that address", Identifier

        return this_application, Remote_address, Identifier
    except Exception, e:
        _log.exception("an error has occurred: %s", e)
        return None
Пример #6
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)

    # 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")
Пример #7
0
def main():
    global this_device
    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 = WhoIsIAmApplication(this_device, args.ini.address)

    # 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")
Пример #8
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")
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")
Пример #10
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(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

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

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #11
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")
Пример #12
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "--host", type=str,
        help="address of host (default {!r})".format(SERVER_HOST),
        default=SERVER_HOST,
        )
    parser.add_argument(
        "--port", type=int,
        help="server port (default {!r})".format(SERVER_PORT),
        default=SERVER_PORT,
        )
    args = parser.parse_args()

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

    # local IO functions
    bind(SimpleServer(), ModbusServer(port=args.port))

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #13
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for seconds per dog
    parser.add_argument('seconds', metavar='N', type=int, nargs='+',
          help='number of seconds for each dog',
          )

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

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

    # make some dogs
    for i, sec in enumerate(args.seconds):
        dog = PrairieDog(i, sec * 1000)
        if _debug: _log.debug("    - dog: %r", dog)

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #14
0
 def make_request(self, request, expected_device_id=None):
     self.expected_device_id = expected_device_id
     self._request = request
     
     self.request(request)
     run()
     return self.apdu
Пример #15
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(usage=__doc__)
    args = parser.parse_args()

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

    address = Address("192.168.0.1/24")
    if _debug: _log.debug("    - local_address: %r", address)

    # make a network
    network = IPNetwork()

    console = ConsoleClient()
    middle_man = MiddleMan()

    fauxmux = FauxMux(address, network)
    bind(console, middle_man, fauxmux)

    # add some more debugging nodes
    for i in range(2, 4):
        debug_address = "192.168.0.{}/24".format(i)

        debug_debug = Debug(debug_address)
        debug_fauxmux = FauxMux(Address(debug_address), network)

        bind(debug_debug, debug_fauxmux)

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #16
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")
Пример #17
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 = WhoIsIAmApplication(this_device, args.ini.address)

    _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("")
Пример #18
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(ini=args.ini)
    if _debug: _log.debug("    - this_device: %r", this_device)

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

    # 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")
Пример #19
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()
Пример #20
0
def main():
    """
    Main function, called when run as an application.
    """
    global server_address

    # 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
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host",
        nargs='?',
        help="address of host (default %r)" % (SERVER_HOST, ),
        default=SERVER_HOST,
    )
    parser.add_argument(
        "port",
        nargs='?',
        type=int,
        help="server port (default %r)" % (SERVER_PORT, ),
        default=SERVER_PORT,
    )
    args = parser.parse_args()

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

    # extract the server address and port
    host = args.host
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # build the stack
    this_console = ConsoleClient()
    if _debug: _log.debug("    - this_console: %r", this_console)

    this_middle_man = MiddleMan()
    if _debug: _log.debug("    - this_middle_man: %r", this_middle_man)

    this_director = TCPClientDirector()
    if _debug: _log.debug("    - this_director: %r", this_director)

    bind(this_console, this_middle_man, this_director)
    bind(MiddleManASE(), this_director)

    # create a task manager for scheduled functions
    task_manager = TaskManager()
    if _debug: _log.debug("    - task_manager: %r", task_manager)

    # don't wait to connect
    this_director.connect(server_address)

    if _debug: _log.debug("running")

    run()
Пример #21
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)

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

    # make a subscription context
    context = SubscriptionContext(Address("10.0.1.31"), ('analogValue', 1), False, 60)

    # send the subscription when the stack is ready
    deferred(this_application.send_subscription, context)

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #22
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(usage=__doc__)
    args = parser.parse_args()

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

    # make a network
    network = IPNetwork()

    console = ConsoleClient()
    middle_man = MiddleMan()

    bip = BIPSimple()
    annexj = AnnexJCodec()
    mux = FauxMultiplexer("192.168.0.1/24", network)
    bind(console, middle_man, bip, annexj, mux)

    # add some more debugging nodes
    for i in range(2, 4):
        debug_address = "192.168.0.{}/24".format(i)

        debug_debug = Debug(debug_address)
        debug_bip = BIPSimple()
        debug_annexj = AnnexJCodec()
        debug_mux = FauxMultiplexer(debug_address, network)

        bind(debug_debug, debug_bip, debug_annexj, debug_mux)

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #23
0
    def make_request(self, request, expected_device_id=None):
        self.expected_device_id = expected_device_id
        self._request = request

        self.request(request)
        run()
        return self.apdu
Пример #24
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for seconds per dog
    parser.add_argument(
        'seconds',
        metavar='N',
        type=int,
        nargs='+',
        help='number of seconds for each dog',
    )

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

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

    # make some dogs
    for i, sec in enumerate(args.seconds):
        dog = PrairieDog(i, sec * 1000)
        if _debug: _log.debug("    - dog: %r", dog)

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #25
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")
Пример #26
0
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")
Пример #27
0
def main():
    global this_application
    ConsoleLogHandler('bacpypes.consolelogging')

    # 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")
Пример #28
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")
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")
Пример #30
0
def main():
    """
    Main function, called when run as an application.
    """
    global server_address

    # 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
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host", nargs='?',
        help="address of host (default %r)" % (SERVER_HOST,),
        default=SERVER_HOST,
        )
    parser.add_argument(
        "port", nargs='?', type=int,
        help="server port (default %r)" % (SERVER_PORT,),
        default=SERVER_PORT,
        )
    args = parser.parse_args()

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

    # extract the server address and port
    host = args.host
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # build the stack
    this_console = ConsoleClient()
    if _debug: _log.debug("    - this_console: %r", this_console)

    this_middle_man = MiddleMan()
    if _debug: _log.debug("    - this_middle_man: %r", this_middle_man)

    this_director = TCPClientDirector()
    if _debug: _log.debug("    - this_director: %r", this_director)

    bind(this_console, this_middle_man, this_director)
    bind(MiddleManASE(), this_director)

    # create a task manager for scheduled functions
    task_manager = TaskManager()
    if _debug: _log.debug("    - task_manager: %r", task_manager)

    # don't wait to connect
    this_director.connect(server_address)

    if _debug: _log.debug("running")

    run()
Пример #31
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")
Пример #32
0
def main():
    global test_av, test_bv, test_application

    # make a parser
    parser = ConfigArgumentParser(description=__doc__)

    # 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 sample application
    test_application = SampleApplication(this_device, args.ini.address)

    # 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", this_device.objectList)

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

    # binary value task
    do_something_task = DoSomething(INTERVAL)
    do_something_task.install_task()

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #33
0
def run_application(objectidentifier: int):
    global this_device
    global this_application

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

    # add an argument for interval
    parser.add_argument(
        'device_id',
        type=int,
        help='device identifier',
    )

    # add an argument for interval
    parser.add_argument(
        'device_addr',
        type=str,
        help='device address',
    )

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

    import netifaces
    from ipaddress import IPv4Network

    wifi_ip = netifaces.ifaddresses('en0')[netifaces.AF_INET][0]
    #Addres of this device which will perform the querying.
    address = wifi_ip['addr'] + "/" + str(
        IPv4Network("0.0.0.0/" + wifi_ip['netmask']).prefixlen) + ":47809"

    # make a simple application
    this_application = ReadAllObjectPropertiesApplication(this_device, address)

    # build a device object identifier
    device_id = ('device', objectidentifier)

    # Address of device being queried.
    device_addr = Address(
        wifi_ip['addr'] + "/" +
        str(IPv4Network("0.0.0.0/" + wifi_ip['netmask']).prefixlen) + ":47808")

    # kick off the process after the core is up and running
    deferred(this_application.read_object_list, device_id, device_addr)

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #34
0
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")
Пример #35
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
    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")
Пример #36
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")
Пример #37
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)

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

    # make a commandable analog value object, add to the device
    avo1 = AnalogValueCmdObject(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 = BinaryOutputCmdObject(
        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 = DateValueCmdObject(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")
Пример #38
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")
Пример #39
0
def main():
    if _debug: main._debug("initialization")

    try:
        # parse the command line arguments
        args = ConfigArgumentParser(description=__doc__).parse_args()

        if _debug: main._debug("initialization")
        if _debug: main._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: main._debug("    - ravo1: %r", ravo1)

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

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

        if _debug: main._debug("running")

        run()

    except Exception as error:
        main._exception("an error has occurred: %s", error)
    finally:
        if _debug: main._debug("finally")
Пример #40
0
    def make_request(self, request, expected_device_id=None):
        self.expected_device_id = expected_device_id
        self._request = request
        
        _log.debug("SAM:11")
        _log.debug(expected_device_id)
        self.request(request)
        request.debug_contents()

        _log.debug("SAM:12")
        run()
        return self.apdu
Пример #41
0
def main():
    """
    Main function, called when run as an application.
    """
    global server_address

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host", nargs='?',
        help="address of host",
        default=default_server_host,
        )
    parser.add_argument(
        "port", nargs='?', type=int,
        help="server port",
        default=default_server_port,
        )
    args = parser.parse_args()

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

    # extract the server address and port
    host = args.host
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # build the stack
    this_console = ConsoleClient()
    if _debug: _log.debug("    - this_console: %r", this_console)

    this_middle_man = MiddleMan()
    if _debug: _log.debug("    - this_middle_man: %r", this_middle_man)

    this_director = TCPClientDirector()
    if _debug: _log.debug("    - this_director: %r", this_director)

    bind(this_console, this_middle_man, this_director)
    bind(MiddleManASE(), this_director)

    # create a task manager for scheduled functions
    task_manager = TaskManager()
    if _debug: _log.debug("    - task_manager: %r", task_manager)

    # don't wait to connect
    this_director.connect(server_address)

    if _debug: _log.debug("running")

    run()
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")
Пример #43
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for interval
    parser.add_argument('localaddr', type=str,
          help='local address of the BBMD',
          )

    # add an argument for interval
    parser.add_argument('bdtentry', type=str, nargs='*',
          help='list of addresses of peers',
          )

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

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

    local_address = Address(args.localaddr)
    if _debug: _log.debug("    - local_address: %r", local_address)

    # create a null client that will accept, but do nothing with upstream
    # packets from the BBMD
    null_client = NullClient()
    if _debug: _log.debug("    - null_client: %r", null_client)

    # create a BBMD, bound to the Annex J server on a UDP multiplexer
    bbmd = BIPBBMD(local_address)
    annexj = AnnexJCodec()
    multiplexer = UDPMultiplexer(local_address)

    # bind the layers together
    bind(null_client, bbmd, annexj, multiplexer.annexJ)

    # loop through the rest of the addresses
    for bdtentry in args.bdtentry:
        if _debug: _log.debug("    - bdtentry: %r", bdtentry)

        bdt_address = Address(bdtentry)
        bbmd.add_peer(bdt_address)

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

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #44
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")
Пример #45
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
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host", nargs='?',
        help="listening address of server or 'any' (default %r)" % (SERVER_HOST,),
        default=SERVER_HOST,
        )
    parser.add_argument(
        "port", nargs='?', type=int,
        help="server port (default %r)" % (SERVER_PORT,),
        default=SERVER_PORT,
        )
    args = parser.parse_args()

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

    # extract the server address and port
    host = args.host
    if host == "any":
        host = ''
    server_address = (host, args.port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # create a director listening to the address
    this_director = TCPServerDirector(server_address)
    if _debug: _log.debug("    - this_director: %r", this_director)

    # create an echo
    echo_master = EchoMaster()
    if _debug: _log.debug("    - echo_master: %r", echo_master)

    # bind everything together
    bind(echo_master, this_director)
    bind(MiddleManASE(), this_director)

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #46
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")
Пример #47
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")
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")
Пример #50
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")
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")
Пример #52
0
def main():
    if _debug: main._debug("initialization")
    global this_application

    try:
        # parse the command line arguments
        args = ConfigArgumentParser(description=__doc__).parse_args()

        if _debug: main._debug("initialization")
        if _debug: main._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 = ReadPropertyApplication(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()

        main._debug("running")

        run()

    except Exception as error:
        main._exception("an error has occurred: %s", error)
    finally:
        main._debug("finally")
Пример #53
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "--host", nargs='?',
        help="listening address of server",
        default=default_server_host,
        )
    parser.add_argument(
        "--port", nargs='?', type=int,
        help="server port",
        default=default_server_port,
        )
    args = parser.parse_args()

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

    # extract the server address and port
    host = args.host
    if host == "any":
        host = ''
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # create a director listening to the address
    this_director = TCPServerDirector(server_address)
    if _debug: _log.debug("    - this_director: %r", this_director)

    # create an echo
    echo_master = EchoMaster()
    if _debug: _log.debug("    - echo_master: %r", echo_master)

    # bind everything together
    bind(echo_master, this_director)
    bind(MiddleManASE(), this_director)

    _log.debug("running")

    run()
Пример #54
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")
def main():
    if _debug: main._debug("initialization")
    global this_application

    try:
        # parse the command line arguments
        args = ConfigArgumentParser(description=__doc__).parse_args()

        if _debug: main._debug("initialization")
        if _debug: main._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
        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 = ReadPropertyApplication(this_device, args.ini.address)
        this_console = ReadWritePropertyConsoleCmd()

        main._debug("running")

        run()

    except Exception, e:
        main._exception("an error has occurred: %s", e)
Пример #56
0
def main():
    try:
        # parse the command line arguments
        parser = ArgumentParser(description=__doc__)

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

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

        # local IO functions
        bind(ConsoleClient(), ModbusClient())

        _log.debug("running")

        run()

    except Exception as err:
        _log.exception("an error has occurred: %s" % (err,))
    finally:
        _log.debug("finally")
Пример #57
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # 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('addr2', type=str,
          help='address of second network',
          )

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

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

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

    # create the router
    router = IP2IPRouter(Address(args.addr1), args.net1, Address(args.addr2), args.net2)
    if _debug: _log.debug("    - router: %r", router)

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #58
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # connection timeout paramters
    parser.add_argument(
        "--connect-timeout", nargs='?', type=int,
        help="idle connection timeout",
        default=CONNECT_TIMEOUT,
        )
    parser.add_argument(
        "--idle-timeout", nargs='?', type=int,
        help="idle connection timeout",
        default=IDLE_TIMEOUT,
        )

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

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

    # make a controller
    this_controller = ModbusClientController(
        connect_timeout=args.connect_timeout,
        idle_timeout=args.idle_timeout,
        )
    if _debug: _log.debug("    - this_controller: %r", this_controller)

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

    _log.debug("running")

    run()

    _log.debug("fini")
Пример #59
0
def main():
    global this_console

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

    _log.debug("running")

    run()
Пример #60
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # listener arguments
    parser.add_argument(
        "--host", type=str,
        help="address of host (default {!r})".format(SERVER_HOST),
        default=SERVER_HOST,
        )
    parser.add_argument(
        "--port", type=int,
        help="server port (default {!r})".format(SERVER_PORT),
        default=SERVER_PORT,
        )

    # connection timeout arguments
    parser.add_argument(
        "--idle-timeout", nargs='?', type=int,
        help="idle connection timeout",
        default=IDLE_TIMEOUT,
        )

    args = parser.parse_args()

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

    # local IO functions
    bind(SimpleServer(), ModbusServer(port=args.port, idle_timeout=args.idle_timeout))

    _log.debug("running")

    run()

    _log.debug("fini")