project: reorder
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
This commit is contained in:
parent
e541023bba
commit
4646c7d7a6
@ -9,8 +9,8 @@ stages:
|
|||||||
tests:
|
tests:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- "python scripts/pylint_wrapper.py -s source -s tests"
|
- "python scripts/pylint_wrapper.py -s gate_guard -s tests"
|
||||||
- "nosetests --with-coverage --cover-package=source --cover-xml"
|
- "nosetests --with-coverage --cover-package=gate_guard --cover-xml"
|
||||||
- "nosetests --with-xunit tests/unittests/"
|
- "nosetests --with-xunit tests/unittests/"
|
||||||
- "sonar-runner"
|
- "sonar-runner"
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<?eclipse-pydev version="1.0"?><pydev_project>
|
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||||
<path>/${PROJECT_DIR_NAME}/source</path>
|
|
||||||
<path>/${PROJECT_DIR_NAME}/scripts</path>
|
<path>/${PROJECT_DIR_NAME}/scripts</path>
|
||||||
<path>/${PROJECT_DIR_NAME}/tests</path>
|
<path>/${PROJECT_DIR_NAME}/tests</path>
|
||||||
</pydev_pathproperty>
|
</pydev_pathproperty>
|
||||||
|
@ -3,8 +3,6 @@ Created on Dec 19, 2016
|
|||||||
|
|
||||||
@author: klaehn
|
@author: klaehn
|
||||||
'''
|
'''
|
||||||
import sys
|
|
||||||
sys.path.append('source/')
|
|
||||||
import time
|
import time
|
||||||
import gate
|
import gate
|
||||||
|
|
@ -1,3 +1,8 @@
|
|||||||
|
'''
|
||||||
|
Created on Mar 30, 2017
|
||||||
|
|
||||||
|
@author: tkla
|
||||||
|
'''
|
||||||
|
|
||||||
class DataBuffer(object):
|
class DataBuffer(object):
|
||||||
def __init__(self, length):
|
def __init__(self, length):
|
@ -1,3 +1,8 @@
|
|||||||
|
'''
|
||||||
|
Created on Mar 30, 2017
|
||||||
|
|
||||||
|
@author: tkla
|
||||||
|
'''
|
||||||
import gpio
|
import gpio
|
||||||
|
|
||||||
class Engine(object):
|
class Engine(object):
|
@ -3,14 +3,13 @@ Created on Dec 19, 2016
|
|||||||
|
|
||||||
@author: klaehn
|
@author: klaehn
|
||||||
'''
|
'''
|
||||||
import sys
|
|
||||||
sys.path.append('source/')
|
|
||||||
import time
|
import time
|
||||||
import mqtt
|
import mqtt
|
||||||
import data_buffer
|
import data_buffer
|
||||||
import light_sensor
|
import light_sensor
|
||||||
import engine
|
import engine
|
||||||
from power_sensor import PowerSensor
|
import power_sensor
|
||||||
|
from numpy.core.umath import power
|
||||||
|
|
||||||
STATE_INIT = "init"
|
STATE_INIT = "init"
|
||||||
STATE_OPENED = "open"
|
STATE_OPENED = "open"
|
||||||
@ -54,7 +53,7 @@ class Gate(object):
|
|||||||
self.__light_data = data_buffer.DataBuffer(LIGHT_CONSECUTIVE_READS)
|
self.__light_data = data_buffer.DataBuffer(LIGHT_CONSECUTIVE_READS)
|
||||||
self.__comserver = mqtt.Mqtt(MQTT_HOST)
|
self.__comserver = mqtt.Mqtt(MQTT_HOST)
|
||||||
self.__engine = engine.Engine(gpio_1=13, gpio_2=19)
|
self.__engine = engine.Engine(gpio_1=13, gpio_2=19)
|
||||||
self.__power_sensor = PowerSensor(POWER_SENSOR_I2C_BUS, \
|
self.__power_sensor = power_sensor.PowerSensor(POWER_SENSOR_I2C_BUS, \
|
||||||
POWER_SENSOR_I2C_ADDRESS)
|
POWER_SENSOR_I2C_ADDRESS)
|
||||||
self.__power_data = data_buffer.DataBuffer(POWER_CONSECUTIVE_READS)
|
self.__power_data = data_buffer.DataBuffer(POWER_CONSECUTIVE_READS)
|
||||||
self.__gate_move_timeout = 0
|
self.__gate_move_timeout = 0
|
@ -1,3 +1,8 @@
|
|||||||
|
'''
|
||||||
|
Created on Mar 30, 2017
|
||||||
|
|
||||||
|
@author: tkla
|
||||||
|
'''
|
||||||
import smbus
|
import smbus
|
||||||
|
|
||||||
class LightSensor(object):
|
class LightSensor(object):
|
@ -3,7 +3,6 @@ Created on Dec 19, 2016
|
|||||||
|
|
||||||
@author: klaehn
|
@author: klaehn
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import smbus
|
import smbus
|
||||||
|
|
||||||
class PowerSensor(object):
|
class PowerSensor(object):
|
@ -2,7 +2,7 @@ sonar.projectKey=chickenhouse:python
|
|||||||
sonar.projectName=chickenhouse:python
|
sonar.projectName=chickenhouse:python
|
||||||
sonar.projectVersion=1.0
|
sonar.projectVersion=1.0
|
||||||
sonar.host.url=http://sonarqube:9000
|
sonar.host.url=http://sonarqube:9000
|
||||||
sonar.sources=source
|
sonar.sources=gate_guard
|
||||||
sonar.tests=tests/unittests
|
sonar.tests=tests/unittests
|
||||||
sonar.language=py
|
sonar.language=py
|
||||||
sonar.sourceEncoding=UTF-8
|
sonar.sourceEncoding=UTF-8
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
'''
|
|
||||||
Created on Dec 23, 2016
|
|
||||||
|
|
||||||
@author: klaehn
|
|
||||||
'''
|
|
||||||
import sys
|
|
||||||
sys.path.append('source/')
|
|
||||||
import time
|
|
||||||
|
|
||||||
import data_buffer
|
|
||||||
import engine
|
|
||||||
import power_sensor
|
|
||||||
|
|
||||||
POWER_SENSOR_I2C_BUS = 1
|
|
||||||
POWER_SENSOR_I2C_ADDRESS = 0x40
|
|
||||||
|
|
||||||
CONSECUTIVE_POWER_READS = 1000
|
|
||||||
|
|
||||||
MAX_ENGINE_POWER = {"up":330, "down":280}
|
|
||||||
|
|
||||||
def main(argv):
|
|
||||||
__engine = engine.Engine(gpio_1=13, gpio_2=19)
|
|
||||||
__power_sensor = power_sensor.PowerSensor(POWER_SENSOR_I2C_BUS, POWER_SENSOR_I2C_ADDRESS)
|
|
||||||
__power_data = data_buffer.DataBuffer(CONSECUTIVE_POWER_READS)
|
|
||||||
__engine.down()
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
rd = __power_sensor.power_mw()
|
|
||||||
__power_data.push(rd)
|
|
||||||
average = __power_data.average()
|
|
||||||
print str(time.time()) + " " + str(rd)
|
|
||||||
if average != None:
|
|
||||||
if average > MAX_ENGINE_POWER["down"]:
|
|
||||||
__engine.stop()
|
|
||||||
# print "Gate successfully closed"
|
|
||||||
return 0
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
__engine.stop()
|
|
||||||
# print "Closing procedure interrupted."
|
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main(sys.argv[1:]))
|
|
@ -1,19 +0,0 @@
|
|||||||
'''
|
|
||||||
Created on Dec 24, 2016
|
|
||||||
|
|
||||||
@author: tkl
|
|
||||||
'''
|
|
||||||
import sys
|
|
||||||
sys.path.append('source/')
|
|
||||||
import time
|
|
||||||
import light_sensor
|
|
||||||
import mqtt
|
|
||||||
|
|
||||||
def main():
|
|
||||||
conn = mqtt.Mqtt(hostname='proxy')
|
|
||||||
light = light_sensor.LightSensor(1, 0x23)
|
|
||||||
conn.transmit("outdoor/chickenhouse/sensors/light", \
|
|
||||||
str(int(time.time())) + " " + str(light.read()))
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main())
|
|
@ -1,45 +0,0 @@
|
|||||||
'''
|
|
||||||
Created on Dec 23, 2016
|
|
||||||
|
|
||||||
@author: klaehn
|
|
||||||
'''
|
|
||||||
import sys
|
|
||||||
sys.path.append('source/')
|
|
||||||
import time
|
|
||||||
|
|
||||||
import data_buffer
|
|
||||||
import engine
|
|
||||||
import power_sensor
|
|
||||||
|
|
||||||
POWER_SENSOR_I2C_BUS = 1
|
|
||||||
POWER_SENSOR_I2C_ADDRESS = 0x40
|
|
||||||
|
|
||||||
CONSECUTIVE_POWER_READS = 1000
|
|
||||||
|
|
||||||
MAX_ENGINE_POWER = {"up":330, "down":290}
|
|
||||||
|
|
||||||
def main(argv):
|
|
||||||
__engine = engine.Engine(gpio_1=13, gpio_2=19)
|
|
||||||
__power_sensor = power_sensor.PowerSensor(POWER_SENSOR_I2C_BUS, POWER_SENSOR_I2C_ADDRESS)
|
|
||||||
power_data = data_buffer.DataBuffer(CONSECUTIVE_POWER_READS)
|
|
||||||
__engine.up()
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
rd = __power_sensor.power_mw()
|
|
||||||
power_data.push(rd)
|
|
||||||
average = power_data.average()
|
|
||||||
print str(time.time()) + " " + str(rd)
|
|
||||||
if average != None:
|
|
||||||
if average > MAX_ENGINE_POWER["up"]:
|
|
||||||
__engine.stop()
|
|
||||||
# print "Gate successfully opened"
|
|
||||||
return 0
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
__engine.stop()
|
|
||||||
print "Closing procedure interrupted."
|
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main(sys.argv[1:]))
|
|
@ -3,24 +3,22 @@ Created on Dec 19, 2016
|
|||||||
|
|
||||||
@author: klaehn
|
@author: klaehn
|
||||||
'''
|
'''
|
||||||
import sys
|
|
||||||
sys.path.append('source/')
|
|
||||||
import unittest
|
import unittest
|
||||||
import random
|
import random
|
||||||
import data_buffer
|
import gate_guard.data_buffer
|
||||||
|
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
def test_zero_space(self):
|
def test_zero_space(self):
|
||||||
dut = data_buffer.DataBuffer(0)
|
dut = gate_guard.data_buffer.DataBuffer(0)
|
||||||
result = dut.push(10)
|
result = dut.push(10)
|
||||||
self.assertFalse(result, "test_zero_space - exp: False res: True")
|
self.assertFalse(result, "test_zero_space - exp: False res: True")
|
||||||
|
|
||||||
def test_max_data(self):
|
def test_max_data(self):
|
||||||
buffer_size = 10
|
buffer_size = 10
|
||||||
dut = data_buffer.DataBuffer(buffer_size)
|
dut = gate_guard.data_buffer.DataBuffer(buffer_size)
|
||||||
for _ in range(11):
|
for _ in range(11):
|
||||||
dut.push(random.random())
|
dut.push(random.random())
|
||||||
result = dut.length()
|
result = dut.length()
|
||||||
|
Loading…
Reference in New Issue
Block a user