from sys import stdout
from os import mkdir, remove, listdir
from os.path import exists
from socket import setdefaulttimeout
from loguru import logger


ip_addr = "192.168.2.160"
# ip_addr = "192.168.168.128"
# ip_addr = "192.168.40.130"
ssh_port = 22
socket_port = 5050
username = "luoshi"
password = "luoshi2019"  # for real robot
# password = "forpqart"  # for robot vm
xService_port = 6666
external_port = 8080
modbus_port = 502
interval = 0.5  # interval after actions being triggered, such as modbus/socket/external communication operations
heartbeat_interval = 2
RADIAN = 57.3  # 180 / 3.1415926
MAX_FRAME_SIZE = 1024
TIMEOUT = 3
setdefaulttimeout(TIMEOUT)
PREFIX = "../assets"
log_path = f"{PREFIX}/logs/"
log_data_debug = f"{PREFIX}/logs/debug.log"
log_data_reqs = f"{PREFIX}/logs/reqs.log"

if not exists(log_path):
    mkdir(log_path)
else:
    for _ in listdir(log_path):
        remove("".join([log_path, _]))

logger.remove()
logger.add(stdout, level="INFO")
logger.add(
    sink=log_data_debug,
    level="DEBUG",
    format="{time: YYYY-MM-DD HH:mm:ss} | {level} | {message}",
    rotation="50 MB",
    encoding="utf-8",
    enqueue=True,
    diagnose=True,
    colorize=True,
    # filter=lambda x: "DEBUG" in str(x["level"]).upper()
)
