41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import logging
|
|
import sys
|
|
import os
|
|
import threading
|
|
|
|
# 添加项目路径
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.append(current_dir)
|
|
# logging.debug(f"Current directory: {current_dir}") # 移除控制台输出,改为日志
|
|
|
|
from core.direct_connection import ChargingPileDirectConnection
|
|
|
|
# 配置日志,仅记录到文件
|
|
log_file = os.path.join(current_dir, 'direct_connect.log')
|
|
logging.basicConfig(
|
|
level=logging.DEBUG,
|
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
|
encoding='utf-8',
|
|
force=True,
|
|
handlers=[
|
|
logging.FileHandler(log_file, encoding='utf-8')
|
|
]
|
|
)
|
|
|
|
def main():
|
|
logging.info("启动直连服务器...")
|
|
direct_conn = ChargingPileDirectConnection(host="0.0.0.0", port=52461)
|
|
|
|
try:
|
|
direct_conn.run()
|
|
except KeyboardInterrupt:
|
|
logging.info("接收到中断信号,停止程序")
|
|
direct_conn.stop()
|
|
except Exception as e:
|
|
logging.error(f"发生异常: {str(e)}")
|
|
direct_conn.stop()
|
|
finally:
|
|
direct_conn.stop()
|
|
|
|
if __name__ == "__main__":
|
|
main() |