Example #1
0
# See LICENSE file for details.

"""
Integration test for the Pumpkin MCU Service. 

Runs the moduleList query
"""

import socket
from kubos_service.config import Config
import json


print "\n###################################"
print "Service and Test Port Configuration"
c = Config("pumpkin-mcu-service")
testing_port = c.port + 1000
ERRORS = {}

print "Service IP:", c.ip
print "Service port:", c.port
print "Testing port:", testing_port

sock = socket.socket(socket.AF_INET,  # Internet
                     socket.SOCK_DGRAM)  # UDP
sock.bind((c.ip, testing_port))

print "\n###########################"
print "Query Modules and Addresses"
query = 'query {moduleList}'
print "\nquery: " + query
#!/usr/bin/env python3

# Copyright 2020 Judd Bowman
# Licensed under the Apache License, Version 2.0
# See LICENSE file for details.

"""
Based on the KubOS example for service applications
"""

from service import schema
from kubos_service.config import Config
from kubos_service import http_service

# Get the configuration (uses command line argument -c if present)
config = Config("dora-sensor-service")

# Start an http service
http_service.start(config, schema.schema)



#from kubos_service import udp_service

# Start a udp service with optional context
# udp_service.start(config, schema, {'bus': '/dev/ttyS3'})

# Start a udp service
#udp_service.start(logger, config, schema)
Example #3
0
"""

__author__ = "Jon Grebe"
__version__ = "0.1.0"
__license__ = "MIT"

import logging

from service import schema
from logging.handlers import SysLogHandler
import sys
#import toml

#print("hello")
from kubos_service.config import Config
config = Config("radio-service")
#print(toml.dumps(config))

# Setup logging
logger = logging.getLogger("radio-service")
logger.setLevel(logging.DEBUG)
logger.debug("DEBUG TEST")
handler = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_DAEMON, level=logging.DEBUG)
formatter = logging.Formatter('radio-service: %(message)s')
handler.formatter = formatter
logger.addHandler(handler)

# Set up a handler for logging to stdout
stdout = logging.StreamHandler(stream=sys.stdout, level=logging.DEBUG)
stdout.setFormatter(formatter)
logger.addHandler(stdout)
Example #4
0
# Copyright 2017 Kubos Corporation
# Licensed under the Apache License, Version 2.0
# See LICENSE file for details.
"""
Boilerplate main for service application.
"""

import logging

from service import schema
from kubos_service.config import Config
from logging.handlers import SysLogHandler
import sys

config = Config("example-service")

# Setup logging
logger = logging.getLogger("example-service")
logger.setLevel(logging.DEBUG)
handler = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_DAEMON)
formatter = logging.Formatter('example-service: %(message)s')
handler.formatter = formatter
logger.addHandler(handler)

# Set up a handler for logging to stdout
stdout = logging.StreamHandler(stream=sys.stdout)
stdout.setFormatter(formatter)
logger.addHandler(stdout)

from kubos_service import http_service
Example #5
0
"""

__author__ = "Jon Grebe"
__version__ = "0.1.0"
__license__ = "MIT"

import logging

from service import schema
from logging.handlers import SysLogHandler
import sys
#import toml

#print("hello")
from kubos_service.config import Config
config = Config("rtc-service")
#print(toml.dumps(config))

# Setup logging
logger = logging.getLogger("rtc-service")
logger.setLevel(logging.DEBUG)
handler = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_DAEMON)
formatter = logging.Formatter('rtc-service: %(message)s')
handler.formatter = formatter
logger.addHandler(handler)

# Set up a handler for logging to stdout
stdout = logging.StreamHandler(stream=sys.stdout)
stdout.setFormatter(formatter)
logger.addHandler(stdout)
Example #6
0
Boilerplate service code which reads the config file and starts up the
GraphQL/HTTP endpoint. (should not need to much modification)
"""

__author__ = "Jon Grebe"
__version__ = "0.1.0"
__license__ = "MIT"

import logging

from service import schema
from kubos_service.config import Config
from logging.handlers import SysLogHandler
import sys

config = Config("eps-service")

# Setup logging
logger = logging.getLogger("eps-service")
logger.setLevel(logging.DEBUG)
handler = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_DAEMON)
formatter = logging.Formatter('eps-service: %(message)s')
handler.formatter = formatter
logger.addHandler(handler)

# Set up a handler for logging to stdout
stdout = logging.StreamHandler(stream=sys.stdout)
stdout.setFormatter(formatter)
logger.addHandler(stdout)

from kubos_service import http_service
Example #7
0
Boilerplate service code which reads the config file and starts up the
GraphQL/HTTP endpoint. (should not need to much modification)
"""

__author__ = "Jon Grebe"
__version__ = "0.1.0"
__license__ = "MIT"

import logging

from service import schema
from kubos_service.config import Config
from logging.handlers import SysLogHandler
import sys

config = Config("imu-service")

# Setup logging
logger = logging.getLogger("imu-service")
logger.setLevel(logging.DEBUG)
handler = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_DAEMON)
formatter = logging.Formatter('imu-service: %(message)s')
handler.formatter = formatter
logger.addHandler(handler)

# Set up a handler for logging to stdout
stdout = logging.StreamHandler(stream=sys.stdout)
stdout.setFormatter(formatter)
logger.addHandler(stdout)

from kubos_service import http_service
Example #8
0
Boilerplate service code which reads the config file and starts up the
GraphQL/HTTP endpoint. (should not need to much modification)
"""

__author__ = "Jon Grebe"
__version__ = "0.1.0"
__license__ = "MIT"

import logging

from service import schema
from kubos_service.config import Config
from logging.handlers import SysLogHandler
import sys

config = Config("payload-service")

# Setup logging
logger = logging.getLogger("payload-service")
logger.setLevel(logging.DEBUG)
handler = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_DAEMON)
formatter = logging.Formatter('payload-service: %(message)s')
handler.formatter = formatter
logger.addHandler(handler)

# Set up a handler for logging to stdout
stdout = logging.StreamHandler(stream=sys.stdout)
stdout.setFormatter(formatter)
logger.addHandler(stdout)

from kubos_service import http_service
Example #9
0
    def __init__(self):
        """
        Initialize the hardware when the service starts
        """

        # Setup logging
        self.logger = logging.getLogger(self.app_name)
        self.logger.setLevel(logging.DEBUG)
        handler = SysLogHandler(address='/dev/log',
                                facility=SysLogHandler.LOG_DAEMON)
        formatter = logging.Formatter('{}[%(process)d]: %(message)s'.format(
            self.app_name))
        handler.formatter = formatter
        self.logger.addHandler(handler)

        # Get the configuration options for the service out of the `config.toml` file
        config = Config(self.app_name)
        sensor1_bus = config.raw['device']['bus1']
        sensor2_bus = config.raw['device']['bus2']

        # Create the sensor objects
        self.sensor1 = vcnl4040(sensor1_bus)
        self.sensor2 = vcnl4040(sensor2_bus)

        # Report settings
        print('\n--- Sensor 1 ---')
        print('I2C bus: ', self.sensor1.bus)
        print('I2C slave address: ', self.sensor1.addr)

        print('\n--- Sensor 2 ---')
        print('I2C bus: ', self.sensor2.bus)
        print('I2C slave address: ', self.sensor2.addr)

        self.telemetry = Telemetry(connected=self.noop(),
                                   power_on=False,
                                   integration_time=0,
                                   sensor1_value=0,
                                   sensor2_value=0,
                                   angle_of_arrival=0)

        print('\n--- Initializing ---')
        print('Power off proximity sensor 1: ',
              self.sensor1.powerOffProximity())
        print('Power off ambient sensor 1: ', self.sensor1.powerOffAmbient())
        print(
            'Set ambient integration time: ',
            self.sensor1.setAmbientIntegrationTime(self.getIntegrationFlag()))

        print('Power off proximity sensor 2: ',
              self.sensor2.powerOffProximity())
        print('Power off ambient sensor 2: ', self.sensor2.powerOffAmbient())
        print(
            'Set ambient integration time: ',
            self.sensor2.setAmbientIntegrationTime(self.getIntegrationFlag()))

        time.sleep(0.25)

        self.logger.info('Starting DORA sensor service')
        self.logger.info('Listening on: {}:{}'.format(config.ip, config.port))
        self.logger.info(
            'Using i2c bus {} for sensor 1 and bus {} for sensor 2'.format(
                self.sensor1.bus, self.sensor2.bus))
        self.start_time = datetime.datetime.now()