import wx
import window_screen as ws
import async_communication as CM
import led
import DatabaseSearch as DB
import threading
#db参数
db_ip="192.168.1.233"
db_port=3306
db_name="ct_project"
db_user="zx"
db_password="zx123456"

#启动led
led=led.EntranceLED("192.168.1.165",5005)
def db_callback(suv,small):
    led.fresh_led(suv,small,False)
#启动数据库，绑定led与数据库
DBSearcher=DB.DBSeacher(db_ip,db_port,db_name,db_user,db_password,1)
DBSearcher.set_ledcallback(db_callback)

#启动入口单片机,向rabbitmq发送数据，并接收关门请求
#[消息服务器ip,port,用户，密码，状态交换机名称,状态消息key]
rabbitmq_parameter={"ip":"192.168.1.233","port":5672,"user":"zx","password":"zx123456"}
statu_ex_keys=[["statu_ex","in_mcpu_1_statu_port"],
               ["statu_ex","measure_1_statu_port"]
]
cpu_ex,cpu_key=statu_ex_keys[0]
measure_ex,measure_key=statu_ex_keys[1]
g_rabbitmq=CM.RabbitAsyncCommunicator(rabbitmq_parameter["ip"],rabbitmq_parameter["port"],
                         rabbitmq_parameter["user"],rabbitmq_parameter["password"])
g_rabbitmq.Init(None,statu_ex_keys)

#启动界面
#绑定单片机与界面
images={"传感器超时":"./resource/arrows/传感器超时.png",
          "测绘超时":"./resource/arrows/测绘超时.png",
          "正确文字":"./resource/arrows/正确文字.png",
          "正确图片":"./resource/arrows/正确图片.png",
        "超宽车辆":"./resource/arrows/超宽车辆.png",
        "轴距超差":"./resource/arrows/轴距超差.png",
        "请调整":"./resource/arrows/请调整.png",
        "向前调整":"./resource/arrows/向前调整.png",
        "向后调整":"./resource/arrows/向后调整.png",
        "向左调整":"./resource/arrows/向左调整.png",
        "向右调整":"./resource/arrows/向右调整.png",
        "左前调整":"./resource/arrows/左前调整.png",
        "左后调整":"./resource/arrows/左后调整.png",
        "右前调整":"./resource/arrows/右前调整.png",
        "右后调整":"./resource/arrows/右后调整.png",
        "向左旋转":"./resource/arrows/向左旋转.png",
        "向右旋转":"./resource/arrows/向右旋转.png",
        "空闲":"./resource/arrows/空闲.png",
        "回正方向盘":"./resource/arrows/回正方向盘.png"}
imageArrow={}
app = wx.App()
frame = ws.Frame(None,images=images,title="zx123456",size=(500,1000),second_screen=False)
frame.Show(True)  # frame.Show(False) 或 frame.Hide()是隐藏
g_rabbitmq.bind_statu_callback(cpu_ex,cpu_key,frame.receive_icpu)
g_rabbitmq.bind_statu_callback(measure_ex,measure_key,frame.receive_measureInfo)
g_rabbitmq.start()
DBSearcher.start()
# 一个app可以包含好几个frame，只有一个是顶级
app.SetTopWindow(frame)
app.MainLoop()
g_rabbitmq.close()
DBSearcher.close()
g_rabbitmq.join()
DBSearcher.join()