예제 #1
0
 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)
예제 #2
0
 def siren(activate=None):
     '''
     Aktivate the siren and get if it is activated
     '''    
     if activate!=None:
         if activate:
             steelsquid_pi.gpio_set(17, True);
         else:
             steelsquid_pi.gpio_set(17, False);
         GLOBAL.is_siren_on=activate
     return GLOBAL.is_siren_on
def gpio_set(gpio, state, use_piio_pin_nr=True):
    '''
    Set gpio pin to hight (true) or low (false) on a pin
    This is marked with GPIO and GPIO_5V on the PIIO board.
    @param gpio: GPIO number (Raspberry GPIO or piio pin nr)
    @param state: True/False
    @param use_piio_pin_nr: Use PIIO pin nr or Raspberry GPIO nr.
    '''
    state = steelsquid_utils.to_boolean(state)
    if use_piio_pin_nr:
        gpio = __convert_to_gpio(gpio)
    steelsquid_pi.gpio_set(gpio, state)
def gpio_set(gpio, state, use_piio_pin_nr=True):
    '''
    Set gpio pin to hight (true) or low (false) on a pin
    This is marked with GPIO and GPIO_5V on the PIIO board.
    @param gpio: GPIO number (Raspberry GPIO or piio pin nr)
    @param state: True/False
    @param use_piio_pin_nr: Use PIIO pin nr or Raspberry GPIO nr.
    '''
    state = steelsquid_utils.to_boolean(state)
    if use_piio_pin_nr:
        gpio = __convert_to_gpio(gpio)
    steelsquid_pi.gpio_set(gpio, state)
 def connected(status, dummy=False):
     '''
     Fire connection lost or not
     ''' 
     if not dummy:
         if status:
             steelsquid_utils.execute_one_time_clean()
             UTILS.play("connected.wav")
             lmatrix.animate_stop()
         else:
             UTILS.play("reconnect.wav")
             lmatrix.animate_connect(True)
         steelsquid_utils.execute_blink("connected_flash_1", not status, DO.connected, (True, True,), 0.04, DO.connected, (False, True,), 2)
     else:
         steelsquid_pi.gpio_set(16, not status)
         steelsquid_pi.po12_digital_out(1, status)
         steelsquid_pi.po12_digital_out(2, status)
 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)
예제 #7
0
 def lamp(activate=None):
     '''
     Aktivate the lamp and get if it is activated
     '''    
     if activate!=None:
         if activate:
             steelsquid_pi.gpio_set(22, True);
             steelsquid_pi.gpio_set(27, True);
         else:
             steelsquid_pi.gpio_set(22, False);
             steelsquid_pi.gpio_set(27, False);
         GLOBAL.is_lamp_on=activate
     return GLOBAL.is_lamp_on
예제 #8
0
 def highbeam(status):
     '''
     Enable highbeam
     '''
     status = not status
     #steelsquid_pi.gpio_set(7, status)
     steelsquid_pi.gpio_set(12, status)
     steelsquid_pi.gpio_set(25, status)
     steelsquid_pi.gpio_set(24, status)
 def highbeam(status):
     '''
     Enable highbeam
     ''' 
     status = not status
     #steelsquid_pi.gpio_set(7, status)
     steelsquid_pi.gpio_set(12, status)
     steelsquid_pi.gpio_set(25, status) 
     steelsquid_pi.gpio_set(24, status) 
def _send_command(com):
    '''
    Send a command to the transiver
    '''
    # Set the HM-TRLR-S in command mode
    steelsquid_pi.gpio_set(config_gpio_, False)
    try:
        time.sleep(STRANS_SLEEP)
        ser.write(com)
        ser.write("\n")
        ser.flush()
        line = ser.readline()
        if "ERROR" in line:
            if line.split(":")[1]=="0":
                raise Exception("The command format is wrong.")
            elif line.split(":")[1]=="1":
                raise Exception("The parameter is wrong.")
            else:
                raise Exception("The command is failed. ")
        time.sleep(STRANS_SLEEP)
    finally:
        # Set the HM-TRLR-S in communication mode
        steelsquid_pi.gpio_set(config_gpio_, True)
        time.sleep(STRANS_SLEEP)
예제 #11
0
def _send_command(com):
    '''
    Send a command to the transiver
    '''
    # Set the HM-TRLR-S in command mode
    steelsquid_pi.gpio_set(config_gpio_, False)
    try:
        time.sleep(STRANS_SLEEP)
        ser.write(com)
        ser.write("\n")
        ser.flush()
        line = ser.readline()
        if "ERROR" in line:
            if line.split(":")[1]=="0":
                raise Exception("The command format is wrong.")
            elif line.split(":")[1]=="1":
                raise Exception("The parameter is wrong.")
            else:
                raise Exception("The command is failed. ")
        time.sleep(STRANS_SLEEP)
    finally:
        # Set the HM-TRLR-S in communication mode
        steelsquid_pi.gpio_set(config_gpio_, True)
        time.sleep(STRANS_SLEEP)
예제 #12
0
 def connected(status, dummy=False):
     '''
     Fire connection lost or not
     '''
     if not dummy:
         if status:
             steelsquid_utils.execute_one_time_clean()
             UTILS.play("connected.wav")
             lmatrix.animate_stop()
         else:
             UTILS.play("reconnect.wav")
             lmatrix.animate_connect(True)
         steelsquid_utils.execute_blink("connected_flash_1", not status,
                                        DO.connected, (
                                            True,
                                            True,
                                        ), 0.04, DO.connected, (
                                            False,
                                            True,
                                        ), 2)
     else:
         steelsquid_pi.gpio_set(16, not status)
         steelsquid_pi.po12_digital_out(1, status)
         steelsquid_pi.po12_digital_out(2, status)
 def highbeam(status):
     '''
     highbeam
     '''
     steelsquid_pi.gpio_set(13, status)
 def headlights(status):
     '''
     headlights
     '''
     steelsquid_pi.gpio_set(26, status)
def setup(serial_port="/dev/ttyAMA0", config_gpio=25, reset_gpio=23, baudrate=38400, mode=MODE_MEDIUM, timeout_mutipple=1):
    '''
    Setup the serial interface
    serial_port: The serial port (/dev/ttyAMA0, /dev/ttyUSB1...)
    config_gpio_: GPIO number to use for setting the device in configuration mode or communication mode
    reset_gpio_: GPIO to use to send reset signal
    mode: MODE_SLOW   = Long range but slow speed
          MODE_MEDIUM = Medum range and medium speed
          MODE_FAST   = Fast speed but short range
    timeout_mutipple: mitipply the timeout time on the different modes with this...
                      MODE_SLOW   = 6s * timeout_mutipple
                      MODE_MEDIUM = 0.5s * timeout_mutipple
                      MODE_FAST   = 0.2s * timeout_mutipple
    
    '''
    global ser
    global serial_port_
    global config_gpio_
    global reset_gpio_
    global baudrate_
    global mode_

    serial_port_=serial_port
    config_gpio_ = config_gpio
    reset_gpio_ = reset_gpio
    baudrate_ = baudrate
    mode_ = mode
    
    # Create the serial interface
    ser = serial.Serial(serial_port, 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, writeTimeout=0, dsrdtr=True, timeout=0.5)
    time.sleep(STRANS_SLEEP)
    # Set reset hight (low will reset the device)
    steelsquid_pi.gpio_set(reset_gpio, True)
    time.sleep(STRANS_SLEEP)
    # Set baudrate
    try:
        _send_command("AT+SPR=6")
    except:
        steelsquid_utils.shout("Unable to use default baudrate, trying new boudrate...")
    # Create the serial interface with new  baudrate
    try:
        ser.close
    except:
        pass
    if mode==MODE_SLOW:
        ser = serial.Serial(serial_port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, writeTimeout=0, dsrdtr=True, timeout=7*timeout_mutipple)
    elif mode==MODE_MEDIUM:
        ser = serial.Serial(serial_port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, writeTimeout=0, dsrdtr=True, timeout=0.3*timeout_mutipple)
    elif mode==MODE_FAST:
        ser = serial.Serial(serial_port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, writeTimeout=0, dsrdtr=True, timeout=0.2*timeout_mutipple)
    time.sleep(STRANS_SLEEP)
    # Set the HM-TRLR-S in communication mode
    steelsquid_pi.gpio_set(config_gpio, True)
    # Enable CRC
    _send_command("AT+LRCRC=1")
    # Packagesize
    _send_command("AT+LRPL=32")
    # Syncworld
    _send_command("AT+SYNL=2")
    _send_command("AT+SYNW=3412")
    # Set mode
    if mode==MODE_SLOW:
        # Set LoRa
        _send_command("AT+MODE=0")
        _send_command("AT+LRSBW=6")
        _send_command("AT+LRSF=C")
    elif mode==MODE_MEDIUM:
        # Set LoRa
        _send_command("AT+MODE=0")
        _send_command("AT+LRSBW=8")
        _send_command("AT+LRSF=9")
    elif mode==MODE_FAST:
        # Set FSK 
        _send_command("AT+MODE=2")
    
    time.sleep(STRANS_SLEEP)
예제 #16
0
 def headlight(status):
     '''
     Enable headlights
     '''
     steelsquid_pi.gpio_set(16, not status)
     steelsquid_pi.gpio_set(20, not status)
예제 #17
0
 def speeker(status):
     '''
     Turn on and off speekers
     '''
     steelsquid_pi.gpio_set(21, not status)
예제 #18
0
 def headlight(status):
     '''
     Enable headlights
     ''' 
     steelsquid_pi.gpio_set(16, not status)        
     steelsquid_pi.gpio_set(20, not status)        
 def video(status):
     '''
     Is video on
     '''
     steelsquid_pi.gpio_set(19, status)
예제 #20
0
def setup(serial_port="/dev/ttyS0", config_gpio=18, reset_gpio=23, baudrate=38400, mode=MODE_MEDIUM_FAST, timeout_mutipple=1):
    '''
    Setup the serial interface
    serial_port: The serial port (/dev/ttyAMA0, /dev/ttyUSB1...)
    config_gpio_: GPIO number to use for setting the device in configuration mode or communication mode
    reset_gpio_: GPIO to use to send reset signal
    mode: MODE_SLOW   = Long range but slow speed
          MODE_MEDIUM = Medum range and medium speed
          MODE_FAST   = Fast speed but short range
    timeout_mutipple: mitipply the timeout time on the different modes with this...
                      MODE_SLOW   = 6s * timeout_mutipple
                      MODE_MEDIUM = 0.5s * timeout_mutipple
                      MODE_FAST   = 0.2s * timeout_mutipple
    
    '''
    global ser
    global serial_port_
    global config_gpio_
    global reset_gpio_
    global baudrate_
    global mode_

    serial_port_=serial_port
    config_gpio_ = config_gpio
    reset_gpio_ = reset_gpio
    baudrate_ = baudrate
    mode_ = mode
    
    # Create the serial interface
    ser = serial.Serial(serial_port, 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, writeTimeout=0, dsrdtr=True, timeout=1)
    time.sleep(STRANS_SLEEP)
    # Set reset hight (low will reset the device)
    steelsquid_pi.gpio_set(reset_gpio, True)
    time.sleep(STRANS_SLEEP)
    # Set baudrate
    try:
        _send_command("AT+SPR=6")
    except:
        steelsquid_utils.shout("Unable to use default baudrate, trying new boudrate...")
    # Create the serial interface with new  baudrate
    try:
        ser.close
    except:
        pass
    if mode==MODE_SLOW:
        ser = serial.Serial(serial_port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, writeTimeout=0, dsrdtr=True, timeout=7*timeout_mutipple)
    elif mode==MODE_MEDIUM or mode==MODE_MEDIUM_FAST:
        ser = serial.Serial(serial_port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, writeTimeout=0, dsrdtr=True, timeout=1*timeout_mutipple)
    elif mode==MODE_FAST:
        ser = serial.Serial(serial_port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, writeTimeout=0, dsrdtr=True, timeout=1*timeout_mutipple)
    time.sleep(STRANS_SLEEP)
    # Set the HM-TRLR-S in communication mode
    steelsquid_pi.gpio_set(config_gpio, True)
    # Enable CRC
    _send_command("AT+LRCRC=1")
    # Packagesize
    _send_command("AT+LRPL=32")
    # Syncworld
    _send_command("AT+SYNL=2")
    _send_command("AT+SYNW=3412")
    # set channel
    set_chanel(11)
    # Set mode
    if mode==MODE_SLOW:
        # Set LoRa
        _send_command("AT+MODE=0")
        _send_command("AT+LRSBW=6")
        _send_command("AT+LRSF=C")
    elif mode==MODE_MEDIUM:
        # Set LoRa
        _send_command("AT+MODE=0")
        _send_command("AT+LRSBW=8")
        _send_command("AT+LRSF=9")
    elif mode==MODE_MEDIUM_FAST:
        # Set LoRa
        _send_command("AT+MODE=0")
        _send_command("AT+LRSBW=9")
        _send_command("AT+LRSF=7")
    elif mode==MODE_FAST:
        # Set FSK 
        _send_command("AT+MODE=2")
    
    time.sleep(STRANS_SLEEP)
예제 #21
0
 def speeker(status):
     '''
     Turn on and off speekers
     '''
     steelsquid_pi.gpio_set(21, not status)