-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrobodk.py
50 lines (39 loc) · 1.22 KB
/
robodk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
from robodkdriver.robot import Robot
ROBOTCOM_STATUS = {
'ready': 'Ready',
'working': 'Working...',
'waiting': 'Waiting...',
'disconnected': 'Disconnected',
'not_connected': 'Not connected',
'connection_problems': 'Connection problems',
}
class RoboDK:
def __init__(self, robot: Robot):
self._robot = robot
@classmethod
def update_status(cls, status: str):
if status in ROBOTCOM_STATUS:
status = 'SMS:' + ROBOTCOM_STATUS[status]
cls._print_message('{status}'.format(status=status))
def run_driver(self):
while True:
# If input is available
if not sys.stdin.isatty():
command = sys.stdin.readline()
command = self._parse_command(command)
status = self._robot.run_command(**command)
self.update_status(status)
@staticmethod
def _print_message(message):
print(message)
sys.stdout.flush()
@staticmethod
def _parse_command(command):
parts = command[0:-1].split(' ')
parts = list(map(str.strip, parts))
parts = {
'cmd': parts[0],
'args': parts[1:]
}
return parts