Python test suite
This commit is contained in:
parent
379dd7118a
commit
a868d08474
3 changed files with 122 additions and 65 deletions
31
app/test.py
31
app/test.py
|
@ -1,31 +0,0 @@
|
||||||
from numpy import uint8
|
|
||||||
|
|
||||||
|
|
||||||
def send_hud(buf: list):
|
|
||||||
n = len(buf)
|
|
||||||
chars = []
|
|
||||||
crc = uint8(0xeb + n + n)
|
|
||||||
chars.append(0x10)
|
|
||||||
chars.append(0x7b)
|
|
||||||
chars.append(n + 6)
|
|
||||||
if n == 0xa:
|
|
||||||
chars.append(0x10)
|
|
||||||
chars.append(n)
|
|
||||||
chars.append(0x00)
|
|
||||||
chars.append(0x00)
|
|
||||||
chars.append(0x00)
|
|
||||||
chars.append(0x55)
|
|
||||||
chars.append(0x15)
|
|
||||||
for char in buf:
|
|
||||||
crc = uint8(crc + char)
|
|
||||||
chars.append(char)
|
|
||||||
if char == 0x10:
|
|
||||||
chars.append(0x10)
|
|
||||||
chars.append((-crc) & 0xff)
|
|
||||||
chars.append(0x10)
|
|
||||||
chars.append(0x03)
|
|
||||||
print(chars)
|
|
||||||
print([bytes(chr(char), 'raw_unicode_escape') for char in chars])
|
|
||||||
|
|
||||||
|
|
||||||
send_hud([0x04, 0x01])
|
|
|
@ -52,11 +52,13 @@ class Lane(Enum):
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, device: str = None):
|
||||||
self.gps = False
|
self.gps = False
|
||||||
self.ser = None#serial.Serial('COM9', 9600)
|
self.debug = device is None
|
||||||
time.sleep(2)
|
if not self.debug:
|
||||||
# print(self.ser.read_all())
|
self.ser = serial.Serial(device, 9600)
|
||||||
|
time.sleep(2)
|
||||||
|
print(self.ser.read_all())
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.send_hud([0x03, 0, 0, 0, 0x00, 0, 0])
|
self.send_hud([0x03, 0, 0, 0, 0x00, 0, 0])
|
||||||
|
@ -123,8 +125,8 @@ class Controller:
|
||||||
self.send_hud([0x07, 0x01])
|
self.send_hud([0x07, 0x01])
|
||||||
self.gps = state
|
self.gps = state
|
||||||
|
|
||||||
def set_speed_control(self):
|
def set_speed_control(self, on: bool = True):
|
||||||
self.send_hud([0x04, 0x01])
|
self.send_hud([0x04, 0x01 if on else 0x00])
|
||||||
|
|
||||||
def set_compass(self, direction: float):
|
def set_compass(self, direction: float):
|
||||||
if direction > 337.5 or direction <= 22.5:
|
if direction > 337.5 or direction <= 22.5:
|
||||||
|
@ -172,35 +174,18 @@ class Controller:
|
||||||
self.send_packet(chars)
|
self.send_packet(chars)
|
||||||
|
|
||||||
def send_packet(self, buff):
|
def send_packet(self, buff):
|
||||||
print("raw", buff)
|
|
||||||
encoded = [bytes(chr(char), 'raw_unicode_escape') for char in buff]
|
encoded = [bytes(chr(char), 'raw_unicode_escape') for char in buff]
|
||||||
print("enc", encoded)
|
if self.debug:
|
||||||
# for char in buff:
|
print("raw", buff)
|
||||||
# self.ser.write(bytes(chr(char), 'raw_unicode_escape'))
|
print("enc", encoded)
|
||||||
# time.sleep(0.2)
|
else:
|
||||||
# print(self.ser.read_all())
|
for char in buff:
|
||||||
|
self.ser.write(bytes(chr(char), 'raw_unicode_escape'))
|
||||||
|
time.sleep(0.2)
|
||||||
def test():
|
print(self.ser.read_all())
|
||||||
c.set_direction(OutAngle.Straight, OutType.Lane)
|
|
||||||
target = 100
|
|
||||||
for i in range(10):
|
|
||||||
c.set_distance(target, Unit.Kilometres)
|
|
||||||
time.sleep(0.5)
|
|
||||||
target -= 1
|
|
||||||
c.set_speed_control()
|
|
||||||
time.sleep(0.5)
|
|
||||||
for i in range(10):
|
|
||||||
c.set_distance(target, Unit.Kilometres)
|
|
||||||
time.sleep(0.5)
|
|
||||||
target -= 1
|
|
||||||
c.set_direction(OutAngle.Right, OutType.LongerLane)
|
|
||||||
for i in range(10):
|
|
||||||
c.set_distance(target, Unit.Kilometres)
|
|
||||||
time.sleep(0.5)
|
|
||||||
target -= 1
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
c = Controller()
|
import sys
|
||||||
test()
|
device = sys.argv[1] if len(sys.argv) > 1 else None
|
||||||
|
c = Controller(device)
|
103
python/test.py
Normal file
103
python/test.py
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
from main import *
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
interval = 0.2
|
||||||
|
|
||||||
|
|
||||||
|
def suite(controller: Controller):
|
||||||
|
lines(controller)
|
||||||
|
direction(controller)
|
||||||
|
distance(controller)
|
||||||
|
speed(controller)
|
||||||
|
time(controller)
|
||||||
|
control(controller)
|
||||||
|
|
||||||
|
|
||||||
|
def lines(controller: Controller):
|
||||||
|
controller.set_lines([Lane.DotsLeft], [])
|
||||||
|
controller.set_lines([Lane.OuterRight], [Lane.OuterLeft])
|
||||||
|
controller.set_lines([Lane.MiddleRight], [Lane.MiddleLeft])
|
||||||
|
controller.set_lines([Lane.InnerRight], [Lane.InnerLeft])
|
||||||
|
controller.set_lines([Lane.InnerLeft], [Lane.InnerRight])
|
||||||
|
controller.set_lines([Lane.MiddleLeft], [Lane.MiddleRight])
|
||||||
|
controller.set_lines([Lane.OuterLeft], [Lane.OuterRight])
|
||||||
|
controller.set_lines(
|
||||||
|
[Lane.DotsRight],
|
||||||
|
[Lane.OuterRight, Lane.MiddleRight, Lane.InnerRight, Lane.InnerLeft, Lane.MiddleLeft, Lane.OuterLeft]
|
||||||
|
)
|
||||||
|
controller.set_lines([], [])
|
||||||
|
|
||||||
|
|
||||||
|
def direction(controller: Controller):
|
||||||
|
controller.set_direction(OutAngle.RightDown)
|
||||||
|
controller.set_direction(OutAngle.SharpRight)
|
||||||
|
controller.set_direction(OutAngle.Right)
|
||||||
|
controller.set_direction(OutAngle.EasyRight)
|
||||||
|
controller.set_direction(OutAngle.Straight)
|
||||||
|
controller.set_direction(OutAngle.EasyLeft)
|
||||||
|
controller.set_direction(OutAngle.Left)
|
||||||
|
controller.set_direction(OutAngle.SharpLeft)
|
||||||
|
controller.set_direction(OutAngle.LeftDown)
|
||||||
|
controller.set_direction(OutAngle.Down)
|
||||||
|
controller.set_direction(OutAngle.SharpRight, OutType.LongerLane)
|
||||||
|
controller.set_direction(OutAngle.Right, OutType.LongerLane)
|
||||||
|
controller.set_direction(OutAngle.EasyRight, OutType.LongerLane)
|
||||||
|
controller.set_direction(OutAngle.Straight, OutType.LongerLane)
|
||||||
|
controller.set_direction(OutAngle.EasyLeft, OutType.LongerLane)
|
||||||
|
controller.set_direction(OutAngle.Left, OutType.LongerLane)
|
||||||
|
controller.set_direction(OutAngle.SharpLeft, OutType.LongerLane)
|
||||||
|
controller.set_direction(OutAngle.SharpRight, OutType.RightRoundabout)
|
||||||
|
controller.set_direction(OutAngle.Right, OutType.RightRoundabout)
|
||||||
|
controller.set_direction(OutAngle.EasyRight, OutType.RightRoundabout)
|
||||||
|
controller.set_direction(OutAngle.Straight, OutType.RightRoundabout)
|
||||||
|
controller.set_direction(OutAngle.EasyLeft, OutType.RightRoundabout)
|
||||||
|
controller.set_direction(OutAngle.Left, OutType.RightRoundabout)
|
||||||
|
controller.set_direction(OutAngle.SharpLeft, OutType.RightRoundabout)
|
||||||
|
controller.set_direction(OutAngle.Left, OutType.Flag)
|
||||||
|
controller.set_direction(OutAngle.Right, OutType.Flag)
|
||||||
|
|
||||||
|
|
||||||
|
def distance(controller: Controller):
|
||||||
|
controller.set_distance(999)
|
||||||
|
controller.set_distance(999, Unit.Kilometres)
|
||||||
|
controller.set_distance(999, Unit.Metres)
|
||||||
|
controller.set_distance(999, Unit.Foot)
|
||||||
|
controller.set_distance(999, Unit.Miles)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def speed(controller: Controller):
|
||||||
|
controller.set_gps(True)
|
||||||
|
controller.set_speed(50)
|
||||||
|
controller.set_speed(50, 100)
|
||||||
|
controller.set_speed(150, 100)
|
||||||
|
controller.set_speed(50, 100, True)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def time(controller: Controller):
|
||||||
|
controller.set_time(22, 22)
|
||||||
|
controller.set_time(22, 22, traffic=True)
|
||||||
|
controller.set_time(22, 22, flag=True)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def control(controller: Controller):
|
||||||
|
controller.set_speed_control()
|
||||||
|
controller.set_speed_control(False)
|
||||||
|
|
||||||
|
|
||||||
|
def compass(controller: Controller):
|
||||||
|
controller.set_compass(22.5)
|
||||||
|
controller.set_compass(67.5)
|
||||||
|
controller.set_compass(112.5)
|
||||||
|
controller.set_compass(157.5)
|
||||||
|
controller.set_compass(202.5)
|
||||||
|
controller.set_compass(247.5)
|
||||||
|
controller.set_compass(292.5)
|
||||||
|
controller.set_compass(337.5)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
instance = Controller('/dev/rfcomm0')
|
Loading…
Add table
Add a link
Reference in a new issue