1
0
Fork 0

refactor for multiple devices

This commit is contained in:
Kevin Matz 2019-11-17 12:36:11 -05:00
parent fcc44e6f49
commit d69583c60b
2 changed files with 42 additions and 12 deletions

View File

@ -42,16 +42,28 @@ ch = logging.StreamHandler() # create console handler and
ch.setLevel(logging.INFO) # set console log level to INFO
logger.addHandler(ch) # add console log handler
# TODO: refactor this to support multiple net#s
# empty server dictionary
servers = {}
# open config file
config = configparser.ConfigParser(allow_no_value=True)
config.read('server.cfg') # open config file
servers = {} # init an empty dictionary
server = config['hog4'] # section of config file
net = server.getint("net", 1) # default to net #1
logger.info("Adding Hog device at net# " + str(net))
# osc clients are added to the dictionary with the net # as the key
servers[net] = udp_client.SimpleUDPClient(server.get("ip", "10.0.0.100"),
server.getint("port", 7001))
config.read('server.cfg')
# set up each hog device
for name in config.get('network', 'hogs').split(','):
try:
# move to config section
server = config[name]
# read settings
ip = server.get("ip", "10.0.0.100")
port = server.getint("port", 7001)
net = server.getint("net", 1)
# osc clients are added to the dictionary with the net # as the key
logger.info("Adding Hog device at net# " + str(net))
servers[net] = udp_client.SimpleUDPClient(ip, port)
except KeyError as e:
print('Error configuring button', b, e)
continue
oscMacro = OscCommentMacroListener(servers)
walker = ParseTreeWalker()

View File

@ -1,4 +1,22 @@
[hog4]
ip: 10.0.0.100
[network]
hogs=hog4_235,hedgehog_235,server_pc, server_rackhog
[hog4_235]
ip: 10.235.1.53
port: 7001
net: 1
net: 53
[hedgehog_235]
ip: 10.235.1.63
port: 7001
net: 63
[server_pc]
ip: 10.235.1.12
port: 7001
net: 12
[server_rackhog]
ip: 10.235.1.22
port: 7001
net: 22