def main():
    global args, this_application

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

    # add an option to override the interval time
    parser.add_argument(
        '--interval',
        type=float,
        help="amount of time between intervals",
        default=INTERVAL,
    )

    # 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 = ReadPointListApplication(this_device, args.ini.address)

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 2
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")
Esempio n. 3
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")
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")
Esempio n. 5
0
def main():
    global args, this_application

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

    # add an argument for seconds per dog
    parser.add_argument("daddr", help="destination address")
    parser.add_argument("objid", help="object identifier")
    parser.add_argument("propid", help="property identifier")

    # list of values to write
    parser.add_argument("values",
                        metavar="N",
                        nargs="+",
                        help="values to write")

    # add an argument for seconds between writes
    parser.add_argument("--delay",
                        type=float,
                        help="delay between writes in seconds",
                        default=5.0)

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

    # convert the parameters
    args.daddr = Address(args.daddr)
    args.objid = ObjectIdentifier(args.objid).value
    args.propid = PropertyIdentifier(args.propid).value

    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 dog, task scheduling is in milliseconds
    dog = PrairieDog(args.delay * 1000)
    if _debug:
        _log.debug("    - dog: %r", dog)

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 6
0
def main():
    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',
    )

    # parse the args
    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 = ReadObjectListApplication(this_device, args.ini.address)

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

    # translate the address
    device_addr = Address(args.device_addr)

    # 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")
Esempio n. 7
0
    def setUp(self):
        global server, server_thread, this_application
        # parse the command line arguments
        parser = ConfigArgumentParser(description=__doc__)
        # add an option for the server host
        parser.add_argument("--host",
                            type=str,
                            help="server host",
                            default=HOST)
        # add an option for the server port
        parser.add_argument("--port",
                            type=int,
                            help="server port",
                            default=PORT)

        # Adding arguments to the argument parser
        config_path = "./bacnet_client.ini"
        args = parser.parse_args(['--ini', config_path])

        # Make a HTTP Server
        server = ThreadedTCPServer((args.host, args.port), HTTPRequestHandler)

        # Start a thread with the server -- that thread will then start a thread for each request
        server_thread = threading.Thread(target=server.serve_forever)

        # exit the server thread when the main thread terminates
        server_thread.daemon = True  # Exit when program terminates
        server_thread.start()
        print("HTTP Server Thread is Alive : ", server_thread.is_alive())

        # Make a device object
        this_device = LocalDeviceObject(ini=args.ini)

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

        # Start the BACnet application in a child thread
        # Child threads do not receive signals SIGTERM or SIGUSR1
        bac_thread = threading.Thread(target=run)
        bac_thread.daemon = True  # Exit when program terminates
        bac_thread.start()
        print("BACnet client Thread is Alive : ", bac_thread.is_alive())

        return
def main():
    global args, this_application

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

    # add an option to override the interval time
    parser.add_argument(
        '--interval',
        type=float,
        help="amount of time between intervals",
        default=INTERVAL,
    )

    # 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=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(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")
Esempio n. 9
0
def main():
    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)

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

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

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

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

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

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

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

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 10
0
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(
        "objid",
        help="object identifier",
        )
    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.objid
    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")
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. 12
0
def main():
    global this_application, device_address, object_identifier, property_list

    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)
    parser.add_argument(
        "address",
        help="device address",
    )
    parser.add_argument(
        "objtype",
        help="object types, e.g., analogInput",
    )
    parser.add_argument(
        "objinstance",
        type=int,
        help="object instance",
    )
    args = parser.parse_args()

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

    # interpret the address
    device_address = Address(args.address)
    if _debug: _log.debug("    - device_address: %r", device_address)

    # build an identifier
    object_identifier = (args.objtype, args.objinstance)
    if _debug: _log.debug("    - object_identifier: %r", object_identifier)

    # get the object class
    object_class = get_object_class(args.objtype)
    if _debug: _log.debug("    - object_class: %r", object_class)

    # make a queue of the properties
    property_list = deque(prop.identifier for prop in object_class.properties)
    if _debug: _log.debug("    - property_list: %r", property_list)

    # 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 = ReadPropertyApplication(this_device, args.ini.address)

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

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 13
0
def main():
    # parse the command line arguments
    arg_parser = ConfigArgumentParser(description=__doc__)

    arg_parser.add_argument("device_id",
                            type=int,
                            help="Device ID of the target device")

    arg_parser.add_argument(
        "--address",
        help=
        "Address of target device, may be needed to help route initial request to device."
    )

    arg_parser.add_argument("--out-file",
                            type=argparse.FileType('wb'),
                            help="Optional output file for configuration",
                            default=sys.stdout)

    arg_parser.add_argument(
        "--max_range_report",
        nargs='?',
        type=float,
        help=
        'Affects how very large numbers are reported in the "Unit Details" column of the output. '
        'Does not affect driver behavior.',
        default=1.0e+20)

    args = arg_parser.parse_args()

    _log.debug("initialization")
    _log.debug("    - args: %r", args)
    ips = getIPs()
    print "found local ip as ", ips
    device_address = ips[0] + "/24"
    # make a device object
    this_device = LocalDeviceObject(
        objectName="BEMOSS",
        objectIdentifier=int(599),
        maxApduLengthAccepted=int(1024),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a simple application
    this_application = SynchronousApplication(this_device, device_address)

    _log.debug("starting build")

    result = get_iam(this_application, args.device_id, args.address)

    target_address = result.pduSource

    _log.debug('pduSource = ' + repr(result.pduSource))
    _log.debug('iAmDeviceIdentifier = ' + str(result.iAmDeviceIdentifier))
    _log.debug('maxAPDULengthAccepted = ' + str(result.maxAPDULengthAccepted))
    _log.debug('segmentationSupported = ' + str(result.segmentationSupported))
    _log.debug('vendorID = ' + str(result.vendorID))

    device_id = result.iAmDeviceIdentifier[1]

    try:
        device_name = read_prop(this_application, target_address, "device",
                                device_id, "objectName")
        _log.debug('device_name = ' + str(device_name))
    except TypeError:
        _log.debug('device missing objectName')

    try:
        device_description = read_prop(this_application, target_address,
                                       "device", device_id, "description")
        _log.debug('description = ' + str(device_description))
    except TypeError:
        _log.debug('device missing description')

    config_writer = DictWriter(
        args.out_file, ('Reference Point Name', 'Volttron Point Name', 'Units',
                        'Unit Details', 'BACnet Object Type', 'Property',
                        'Writable', 'Index', 'Write Priority', 'Notes'))

    config_writer.writeheader()

    try:
        objectCount = read_prop(this_application,
                                target_address,
                                "device",
                                device_id,
                                "objectList",
                                index=0)
        list_property = "objectList"
    except TypeError:
        objectCount = read_prop(this_application,
                                target_address,
                                "device",
                                device_id,
                                "structuredObjectList",
                                index=0)
        list_property = "structuredObjectList"

    _log.debug('objectCount = ' + str(objectCount))

    for object_index in xrange(1, objectCount + 1):
        _log.debug('object_device_index = ' + repr(object_index))

        bac_object = read_prop(this_application,
                               target_address,
                               "device",
                               device_id,
                               list_property,
                               index=object_index)

        obj_type, index = bac_object
        print object_index
        print
        print
        process_object(this_application, target_address, obj_type, index,
                       args.max_range_report, config_writer)
Esempio n. 14
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. 15
0
    result = this_application.make_request(request)
    if not isinstance(result, ReadPropertyACK):
        result.debug_contents(file=sys.stderr)
        raise TypeError, "Error reading property"

    # find the datatype
    datatype = get_datatype(obj_type, prop_id)

    return result.propertyValue.cast_out(datatype)


try:
    # parse the command line arguments
    arg_parser = ConfigArgumentParser(description=__doc__)

    arg_parser.add_argument("address", help="Address of target device")
    arg_parser.add_argument("out_file",
                            nargs='?',
                            type=argparse.FileType('wb'),
                            help="Optional output file for configuration",
                            default=sys.stdout)

    arg_parser.add_argument(
        "--max_range_report",
        nargs='?',
        type=float,
        help=
        'Affects how very large numbers are reported in the "Unit Details" column of the output. '
        'Does not affect sMap driver behavior.',
        default=1.0e+20)
Esempio n. 16
0
def main():
    global args, this_device, this_application, snapshot

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

    # input file for exiting configuration
    parser.add_argument(
        "infile",
        default="-",
        help="input file",
    )

    # output file for discovered configuration
    parser.add_argument(
        "outfile",
        nargs='?',
        default='-unspecified-',
        help="output file",
    )

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

    # make a snapshot 'database'
    snapshot = Snapshot()

    # read in an existing snapshot
    if args.infile != '-':
        snapshot.read_file(args.infile)

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

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")

    # write out the snapshot, outfile defaults to infile if not specified
    if args.outfile == '-unspecified-':
        args.outfile = args.infile
    if args.outfile != '-':
        snapshot.write_file(args.outfile)
        sys.stdout.write("%d woof!\n" % (self.dog_number, ))


#
#   __main__
#

try:
    # parse the command line arguments
    parser = ConfigArgumentParser(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)
Esempio n. 18
0

class ThreadedTCPServer(ThreadingMixIn, TCPServer):
    pass


#
#   __main__
#

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

    # add an option for the server host
    parser.add_argument("--host", type=str, help="server host", default=HOST)
    # add an option for the server port
    parser.add_argument("--port", type=int, help="server port", default=PORT)
    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
Esempio n. 19
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")
class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
    pass


#
#   __main__
#

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

    # add an option to override the port in the config file
    parser.add_argument(
        '--port',
        help="override the port in the config file to PORT",
        default="9000",
    )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")

    # 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),
    )
Esempio n. 21
0
def main():
    global args, this_device, this_application

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

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

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

    # add an argument for interval
    parser.add_argument('addr2', type=str,
        help='address on the VLAN network',
        )

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

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

    local_network = args.net1
    local_address = Address(args.ini.address)
    if _debug: _log.debug("    - local_network, local_address: %r, %r", local_network, local_address)

    vlan_network = args.net2
    vlan_address = Address(args.addr2)
    if _debug: _log.debug("    - vlan_network, vlan_address: %r, %r", vlan_network, vlan_address)

    # 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_node = Node(Address(1))
    vlan.add_node(router_node)

    # bind the router stack to the vlan network through this node
    router.nsap.bind(router_node, vlan_network)
    
    # send network topology
    deferred(router.nse.i_am_router_to_network)

    # make a vlan device object
    this_device = \
        LocalDeviceObject(
            objectName=args.ini.objectname,
            objectIdentifier=("device", int(args.ini.objectidentifier)),
            maxApduLengthAccepted=1024,
            segmentationSupported='noSegmentation',
            vendorIdentifier=15,
            )
    _log.debug("    - this_device: %r", this_device)

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

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

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 22
0
            # give it to the application
            this_application.request(request)

        except Exception, e:
            WhoIsIAmConsoleCmd._exception("exception: %r", e)

#
#   __main__
#

try:
    # parse the command line arguments
    arg_parser = ConfigArgumentParser(description=__doc__)

    arg_parser.add_argument("--address", 
                            help="Target only device(s) at <address> for request" )

    arg_parser.add_argument("--range", type=int, nargs=2, metavar=('LOW', 'HIGH'),
                            help="Lower and upper limit on device ID in results" )

    arg_parser.add_argument("--timeout", type=int, metavar=('SECONDS'),
                            help="Time, in seconds, to wait for responses. Default: %(default)s",
                            default = 5)

    args = arg_parser.parse_args()

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

    # make a device object
    this_device = LocalDeviceObject(
Esempio n. 23
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. 24
0
def main():
    # parse the command line arguments
    arg_parser = ConfigArgumentParser(description=__doc__)
        
    arg_parser.add_argument("device_id", type=int,
                            help="Device ID of the target device" )
    
    arg_parser.add_argument("--address",
                            help="Address of target device, may be needed to help route initial request to device." )
    
    arg_parser.add_argument("--registry-out-file", type=argparse.FileType('wb'),
                            help="Output registry to CSV file",
                            default=sys.stdout )

    arg_parser.add_argument("--driver-out-file", type=argparse.FileType('wb'),
                            help="Output driver configuration to JSON file.",
                            default=sys.stdout)
    
    arg_parser.add_argument("--max-range-report", nargs='?', type=float,
                            help='Affects how very large numbers are reported in the "Unit Details" column of the output. ' 
                            'Does not affect driver behavior.',
                            default=1.0e+20 )
    
    args = arg_parser.parse_args()

    _log.debug("initialization")
    _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 = SynchronousApplication(this_device, args.ini.address)

    _log.debug("starting build")
    
    result = get_iam(this_application, args.device_id, args.address)
    
#     request = WhoIsRequest()
#     request.pduDestination = target_address
#     result = this_application.make_request(request, expect_confirmation = False)
    
#     if not isinstance(result, IAmRequest):
#         result.debug_contents()
#         raise TypeError("Error making WhoIs request, try running again.")
        
    
#     device_type, device_instance = result.iAmDeviceIdentifier
#     if device_type != 'device':
#         raise DecodingError("invalid object type")

    target_address = result.pduSource
    device_id = result.iAmDeviceIdentifier[1]
    
    _log.debug('pduSource = ' + repr(result.pduSource))
    _log.debug('iAmDeviceIdentifier = ' + str(result.iAmDeviceIdentifier))
    _log.debug('maxAPDULengthAccepted = ' + str(result.maxAPDULengthAccepted))
    _log.debug('segmentationSupported = ' + str(result.segmentationSupported))
    _log.debug('vendorID = ' + str(result.vendorID))

    config_file_name = basename(args.registry_out_file.name)

    config = {
        "driver_config":{"device_address":str(target_address),
                         "device_id": device_id},
        "driver_type":"bacnet",
        "registry_config":"config://registry_configs/{}".format(config_file_name)
    }

    json.dump(config, args.driver_out_file,indent=4)
    
    try:
        device_name = read_prop(this_application, target_address, "device", device_id, "objectName")
        _log.debug('device_name = ' + str(device_name))
    except TypeError:
        _log.debug('device missing objectName')
    
    try:
        device_description = read_prop(this_application, target_address, "device", device_id, "description")
        _log.debug('description = ' + str(device_description))
    except TypeError:
        _log.debug('device missing description')
    
    
    
    config_writer = DictWriter(args.registry_out_file,
                               ('Reference Point Name',
                                'Volttron Point Name',
                                'Units',
                                'Unit Details',
                                'BACnet Object Type',
                                'Property',
                                'Writable',
                                'Index',
                                'Write Priority',
                                'Notes'))
    
    config_writer.writeheader()
    
    
    try:
        objectCount = read_prop(this_application, target_address, "device", device_id, "objectList", index=0)
        list_property = "objectList"
    except TypeError:
        objectCount = read_prop(this_application, target_address, "device", device_id, "structuredObjectList", index=0)
        list_property = "structuredObjectList"
    
    _log.debug('objectCount = ' + str(objectCount))
    
    for object_index in xrange(1,objectCount+1):
        _log.debug('object_device_index = ' + repr(object_index))
        
        bac_object = read_prop(this_application, 
                                target_address, 
                                "device", 
                                device_id, 
                                list_property,
                                index=object_index)
        
        obj_type, index = bac_object

        try:
            process_object(this_application, target_address, obj_type, index, args.max_range_report, config_writer)
        except:
            _log.debug("Unexpected error processing object: {} {}".format(obj_type, index))
            _log.debug(traceback.format_exc())
Esempio n. 25
0
def main():
    global test_av, test_bv, test_application

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

    # analog value task and thread
    parser.add_argument(
        "--avtask",
        type=float,
        help="analog value recurring task",
    )
    parser.add_argument(
        "--avthread",
        type=float,
        help="analog value thread",
    )

    # analog value task and thread
    parser.add_argument(
        "--bvtask",
        type=float,
        help="binary value recurring task",
    )
    parser.add_argument(
        "--bvthread",
        type=float,
        help="binary value thread",
    )

    # provide a different spin value
    parser.add_argument(
        "--spin",
        type=float,
        help="spin time",
        default=1.0,
    )

    # 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 = SubscribeCOVApplication(this_device, args.ini.address)

    # make an analog value object
    test_av = WritableAnalogValueObject(
        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)

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

        # enable sleeping will help with threads
        enable_sleeping()

    # analog value task
    if args.avtask:
        test_av_task = TestAnalogValueTask(args.avtask)
        test_av_task.install_task()

    # analog value thread
    if args.avthread:
        test_av_thread = TestAnalogValueThread(args.avthread)
        deferred(test_av_thread.start)

    # binary value task
    if args.bvtask:
        test_bv_task = TestBinaryValueTask(args.bvtask)
        test_bv_task.install_task()

    # binary value thread
    if args.bvthread:
        test_bv_thread = TestBinaryValueThread(args.bvthread)
        deferred(test_bv_thread.start)

    _log.debug("running")

    run(args.spin)

    _log.debug("fini")
Esempio n. 26
0
def main():
    global test_ai, test_application

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

    # analog value task and thread
    parser.add_argument(
        "--aitask",
        type=float,
        help="analog input recurring task",
    )
    parser.add_argument(
        "--aithread",
        type=float,
        help="analog input thread",
    )

    # analog value task and thread
    parser.add_argument(
        "--bvtask",
        type=float,
        help="binary value recurring task",
    )
    parser.add_argument(
        "--bvthread",
        type=float,
        help="binary value thread",
    )

    # provide a different spin value
    parser.add_argument(
        "--spin",
        type=float,
        help="spin time",
        default=1.0,
    )

    # 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 = SubscribeCOVApplication(this_device, args.ini.address)

    # make an analog value object
    test_ai = AnalogInputObject(
        objectIdentifier=("analogInput", 1),
        objectName="ai",
        presentValue=0.0,
        covIncrement=0.5,
        eventDetectionEnable=True,
        eventEnable=[1, 1, 1],
        ackedTransitions=[1, 1, 1],
        notifyType=1,
        reliability=1,
        outOfService=False,
        eventState=0,
        statusFlags=[0, 0, 0, 0],
        units=19,
    )
    _log.debug("    - test_ai: %r", test_ai)

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

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

        # enable sleeping will help with threads
        enable_sleeping()

    # analog input task
    if args.aitask:
        test_ai_task = TestAnalogInputTask(args.aitask)
        test_ai_task.install_task()

    # analog input thread
    if args.aithread:
        test_ai_thread = TestAnalogInputThread(args.aithread)
        deferred(test_ai_thread.start)

    _log.debug("running")

    run(args.spin)

    _log.debug("fini")
Esempio n. 27
0
def main():
    global this_application, device_address, object_identifier, property_list

    # parse the command line arguments
    parser = ConfigArgumentParser(description=__doc__)
    parser.add_argument(
        "address",
        help="device address",
    )
    parser.add_argument(
        "objtype",
        help="object types, e.g., analogInput",
    )
    parser.add_argument(
        "objinstance",
        type=int,
        help="object instance",
    )
    args = parser.parse_args()

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

    # interpret the address
    device_address = Address(args.address)
    if _debug: _log.debug("    - device_address: %r", device_address)

    # build an identifier
    object_identifier = (args.objtype, args.objinstance)
    if _debug: _log.debug("    - object_identifier: %r", object_identifier)

    # get the object class
    object_class = get_object_class(args.objtype)
    if _debug: _log.debug("    - object_class: %r", object_class)

    # make a queue of the properties
    property_list = deque(prop.identifier for prop in object_class.properties)
    if _debug: _log.debug("    - property_list: %r", property_list)

    # 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

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

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 28
0
            self.response_values.append(value)

        # fire off another request
        deferred(self.next_request)

#
#   __main__
#

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

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

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

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

    # make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
Esempio n. 29
0
def main():
    global args, this_application

    # parse the command line arguments
    parser = ConfigArgumentParser(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,
        )
    parser.add_argument(
        "--idle-timeout", nargs='?', type=int,
        help="idle connection timeout",
        default=IDLE_TIMEOUT,
        )
    parser.add_argument(
        "--hello", action="store_true",
        default=False,
        help="send a hello message to a client when it connects",
        )
    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 = BIPSimpleApplication(this_device, args.ini.address)

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

    # create a client
    write_property_client = WritePropertyClient()
    if _debug: _log.debug("    - write_property_client: %r", write_property_client)

    # bind everything together
    bind(write_property_client, this_director)
    bind(WritePropertyASE(), this_director)

    _log.debug("running")

    run()

    _log.debug("fini")
Esempio n. 30
0
        json.dump(result, self.wfile)

class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
    pass

#
#   __main__
#

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

    # add an option to override the port in the config file
    parser.add_argument('--port', type=int,
        help="override the port in the config file to PORT",
        default=9000,
        )
    args = parser.parse_args()

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

    # make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=int(args.ini.objectidentifier),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
        )
Esempio n. 31
0
def main():
    # parse the command line arguments
    arg_parser = ConfigArgumentParser(description=__doc__)
        
    arg_parser.add_argument("device_id", type=int,
                            help="Device ID of the target device" )
    
    arg_parser.add_argument("--address",
                            help="Address of target device, may be needed to help route initial request to device." )
    
    arg_parser.add_argument("--registry-out-file", type=argparse.FileType('wb'),
                            help="Output registry to CSV file",
                            default=sys.stdout )

    arg_parser.add_argument("--driver-out-file", type=argparse.FileType('wb'),
                            help="Output driver configuration to JSON file.",
                            default=sys.stdout)
    
    arg_parser.add_argument("--max-range-report", nargs='?', type=float,
                            help='Affects how very large numbers are reported in the "Unit Details" column of the output. ' 
                            'Does not affect driver behavior.',
                            default=1.0e+20 )
    
    args = arg_parser.parse_args()

    _log.debug("initialization")
    _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 = SynchronousApplication(this_device, args.ini.address)

    _log.debug("starting build")
    
    result = get_iam(this_application, args.device_id, args.address)
    
#     request = WhoIsRequest()
#     request.pduDestination = target_address
#     result = this_application.make_request(request, expect_confirmation = False)
    
#     if not isinstance(result, IAmRequest):
#         result.debug_contents()
#         raise TypeError("Error making WhoIs request, try running again.")
        
    
#     device_type, device_instance = result.iAmDeviceIdentifier
#     if device_type != 'device':
#         raise DecodingError("invalid object type")

    target_address = result.pduSource
    device_id = result.iAmDeviceIdentifier[1]
    
    _log.debug('pduSource = ' + repr(result.pduSource))
    _log.debug('iAmDeviceIdentifier = ' + str(result.iAmDeviceIdentifier))
    _log.debug('maxAPDULengthAccepted = ' + str(result.maxAPDULengthAccepted))
    _log.debug('segmentationSupported = ' + str(result.segmentationSupported))
    _log.debug('vendorID = ' + str(result.vendorID))

    config_file_name = basename(args.registry_out_file.name)

    config = {
        "driver_config":{"device_address":str(target_address),
                         "device_id": device_id},
        "driver_type":"bacnet",
        "registry_config":"config://registry_configs/{}".format(config_file_name)
    }

    json.dump(config, args.driver_out_file,indent=4)
    
    try:
        device_name = read_prop(this_application, target_address, "device", device_id, "objectName")
        _log.debug('device_name = ' + str(device_name))
    except TypeError:
        _log.debug('device missing objectName')
    
    try:
        device_description = read_prop(this_application, target_address, "device", device_id, "description")
        _log.debug('description = ' + str(device_description))
    except TypeError:
        _log.debug('device missing description')
    
    
    
    config_writer = DictWriter(args.registry_out_file,
                               ('Reference Point Name',
                                'Volttron Point Name',
                                'Units',
                                'Unit Details',
                                'BACnet Object Type',
                                'Property',
                                'Writable',
                                'Index',
                                'Write Priority',
                                'Notes'))
    
    config_writer.writeheader()
    
    
    try:
        objectCount = read_prop(this_application, target_address, "device", device_id, "objectList", index=0)
        list_property = "objectList"
    except TypeError:
        objectCount = read_prop(this_application, target_address, "device", device_id, "structuredObjectList", index=0)
        list_property = "structuredObjectList"
    
    _log.debug('objectCount = ' + str(objectCount))
    
    for object_index in xrange(1,objectCount+1):
        _log.debug('object_device_index = ' + repr(object_index))
        
        bac_object = read_prop(this_application, 
                                target_address, 
                                "device", 
                                device_id, 
                                list_property,
                                index=object_index)
        
        obj_type, index = bac_object

        try:
            process_object(this_application, target_address, obj_type, index, args.max_range_report, config_writer)
        except:
            _log.debug("Unexpected error processing object: {} {}".format(obj_type, index))
            _log.debug(traceback.format_exc())
Esempio n. 32
0
    def process_task(self):
        if _debug: PrairieDog._debug("process_task")

        sys.stdout.write("%d woof!\n" % (self.dog_number,))

#
#   __main__
#

try:
    # parse the command line arguments
    parser = ConfigArgumentParser(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")
    
    result = this_application.make_request(request)
    if not isinstance(result, ReadPropertyACK):
        result.debug_contents(file=sys.stderr)
        raise TypeError("Error reading property")
    
    # find the datatype
    datatype = get_datatype(obj_type, prop_id)
    
    return result.propertyValue.cast_out(datatype)

try:
    # parse the command line arguments
    arg_parser = ConfigArgumentParser(description=__doc__)
    
    arg_parser.add_argument("address",
                            help="Address of target device" )
    arg_parser.add_argument("out_file", nargs='?', type=argparse.FileType('wb'),
                            help="Optional output file for configuration",
                            default=sys.stdout )
    
    arg_parser.add_argument("--max_range_report", nargs='?', type=float,
                            help='Affects how very large numbers are reported in the "Unit Details" column of the output. ' 
                            'Does not affect sMap driver behavior.',
                            default=1.0e+20 )
    
    args = arg_parser.parse_args()

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

    # make a device object
Esempio n. 34
0
from bacpypes.constructeddata import Array
from bacpypes.app import BIPSimpleApplication
from bacpypes.object import get_object_class, get_datatype
from bacpypes.local.device import LocalDeviceObject


# Initialization
# some debugging
_debug = True
_log = ModuleLogger(globals())

# settings
# parse the command line arguments
parser = ConfigArgumentParser(description=__doc__)
# add an option for the server host
parser.add_argument("--host", type=str, help="server host")
# add an option for the server port
parser.add_argument("--port", type=int, help="server port")
DEFAULT_CONFIG_PATH = r"./weather_config.ini"

# reference a simple application
this_application = None
server = None

# TODO
# Cache control heder?

# favorite icon
favicon = zlib.decompress(
    b'x\x9c\xab\x983\n\x90\x00\x00\x9b,\xa5\x01'
    )