state machine

This commit is contained in:
End 2020-08-11 00:24:08 +02:00
parent fa9fa1746c
commit 5e60c3e540

View file

@ -6,6 +6,7 @@ from queue import Queue, Empty
import time import time
import zmq import zmq
import json import json
from enum import Enum
NO_MSG = {"msg": None} NO_MSG = {"msg": None}
INIT_MSG = {"msg": "init"} INIT_MSG = {"msg": "init"}
@ -13,6 +14,12 @@ ACK_MSG = {"msg": "ack"}
PING_MSG = {"msg": "ping"} PING_MSG = {"msg": "ping"}
PONG_MSG = {"msg": "pong"} PONG_MSG = {"msg": "pong"}
class NetworkState(Enum):
DISCONNECTED = auto()
CONNECTED = auto()
PING = auto()
SENDING = auto()
def convert_to_strings(obj): def convert_to_strings(obj):
if isinstance(obj, dict): if isinstance(obj, dict):
return {convert_to_strings(key): convert_to_strings(value) return {convert_to_strings(key): convert_to_strings(value)