Exemplo n.º 1
0
    def __init__(self, camera, settings_file = None):
        # Gettings settings from settings file
        if not settings_file:
            try:
                self.settings = json.load (open (proto_base_path + "/src/communication/Video_Settings.json", "r"))
            except:
                self.debug.print_d ("Video_settings.json is not in json format!")
                sys.exit ()
        else:
            try:
                self.settings = json.load (open (settings_file, "r"))
            except:
                self.debug.print_d ("Specified file [{sfile}] doesn't exist or is not in json format!".format (sfile = settings_file))
                sys.exit ()

        context = zmq.Context ()

        self.debug = debugging ()

        # ZMQ Settings  
        self.confirmer = context.socket (zmq.PUB)
        #self.confirmer.setsockopt (zmq.SNDTIMEO, 5000)
        self.confirmer.bind ("tcp://" + self.settings["Reciever_IP"] + ":" + self.settings["Reciever_Port"])

        self.reciever = context.socket (zmq.SUB)
        self.reciever.setsockopt (zmq.SUBSCRIBE, "")
        #self.reciever.setsockopt (zmq.RCVTIMEO, 5000)
        self.reciever.connect ("tcp://" + self.settings["Server_IP"] + ":" + self.settings["Server_Port"])

        com = communicator ("Pinger_Base")

        self.pinger = passive_pinger (communicator=com)
        self.pinger.daemon = True
        self.pinger.start ()
Exemplo n.º 2
0
    def __init__(self, communicator, _ping_threshold=5, _ping_frequency=1):
        threading.Thread.__init__(self)

        self.com = communicator
        self.ping_frequency = _ping_frequency
        self.ping_threshold = _ping_threshold

        self.debug = debugging ()

        self.current_timestamp = None

        self.listening_to = communicator.get_listening_to ()
        self.listening_to = self.listening_to[-1] # This only works if the pinger is only listening to a single other module (the other pinger)
        
        self.CONNECTED = False
    def __init__(self, module_name, settings_file=None):
        self.debug = debugging ()

        # Gettings settings from settings file
        if not settings_file:
            try:
                self.settings = json.load (open (proto_base_path + "/src/communication/Communication_Settings.json", "r"))
            except:
                self.debug.print_d ("Communication_Settings.json is not in json format!")
                sys.exit ()
        else:
            try:
                self.settings = json.load (open (settings_file, "r"))
            except:
                self.debug.print_d ("Specified file [{sfile}] doesn't exist or is not in json format!".format (sfile = settings_file))
                sys.exit ()

        # Setting up publisher
        self.publisher = {}
        self.publisher["mname"] = module_name

        # TODO: Make a single context for all subscribers and one for publisher
        self.publisher["context"] = zmq.Context ()  
        self.publisher["socket"] = self.publisher["context"].socket (zmq.PUB)
        self.publisher["socket"].setsockopt (zmq.HWM, 15)
        self.publisher["socket"].bind ("tcp://" + self.settings[module_name]["IP"] + ":" + self.settings[module_name]["Port"])

        # Setting up subscribers
        self.listening_to = []
        for module in self.settings[self.publisher["mname"]]["Listening"]:
            self.listening_to.append (module)

        # TODO: Make a single context for all subscribers and one for publisher
        self.subscriber = {}
        for module in self.listening_to:
            self.subscriber[module] = {}
            self.subscriber[module]["context"] = zmq.Context ()

            self.subscriber[module]["socket"] = self.subscriber[module]["context"].socket (zmq.SUB)
            self.subscriber[module]["socket"].setsockopt (zmq.SUBSCRIBE, "")
            self.subscriber[module]["socket"].setsockopt (zmq.HWM, 15)
            self.subscriber[module]["socket"].connect ("tcp://" + self.settings[module]["IP"] + ":" + self.settings[module]["Port"])
            self.subscriber[module]["msg"] = None
                
        # Setting up refresher system
        self.refresher = self.updater (communicator=self, update_frequency=self.settings[module_name]["Update_Frequency"]) 
        self.refresher.daemon = True
        self.refresher.start()
Exemplo n.º 4
0
    def __init__(self, camera, settings_file = None):
        # Gettings settings from settings file
        if not settings_file:
            try:
                self.settings = json.load (open (proto_base_path + "/src/communication/Video_Settings.json", "r"))
            except:
                self.debug.print_d ("Video_Settings.json is not in json format!")
                sys.exit ()
        else:
            try:
                self.settings = json.load (open (settings_file, "r"))
            except:
                self.debug.print_d ("Specified file [{sfile}] doesn't exist or is not in json format!".format (sfile = settings_file))
                sys.exit ()

        context = zmq.Context ()

        self.debug = debugging ()

        # Camera Settings
        self.cap = cv2.VideoCapture (self.settings[camera]["Index"])
        self.cap.set (cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, self.settings[camera]["Height"])
        self.cap.set (cv2.cv.CV_CAP_PROP_FRAME_WIDTH, self.settings[camera]["Width"])
        self.cap.set (cv2.cv.CV_CAP_PROP_FPS, self.settings[camera]["FPS"])
        self.cap.set (cv2.cv.CV_CAP_PROP_FOURCC, cv2.cv.CV_FOURCC (str (self.settings[camera]["Codec"][0]), str (self.settings[camera]["Codec"][1]), str (self.settings[camera]["Codec"][2]), str (self.settings[camera]["Codec"][3])))

        # ZMQ Settings  
        self.server = context.socket (zmq.PUB)
        self.server.setsockopt (zmq.HWM, self.settings[camera]["HWM"])
        #self.server.setsockopt (zmq.SNDTIMEO, 5000)
        self.server.bind ("tcp://" + self.settings["Server_IP"] + ":" + self.settings["Server_Port"])

        self.confirmer = context.socket (zmq.SUB)
        self.confirmer.setsockopt (zmq.SUBSCRIBE, "")
        #self.confirmer.setsockopt (zmq.RCVTIMEO, 5000)
        self.confirmer.connect ("tcp://" + self.settings["Reciever_IP"] + ":" + self.settings["Reciever_Port"])

        com = communicator ("Pinger_Copter")

        self.pinger = passive_pinger (communicator=com)
        self.pinger.daemon = True
        self.pinger.start ()

        self.msg = "Ready!"