upgrade_both_HW3_HW4
This commit is contained in:
parent
2a3032d4e7
commit
0626f26fea
@ -1,4 +1,4 @@
|
||||
***
|
||||
"""
|
||||
SCADA (Supervisory Control And Data Acquisition)
|
||||
|
||||
SCADA-системы нужны для организации сбора данных в реальном времени,
|
||||
@ -11,4 +11,4 @@ SCADA-системы решают следующие задачи:
|
||||
Ведение базы данных с технологической информацией.
|
||||
Аварийная сигнализация и управление служебными сообщениями о неполадках.
|
||||
Подготовка и генерирование отчетов о ходе технологического процесса.
|
||||
***
|
||||
"""
|
||||
|
@ -1,7 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional, Collection, Any
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from enum import IntEnum
|
||||
|
||||
class DeviceLifecycleState(IntEnum):
|
||||
@ -58,7 +57,7 @@ class Device(ABC):
|
||||
def action_descriptors(self) -> Collection[ActionDescriptor]:
|
||||
pass
|
||||
|
||||
#@abstractmethod
|
||||
@abstractmethod
|
||||
def __getitem__(self, trait_name: str) -> Optional[Any]:
|
||||
"""Return logical state of trait `trait_name`."""
|
||||
pass
|
||||
|
@ -1,18 +1,18 @@
|
||||
import time
|
||||
from turtle import Turtle
|
||||
from typing import Any
|
||||
from equipment.device import SynchronyDevice
|
||||
from equipment.device import Device
|
||||
import inspect
|
||||
import types
|
||||
from typing import Optional, Collection, Any
|
||||
|
||||
class TurtleDevice(SynchronyDevice):
|
||||
def open(self):
|
||||
super().open()
|
||||
return Turtle()
|
||||
self.turtle = Turtle()
|
||||
|
||||
@staticmethod
|
||||
def close (exam):
|
||||
def close (self):
|
||||
super().close()
|
||||
del exam
|
||||
del self.turtle
|
||||
|
||||
@property
|
||||
def trait_descriptors(self):
|
||||
@ -43,20 +43,35 @@ class TurtleDevice(SynchronyDevice):
|
||||
|
||||
def execute(self, action_name: str, *args, **kwargs):
|
||||
"""Execute action `action_name`, using `args` and `kwargs` as action argument."""
|
||||
pass
|
||||
if self.state == 1:
|
||||
f = getattr(self.turtle, action_name)
|
||||
f(int(*args), **kwargs)
|
||||
else:
|
||||
print("It's not opened")
|
||||
self.open()
|
||||
#time.sleep(30)
|
||||
f = getattr(self.turtle, action_name)
|
||||
f(int(*args), **kwargs)
|
||||
|
||||
def read(self, trait_name: str):
|
||||
"""Read physical state of trait `trait_name` from device."""
|
||||
pass
|
||||
return getattr(self.turtle, trait_name)
|
||||
|
||||
def write(self, trait_name: str, value: Any) -> bool:
|
||||
"""Pass `value` to trait `trait_name` of device."""
|
||||
pass
|
||||
setattr(self.turtle, trait_name, value)
|
||||
|
||||
def invalidate(self, trait_name: str):
|
||||
"""Invalidate logical state of trait `trait_name`"""
|
||||
pass
|
||||
if self.read(trait_name) == self.__getitem__(trait_name):
|
||||
print("Everything's okey")
|
||||
else:
|
||||
print(f"Something went wrong with {trait_name}.")
|
||||
|
||||
def __getitem__(self, trait_name: str) -> Optional[Any]:
|
||||
"""Return logical state of trait `trait_name`."""
|
||||
return getattr(self, trait_name)
|
||||
|
||||
#print(inspect.getmembers(Turtle))
|
||||
#t = TurtleDevice()
|
||||
#print(t.trait_descriptors)
|
||||
#print(t.execute("forward", 3))
|
||||
|
@ -2,6 +2,7 @@ import cmd
|
||||
import threading
|
||||
from threading import Thread
|
||||
from threading import Event
|
||||
import argparse
|
||||
import time
|
||||
|
||||
from queue import Queue
|
||||
@ -15,8 +16,10 @@ class TurtleDeviceThread(threading.Thread):
|
||||
def __message_processing__(self):
|
||||
while True:
|
||||
new_message = self.queue.get()
|
||||
print("Name and args of action are {}".format(new_message))
|
||||
#self.device.
|
||||
#print(type(new_message))
|
||||
#print(new_message)
|
||||
#print("Name and args of action are {}".format(new_message))
|
||||
self.device.execute(*new_message)
|
||||
#time.sleep(30)
|
||||
self.queue.task_done()
|
||||
if self.event.is_set():
|
||||
@ -46,7 +49,7 @@ class NoBlockingTurtleShell(cmd.Cmd):
|
||||
|
||||
def do_execute(self, arg):
|
||||
# TODO(Homework 4) \begin
|
||||
turtle_thread.queue.put(arg)
|
||||
turtle_thread.queue.put(parse(arg))
|
||||
# TODO(Homework 4) \end
|
||||
|
||||
def do_exit(self, arg):
|
||||
@ -54,7 +57,9 @@ class NoBlockingTurtleShell(cmd.Cmd):
|
||||
turtle_thread.event.set()
|
||||
# TODO(Homework 4) \end
|
||||
|
||||
|
||||
def parse(arg):
|
||||
'Convert a series of zero or more numbers to an argument tuple'
|
||||
return tuple(arg.split())
|
||||
|
||||
if __name__ == '__main__':
|
||||
turtle_thread = TurtleDeviceThread()
|
||||
|
@ -10,6 +10,7 @@ class TurtleShell(cmd.Cmd):
|
||||
# ----- basic turtle commands -----
|
||||
def do_forward(self, arg):
|
||||
'Move the turtle forward by the specified distance: FORWARD 10'
|
||||
|
||||
forward(*parse(arg))
|
||||
def do_right(self, arg):
|
||||
'Turn turtle right by given number of degrees: RIGHT 20'
|
||||
|
Loading…
Reference in New Issue
Block a user