//
// Created by zx on 2020/1/16.
//

#include <nnxx/message.h>
#include <nnxx/message_control.h>
#include <nnxx/socket.h>
#include <nnxx/pubsub.h>
#include <nnxx/timeout.h>
#include <nnxx/error.h>
#include <iostream>
#include "../wj_lidar/wj_lidar_msg.pb.h"
#include <thread>

int main()
{
    nnxx::socket s{nnxx::SP,nnxx::SUB};
    s.connect("tcp://127.0.0.1:10080");
    nnxx::subscribe(s);
    std::string message;
    while(true)
    {
        message=s.recv<std::string>(0);
        if(message.length()>0)
        {
            wj_lidar_message::Fence_statu_message fence_statu;
            if(fence_statu.ParseFromString(message))
            {
                if(fence_statu.fence_statu_size()==0)
                {
                    std::this_thread::yield();
                    continue;
                }
                char buf[255] = {0};
                sprintf(buf, " terminal status: -----------------------------------------\n");
                for (int i = 0; i < fence_statu.fence_statu_size(); ++i) {
                    sprintf(buf+strlen(buf), "%d: [%d, %d]   %s\n", fence_statu.fence_statu(i).terminal_id(), fence_statu.fence_statu(i).cloud_statu(),
                            fence_statu.fence_statu(i).position_statu(), fence_statu.fence_statu(i).has_error_info()?fence_statu.fence_statu(i).error_info().c_str():"");
                }
                std::cout << buf << std::endl;
            }
        }
    }

}
