Go to the documentation of this file.00001
00020 #ifndef _hardware_UseAX10420_h_
00021 #define _hardware_UseAX10420_h_
00022
00023 #include "AX10420_types.h"
00024 #include <sys/types.h>
00025 #include <sys/stat.h>
00026 #include <fcntl.h>
00027 #include <unistd.h>
00028 #include <string.h>
00029
00036 inline int AX10420_OpenDevice(const char *device_name)
00037 {
00038 int fd;
00039 fd = open(device_name, O_RDWR);
00040 if (fd < 0)
00041 {
00042 ROS_ERROR("error opening the ax10420 device: %s\n",strerror(errno));
00043 return -1;
00044 }
00045
00046 return fd;
00047 };
00048
00056 inline int AX10420_Init(int fd, tAXGroup group,
00057 tAXIOConfigure port_a, tAXIOConfigure port_b,
00058 tAXIOConfigure port_c_upper, tAXIOConfigure port_c_lower)
00059 {
00060 int len;
00061 if (fd < 0)
00062 {
00063 ROS_ERROR("AX10420_Init invalid fd:%x\n",fd);
00064 return -1;
00065 }
00066
00067 AX10420_msg_init init;
00068 init.group = group;
00069 init.port_a = port_a;
00070 init.port_b = port_a;
00071 init.port_c_upper = port_c_upper;
00072 init.port_c_lower = port_c_lower;
00073
00074 AX10420_msg msg;
00075 msg.type = tInit;
00076 msg.msginit = init;
00077
00078 len = write(fd, &msg, sizeof(AX10420_msg));
00079
00080 if (len>0)
00081 {
00082 return 0;
00083 }
00084 else
00085 {
00086 ROS_ERROR("AX10420_Init write failed: %s\n",strerror(errno));
00087 return -errno;
00088 }
00089
00090 return -1;
00091 }
00092
00100 inline int AX10420_GetInput(int fd, tAXGroup group, tAXPort port)
00101 {
00102 int len;
00103 if (fd < 0)
00104 {
00105 ROS_ERROR("AX10420_GetInput invalid fd:%x\n",fd);
00106 return -1;
00107 }
00108
00109 AX10420_msg_state state;
00110 len = read(fd, &state, sizeof(AX10420_msg_state));
00111
00112 if (len > 0)
00113 {
00114 switch (group)
00115 {
00116 case eG1:
00117 switch (port)
00118 {
00119 case ePA:
00120 return state.port1_a;
00121 break;
00122 case ePB:
00123 return state.port1_b;
00124 break;
00125 case ePC:
00126 return state.port1_c;
00127 break;
00128 default:
00129 return -1;
00130 break;
00131 };
00132 break;
00133 case eG2:
00134 switch (port)
00135 {
00136 case ePA:
00137 return state.port2_a;
00138 break;
00139 case ePB:
00140 return state.port2_b;
00141 break;
00142 case ePC:
00143 return state.port2_c;
00144 break;
00145 default:
00146 return -1;
00147 break;
00148 };
00149 break;
00150 default:
00151 return -1;
00152 break;
00153 }
00154 }
00155 else
00156 {
00157 ROS_ERROR("AX10420_GetInput read failed: %s\n",strerror(errno));
00158 return -errno;
00159 }
00160
00161 return -1;
00162 }
00163
00172 inline int AX10420_SetOutput(int fd, tAXGroup group, tAXPort port, unsigned value)
00173 {
00174 int len;
00175 if (fd < 0)
00176 {
00177 ROS_ERROR("AX10420_SetOutput invalid fd:%x\n",fd);
00178 return -1;
00179 }
00180
00181 AX10420_msg_setOutput set;
00182 set.group = group;
00183 set.port = port;
00184 set.value = value;
00185
00186 AX10420_msg msg;
00187 msg.type = tSetOutput;
00188 msg.msgsetoutput = set;
00189
00190 len = write(fd, &msg, sizeof(AX10420_msg));
00191
00192 if (len>0)
00193 {
00194 return 0;
00195 }
00196 else
00197 {
00198 ROS_ERROR("AX10420_SetOutput write failed: %s\n",strerror(errno));
00199 return -errno;
00200 }
00201
00202 return -1;
00203
00204 }
00205
00206 #endif
asr_mild_base_driving
Author(s): Aumann Florian, Borella Jocelyn, Dehmani Souheil, Marek Felix, Meißner Pascal, Reckling Reno
autogenerated on Thu Jun 6 2019 22:02:58