plc_s7.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Created by zx on 2020/1/16.
  3. //
  4. #include <nnxx/message.h>
  5. #include <nnxx/message_control.h>
  6. #include <nnxx/socket.h>
  7. #include <nnxx/pubsub.h>
  8. #include <nnxx/timeout.h>
  9. #include <nnxx/error.h>
  10. #include <iostream>
  11. #include "../wj_lidar/wj_lidar_msg.pb.h"
  12. #include <thread>
  13. int main()
  14. {
  15. nnxx::socket s{nnxx::SP,nnxx::SUB};
  16. s.connect("tcp://127.0.0.1:10080");
  17. nnxx::subscribe(s);
  18. std::string message;
  19. while(true)
  20. {
  21. message=s.recv<std::string>(0);
  22. if(message.length()>0)
  23. {
  24. wj_lidar_message::Fence_statu_message fence_statu;
  25. if(fence_statu.ParseFromString(message))
  26. {
  27. if(fence_statu.fence_statu_size()==0)
  28. {
  29. std::this_thread::yield();
  30. continue;
  31. }
  32. char buf[255] = {0};
  33. sprintf(buf, " terminal status: ");
  34. for (int i = 0; i < fence_statu.fence_statu_size(); ++i) {
  35. sprintf(buf+strlen(buf), "[%d, %d] ", fence_statu.fence_statu(i).cloud_statu(),
  36. fence_statu.fence_statu(i).position_statu());
  37. }
  38. std::cout << buf << std::endl;
  39. }
  40. }
  41. }
  42. }