import glog, signal, os, json
import SDK.ZX.async_communication as cm
import SDK.ZX.async_communication_etc_pb2 as rce
import SDK.ZX.tool as zx_tool
import receive


if __name__ == '__main__':
    # 加载配置
    rabbitmq_etc = zx_tool.getProtobufJsonConfig(os.path.dirname(os.path.abspath(__file__)) + "/etc/rabbitmq.json", rce.RabbitmqEtc())
    print(rabbitmq_etc)
    g_rabbitmq = cm.RabbitAsyncCommunicator(rabbitmq_etc.ip, rabbitmq_etc.port,
                                            rabbitmq_etc.user, rabbitmq_etc.password)
    statu_ex_keys = []
    for bind in rabbitmq_etc.binds:
        key = [bind.ex, bind.route_key]
        statu_ex_keys.append(key)

    glog.info(statu_ex_keys)
    # 初始化
    g_rabbitmq.Init(None, statu_ex_keys)
    g_rabbitmq.start()

    # 绑定rabbitmq
    g_rabbitmq.bind_statu_callback(statu_ex_keys[0][0], statu_ex_keys[0][1], receive.ReceivedTofData)
    g_rabbitmq.bind_statu_callback(statu_ex_keys[1][0], statu_ex_keys[1][1], receive.ReceivedLidarData)

    while True:
        message = input("input q or Q exit this progress\n")
        if message == "q" or message == "Q":
            break

    # 强制结束进程
    pid = os.getpid()
    os.kill(pid, 1)

