43 #include <sys/iofunc.h> 44 #include <sys/dispatch.h> 46 #include <sys/neutrino.h> 59 #define cfsetspeed(term, baudrate)\ 60 cfsetispeed(term, baudrate);\ 61 cfsetospeed(term, baudrate); 66 char *pmesg = strerror(errno);
67 fprintf(
stderr,
"failed to open : %s\n", pmesg);
72 res = tcgetattr(fdc, &term);
75 char *pmesg = strerror(errno);
76 fprintf(
stderr,
"failed to tcgetattr(): %s\n", pmesg);
84 char *pmesg = strerror(errno);
85 fprintf(
stderr,
"failed to cfsetspeed(): %s\n", pmesg);
90 term.c_iflag |= IGNPAR;
91 term.c_cflag |= (CLOCAL | CREAD);
92 term.c_cflag &= ~PARENB;
94 term.c_cflag &= ~CSTOPB;
97 term.c_lflag &= ~(ECHO | ECHOCTL | ECHONL);
100 term.c_iflag &= ~INPCK;
103 term.c_cc[VINTR] = 0;
104 term.c_cc[VQUIT] = 0; term.c_cc[VERASE] = 0;
105 term.c_cc[VKILL] = 0;
107 term.c_cc[VTIME] = 0;
110 term.c_cc[VSTART] = 0;
111 term.c_cc[VSTOP] = 0;
112 term.c_cc[VSUSP] = 0;
114 term.c_cc[VREPRINT] = 0;
115 term.c_cc[VDISCARD] = 0;
116 term.c_cc[VWERASE] = 0;
117 term.c_cc[VLNEXT] = 0;
118 term.c_cc[VEOL2] = 0;
120 term.c_cflag &= ~(IHFLOW | OHFLOW);
124 term.c_cc[VMIN] = 100;
125 term.c_cc[VTIME] = 0;
127 res = tcsetattr(fdc, TCSANOW, &term);
129 char *pmesg = strerror(errno);
130 fprintf(
stderr,
"failed to tcsetattr(): %s\n", pmesg);
142 #define DATA_LENGTH 27 147 n = write(fdc,
"R", 1);
149 printf(
"write data ret=%d, fd=%d\n", n, fdc);
156 printf(
"read data %d (%d)\n", n, len);
160 char *pmesg = strerror(errno);
161 fprintf(
stderr,
"failed to read data (ret=%d, fd=%d): %s (%d)\n", n,
169 fprintf(
stderr,
"%02x:", 0x0000ff & str[i]);
174 sscanf(str,
"%1d%4hx%4hx%4hx%4hx%4hx%4hx", &tick, &data[0], &data[1],
175 &data[2], &data[3], &data[4], &data[5]);
177 sprintf(str,
"%d,%05d,%05d,%05d,%05d,%05d,%05d\n", tick, data[0], data[1],
178 data[2], data[3], data[4], data[5]);
187 #define min(a, b) ((a) < (b) ? (a) : (b)) 189 int io_read(resmgr_context_t * ctp, io_read_t * msg, RESMGR_OCB_T * ocb);
190 static char *
buffer = (
char *)
"Hello world\n";
223 num = type - _IO_MAX;
229 -1.0 * (float) data_0->
filter0.
fx / (
float) data_0->full_scale.fx,
230 -1.0 * (float) data_0->filter0.fy / (
float) data_0->full_scale.fy,
231 -1.0 * (float) data_0->filter0.fz / (
float) data_0->full_scale.fz,
232 -1.0 * (float) data_0->filter0.mx / (
float) data_0->full_scale.mx * 0.1,
233 -1.0 * (float) data_0->filter0.my / (
float) data_0->full_scale.my * 0.1,
234 -1.0 * (float) data_0->filter0.mz / (
float) data_0->full_scale.mz * 0.1,
235 -1.0 * (float) data_1->filter0.fx / (
float) data_1->full_scale.fx,
236 -1.0 * (float) data_1->filter0.fy / (
float) data_1->full_scale.fy,
237 -1.0 * (float) data_1->filter0.fz / (
float) data_1->full_scale.fz,
238 -1.0 * (float) data_1->filter0.mx / (
float) data_1->full_scale.mx * 0.1,
239 -1.0 * (float) data_1->filter0.my / (
float) data_1->full_scale.my * 0.1,
240 -1.0 * (float) data_1->filter0.mz / (
float) data_1->full_scale.mz * 0.1
255 memcpy(msg_reply, tmp,
sizeof(
float) * 12);
261 data_0->offsets.fx += data_0->filter0.fx;
262 data_0->offsets.fy += data_0->filter0.fy;
263 data_0->offsets.fz += data_0->filter0.fz;
264 data_0->offsets.mx += data_0->filter0.mx;
265 data_0->offsets.my += data_0->filter0.my;
266 data_0->offsets.mz += data_0->filter0.mz;
267 data_1->offsets.fx += data_1->filter0.fx;
268 data_1->offsets.fy += data_1->filter0.fy;
269 data_1->offsets.fz += data_1->filter0.fz;
270 data_1->offsets.mx += data_1->filter0.mx;
271 data_1->offsets.my += data_1->filter0.my;
272 data_1->offsets.mz += data_1->filter0.mz;
286 MsgReply(ctp->rcvid, EOK, msg_reply, 255);
290 int main(
int argc,
char **argv) {
291 resmgr_attr_t resmgr_attr;
292 message_attr_t message_attr;
294 dispatch_context_t *ctp, *ctp_ret;
295 int resmgr_id, message_id;
299 fd1 = open(
"/dev/serusb1", O_RDWR | O_NOCTTY | O_NONBLOCK);
301 fprintf(
stderr,
"could not open /dev/serusb1\n");
303 fd2 = open(
"/dev/serusb2", O_RDWR | O_NOCTTY | O_NONBLOCK);
305 fprintf(
stderr,
"could not open /dev/serusb2\n");
308 slogf(0, _SLOG_INFO,
"Started fd1 = %d, fd2 = %d\n", fd1, fd2);
314 dpp = dispatch_create();
316 fprintf(
stderr,
"dispatch_create() failed: %s\n", strerror(errno));
320 memset(&resmgr_attr, 0,
sizeof(resmgr_attr));
321 resmgr_attr.nparts_max = 1;
322 resmgr_attr.msg_max_size = 2048;
325 iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &
ConnectFuncs, _RESMGR_IO_NFUNCS,
331 iofunc_attr_init(&
IoFuncAttr, S_IFNAM | 0666, 0, 0);
334 resmgr_id = resmgr_attach(dpp, &resmgr_attr,
"/dev/jr3q", _FTYPE_ANY, 0,
336 if (resmgr_id == -1) {
337 fprintf(
stderr,
"resmgr_attach() failed: %s\n", strerror(errno));
344 memset(&message_attr, 0,
sizeof(message_attr));
345 message_attr.nparts_max = 1;
346 message_attr.msg_max_size = 4096;
349 message_id = message_attach(dpp, &message_attr, _IO_MAX + 1, _IO_MAX + 10,
351 if (message_id == -1) {
352 fprintf(
stderr,
"message_attach() failed: %s\n", strerror(errno));
357 ctp = dispatch_context_alloc(dpp);
359 fprintf(
stderr,
"dispatch_context_alloc() failed: %s\n",
370 printf(
"dispatch\n");
372 ctp_ret = dispatch_block(ctp);
374 dispatch_handler(ctp);
376 fprintf(
stderr,
"dispatch_block() failed: %s\n", strerror(errno));
384 int io_read(resmgr_context_t * ctp, io_read_t * msg, RESMGR_OCB_T * ocb) {
390 if ((status = iofunc_read_verify(ctp, msg, ocb, NULL)) != EOK)
393 if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
403 nleft = ocb->attr->nbytes - ocb->offset;
404 nbytes =
min(msg->i.nbytes, nleft);
408 SETIOV(ctp->iov,
buffer + ocb->offset, nbytes);
411 _IO_SET_READ_NBYTES(ctp, nbytes);
418 ocb->offset += nbytes;
425 _IO_SET_READ_NBYTES(ctp, 0);
431 if (msg->i.nbytes > 0)
432 ocb->attr->flags |= IOFUNC_ATTR_ATIME;
434 return (_RESMGR_NPARTS(nparts));
439 struct timeval tv, tv1;
444 gettimeofday(&tv, NULL);
445 }
while (tv.tv_sec - tv1.tv_sec < 3);
unsigned short force_sensor_data_0[6]
static iofunc_attr_t IoFuncAttr
int message_callback(message_context_t *ctp, int type, unsigned flags, void *handle)
unsigned short force_sensor_data_1[6]
static resmgr_io_funcs_t IoFuncs
int gettimeofday(struct timeval *tv, struct timezone *tz)
#define cfsetspeed(term, baudrate)
int ReadCom(int fdc, unsigned short *data)
static resmgr_connect_funcs_t ConnectFuncs
int io_read(resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb)
std::string sprintf(char const *__restrict fmt,...)
volatile uint32_t Jr3BaseAddress0H
void get_force_sensor_info(force_sensor_data *data, char *msg)
int main(int argc, char **argv)
volatile uint32_t Jr3BaseAddress1H