def _video_display_thread(): ''' Thread ''' while running: try: if enable_video: kill_video() if save_to_disk: f = get_file("video.mp4") steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "tcpserversrc", "host=0.0.0.0", "port=" + video_port, "!", "tee", "name=t", "!", "h264parse", "!", "omxh264dec", "!", "autovideosink", "text-overlay=false", "sync=false", "t.", "!", "queue", "!", "video/x-h264,width=" + width + ",height=" + height + ",framerate=" + fps + "/1,profile=constrained-baseline", "!", "h264parse", "disable-passthrough=true", "!", "queue", "!", "mp4mux", "!", "filesink", "location=" + f ]) else: steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "tcpserversrc", "host=0.0.0.0", "port=" + video_port, "!", "h264parse", "!", "omxh264dec", "!", "autovideosink", "text-overlay=false", "sync=false" ]) else: interrupt.wait(1) interrupt.clear() except: pass
def _audio_speaker_thread(): ''' Thread ''' while running: try: if enable_audio: if save_to_disk: f = get_file("audio.wav") steelsquid_utils.execute_system_command_blind([ "nice", "-n", "8", "gst-launch-1.0", "-e", "udpsrc", "port=" + audio_port, "caps=application/x-rtp", "!", "rtpjitterbuffer", "!", "rtppcmudepay", "!", "mulawdec", "!", "tee", "name=myt", "!", "queue", "!", "alsasink", "sync=false", "myt.", "!", "queue", "!", "audiorate", "!", "audioconvert", "!", "audioresample", "!", "wavenc", "!", "filesink", "location=" + f ]) time.sleep(1) else: kill_audio() steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "udpsrc", "port=" + audio_port, "caps=application/x-rtp", "!", "rtpjitterbuffer", "!", "rtppcmudepay", "!", "mulawdec", "!", "alsasink", "sync=false" ]) #steelsquid_utils.execute_system_command_blind(["gst-launch-1.0", "-e", "udpsrc", "port="+audio_port, "!", "vorbisdec", "!", "audioconvert", "!", "alsasink", "sync=false"]) else: interrupt.wait(1) interrupt.clear() except: pass
def shutdown(): ''' Shutdown and power off the PIIO board ''' steelsquid_pi.po16_gpio_set(1, True) steelsquid_utils.execute_system_command_blind(['shutdown', '-h', 'now'], wait_for_finish=False)
def kill_video(): ''' Kill gstreamer video ''' if is_camera_mic: steelsquid_utils.execute_system_command_blind( ["pkill", "-f", "gst-launch-1.0 -e v4l2src"]) elif save_to_disk: steelsquid_utils.execute_system_command_blind([ "pkill", "-SIGINT", "-f", "gst-launch-1.0 -e tcpserversrc host=0.0.0.0 port=" + video_port ]) steelsquid_utils.execute_system_command_blind([ "pkill", "-SIGINT", "-f", "gst-launch-1.0 -e udpsrc port=" + video_port ]) else: steelsquid_utils.execute_system_command_blind([ "pkill", "-SIGINT", "-f", "gst-launch-1.0 -e tcpserversrc host=0.0.0.0 port=" + video_port ]) steelsquid_utils.execute_system_command_blind([ "pkill", "-SIGINT", "-f", "gst-launch-1.0 -e udpsrc port=" + video_port ]) interrupt.set()
def _audio_mic_thread(): ''' Thread ''' while running: try: if enable_audio: kill_audio() if low_bandwidth_mode: interrupt.wait(1) interrupt.clear() else: steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "alsasrc", "latency-time=1", "device=sysdefault:CARD=1", "!", "audioconvert", "!", "audio/x-raw,channels=1,depth=16,width=16,rate=22000", "!", "rtpL16pay", "!", "udpsink", "host=" + audio_ip, "port=" + audio_port ]) #steelsquid_utils.execute_system_command_blind(["gst-launch-1.0", "-e", "alsasrc", "latency-time=1", "device=sysdefault:CARD=1", "!", "mulawenc", "!", "rtppcmupay", "!", "udpsink", "host="+audio_ip, "port="+audio_port]) else: interrupt.wait(1) interrupt.clear() except: pass
def kill_hud(): ''' Kill gstreamer hud ''' if not is_camera_mic: steelsquid_utils.execute_system_command_blind( ["pkill", "-SIGINT", "-f", "gst-launch-1.0 -e ximagesrc"]) interrupt.set()
def _play(sound, times, sleep1): #sleep = False #if LOOP.last_speek == None: # sleep = True #LOOP.last_speek = time.time() #IO.UNITS.speeker(True) #if sleep: # time.sleep(5) time.sleep(sleep1) for i in range(times): steelsquid_utils.execute_system_command_blind(["aplay", sound])
def enable(argument=None): ''' When this module is enabled what needs to be done (execute: steelsquid module XXX on) Maybe you need create some files or enable other stuff. argument: Send data to the enable or disable method in the module Usually a string to tell the start/stop something (execute: steelsquid module XXX on theArgument) ''' # Clear any saved settings for this module steelsquid_kiss_global.clear_modules_settings("kiss_irrbloss") # Change hostname steelsquid_utils.set_hostname("irrbloss") # Enable transeiver as client steelsquid_kiss_global.radio_hmtrlrs(True) # Enable TCP-radio as client steelsquid_kiss_global.radio_hmtrlrs(True) # Enable tcp radio as client and then listen for command from the host steelsquid_kiss_global.radio_tcp(False, steelsquid_utils.network_ip_wan()) # Change GPIO for transceiver steelsquid_utils.set_parameter("hmtrlrs_config_gpio", str(STATIC.gpio_hmtrlrs_config)) steelsquid_utils.set_parameter("hmtrlrs_reset_gpio", str(STATIC.gpio_hmtrlrs_reset)) # Enable camera steelsquid_utils.execute_system_command_blind(["steelsquid", "camera-on"], wait_for_finish=True) # Max volume steelsquid_utils.execute_system_command_blind(["amixer", "set", "PCM", "unmute"], wait_for_finish=True) steelsquid_utils.execute_system_command_blind(["amixer", "set", "PCM", "100%"], wait_for_finish=True) steelsquid_utils.execute_system_command_blind(["alsactl", "store"], wait_for_finish=True)
def enable(argument=None): ''' When this module is enabled what needs to be done (execute: steelsquid module XXX on) Maybe you need create some files or enable other stuff. argument: Send data to the enable or disable method in the module Usually a string to tell the start/stop something (execute: steelsquid module XXX on theArgument) ''' # Clear any saved settings for this module steelsquid_kiss_global.clear_modules_settings("kiss_irrbloss") # Change hostname steelsquid_utils.set_hostname("irrbloss") # Enable transeiver as client steelsquid_kiss_global.radio_hmtrlrs(True) # Enable TCP-radio as client steelsquid_kiss_global.radio_hmtrlrs(True) # Enable tcp radio as client and then listen for command from the host steelsquid_kiss_global.radio_tcp(False, steelsquid_utils.network_ip_wan()) # Change GPIO for transceiver steelsquid_utils.set_parameter("hmtrlrs_config_gpio", str(STATIC.gpio_hmtrlrs_config)) steelsquid_utils.set_parameter("hmtrlrs_reset_gpio", str(STATIC.gpio_hmtrlrs_reset)) # Enable camera steelsquid_utils.execute_system_command_blind(["steelsquid", "camera-on"], wait_for_finish=True) # Max volume steelsquid_utils.execute_system_command_blind( ["amixer", "set", "PCM", "unmute"], wait_for_finish=True) steelsquid_utils.execute_system_command_blind( ["amixer", "set", "PCM", "100%"], wait_for_finish=True) steelsquid_utils.execute_system_command_blind(["alsactl", "store"], wait_for_finish=True)
def play(play_this, use_playlist=0): ''' Play file ''' global play_thread try: play_thread.stop() except: pass steelsquid_utils.execute_system_command_blind( ['sudo', 'steelsquid', 'omxplayer-kill']) play_thread = PlayThread(str(play_this), use_playlist) play_thread.start()
def previous(self): ''' Stop the thread ''' self.use_playlist = 1 try: self.child.send("q") except: pass try: self.join(0.5) except: pass steelsquid_utils.execute_system_command_blind( ['sudo', 'steelsquid', 'omxplayer-kill'])
def bluetooth_agent(): ''' Start the bluetooth_agent (enable pairing) ''' steelsquid_utils.execute_system_command_blind(["hciconfig", "hci0", "piscan"], wait_for_finish=False) while True: answer = steelsquid_utils.execute_system_command(["hciconfig", "-a"]) bluetooth = None for line in answer: if "Name: " in line: line = line.replace("Name: '","") line = line.replace("'","") bluetooth = line break if bluetooth == None: steelsquid_utils.shout("No local bluetooth device found!") else: steelsquid_utils.shout("Start bluetooth: " + bluetooth) steelsquid_kiss_global._execute_all_modules("SYSTEM", "on_bluetooth", (True,)) execute_task_event("network") try: proc=Popen("bluetoothctl", stdout=PIPE, stdin=PIPE, stderr=PIPE) proc.stdin.write('power on\n') proc.stdin.flush() time.sleep(1) proc.stdin.write('discoverable on\n') proc.stdin.flush() time.sleep(1) proc.stdin.write('pairable on\n') proc.stdin.flush() time.sleep(1) proc.stdin.write('agent on\n') proc.stdin.flush() time.sleep(1) proc.stdin.write('default-agent\n') proc.stdin.flush() while True: proc_read = proc.stdout.readline() if proc_read: if "Request PIN code" in proc_read: proc.stdin.write(steelsquid_utils.get_parameter("bluetooth_pin")+"\n") proc.stdin.flush() except: steelsquid_utils.shout("Error on start bluetoothctl", is_error=True) steelsquid_kiss_global._execute_all_modules("SYSTEM", "on_bluetooth", (False,)) execute_task_event("network") time.sleep(20)
def _audio_mic_thread(): ''' Thread ''' while running: try: if enable_audio: kill_audio() steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "alsasrc", "latency-time=1", "device=sysdefault:CARD=1", "!", "mulawenc", "!", "rtppcmupay", "!", "udpsink", "host=" + audio_ip, "port=" + audio_port ]) #steelsquid_utils.execute_system_command_blind(["gst-launch-1.0", "-e", "alsasrc", "latency-time=1", "device=sysdefault:CARD=1", "!", "audioconvert", "!", "audioresample", "!", "vorbisenc", "!", "udpsink", "host="+audio_ip, "port="+audio_port]) else: interrupt.wait(1) interrupt.clear() except: pass
def _video_cam_thread(): ''' Thread ''' while running: try: if enable_video: kill_video() steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "v4l2src", "device=/dev/video0", "!", "video/x-raw,width=" + width + ",height=" + height + ",framerate=" + fps + "/1", "!", "clockoverlay", "xpad=0", "ypad=0", "!", "omxh264enc", "target-bitrate=" + bitrate, "control-rate=3", "!", "tcpclientsink", "host=" + video_ip, "port=" + video_port ]) else: interrupt.wait(1) interrupt.clear() except: pass
def _hud_thread(): ''' Thread ''' while running: try: if enable_hud: kill_hud() f = get_file("hud.avi") #steelsquid_utils.execute_system_command_blind(["nice", "-n", "10", "avconv", "-f", "x11grab", "-r", "2", "-s", width+"x"+height, "-i", ":0.0", "-vcodec", "libx264", "-threads", "1", f]) steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "ximagesrc", "display-name=:0", "use-damage=0", "!", "video/x-raw,framerate=2/1", "!", "videoconvert", "!", "omxh264enc", "!", "video/x-h264,profile=high", "!", "avimux", "!", "filesink", "location=" + f ]) else: interrupt.wait(1) interrupt.clear() except: pass
def on_start(): ''' This will execute when system starts Do not execute long running stuff here, do it in on_loop... ''' # Startup message steelsquid_utils.shout("Steelsquid Irrbloss start") if SETTINGS.control == 1: co = "Radio" elif SETTINGS.control == 2: co = "WIFI" elif SETTINGS.control == 3: co = "3G/4G" else: co = "Not saved" steelsquid_utils.shout("Control: " + co + "\n" + "Control IP: " + SETTINGS.control_ip + "\n" + "Video stream IP: " + SETTINGS.video_ip + "\n" + "Audio stream IP: " + SETTINGS.audio_ip + "\n" + "Resolution: " + SETTINGS.width + "x" + SETTINGS.height + "\n" + "FPS: " + SETTINGS.fps + "\n") # Set the on OK and ERROR callback methods...they just flash some LED steelsquid_utils.on_ok_callback_method = UTILS.on_ok steelsquid_utils.on_err_callback_method = UTILS.on_err # Enable network by default try: steelsquid_nm.set_network_status(True) except: pass # Enable and disable networkcards UTILS.set_net_status(SETTINGS.control) # Reset some GPIO IO.OUTPUT.sum_flash() IO.UNITS.headlight(False) IO.UNITS.highbeam(False) IO.UNITS.siren(False) IO.UNITS.speeker(True) IO.OUTPUT.mood(0) # Way ??? steelsquid_pi.gpio_set(26, True) # Max volume steelsquid_utils.execute_system_command_blind( ["amixer", "set", "PCM", "unmute"], wait_for_finish=True) steelsquid_utils.execute_system_command_blind( ["amixer", "set", "PCM", "100%"], wait_for_finish=True) steelsquid_utils.execute_system_command_blind(["alsactl", "store"], wait_for_finish=True) # Center camera IO.UNITS.camera(0, STATIC.servo_position_tilt_start, False) # Setup gstreamer steelsquid_gstreamer.setup_camera_mic(SETTINGS.video_ip, 6607, SETTINGS.audio_ip, 6608, SETTINGS.width, SETTINGS.height, SETTINGS.fps, SETTINGS.bitrate, SETTINGS.tcp_video, SETTINGS.low_light)
def _audio_speaker_thread(): ''' Thread ''' while running: try: if enable_audio: if save_to_disk: f = get_file("audio.wav") steelsquid_utils.execute_system_command_blind([ "nice", "-n", "8", "gst-launch-1.0", "-e", "udpsrc", "port=" + audio_port, "!", "application/x-rtp,media=audio,clock-rate=22000,width=16,height=16,encoding-name=L16,encoding-params=1,channels=1,channel-positions=1,payload=96", "!", "rtpjitterbuffer", "!", "rtpL16depay", "!", "audioconvert", "!", "tee", "name=myt", "!", "queue", "!", "alsasink", "sync=false", "myt.", "!", "queue", "!", "audiorate", "!", "audioconvert", "!", "audioresample", "!", "wavenc", "!", "filesink", "location=" + f ]) #steelsquid_utils.execute_system_command_blind(["nice", "-n", "8", "gst-launch-1.0", "-e", "udpsrc", "port="+audio_port, "caps=application/x-rtp", "!", "rtpjitterbuffer", "!", "rtppcmudepay", "!", "mulawdec", "!", "tee", "name=myt", "!", "queue", "!", "alsasink", "sync=false", "myt.", "!", "queue", "!", "audiorate", "!", "audioconvert", "!", "audioresample", "!", "wavenc", "!", "filesink", "location="+f]) time.sleep(1) else: kill_audio() steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "udpsrc", "port=" + audio_port, "!", "application/x-rtp,media=audio,clock-rate=22000,width=16,height=16,encoding-name=L16,encoding-params=1,channels=1,channel-positions=1,payload=96", "!", "rtpjitterbuffer", "!", "rtpL16depay", "!", "audioconvert", "!", "alsasink", "sync=false" ]) #steelsquid_utils.execute_system_command_blind(["gst-launch-1.0", "-e", "udpsrc", "port="+audio_port, "caps=application/x-rtp", "!", "rtpjitterbuffer", "!", "rtppcmudepay", "!", "mulawdec", "!", "alsasink", "sync=false"]) else: interrupt.wait(1) interrupt.clear() except: pass
def kill_audio(): ''' Kill gstreamer audio ''' if is_camera_mic: steelsquid_utils.execute_system_command_blind( ["pkill", "-f", "gst-launch-1.0 -e alsasrc"]) elif save_to_disk: steelsquid_utils.execute_system_command_blind([ "pkill", "-SIGINT", "-f", "gst-launch-1.0 -e udpsrc port=" + audio_port ]) else: steelsquid_utils.execute_system_command_blind([ "pkill", "-SIGINT", "-f", "gst-launch-1.0 -e udpsrc port=" + audio_port ]) interrupt.set()
def on_start(): ''' This will execute when system starts Do not execute long running stuff here, do it in on_loop... ''' # Startup message steelsquid_utils.shout("Steelsquid Irrbloss start") if SETTINGS.control==1: co = "Radio" elif SETTINGS.control==2: co = "WIFI" elif SETTINGS.control==3: co = "3G/4G" else: co = "Not saved" steelsquid_utils.shout("Control: " + co + "\n" + "Control IP: " + SETTINGS.control_ip + "\n" + "Video stream IP: " + SETTINGS.video_ip + "\n" + "Audio stream IP: " + SETTINGS.audio_ip + "\n" + "Resolution: " + SETTINGS.width+"x"+SETTINGS.height+ "\n" + "FPS: " + SETTINGS.fps + "\n") # Set the on OK and ERROR callback methods...they just flash some LED steelsquid_utils.on_ok_callback_method=UTILS.on_ok steelsquid_utils.on_err_callback_method=UTILS.on_err # Enable network by default try: steelsquid_nm.set_network_status(True) except: pass # Enable and disable networkcards UTILS.set_net_status(SETTINGS.control) # Reset some GPIO IO.OUTPUT.sum_flash() IO.UNITS.headlight(False) IO.UNITS.highbeam(False) IO.UNITS.siren(False) IO.UNITS.speeker(True) IO.OUTPUT.mood(0) # Way ??? steelsquid_pi.gpio_set(26, True) # Max volume steelsquid_utils.execute_system_command_blind(["amixer", "set", "PCM", "unmute"], wait_for_finish=True) steelsquid_utils.execute_system_command_blind(["amixer", "set", "PCM", "100%"], wait_for_finish=True) steelsquid_utils.execute_system_command_blind(["alsactl", "store"], wait_for_finish=True) # Center camera IO.UNITS.camera(0, STATIC.servo_position_tilt_start, False) # Setup gstreamer steelsquid_gstreamer.setup_camera_mic(SETTINGS.video_ip, 6607, SETTINGS.audio_ip, 6608, SETTINGS.width, SETTINGS.height, SETTINGS.fps, SETTINGS.bitrate, SETTINGS.tcp_video, SETTINGS.low_light)
def main(): ''' The main function ''' try: if len(sys.argv) < 2: print_help() else: command = sys.argv[1] # Start the system if command == "start": # Set keyboard to use steelsquid_utils.execute_system_command_blind(["/usr/bin/termfix", steelsquid_utils.get_parameter("keyboard")], wait_for_finish=True) # Redirect sys.stdout to shout sys.stdout = Logger() # Create the task event dir steelsquid_utils.make_dirs(system_event_dir) # Print welcome message steelsquid_utils.shout("Steelsquid Kiss OS "+steelsquid_utils.steelsquid_kiss_os_version()[1], to_lcd=False, wait_for_finish=False) # Use locking on the I2C bus if steelsquid_utils.get_flag("i2c_lock"): steelsquid_i2c.enable_locking(True) else: steelsquid_i2c.enable_locking(False) # Disable the monitor if steelsquid_utils.get_flag("disable_monitor"): steelsquid_utils.execute_system_command_blind(["/opt/vc/bin/tvservice", "-o"], wait_for_finish=False) # Listen for shutdown on GPIO if steelsquid_utils.has_parameter("power_gpio"): gpio = steelsquid_utils.get_parameter("power_gpio") steelsquid_utils.shout("Listen for clean shutdown on GPIO " + gpio) steelsquid_pi.gpio_click(gpio, poweroff, steelsquid_pi.PULL_DOWN) # Load all modules pkgpath = os.path.dirname(modules.__file__) for name in pkgutil.iter_modules([pkgpath]): if steelsquid_utils.get_flag("module_"+name[1]): steelsquid_utils.shout("Load module: " +name[1], debug=True) n = name[1] steelsquid_kiss_global.loaded_modules[n]=import_module('modules.'+n) # Enable the download manager if steelsquid_utils.get_flag("download"): if steelsquid_utils.get_parameter("download_dir") == "": steelsquid_utils.set_parameter("download_dir", "/root") steelsquid_utils.execute_system_command_blind(['steelsquid', 'download-on'], wait_for_finish=False) # Enable NRF24L01+ as server if steelsquid_utils.get_flag("nrf24_server"): steelsquid_utils.shout("Enable NRF24L01+ server") steelsquid_nrf24.server() thread.start_new_thread(nrf24_server_thread, ()) # Enable NRF24L01+ as client elif steelsquid_utils.get_flag("nrf24_client"): steelsquid_utils.shout("Enable NRF24L01+ client") steelsquid_nrf24.client() # Enable NRF24L01+ as master if steelsquid_utils.get_flag("nrf24_master"): steelsquid_utils.shout("Enable NRF24L01+ master") steelsquid_nrf24.master(nrf24_callback) # Enable NRF24L01+ as slave elif steelsquid_utils.get_flag("nrf24_slave"): steelsquid_utils.shout("Enable NRF24L01+ slave") steelsquid_nrf24.slave() thread.start_new_thread(nrf24_slave_thread, ()) # Enable HM-TRLR-S as server if steelsquid_utils.get_flag("hmtrlrs_server"): config_gpio = int(steelsquid_utils.get_parameter("hmtrlrs_config_gpio", "25")) reset_gpio = int(steelsquid_utils.get_parameter("hmtrlrs_reset_gpio", "23")) steelsquid_utils.shout("Enable HM-TRLR-S server") steelsquid_hmtrlrs.setup(config_gpio=config_gpio, reset_gpio=reset_gpio) thread.start_new_thread(hmtrlrs_server_thread, ()) # Enable HM-TRLR-S as client elif steelsquid_utils.get_flag("hmtrlrs_client"): config_gpio = int(steelsquid_utils.get_parameter("hmtrlrs_config_gpio", "25")) reset_gpio = int(steelsquid_utils.get_parameter("hmtrlrs_reset_gpio", "23")) steelsquid_utils.shout("Enable HM-TRLR-S client") steelsquid_hmtrlrs.setup(config_gpio=config_gpio, reset_gpio=reset_gpio) thread.start_new_thread(hmtrlrs_client_thread, ()) # Start the modules for obj in steelsquid_kiss_global.loaded_modules.itervalues(): thread.start_new_thread(import_file_dyn, (obj,)) # Enable the webserver if steelsquid_utils.get_flag("web"): port = None if steelsquid_utils.has_parameter("web_port"): port = steelsquid_utils.get_parameter("web_port") steelsquid_kiss_global.http_server = steelsquid_kiss_http_server.SteelsquidKissHttpServer(port, steelsquid_utils.STEELSQUID_FOLDER+"/web/", steelsquid_utils.get_flag("web_authentication"), steelsquid_utils.get_flag("web_local"), steelsquid_utils.get_flag("web_authentication"), steelsquid_utils.get_flag("web_https")) for obj in steelsquid_kiss_global.loaded_modules.itervalues(): if hasattr(obj, "WEB"): steelsquid_kiss_global.http_server.external_objects.append(getattr(obj, "WEB")) steelsquid_kiss_global.http_server.start_server() # Enable the socket server as server if steelsquid_utils.get_flag("socket_server"): steelsquid_kiss_global.socket_connection = steelsquid_kiss_socket_connection.SteelsquidKissSocketConnection(True) for obj in steelsquid_kiss_global.loaded_modules.itervalues(): if hasattr(obj, "SOCKET"): steelsquid_kiss_global.socket_connection.external_objects.append(getattr(obj, "SOCKET")) steelsquid_kiss_global.socket_connection.start() # Enable the socket server as client elif steelsquid_utils.has_parameter("socket_client"): steelsquid_kiss_global.socket_connection = steelsquid_kiss_socket_connection.SteelsquidKissSocketConnection(False, steelsquid_utils.get_parameter("socket_client")) for obj in steelsquid_kiss_global.loaded_modules.itervalues(): if hasattr(obj, "SOCKET"): steelsquid_kiss_global.socket_connection.external_objects.append(getattr(obj, "SOCKET")) steelsquid_kiss_global.socket_connection.start() # Enable the bluetooth if steelsquid_utils.get_flag("bluetooth_pairing"): if not steelsquid_utils.has_parameter("bluetooth_pin"): steelsquid_utils.set_parameter("bluetooth_pin", "1234") thread.start_new_thread(bluetooth_agent, ()) fd = inotifyx.init() inotifyx.add_watch(fd, system_event_dir, inotifyx.IN_CLOSE_WRITE) # Execute a network event so the IP is shown execute_task_event("network") # Delete old stop eventa and execute others... for f in os.listdir(system_event_dir): if f=="stop" or f=="shutdown": steelsquid_utils.deleteFileOrFolder(system_event_dir+"/"+f) else: read_task_event(f) # Listen for events try: while running: events = inotifyx.get_events(fd) for event in events: read_task_event(event.name) except KeyboardInterrupt: pass os.close(fd) _cleanup() # Delete old eventa for f in os.listdir(system_event_dir): steelsquid_utils.deleteFileOrFolder(system_event_dir+"/"+f) # Broadcast the event else: if len(sys.argv)>2: broadcast_task_event(command, sys.argv[2:]) else: broadcast_task_event(command) except: steelsquid_utils.shout("Fatal error when on boot steelsquid service", is_error=True) os._exit(0)
def _cleanup(): ''' Clean ''' global running running = False event.set() try: for obj in steelsquid_kiss_global.loaded_modules.itervalues(): class_system = steelsquid_kiss_global._get_object(obj, "SYSTEM") if class_system!=None: method_event = steelsquid_kiss_global._get_object(class_system, "on_event_data") if method_event!=None: steelsquid_kiss_global.remove_event_data_callback(method_event) class_events = steelsquid_kiss_global._get_object(obj, "EVENTS") if class_events!=None: steelsquid_kiss_global.remove_broadcast_event_callback(class_events) if class_system!=None: steelsquid_kiss_global._exec_method_set_started(class_system, "on_stop", is_started=False) class_settings = steelsquid_kiss_global._get_object(obj, "SETTINGS") if class_settings!=None: persistent_off=False try: persistent_off = getattr(class_settings, "_persistent_off")==True except: pass if not persistent_off: members = [attr for attr in dir(class_settings) if not callable(getattr(class_settings, attr)) and not attr.startswith("_")] for var_name in members: the_var = getattr(class_settings, var_name, None) if isinstance(the_var, (bool)): if the_var: steelsquid_utils.set_flag(var_name) else: steelsquid_utils.del_flag(var_name) elif isinstance(the_var, list): steelsquid_utils.set_list(var_name, the_var) else: steelsquid_utils.set_parameter(var_name, str(the_var)) except: steelsquid_utils.shout() if steelsquid_utils.get_flag("nrf24_master") or steelsquid_utils.get_flag("nrf24_slave"): try: steelsquid_nrf24.stop() except: steelsquid_utils.shout() if steelsquid_utils.get_flag("hmtrlrs_server") or steelsquid_utils.get_flag("hmtrlrs_client"): try: steelsquid_hmtrlrs.stop() except: steelsquid_utils.shout() if steelsquid_utils.get_flag("socket_connection"): try: steelsquid_kiss_global.socket_connection.stop() except: pass if steelsquid_utils.get_flag("web"): try: steelsquid_kiss_global.http_server.stop_server() except: pass steelsquid_utils.execute_system_command_blind(['killall', 'aria2c']) steelsquid_utils.shout("Goodbye :-(")
def poweroff(gpio=None): ''' Power of the system Send command to OS ''' steelsquid_utils.execute_system_command_blind(['shutdown', '-h', 'now'], wait_for_finish=False)
def set_net_status(con): ''' Set with way to control rover 1=radio 2=wifi 3=3g4g ''' # Enable wifi but disable usb0 (3G/4G modem) if con == 1: steelsquid_utils.execute_system_command_blind( ["killall", "gst-launch-1.0"]) steelsquid_utils.execute_system_command_blind( ["ip", "link", "set", "wlan0", "up"]) steelsquid_utils.execute_system_command_blind( ["ip", "link", "set", "usb0", "down"]) # Enable wifi but disable usb0 (3G/4G modem) elif con == 2: steelsquid_utils.execute_system_command_blind( ["killall", "gst-launch-1.0"]) steelsquid_utils.execute_system_command_blind( ["ip", "link", "set", "wlan0", "up"]) steelsquid_utils.execute_system_command_blind( ["ip", "link", "set", "usb0", "down"]) # Disable wifi but enable usb0 (3G/4G modem) elif con == 3: steelsquid_utils.execute_system_command_blind( ["killall", "gst-launch-1.0"]) #steelsquid_utils.execute_system_command_blind(["ip", "link", "set", "wlan0", "down"]) steelsquid_utils.execute_system_command_blind( ["ip", "link", "set", "usb0", "up"])
def _video_cam_thread(): ''' Thread ''' while running: try: if enable_video: kill_video() if low_bandwidth_mode: if tcp_video: steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "v4l2src", "extra-controls=\"c,vertical_flip=1,horizontal_flip=1," + low_light_v + "\"", "device=/dev/video0", "!", "video/x-raw,width=" + width + ",height=" + height + ",framerate=" + "5" + "/1", "!", "clockoverlay", "xpad=0", "ypad=0", "!", "omxh264enc", "target-bitrate=" + "100000", "control-rate=3", "!", "tcpclientsink", "host=" + video_ip, "port=" + video_port ]) else: steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "v4l2src", "extra-controls=\"c,vertical_flip=1,horizontal_flip=1," + low_light_v + "\"", "device=/dev/video0", "!", "video/x-raw,width=" + width + ",height=" + height + ",framerate=" + "5" + "/1", "!", "clockoverlay", "xpad=0", "ypad=0", "!", "omxh264enc", "target-bitrate=" + "100000", "control-rate=3", "!", "rtph264pay", "pt=96", "config-interval=1", "!", "udpsink", "sync=false", "host=" + video_ip, "port=" + video_port ]) else: if tcp_video: steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "v4l2src", "extra-controls=\"c,vertical_flip=1,horizontal_flip=1," + low_light_v + "\"", "device=/dev/video0", "!", "video/x-raw,width=" + width + ",height=" + height + ",framerate=" + fps + "/1", "!", "clockoverlay", "xpad=0", "ypad=0", "!", "omxh264enc", "target-bitrate=" + bitrate, "control-rate=3", "!", "tcpclientsink", "host=" + video_ip, "port=" + video_port ]) else: steelsquid_utils.execute_system_command_blind([ "gst-launch-1.0", "-e", "v4l2src", "extra-controls=\"c,vertical_flip=1,horizontal_flip=1," + low_light_v + "\"", "device=/dev/video0", "!", "video/x-raw,width=" + width + ",height=" + height + ",framerate=" + fps + "/1", "!", "clockoverlay", "xpad=0", "ypad=0", "!", "omxh264enc", "target-bitrate=" + bitrate, "control-rate=3", "!", "rtph264pay", "pt=96", "config-interval=1", "!", "udpsink", "sync=false", "host=" + video_ip, "port=" + video_port ]) else: interrupt.wait(1) interrupt.clear() except: pass
def set_net_status(con): ''' Set with way to control rover 1=radio 2=wifi 3=3g4g ''' # Enable wifi but disable usb0 (3G/4G modem) if con==1: steelsquid_utils.execute_system_command_blind(["killall", "gst-launch-1.0"]) steelsquid_utils.execute_system_command_blind(["ip", "link", "set", "wlan0", "up"]) steelsquid_utils.execute_system_command_blind(["ip", "link", "set", "usb0", "down"]) # Enable wifi but disable usb0 (3G/4G modem) elif con==2: steelsquid_utils.execute_system_command_blind(["killall", "gst-launch-1.0"]) steelsquid_utils.execute_system_command_blind(["ip", "link", "set", "wlan0", "up"]) steelsquid_utils.execute_system_command_blind(["ip", "link", "set", "usb0", "down"]) # Disable wifi but enable usb0 (3G/4G modem) elif con==3: steelsquid_utils.execute_system_command_blind(["killall", "gst-launch-1.0"]) #steelsquid_utils.execute_system_command_blind(["ip", "link", "set", "wlan0", "down"]) steelsquid_utils.execute_system_command_blind(["ip", "link", "set", "usb0", "up"])