| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- from socket import *
- import time
- import subprocess
- # import pigpio
- # from controlServer import ControlServer
- from videoServer import VideoServer
- # 控制服务配置
- HOST = '0.0.0.0'
- PORT = 49800
- ADDR = (HOST, PORT)
- # 电调+舵机配置
- MSLIST = [
- {
- "name": 'MOTOR',
- "pinList": [13, 16]
- },
- {
- "name": 'SERVO',
- "pinList": [12, 19]
- },
- ]
- # 用户列表配置
- USERLIST = []
- # PI配置
- PI = None
- # 视频服务配置
- VPORT = 49700
- VADDR = (HOST, VPORT)
- FX = 0.5 # 缩放
- SPD = 0.1 # fps=>越小,FPS越高,cpu消耗越大
- # def Calibration():
- # # 自动校准
- # global PI, MSLIST
- # # 启动pigpiod服务
- # port = subprocess.check_output(
- # "ps -ef |grep pigpiod |awk '{print $2}'", shell=True).decode().split('\n')
- # if '' in port and len(port) <= 3:
- # subprocess.run('pigpiod', shell=True)
- # time.sleep(0.5)
- # PI = pigpio.pi()
- # print('开始自动校准')
- # # 校准服务
- # speed = 0
- # while True:
- # speed += 1
- # for s in MSLIST:
- # for d in s['pinList']:
- # if s['name'] == 'MOTOR':
- # # Set ESC speed via PWM
- # PI.set_servo_pulsewidth(
- # d, speed * 1000 / 7 + 1000)
- # else:
- # PI.set_servo_pulsewidth(d, 1500)
- # time.sleep(2)
- # print(speed)
- # if speed > 2:
- # break
- def loopServer(SOCK):
- # 服务监听
- global USERLIST
- while True:
- print('Waiting For Contorl Client Connection ...')
- client, addr = SOCK.accept() # 会阻塞
- print('New control User', addr)
- # 增加线程
- if client not in USERLIST and len(USERLIST) < 2:
- USERLIST.append(client)
- # 接收
- # contrl = ControlServer(client, USERLIST, MSLIST, PI)
- # contrl.start()
- else:
- # 不允许连接
- print('不允许连接')
- client.close()
- if __name__ == '__main__':
- # 启动校准服务
- # Calibration()
- print('1S后启动视频服务')
- time.sleep(1)
- # 视频服务
- VideoServer(VADDR, SPD, FX).start()
- print('1S后启动控制服务')
- time.sleep(1)
- # 启动socket服务
- SOCK = socket(AF_INET, SOCK_STREAM)
- SOCK.bind(ADDR)
- SOCK.listen(1)
- loopServer(SOCK)
|