constants.py
Go to the documentation of this file.
00001 # MIT License
00002 #
00003 # Copyright (c) <2015> <Ikergune, Etxetar>
00004 #
00005 # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
00006 # (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
00007 # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
00008 # subject to the following conditions:
00009 #
00010 # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
00011 #
00012 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00013 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
00014 # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00015 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00016 
00017 import os
00018 import json
00019 import urllib2
00020 import netifaces
00021 
00022 
00023 def setConfiguration():
00024     try:
00025         current_path = os.path.dirname(os.path.abspath(__file__))
00026         json_path = current_path.replace("scripts/include", "config/config.json")
00027         data = json.load(open(json_path))
00028         return data[data["environment"]]
00029     except:
00030         return {}
00031 
00032 configured = False
00033 
00034 if not configured:
00035     configured = True
00036     configData = setConfiguration()
00037     INTERFACE = configData["interface"] if "interface" in configData else "public"
00038     LOGLEVEL = configData["log_level"] if "log_level" in configData else "INFO"
00039 
00040 
00041 SERVER_PORT = configData["server"]["port"]
00042 if("index" in configData["contextbroker"]):
00043     INDEX_CONTEXTBROKER = {
00044         "ADDRESS": configData["contextbroker"]["index"]["address"],
00045         "PORT": configData["contextbroker"]["index"]["port"],
00046     }
00047 
00048     DATA_CONTEXTBROKER = {
00049         "ADDRESS": configData["contextbroker"]["data"]["address"],
00050         "PORT": configData["contextbroker"]["data"]["port"],
00051     }
00052 else:
00053     INDEX_CONTEXTBROKER = {
00054         "ADDRESS": configData["contextbroker"]["address"],
00055         "PORT": configData["contextbroker"]["port"],
00056     }
00057 
00058     DATA_CONTEXTBROKER = {
00059         "ADDRESS": configData["contextbroker"]["address"],
00060         "PORT": configData["contextbroker"]["port"],
00061     }
00062 
00063 # THROTTLING = "PT1S"
00064 THROTTLING = configData["contextbroker"]["subscription"]["throttling"]
00065 SUBSCRIPTION_LENGTH = configData["contextbroker"]["subscription"]["subscription_length"]
00066 SUBSCRIPTION_REFRESH_DELAY = configData["contextbroker"]["subscription"]["subscription_refresh_delay"]
00067 
00068 SEPARATOR_CHAR = "%27"
00069 
00070 # ROS CONFIG
00071 NODE_NAME = "firos"
00072 DEFAULT_CONTEXT_TYPE = "ROBOT"
00073 DEFAULT_QUEUE_SIZE = 10
00074 
00075 if INTERFACE == "public":
00076     IP = urllib2.urlopen('http://ip.42.pl/raw').read()
00077 else:
00078     netifaces.ifaddresses(INTERFACE)
00079     IP = netifaces.ifaddresses(INTERFACE)[2][0]['addr']
00080 
00081 if "map_server_port" in configData:
00082     MAP_SERVER_PORT = configData["map_server_port"]
00083 else:
00084     MAP_SERVER_PORT = None
00085 
00086 if "rosbridge_port" in configData:
00087     ROSBRIDGE_PORT = configData["rosbridge_port"]
00088 else:
00089     ROSBRIDGE_PORT = 9090


firos
Author(s): IƱigo Gonzalez, igonzalez@ikergune.com
autogenerated on Thu Jun 6 2019 17:51:04