example1_report_norm.cc
Go to the documentation of this file.
1 /* Copyright 2017 UFACTORY Inc. All Rights Reserved.
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Author: Jimy Zhang <jimy92@163.com>
6  ============================================================================*/\
7 #ifndef WIN32
8 #include <unistd.h>
9 #endif
10 
11 #include "ros/ros.h"
12 #include "xarm/core/connect.h"
13 #include "xarm/core/report_data.h"
14 
15 int main(int argc, char **argv) {
16  if (argc < 2) {
17  printf("Please enter IP address\n");
18  return 0;
19  }
20  char *server_ip = argv[1];
21  SocketPort *arm_report = connext_tcp_report_norm(server_ip);
22  if (arm_report == NULL) return 0;
23 
24  int rxcnt = 0;
25  ReportDataNorm *norm_data = new ReportDataNorm();
26 
27  unsigned char rx_data[1280];
28  int ret;
29  int err_num = 0;
30  while (1) {
31  ros::Duration(0.001).sleep(); //1ms
32 
33  ret = arm_report->read_frame(rx_data);
34  if (ret != 0) continue;
35  ret = norm_data->flush_data(rx_data);
36 
37  if (ret == 0) {
38  rxcnt++;
39  printf("\n【normal report】: len = %d, rxcnt = %d, err_num = %d\n",
40  bin8_to_32(rx_data), rxcnt, err_num);
41  norm_data->print_data();
42  } else {
43  printf("Error: norm_data.flush_data failed, ret = %d\n", ret);
44  err_num++;
45  }
46  }
47 }
#define connext_tcp_report_norm
Definition: connect.h:20
int flush_data(unsigned char *rx_data)
Definition: report_data.cc:76
bool sleep() const
int read_frame(unsigned char *data)
Definition: socket.cc:122
int bin8_to_32(unsigned char *a)
Definition: data_type.h:38
int main(int argc, char **argv)
void print_data(void)
Definition: report_data.cc:113


xarm_api
Author(s):
autogenerated on Sat May 8 2021 02:51:23