upgrade_both_HW3_HW4

This commit is contained in:
MarieMih 2023-11-20 16:17:49 +03:00
parent 2a3032d4e7
commit 0626f26fea
5 changed files with 39 additions and 19 deletions

View File

@ -1,4 +1,4 @@
*** """
SCADA (Supervisory Control And Data Acquisition) SCADA (Supervisory Control And Data Acquisition)
SCADA-системы нужны для организации сбора данных в реальном времени, SCADA-системы нужны для организации сбора данных в реальном времени,
@ -11,4 +11,4 @@ SCADA-системы решают следующие задачи:
Ведение базы данных с технологической информацией. Ведение базы данных с технологической информацией.
Аварийная сигнализация и управление служебными сообщениями о неполадках. Аварийная сигнализация и управление служебными сообщениями о неполадках.
Подготовка и генерирование отчетов о ходе технологического процесса. Подготовка и генерирование отчетов о ходе технологического процесса.
*** """

View File

@ -1,7 +1,6 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional, Collection, Any from typing import Optional, Collection, Any
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from enum import IntEnum from enum import IntEnum
class DeviceLifecycleState(IntEnum): class DeviceLifecycleState(IntEnum):
@ -58,7 +57,7 @@ class Device(ABC):
def action_descriptors(self) -> Collection[ActionDescriptor]: def action_descriptors(self) -> Collection[ActionDescriptor]:
pass pass
#@abstractmethod @abstractmethod
def __getitem__(self, trait_name: str) -> Optional[Any]: def __getitem__(self, trait_name: str) -> Optional[Any]:
"""Return logical state of trait `trait_name`.""" """Return logical state of trait `trait_name`."""
pass pass

View File

@ -1,18 +1,18 @@
import time
from turtle import Turtle from turtle import Turtle
from typing import Any
from equipment.device import SynchronyDevice from equipment.device import SynchronyDevice
from equipment.device import Device
import inspect import inspect
import types from typing import Optional, Collection, Any
class TurtleDevice(SynchronyDevice): class TurtleDevice(SynchronyDevice):
def open(self): def open(self):
super().open() super().open()
return Turtle() self.turtle = Turtle()
@staticmethod def close (self):
def close (exam):
super().close() super().close()
del exam del self.turtle
@property @property
def trait_descriptors(self): def trait_descriptors(self):
@ -43,20 +43,35 @@ class TurtleDevice(SynchronyDevice):
def execute(self, action_name: str, *args, **kwargs): def execute(self, action_name: str, *args, **kwargs):
"""Execute action `action_name`, using `args` and `kwargs` as action argument.""" """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): def read(self, trait_name: str):
"""Read physical state of trait `trait_name` from device.""" """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: def write(self, trait_name: str, value: Any) -> bool:
"""Pass `value` to trait `trait_name` of device.""" """Pass `value` to trait `trait_name` of device."""
pass setattr(self.turtle, trait_name, value)
def invalidate(self, trait_name: str): def invalidate(self, trait_name: str):
"""Invalidate logical state of trait `trait_name`""" """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() #t = TurtleDevice()
#print(t.trait_descriptors) #print(t.execute("forward", 3))

View File

@ -2,6 +2,7 @@ import cmd
import threading import threading
from threading import Thread from threading import Thread
from threading import Event from threading import Event
import argparse
import time import time
from queue import Queue from queue import Queue
@ -15,8 +16,10 @@ class TurtleDeviceThread(threading.Thread):
def __message_processing__(self): def __message_processing__(self):
while True: while True:
new_message = self.queue.get() new_message = self.queue.get()
print("Name and args of action are {}".format(new_message)) #print(type(new_message))
#self.device. #print(new_message)
#print("Name and args of action are {}".format(new_message))
self.device.execute(*new_message)
#time.sleep(30) #time.sleep(30)
self.queue.task_done() self.queue.task_done()
if self.event.is_set(): if self.event.is_set():
@ -46,7 +49,7 @@ class NoBlockingTurtleShell(cmd.Cmd):
def do_execute(self, arg): def do_execute(self, arg):
# TODO(Homework 4) \begin # TODO(Homework 4) \begin
turtle_thread.queue.put(arg) turtle_thread.queue.put(parse(arg))
# TODO(Homework 4) \end # TODO(Homework 4) \end
def do_exit(self, arg): def do_exit(self, arg):
@ -54,7 +57,9 @@ class NoBlockingTurtleShell(cmd.Cmd):
turtle_thread.event.set() turtle_thread.event.set()
# TODO(Homework 4) \end # 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__': if __name__ == '__main__':
turtle_thread = TurtleDeviceThread() turtle_thread = TurtleDeviceThread()

View File

@ -10,6 +10,7 @@ class TurtleShell(cmd.Cmd):
# ----- basic turtle commands ----- # ----- basic turtle commands -----
def do_forward(self, arg): def do_forward(self, arg):
'Move the turtle forward by the specified distance: FORWARD 10' 'Move the turtle forward by the specified distance: FORWARD 10'
forward(*parse(arg)) forward(*parse(arg))
def do_right(self, arg): def do_right(self, arg):
'Turn turtle right by given number of degrees: RIGHT 20' 'Turn turtle right by given number of degrees: RIGHT 20'