This repository was archived by the owner on Jan 5, 2024. It is now read-only.
forked from mayeranalytics/pyUBX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSM.py
More file actions
45 lines (37 loc) · 1.21 KB
/
FSM.py
File metadata and controls
45 lines (37 loc) · 1.21 KB
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
"""TODO."""
from enum import Enum
import UBX
def isObj(obj, cls):
"""Test if UBX message obj is of class cls."""
return obj._class == cls._class and obj._id == cls._id
def isACK(obj):
"""Test whether message obj is a ACK."""
return isObj(obj, UBX.ACK.ACK)
def isNAK(obj):
"""Test whether message obj is a NAK."""
return isObj(obj, UBX.ACK.NAK)
def FSM_Get(msgCls):
"""Decorator that makes a getter FSM for use in Manager."""
def decorator(FSMCls):
# 1. class STATE
class STATE(Enum):
START = 0
DONE = 1
setattr(FSMCls, "STATE", STATE)
# 2. function __init__
def __init__(self):
self.state = FSMCls.STATE.START
self.ver = None
setattr(FSMCls, "__init__", __init__)
# 3. function done
def done(self):
return self.state == FSMCls.STATE.DONE
setattr(FSMCls, "done", done)
# 4. function onUBX
def onUBX(self, obj, manager):
if obj._class == msgCls._class and obj._id == msgCls._id:
print(obj)
self.state = FSMCls.STATE.DONE
setattr(FSMCls, "onUBX", onUBX)
return FSMCls
return decorator