예제 #1
0
def run_test():
    args = main_app.parse_args()
    conf = main_app.read_config(args.config_file)
    ports = list_ports.comports()
    for port, desc, hwid in sorted(ports):
        print("port info: {0} {1} {2}".format(port, desc, hwid))

    print("Connecting to gps ports")
    gps = initialisation.gps_init(conf['GPS'], ports)

    print(gps['serial1'])

    print("Showing a few blocks of gps data, if available")
    for i in range(5):
        print(i, gps['serial1'].port, gps['serial1'].inWaiting())
        print(i, gps['serial1'].port, gps['serial1'].read(100))

    print("starting gps managers")
    if gps['manager'] is not None:
        gps['manager'].add_serial_port(gps['serial1'])
        gps['manager'].start()
    else:
        print("No GPS manager identified")
    time.sleep(0.1)

    print("Showing gps manager data for {0}s, CTRL-C to stop".format(test_duration))
    print("Ports used: {0}".format(gps['manager'].serial_ports))
    t0 = time.time()
    print("Last update \t\t\t Latitude \t Longitude \t Speed \t\t Fix \t Heading (check) \t N sat (check)")
    while time.time() - t0 < test_duration:
        try:
            print("""\nTime \t\t {0} \nLat \t\t {1} \t Lon \t {2} \nSpeed \t\t {3} \nFix \t\t {4} \t nSat {7} \t Checks: {8} \nheading \t {5} ({6})""".\
                  format(gps['manager'].last_update, gps['manager'].lat, gps['manager'].lon,
                  gps['manager'].speed, gps['manager'].fix,
                  gps['manager'].heading, check_heading(gps), gps['manager'].satellite_number, check_gps(gps)))
            print("""headMot \t {0} \nrelPosHead \t {1} \nAcc \t\t {2} \nVehH valid \t {3} \nRelPosH valid\t {4} \nDiff Soln\t {5}\n GNSS fix\t {6}""".\
                  format(gps['manager'].headMot, gps['manager'].relPosHeading, gps['manager'].accHeading,
                  gps['manager'].flags_headVehValid, gps['manager'].flag_relPosHeadingValid, gps['manager'].flags_diffSolN, gps['manager'].flags_gnssFixOK))

            time.sleep(0.9)
        except (KeyboardInterrupt, SystemExit):
            print("Stopping GPS manager thread")
            gps['manager'].stop()
            time.sleep(0.5)
            sys.exit(0)
        except Exception:
            raise

    if gps['manager'] is not None:
        print("Stopping GPS manager thread")
        gps['manager'].stop()
        time.sleep(0.5)
예제 #2
0
def run():
    args = parse_args()
    conf = read_config(args.config_file)

    if conf['RADIOMETERS'].getboolean('use_gpio_control'):
        pin = conf['RADIOMETERS'].getint('gpio1')
    else:
        print("GPIO control is not set")

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pin, GPIO.OUT)
    GPIO.output(pin, GPIO.LOW)
    time.sleep(1)
    GPIO.cleanup()
    print("done")
예제 #3
0
def run_test():
    args = main_app.parse_args()
    conf = main_app.read_config(args.config_file)
    ports = list_ports.comports()
    print("connecting to gps ports")
    gps = initialisation.gps_init(conf['GPS'], ports)

    print(gps['serial1'], gps['serial2'])

    print("showing a few blocks of gps data, if available")
    for gserial in [gps['serial1'], gps['serial2']]:
        for i in range(10):
            print(i, gserial.port, gserial.inWaiting())
            print(i, gserial.port, gserial.read(100))

    print("starting gps managers")
    gps_ports = [port for key, port in gps.items() if 'serial' in key]
    # Instantiate GPS monitoring threads
    if len(gps_ports) > 0:
        gps_managers = []
        for port in gps_ports:
            gps_manager = GPSManager()
            gps_manager.add_serial_port(port)
            gps_manager.start()
            gps_managers.append(gps_manager)
    else:
        print("Check GPS sensors and Motor connection settings")
    time.sleep(0.1)

    # Start the GPS checker thread
    # gps_checker_manager = GPSChecker(gps_managers)
    # gps_checker_manager.start()

    print("showing gps manager data, CTRL-C to stop")
    while True:
        try:
            for gpsman in gps_managers:
                print(gpsman.serial_ports[0].port, gpsman.last_update,
                      gpsman.lat, gpsman.lon, gpsman.speed, gpsman.fix)
                time.sleep(0.2)
        except (KeyboardInterrupt, SystemExit):
            for gps_manager in gps_managers:
                print("Stopping GPS manager thread")
                del (gps_manager)
            gpio_off()
            sys.exit(0)
        except Exception:
            raise
예제 #4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A simple test to check connectivity to the database
"""
import os
import sys
import inspect
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))))
import initialisation
import main_app
from functions import db_functions

if __name__ == '__main__':
    args = main_app.parse_args()
    conf = main_app.read_config(args.config_file)
    try:
        db_dict = initialisation.db_init(conf['DATABASE'])
        conn, cur = db_functions.connect_db(db_dict)
    except:
        raise
        sys.exit(1)
    print("Succesfully connected to database")
예제 #5
0
import os
import time
import inspect
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))))
import serial.tools.list_ports as list_ports
from initialisation import motor_init
from main_app import parse_args, read_config
import functions.motor_controller_functions as motor_func
import codecs

test_duration = 3600
print("Run test for {0} seconds. Press CTRL-C to stop".format(test_duration))

if __name__ == '__main__':
    args = parse_args()
    conf = read_config(args.config_file)
    ports = list_ports.comports()
    motor = motor_init(conf['MOTOR'], ports)
    stpd = float(motor['steps_per_degree'])

    t0 = time.time()
    while time.time() - t0 < test_duration:

        # read register 128: present alarm code
        response = motor_func.read_command(motor['serial'], 1, 3, 128, 2)
        # print(response, len(response), type(response))  # bytes class
        #slave_id = int(response[0])
        #function_code = int(response[1])
        length = int(response[2])
        alarm = int.from_bytes(response[3:3+length], byteorder='big')